Skip to content

Commit a5b6520

Browse files
committed
Customize Cards components
1 parent d180c8f commit a5b6520

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

src/components/cards/index.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import * as React from 'react'
2+
import { cva, type VariantProps } from 'class-variance-authority'
3+
import { Card as BaseCard, CardTitle as BaseCardTitle } from '../ui/card'
4+
import { cn } from '../../lib/utils'
5+
export { CardFooter, CardHeader, CardAction, CardDescription, CardContent } from '../ui/card'
6+
7+
const cardVariants = cva('rounded-sm', {
8+
variants: {
9+
variant: {
10+
default: '',
11+
layout: 'flex-1 gap-2 bg-background mb-4 md:mb-6',
12+
},
13+
},
14+
defaultVariants: {
15+
variant: 'default',
16+
},
17+
})
18+
19+
type CardProps = React.ComponentProps<typeof BaseCard> & VariantProps<typeof cardVariants>
20+
21+
export const Card = ({ className, variant, ...props }: CardProps) => (
22+
<BaseCard className={cn(cardVariants({ variant }), className)} {...props} />
23+
)
24+
25+
type CardTitleProps = React.ComponentProps<typeof BaseCardTitle>
26+
27+
export const CardTitle = ({ className, ...props }: CardTitleProps) => (
28+
<BaseCardTitle
29+
className={cn('flex-1 flex justify-between [&>a]:font-medium [&>a]:text-sm', className)}
30+
{...props}
31+
/>
32+
)

src/stories/Card/Card.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
CardFooter,
88
CardHeader,
99
CardTitle,
10-
} from '../../components/ui/card.tsx'
10+
} from '../../components/cards'
1111
import { Button } from '../../components/ui/button.tsx'
1212
import { expect, within } from 'storybook/test'
1313

0 commit comments

Comments
 (0)