From 25d236cbf97b2f87bc8506484fb5c14727cbf849 Mon Sep 17 00:00:00 2001 From: jinhojang6 Date: Thu, 23 Feb 2023 21:30:21 +0900 Subject: [PATCH] refactor: pass down childeren for card component --- .../components/CSSBaseline/CSSBaseline.tsx | 2 - .../src/components/Card/Card.classes.ts | 3 +- .../src/components/Card/Card.context.ts | 10 +++++ .../src/components/Card/Card.stories.tsx | 20 ++++++++-- .../src/components/Card/Card.styles.ts | 14 ++----- .../lsd-react/src/components/Card/Card.tsx | 29 +++------------ .../CardHeader/CardHeader.classes.ts | 7 ---- .../CardHeader/CardHeader.stories.tsx | 26 ------------- .../CardHeader/CardHeader.styles.ts | 30 --------------- .../src/components/CardHeader/CardHeader.tsx | 37 ------------------- .../src/components/CardHeader/index.ts | 1 - packages/lsd-react/src/index.ts | 1 - 12 files changed, 36 insertions(+), 144 deletions(-) create mode 100644 packages/lsd-react/src/components/Card/Card.context.ts delete mode 100644 packages/lsd-react/src/components/CardHeader/CardHeader.classes.ts delete mode 100644 packages/lsd-react/src/components/CardHeader/CardHeader.stories.tsx delete mode 100644 packages/lsd-react/src/components/CardHeader/CardHeader.styles.ts delete mode 100644 packages/lsd-react/src/components/CardHeader/CardHeader.tsx delete mode 100644 packages/lsd-react/src/components/CardHeader/index.ts diff --git a/packages/lsd-react/src/components/CSSBaseline/CSSBaseline.tsx b/packages/lsd-react/src/components/CSSBaseline/CSSBaseline.tsx index 227df62..14c3dc4 100644 --- a/packages/lsd-react/src/components/CSSBaseline/CSSBaseline.tsx +++ b/packages/lsd-react/src/components/CSSBaseline/CSSBaseline.tsx @@ -13,7 +13,6 @@ import { BreadcrumbItemStyles } from '../BreadcrumbItem/BreadcrumbItem.styles' import { defaultThemes, Theme, withTheme } from '../Theme' import { TypographyStyles } from '../Typography/Typography.styles' import { CardStyles } from '../Card/Card.styles' -import { CardHeaderStyles } from '../CardHeader/CardHeader.styles' const componentStyles: Array | SerializedStyles> = [ @@ -28,7 +27,6 @@ const componentStyles: Array | SerializedStyles> = IconTagStyles, BreadcrumbStyles, BreadcrumbItemStyles, - CardHeaderStyles, CardStyles, ] diff --git a/packages/lsd-react/src/components/Card/Card.classes.ts b/packages/lsd-react/src/components/Card/Card.classes.ts index 83ce738..84121cb 100644 --- a/packages/lsd-react/src/components/Card/Card.classes.ts +++ b/packages/lsd-react/src/components/Card/Card.classes.ts @@ -1,8 +1,7 @@ export const cardClasses = { root: `lsd-card`, - text: `lsd-card__text`, + body: `lsd-card-body`, - withHeader: 'lsd-card--with-header', 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 index 55545ef..d50c66c 100644 --- a/packages/lsd-react/src/components/Card/Card.stories.tsx +++ b/packages/lsd-react/src/components/Card/Card.stories.tsx @@ -16,13 +16,25 @@ export default { export const Root: Story = (args) => (
- + +
+ Title +
+
+ A wise man can learn more from a foolish question than a fool can learn + from a wise answer. +
+
) Root.args = { size: 'large', - label: 'Title', - text: 'A wise man can learn more from a foolish question than a fool can learn from a wise answer.', - withHeader: false, } diff --git a/packages/lsd-react/src/components/Card/Card.styles.ts b/packages/lsd-react/src/components/Card/Card.styles.ts index c7c6b7b..05bc3b5 100644 --- a/packages/lsd-react/src/components/Card/Card.styles.ts +++ b/packages/lsd-react/src/components/Card/Card.styles.ts @@ -7,26 +7,18 @@ export const CardStyles = css` background: none; border: 1px solid rgb(var(--lsd-border-primary)); word-break: keep-all; - padding: 8px 16px; box-sizing: border-box; } + .${cardClasses.body} { + } + .${cardClasses.large} { - width: 600px; - padding: 10px 18px; } .${cardClasses.medium} { - width: 540px; - padding: 6px 14px; } .${cardClasses.small} { - width: 480px; - padding: 6px 12px; - } - - .${cardClasses.withHeader} { - border-top: 1px solid transparent; } ` diff --git a/packages/lsd-react/src/components/Card/Card.tsx b/packages/lsd-react/src/components/Card/Card.tsx index f0da8f4..9a1b830 100644 --- a/packages/lsd-react/src/components/Card/Card.tsx +++ b/packages/lsd-react/src/components/Card/Card.tsx @@ -1,41 +1,24 @@ import clsx from 'clsx' import React from 'react' -import { CardHeader } from '../CardHeader' -import { Typography } from '../Typography' import { cardClasses } from './Card.classes' +import { CardContext } from './Card.context' export type CardProps = Omit, 'label'> & { size?: 'small' | 'medium' | 'large' - label?: string - text: string - withHeader?: boolean } export const Card: React.FC & { classes: typeof cardClasses -} = ({ label = '', size = 'large', text, withHeader = false, ...props }) => { +} = ({ size = 'large', children, ...props }) => { return ( -
- {withHeader && } +
- - {text} - + {children}
-
+ ) } diff --git a/packages/lsd-react/src/components/CardHeader/CardHeader.classes.ts b/packages/lsd-react/src/components/CardHeader/CardHeader.classes.ts deleted file mode 100644 index 8d0d7d1..0000000 --- a/packages/lsd-react/src/components/CardHeader/CardHeader.classes.ts +++ /dev/null @@ -1,7 +0,0 @@ -export const cardHeaderClasses = { - root: `lsd-card-header`, - - 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 deleted file mode 100644 index 0fbabd9..0000000 --- a/packages/lsd-react/src/components/CardHeader/CardHeader.stories.tsx +++ /dev/null @@ -1,26 +0,0 @@ -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 = (args) => ( -
- -
-) - -Root.args = { - size: 'large', - label: 'Title', -} diff --git a/packages/lsd-react/src/components/CardHeader/CardHeader.styles.ts b/packages/lsd-react/src/components/CardHeader/CardHeader.styles.ts deleted file mode 100644 index 8c634af..0000000 --- a/packages/lsd-react/src/components/CardHeader/CardHeader.styles.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { css } from '@emotion/react' -import { cardHeaderClasses } from './CardHeader.classes' - -export const CardHeaderStyles = css` - .${cardHeaderClasses.root} { - box-sizing: border-box; - border: 1px solid rgb(var(--lsd-border-primary)); - text-align: center; - display: flex; - justify-content: center; - } - - .${cardHeaderClasses.large} { - width: 600px; - min-height: 40px; - padding: 10px 18px; - } - - .${cardHeaderClasses.medium} { - width: 540px; - min-height: 32px; - padding: 6px 14px; - } - - .${cardHeaderClasses.small} { - width: 480px; - min-height: 28px; - padding: 6px 12px; - } -` diff --git a/packages/lsd-react/src/components/CardHeader/CardHeader.tsx b/packages/lsd-react/src/components/CardHeader/CardHeader.tsx deleted file mode 100644 index d28b1ff..0000000 --- a/packages/lsd-react/src/components/CardHeader/CardHeader.tsx +++ /dev/null @@ -1,37 +0,0 @@ -import clsx from 'clsx' -import React from 'react' -import { Typography } from '../Typography' -import { cardHeaderClasses } from './CardHeader.classes' - -export type CardHeaderProps = Omit< - React.HTMLAttributes, - 'label' -> & { - label: string - size?: 'small' | 'medium' | 'large' -} - -export const CardHeader: React.FC & { - classes: typeof cardHeaderClasses -} = ({ label, size = 'large', ...props }) => { - return ( -
- - {label} - -
- ) -} - -CardHeader.classes = cardHeaderClasses diff --git a/packages/lsd-react/src/components/CardHeader/index.ts b/packages/lsd-react/src/components/CardHeader/index.ts deleted file mode 100644 index f953341..0000000 --- a/packages/lsd-react/src/components/CardHeader/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './CardHeader' diff --git a/packages/lsd-react/src/index.ts b/packages/lsd-react/src/index.ts index e5ff4da..20e1306 100644 --- a/packages/lsd-react/src/index.ts +++ b/packages/lsd-react/src/index.ts @@ -10,4 +10,3 @@ export * from './components/Theme' export * from './components/Breadcrumb' export * from './components/BreadcrumbItem' export * from './components/Card' -export * from './components/CardHeader'