Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tech: Update Card component size variants #4732

Merged
merged 3 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 22 additions & 13 deletions packages/ui/src/components/Card/Card.css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@ import { tokens } from '../../theme'
const cardPadding = createVar()

export const cardRoot = recipe({
base: [
yStack({ gap: 'md' }),
{
position: 'relative',
borderRadius: tokens.radius.xl,
padding: cardPadding,
},
],
base: {
position: 'relative',
padding: cardPadding,
},
variants: {
variant: {
primary: {
Expand All @@ -28,17 +24,30 @@ export const cardRoot = recipe({
},

size: {
md: {
vars: {
[cardPadding]: tokens.space.lg,
md: [
yStack({ gap: 'sm' }),
{
borderRadius: tokens.radius.md,
vars: {
[cardPadding]: tokens.space.md,
},
},
},
],
lg: [
yStack({ gap: 'md' }),
{
borderRadius: tokens.radius.xl,
vars: {
[cardPadding]: tokens.space.lg,
},
},
],
},
},

defaultVariants: {
variant: 'primary',
size: 'md',
size: 'lg',
},
})

Expand Down
19 changes: 14 additions & 5 deletions packages/ui/src/components/Card/Card.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ const meta: Meta<Controls> = {
options: ['primary', 'secondary'],
control: { type: 'select' },
},
size: {
options: ['md', 'lg'],
control: { type: 'radio' },
},
},
parameters: {
design: {
Expand All @@ -35,7 +39,7 @@ type Story = StoryObj<Controls>
export const Default: Story = {
render: (args: Controls) => (
<div style={{ maxWidth: '400px' }}>
<Card.Root variant={args.variant}>
<Card.Root variant={args.variant} size={args.size}>
<Card.Aside>
<IconButton variant="secondary">
<CrossIcon />
Expand All @@ -57,13 +61,14 @@ export const Default: Story = {
),
args: {
variant: 'primary',
size: 'lg',
},
}

export const WithBadge: Story = {
render: (args: Controls) => (
<div style={{ maxWidth: '400px' }}>
<Card.Root variant={args.variant}>
<Card.Root variant={args.variant} size={args.size}>
<Card.Aside>
<Badge color="green50">20%</Badge>
</Card.Aside>
Expand All @@ -83,13 +88,14 @@ export const WithBadge: Story = {
),
args: {
variant: 'primary',
size: 'lg',
},
}

export const WithoutAside: Story = {
render: (args: Controls) => (
<div style={{ maxWidth: '400px' }}>
<Card.Root variant={args.variant}>
<Card.Root variant={args.variant} size={args.size}>
<Card.Header>
<Card.Media>
<BasePillow fill={tokens.colors.amber300} />
Expand All @@ -106,13 +112,14 @@ export const WithoutAside: Story = {
),
args: {
variant: 'primary',
size: 'lg',
},
}

export const WithoutPillow: Story = {
render: (args: Controls) => (
<div style={{ maxWidth: '400px' }}>
<Card.Root variant={args.variant}>
<Card.Root variant={args.variant} size={args.size}>
<Card.Header>
<Card.Heading>
<Card.Title>Homeowner Insurance</Card.Title>
Expand All @@ -126,13 +133,14 @@ export const WithoutPillow: Story = {
),
args: {
variant: 'primary',
size: 'lg',
},
}

export const Secondary: Story = {
render: (args: Controls) => (
<div style={{ maxWidth: '400px' }}>
<Card.Root variant={args.variant}>
<Card.Root variant={args.variant} size={args.size}>
<Tooltip.Root>
<Card.Aside>
<Tooltip.Trigger>
Expand All @@ -151,5 +159,6 @@ export const Secondary: Story = {
),
args: {
variant: 'secondary',
size: 'md',
},
}
11 changes: 7 additions & 4 deletions packages/ui/src/components/Card/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,23 @@
import { Slot } from '@radix-ui/react-slot'
import { type RecipeVariants } from '@vanilla-extract/recipes'
import clsx from 'clsx'
import { type ComponentProps, type PropsWithChildren } from 'react'
import { forwardRef, type ComponentProps, type PropsWithChildren } from 'react'
import { Heading } from '../Heading/Heading'
import { Text } from '../Text/Text'
import { cardAside, cardHeader, cardRoot } from './Card.css'

type RootStyleProps = RecipeVariants<typeof cardRoot>
type RootProps = ComponentProps<'article'> & RootStyleProps
function CardRoot({ variant, size, className, children, ...props }: RootProps) {
const CardRoot = forwardRef(function CardRoot(
{ variant, size, className, children, ...props }: RootProps,
ref: RootProps['ref'],
) {
return (
<article className={clsx(cardRoot({ variant, size }), className)} {...props}>
<article className={clsx(cardRoot({ variant, size }), className)} {...props} ref={ref}>
{children}
</article>
)
}
})

type HeaderProps = ComponentProps<'header'>
function CardHeader({ className, children, ...props }: HeaderProps) {
Expand Down