Skip to content

Commit

Permalink
feat: implement card component
Browse files Browse the repository at this point in the history
  • Loading branch information
jinhojang6 committed Feb 20, 2023
1 parent 5a3928f commit a60ca2b
Show file tree
Hide file tree
Showing 11 changed files with 217 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/lsd-react/src/components/CSSBaseline/CSSBaseline.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { BreadcrumbStyles } from '../Breadcrumb/Breadcrumb.styles'
import { BreadcrumbItemStyles } from '../BreadcrumbItem/BreadcrumbItem.styles'
import { defaultThemes, Theme, withTheme } from '../Theme'
import { TypographyStyles } from '../Typography/Typography.styles'
import { CardItemStyles } from '../CardItem/Cardtem.styles'
import { CardStyles } from '../Card/Card.styles'

const componentStyles: Array<ReturnType<typeof withTheme> | SerializedStyles> =
[
Expand All @@ -26,6 +28,8 @@ const componentStyles: Array<ReturnType<typeof withTheme> | SerializedStyles> =
IconTagStyles,
BreadcrumbStyles,
BreadcrumbItemStyles,
CardItemStyles,
CardStyles,
]

export const CSSBaseline: React.FC<{ theme?: Theme }> = ({
Expand Down
9 changes: 9 additions & 0 deletions packages/lsd-react/src/components/Card/Card.classes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export const cardClasses = {
root: `lsd-card`,
text: `lsd-card__text`,

withHeader: 'lsd-card--with-header',
small: 'lsd-card--small',
medium: 'lsd-card--medium',
large: 'lsd-card--large',
}
28 changes: 28 additions & 0 deletions packages/lsd-react/src/components/Card/Card.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Meta, Story } from '@storybook/react'
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> = (args) => (
<div style={{ width: 'fit-content' }}>
<Card {...args}></Card>
</div>
)

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,
}
32 changes: 32 additions & 0 deletions packages/lsd-react/src/components/Card/Card.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { css } from '@emotion/react'
import { cardClasses } from './Card.classes'

export const CardStyles = css`
.${cardClasses.root} {
color: rgb(var(--lsd-text-primary));
background: none;
border: 1px solid rgb(var(--lsd-border-primary));
word-break: keep-all;
padding: 8px 16px;
box-sizing: border-box;
}
.${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;
}
`
42 changes: 42 additions & 0 deletions packages/lsd-react/src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import clsx from 'clsx'
import React from 'react'
import { CardItem } from '../CardItem'
import { Typography } from '../Typography'
import { cardClasses } from './Card.classes'

export type CardProps = Omit<React.HTMLAttributes<HTMLDivElement>, 'label'> & {
size?: 'small' | 'medium' | 'large'
label?: string
text: string
withHeader?: boolean
}

export const Card: React.FC<CardProps> & {
classes: typeof cardClasses
} = ({ label = '', size = 'large', text, withHeader = false, ...props }) => {
return (
<>
{withHeader && <CardItem label={label} size={size} />}
<div
{...props}
className={clsx(
props.className,
cardClasses.root,
cardClasses[size],
withHeader && cardClasses.withHeader,
)}
>
<Typography
color="primary"
component="label"
variant={size === 'small' ? 'label2' : 'label1'}
className={cardClasses.text}
>
{text}
</Typography>
</div>
</>
)
}

Card.classes = cardClasses
1 change: 1 addition & 0 deletions packages/lsd-react/src/components/Card/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Card'
7 changes: 7 additions & 0 deletions packages/lsd-react/src/components/CardItem/Cardtem.classes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const cardItemClasses = {
root: `lsd-card-item`,

small: `lsd-card-item--small`,
medium: `lsd-card-item--medium`,
large: `lsd-card-item--large`,
}
26 changes: 26 additions & 0 deletions packages/lsd-react/src/components/CardItem/Cardtem.stories.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Meta, Story } from '@storybook/react'
import { CardItem, CardItemProps } from './Cardtem'

export default {
title: 'CardItem',
component: CardItem,
argTypes: {
size: {
type: {
name: 'enum',
value: ['small', 'medium', 'large'],
},
},
},
} as Meta

export const Root: Story<CardItemProps> = (args) => (
<div style={{ width: 'fit-content' }}>
<CardItem {...args}></CardItem>
</div>
)

Root.args = {
size: 'large',
label: 'Title',
}
30 changes: 30 additions & 0 deletions packages/lsd-react/src/components/CardItem/Cardtem.styles.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { css } from '@emotion/react'
import { cardItemClasses } from './Cardtem.classes'

export const CardItemStyles = css`
.${cardItemClasses.root} {
box-sizing: border-box;
border: 1px solid rgb(var(--lsd-border-primary));
text-align: center;
display: flex;
justify-content: center;
}
.${cardItemClasses.large} {
width: 600px;
min-height: 40px;
padding: 10px 18px;
}
.${cardItemClasses.medium} {
width: 540px;
min-height: 32px;
padding: 6px 14px;
}
.${cardItemClasses.small} {
width: 480px;
min-height: 28px;
padding: 6px 12px;
}
`
37 changes: 37 additions & 0 deletions packages/lsd-react/src/components/CardItem/Cardtem.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import clsx from 'clsx'
import React from 'react'
import { Typography } from '../Typography'
import { cardItemClasses } from './Cardtem.classes'

export type CardItemProps = Omit<
React.HTMLAttributes<HTMLDivElement>,
'label'
> & {
label: string
size?: 'small' | 'medium' | 'large'
}

export const CardItem: React.FC<CardItemProps> & {
classes: typeof cardItemClasses
} = ({ label, size = 'large', ...props }) => {
return (
<div
{...props}
className={clsx(
props.className,
cardItemClasses.root,
cardItemClasses[size],
)}
>
<Typography
color="primary"
component="label"
variant={size === 'small' ? 'label2' : 'label1'}
>
{label}
</Typography>
</div>
)
}

CardItem.classes = cardItemClasses
1 change: 1 addition & 0 deletions packages/lsd-react/src/components/CardItem/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './Cardtem'

0 comments on commit a60ca2b

Please sign in to comment.