Skip to content

Commit a180a44

Browse files
authored
Merge pull request #78 from oasisprotocol/mz/cards
Customize Cards components
2 parents 04f820d + 5df23e0 commit a180a44

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

src/components/cards/index.tsx

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import * as React from 'react'
2+
import { cva, type VariantProps } from 'class-variance-authority'
3+
import { Card as BaseCard, CardTitle as BaseCardTitle, CardContent as BaseCardContent } from '../ui/card'
4+
import { cn } from '../../lib/utils'
5+
export { CardFooter, CardHeader, CardAction, CardDescription } 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+
)
33+
34+
type CardContentProps = React.ComponentProps<typeof BaseCardContent>
35+
36+
export const CardContent = ({ className, ...props }: CardContentProps) => (
37+
<BaseCardContent className={cn('text-sm', className)} {...props} />
38+
)

src/stories/Card/Card.stories.tsx

Lines changed: 2 additions & 2 deletions
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

@@ -65,7 +65,7 @@ export const WithAction: Story = {
6565
</Button>
6666
</CardAction>
6767
</CardHeader>
68-
<CardContent>View your notifications here.</CardContent>
68+
<CardContent>View and interact with your notifications here.</CardContent>
6969
<CardFooter>
7070
<Button variant="outline" className="w-full">
7171
View all

0 commit comments

Comments
 (0)