diff --git a/packages/lsd-react/src/components/CSSBaseline/CSSBaseline.tsx b/packages/lsd-react/src/components/CSSBaseline/CSSBaseline.tsx index 6245707..f36c9e3 100644 --- a/packages/lsd-react/src/components/CSSBaseline/CSSBaseline.tsx +++ b/packages/lsd-react/src/components/CSSBaseline/CSSBaseline.tsx @@ -4,6 +4,9 @@ import { AutocompleteStyles } from '../Autocomplete/Autocomplete.styles' import { BreadcrumbStyles } from '../Breadcrumb/Breadcrumb.styles' import { BreadcrumbItemStyles } from '../BreadcrumbItem/BreadcrumbItem.styles' import { ButtonStyles } from '../Button/Button.styles' +import { CardStyles } from '../Card/Card.styles' +import { CardBodyStyles } from '../CardBody/CardBody.styles' +import { CardHeaderStyles } from '../CardHeader/CardHeader.styles' import { CollapseStyles } from '../Collapse/Collapse.styles' import { CollapseHeaderStyles } from '../CollapseHeader/CollapseHeader.styles' import { DropdownStyles } from '../Dropdown/Dropdown.styles' @@ -32,6 +35,9 @@ const componentStyles: Array | SerializedStyles> = DropdownItemStyles, BreadcrumbStyles, BreadcrumbItemStyles, + CardStyles, + CardHeaderStyles, + CardBodyStyles, TagStyles, TextFieldStyles, AutocompleteStyles, diff --git a/packages/lsd-react/src/components/Card/Card.classes.ts b/packages/lsd-react/src/components/Card/Card.classes.ts new file mode 100644 index 0000000..a29dadb --- /dev/null +++ b/packages/lsd-react/src/components/Card/Card.classes.ts @@ -0,0 +1,7 @@ +export const cardClasses = { + root: `lsd-card`, + + small: 'lsd-card--small', + medium: 'lsd-card--medium', + large: 'lsd-card--large', +} diff --git a/packages/lsd-react/src/components/Card/Card.context.ts b/packages/lsd-react/src/components/Card/Card.context.ts new file mode 100644 index 0000000..7156aec --- /dev/null +++ b/packages/lsd-react/src/components/Card/Card.context.ts @@ -0,0 +1,10 @@ +import React from 'react' +import { CardProps } from './Card' + +export type CardContextType = { + size?: CardProps['size'] +} + +export const CardContext = React.createContext(null as any) + +export const useCardContext = () => React.useContext(CardContext) diff --git a/packages/lsd-react/src/components/Card/Card.stories.tsx b/packages/lsd-react/src/components/Card/Card.stories.tsx new file mode 100644 index 0000000..af381c9 --- /dev/null +++ b/packages/lsd-react/src/components/Card/Card.stories.tsx @@ -0,0 +1,37 @@ +import { Meta, Story } from '@storybook/react' +import { CardBody } from '../CardBody' +import { CardHeader } from '../CardHeader' +import { Card, CardProps } from './Card' + +export default { + title: 'Card', + component: Card, + argTypes: { + size: { + type: { + name: 'enum', + value: ['small', 'medium', 'large'], + }, + }, + }, +} as Meta + +export const Root: Story< + CardProps & { + body: string + title: string + } +> = ({ title, body, ...args }) => ( +
+ + {title} + {body} + +
+) + +Root.args = { + size: 'large', + title: 'Title', + body: 'A wise man can learn more from a foolish question than a fool can learn from a wise answer.', +} diff --git a/packages/lsd-react/src/components/Card/Card.styles.ts b/packages/lsd-react/src/components/Card/Card.styles.ts new file mode 100644 index 0000000..ecdd610 --- /dev/null +++ b/packages/lsd-react/src/components/Card/Card.styles.ts @@ -0,0 +1,24 @@ +import { css } from '@emotion/react' +import { cardHeaderClasses } from '../CardHeader/CardHeader.classes' +import { cardClasses } from './Card.classes' + +export const CardStyles = css` + .${cardClasses.root} { + box-sizing: border-box; + display: flex; + flex-direction: column; + } + + .${cardClasses.root} > .${cardHeaderClasses.root} { + margin-bottom: -1px; + } + + .${cardClasses.large} { + } + + .${cardClasses.medium} { + } + + .${cardClasses.small} { + } +` diff --git a/packages/lsd-react/src/components/Card/Card.tsx b/packages/lsd-react/src/components/Card/Card.tsx new file mode 100644 index 0000000..c09660c --- /dev/null +++ b/packages/lsd-react/src/components/Card/Card.tsx @@ -0,0 +1,22 @@ +import clsx from 'clsx' +import React from 'react' +import { cardClasses } from './Card.classes' +import { CardContext } from './Card.context' + +export type CardProps = Omit, 'label'> & { + size?: 'small' | 'medium' | 'large' +} + +export const Card: React.FC & { + classes: typeof cardClasses +} = ({ size = 'large', children, ...props }) => { + return ( + +
+ {children} +
+
+ ) +} + +Card.classes = cardClasses diff --git a/packages/lsd-react/src/components/Card/index.ts b/packages/lsd-react/src/components/Card/index.ts new file mode 100644 index 0000000..067a7c2 --- /dev/null +++ b/packages/lsd-react/src/components/Card/index.ts @@ -0,0 +1 @@ +export * from './Card' diff --git a/packages/lsd-react/src/components/CardBody/CardBody.classes.ts b/packages/lsd-react/src/components/CardBody/CardBody.classes.ts new file mode 100644 index 0000000..3260adc --- /dev/null +++ b/packages/lsd-react/src/components/CardBody/CardBody.classes.ts @@ -0,0 +1,3 @@ +export const cardBodyClasses = { + root: `lsd-card-body`, +} diff --git a/packages/lsd-react/src/components/CardBody/CardBody.stories.tsx b/packages/lsd-react/src/components/CardBody/CardBody.stories.tsx new file mode 100644 index 0000000..bc4d507 --- /dev/null +++ b/packages/lsd-react/src/components/CardBody/CardBody.stories.tsx @@ -0,0 +1,28 @@ +import { Meta, Story } from '@storybook/react' +import { CardBody, CardBodyProps } from './CardBody' + +export default { + title: 'CardBody', + component: CardBody, + argTypes: { + size: { + type: { + name: 'enum', + value: ['small', 'medium', 'large'], + }, + }, + }, +} as Meta + +export const Root: Story = ({ + body, + ...args +}) => ( +
+ {body} +
+) + +Root.args = { + body: 'A wise man can learn more from a foolish question than a fool can learn from a wise answer.', +} diff --git a/packages/lsd-react/src/components/CardBody/CardBody.styles.ts b/packages/lsd-react/src/components/CardBody/CardBody.styles.ts new file mode 100644 index 0000000..1797bb8 --- /dev/null +++ b/packages/lsd-react/src/components/CardBody/CardBody.styles.ts @@ -0,0 +1,10 @@ +import { css } from '@emotion/react' +import { cardBodyClasses } from './CardBody.classes' + +export const CardBodyStyles = css` + .${cardBodyClasses.root} { + box-sizing: border-box; + padding: 14px 22px; + border: 1px solid rgb(var(--lsd-border-primary)); + } +` diff --git a/packages/lsd-react/src/components/CardBody/CardBody.tsx b/packages/lsd-react/src/components/CardBody/CardBody.tsx new file mode 100644 index 0000000..a81bb16 --- /dev/null +++ b/packages/lsd-react/src/components/CardBody/CardBody.tsx @@ -0,0 +1,20 @@ +import clsx from 'clsx' +import React from 'react' +import { cardBodyClasses } from './CardBody.classes' + +export type CardBodyProps = Omit< + React.HTMLAttributes, + 'label' +> & {} + +export const CardBody: React.FC & { + classes: typeof cardBodyClasses +} = ({ children, ...props }) => { + return ( +
+ {children} +
+ ) +} + +CardBody.classes = cardBodyClasses diff --git a/packages/lsd-react/src/components/CardBody/index.ts b/packages/lsd-react/src/components/CardBody/index.ts new file mode 100644 index 0000000..b81eecf --- /dev/null +++ b/packages/lsd-react/src/components/CardBody/index.ts @@ -0,0 +1 @@ +export * from './CardBody' diff --git a/packages/lsd-react/src/components/CardHeader/CardHeader.classes.ts b/packages/lsd-react/src/components/CardHeader/CardHeader.classes.ts new file mode 100644 index 0000000..5a72363 --- /dev/null +++ b/packages/lsd-react/src/components/CardHeader/CardHeader.classes.ts @@ -0,0 +1,8 @@ +export const cardHeaderClasses = { + root: `lsd-card-header`, + title: `lsd-card-header__title`, + + small: `lsd-card-header--small`, + medium: `lsd-card-header--medium`, + large: `lsd-card-header--large`, +} diff --git a/packages/lsd-react/src/components/CardHeader/CardHeader.stories.tsx b/packages/lsd-react/src/components/CardHeader/CardHeader.stories.tsx new file mode 100644 index 0000000..cec8717 --- /dev/null +++ b/packages/lsd-react/src/components/CardHeader/CardHeader.stories.tsx @@ -0,0 +1,29 @@ +import { Meta, Story } from '@storybook/react' +import { CardHeader, CardHeaderProps } from './CardHeader' + +export default { + title: 'CardHeader', + component: CardHeader, + argTypes: { + size: { + type: { + name: 'enum', + value: ['small', 'medium', 'large'], + }, + }, + }, +} as Meta + +export const Root: Story = ({ + title, + ...args +}) => ( +
+ {title} +
+) + +Root.args = { + size: 'large', + title: 'Title', +} diff --git a/packages/lsd-react/src/components/CardHeader/CardHeader.styles.ts b/packages/lsd-react/src/components/CardHeader/CardHeader.styles.ts new file mode 100644 index 0000000..64bf783 --- /dev/null +++ b/packages/lsd-react/src/components/CardHeader/CardHeader.styles.ts @@ -0,0 +1,28 @@ +import { css } from '@emotion/react' +import { cardHeaderClasses } from './CardHeader.classes' + +export const CardHeaderStyles = css` + .${cardHeaderClasses.root} { + box-sizing: border-box; + padding: 10px 18px; + text-align: center; + border: 1px solid rgb(var(--lsd-border-primary)); + } + + .${cardHeaderClasses.title} { + overflow: hidden; + word-break: break-all; + } + + .${cardHeaderClasses.large} { + padding: 10px 18px; + } + + .${cardHeaderClasses.medium} { + padding: 6px 14px; + } + + .${cardHeaderClasses.small} { + padding: 6px 12px; + } +` diff --git a/packages/lsd-react/src/components/CardHeader/CardHeader.tsx b/packages/lsd-react/src/components/CardHeader/CardHeader.tsx new file mode 100644 index 0000000..8899787 --- /dev/null +++ b/packages/lsd-react/src/components/CardHeader/CardHeader.tsx @@ -0,0 +1,40 @@ +import clsx from 'clsx' +import React from 'react' +import { useCardContext } from '../Card/Card.context' +import { Typography } from '../Typography' +import { cardHeaderClasses } from './CardHeader.classes' + +export type CardHeaderProps = Omit< + React.HTMLAttributes, + 'label' +> & { + size?: 'small' | 'medium' | 'large' +} + +export const CardHeader: React.FC & { + classes: typeof cardHeaderClasses +} = ({ size: _size = 'large', children, ...props }) => { + const sizeContext = useCardContext() + const size = sizeContext?.size ?? _size + + return ( +
+ + {children} + +
+ ) +} + +CardHeader.classes = cardHeaderClasses diff --git a/packages/lsd-react/src/components/CardHeader/index.ts b/packages/lsd-react/src/components/CardHeader/index.ts new file mode 100644 index 0000000..f953341 --- /dev/null +++ b/packages/lsd-react/src/components/CardHeader/index.ts @@ -0,0 +1 @@ +export * from './CardHeader' diff --git a/packages/lsd-react/src/index.ts b/packages/lsd-react/src/index.ts index 3e5a8ea..94a2dc2 100644 --- a/packages/lsd-react/src/index.ts +++ b/packages/lsd-react/src/index.ts @@ -2,6 +2,9 @@ export * from './components/Autocomplete' export * from './components/Breadcrumb' export * from './components/BreadcrumbItem' export * from './components/Button' +export * from './components/Card' +export * from './components/CardBody' +export * from './components/CardHeader' export * from './components/Collapse' export * from './components/CollapseHeader' export * from './components/Dropdown'