|
1 | | -import { ComponentProps, FC, ReactNode } from 'react' |
2 | | -import { cn } from '@/lib/utils' |
| 1 | +import * as React from 'react' |
| 2 | +import { cn } from '@/lib/utils/index' |
3 | 3 |
|
4 | | -type CardProps = ComponentProps<'div'> & { |
5 | | - aside?: ReactNode |
| 4 | +function Card({ |
| 5 | + className, |
| 6 | + children, |
| 7 | + aside, |
| 8 | + ...props |
| 9 | +}: React.ComponentProps<'div'> & { aside?: React.ReactNode }) { |
| 10 | + return ( |
| 11 | + <div |
| 12 | + data-slot="card" |
| 13 | + className={cn( |
| 14 | + 'bg-card text-card-foreground border-table-stroke flex flex-nowrap gap-2 rounded-xl border px-3 py-2', |
| 15 | + className |
| 16 | + )} |
| 17 | + {...props} |
| 18 | + > |
| 19 | + {aside && <aside className="shrink-0">{aside}</aside>} |
| 20 | + <div className="flex flex-1 flex-col gap-2">{children}</div> |
| 21 | + </div> |
| 22 | + ) |
6 | 23 | } |
7 | 24 |
|
8 | | -export const Card: FC<CardProps> = ({ className, children, aside, ...props }) => ( |
9 | | - <div |
10 | | - data-slot="card" |
11 | | - className={cn( |
12 | | - 'flex flex-row gap-2 overflow-hidden rounded-sm border border-stone-100 bg-stone-100 px-2 py-3 text-sm tracking-tight text-black shadow-sm dark:border-black dark:bg-stone-900 dark:text-white dark:shadow-none', |
13 | | - className |
14 | | - )} |
15 | | - {...props} |
16 | | - > |
17 | | - <div className="order-2 flex flex-1 flex-col gap-2">{children}</div> |
18 | | - {aside && ( |
19 | | - <aside data-slot="card-aside" className="order-1 max-w-8 shrink-0 overflow-hidden"> |
20 | | - {aside} |
21 | | - </aside> |
22 | | - )} |
23 | | - </div> |
24 | | -) |
25 | | - |
26 | | -type CardAsideCounterProps = ComponentProps<'div'> |
27 | | -export const CardAsideCounter: FC<CardAsideCounterProps> = ({ className, ...props }) => ( |
28 | | - <div |
29 | | - data-slot="card-aside-counter" |
30 | | - className={cn( |
31 | | - 'min-h-5 min-w-5 overflow-hidden rounded-full border border-emerald-700 bg-emerald-700 px-0.5 pt-0.5 pb-1 text-center text-xs leading-none tracking-tight text-ellipsis whitespace-nowrap text-white dark:border-emerald-400 dark:bg-transparent dark:text-emerald-400', |
32 | | - className |
33 | | - )} |
34 | | - {...props} |
35 | | - /> |
36 | | -) |
| 25 | +function CardHeader({ className, ...props }: React.ComponentProps<'div'>) { |
| 26 | + return ( |
| 27 | + <div |
| 28 | + data-slot="card-header" |
| 29 | + className={cn( |
| 30 | + '@container/card-header grid auto-rows-min grid-rows-[auto_auto] items-start gap-0.5 has-data-[slot=card-action]:grid-cols-[1fr_auto] [.border-b]:pb-6', |
| 31 | + className |
| 32 | + )} |
| 33 | + {...props} |
| 34 | + /> |
| 35 | + ) |
| 36 | +} |
37 | 37 |
|
38 | | -type CardHeaderProps = ComponentProps<'div'> |
39 | | -export const CardHeader: FC<CardHeaderProps> = ({ className, ...props }) => ( |
40 | | - <div data-slot="card-header" className={cn('flex flex-col gap-0.5', className)} {...props} /> |
41 | | -) |
| 38 | +function CardTitle({ className, ...props }: React.ComponentProps<'div'>) { |
| 39 | + return ( |
| 40 | + <div |
| 41 | + data-slot="card-title" |
| 42 | + className={cn('text-foreground text-sm leading-none tracking-[-0.00875rem]', className)} |
| 43 | + {...props} |
| 44 | + /> |
| 45 | + ) |
| 46 | +} |
42 | 47 |
|
43 | | -type CardTitleProps = ComponentProps<'div'> |
44 | | -export const CardTitle: FC<CardTitleProps> = ({ className, ...props }) => ( |
45 | | - <div |
46 | | - data-slot="card-title" |
47 | | - className={cn('text-sm leading-none tracking-tight text-black dark:text-white', className)} |
48 | | - {...props} |
49 | | - /> |
50 | | -) |
| 48 | +function CardDescription({ className, ...props }: React.ComponentProps<'div'>) { |
| 49 | + return ( |
| 50 | + <div |
| 51 | + data-slot="card-description" |
| 52 | + className={cn('text-muted text-xs leading-none tracking-[-0.00875rem]', className)} |
| 53 | + {...props} |
| 54 | + /> |
| 55 | + ) |
| 56 | +} |
51 | 57 |
|
52 | | -type CardDescriptionProps = ComponentProps<'div'> |
53 | | -export const CardDescription: FC<CardDescriptionProps> = ({ className, ...props }) => ( |
54 | | - <div |
55 | | - data-slot="card-description" |
56 | | - className={cn( |
57 | | - 'text-xs leading-none tracking-tight text-black/50 dark:text-white/50', |
58 | | - className |
59 | | - )} |
60 | | - {...props} |
61 | | - /> |
62 | | -) |
| 58 | +function CardAction({ className, ...props }: React.ComponentProps<'div'>) { |
| 59 | + return ( |
| 60 | + <div |
| 61 | + data-slot="card-action" |
| 62 | + className={cn('col-start-2 row-span-2 row-start-1 self-start justify-self-end', className)} |
| 63 | + {...props} |
| 64 | + /> |
| 65 | + ) |
| 66 | +} |
63 | 67 |
|
64 | | -type CardContentProps = ComponentProps<'div'> |
65 | | -export const CardContent: FC<CardContentProps> = ({ className, ...props }) => ( |
66 | | - <div |
67 | | - data-slot="card-content" |
68 | | - className={cn('text-base leading-none tracking-tight text-black dark:text-white', className)} |
69 | | - {...props} |
70 | | - /> |
71 | | -) |
| 68 | +function CardContent({ className, ...props }: React.ComponentProps<'div'>) { |
| 69 | + return ( |
| 70 | + <div data-slot="card-content" className={cn('text-foreground text-sm', className)} {...props} /> |
| 71 | + ) |
| 72 | +} |
72 | 73 |
|
73 | | -type CardActionProps = ComponentProps<'div'> |
74 | | -export const CardAction: FC<CardActionProps> = ({ className, ...props }) => ( |
75 | | - <div |
76 | | - data-slot="card-action" |
77 | | - className={cn('flex flex-row-reverse gap-4', className)} |
78 | | - {...props} |
79 | | - /> |
80 | | -) |
| 74 | +function CardFooter({ className, ...props }: React.ComponentProps<'div'>) { |
| 75 | + return ( |
| 76 | + <div |
| 77 | + data-slot="card-footer" |
| 78 | + className={cn('text-foreground flex items-center text-sm [.border-t]:pt-6', className)} |
| 79 | + {...props} |
| 80 | + /> |
| 81 | + ) |
| 82 | +} |
81 | 83 |
|
82 | | -type CardFooterProps = ComponentProps<'div'> |
83 | | -export const CardFooter: FC<CardFooterProps> = ({ className, ...props }) => ( |
84 | | - <div data-slot="card-footer" className={cn('pt-4', className)} {...props} /> |
85 | | -) |
| 84 | +export { Card, CardHeader, CardFooter, CardTitle, CardAction, CardDescription, CardContent } |
0 commit comments