-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathCard.tsx
53 lines (50 loc) · 1.4 KB
/
Card.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { Slot } from '@radix-ui/react-slot';
import cl from 'clsx/lite';
import type { HTMLAttributes, ReactNode } from 'react';
import { forwardRef } from 'react';
export type CardProps = {
/**
* Changes background & border color
* @default neutral
*/
color?: 'neutral' | 'subtle' | 'brand1' | 'brand2' | 'brand3';
/**
* Change the default rendered element for the one passed as a child, merging their props and behavior.
* @default false
*/
asChild?: boolean;
/**
* Changes styling if card is used as a link
* @default false
*/
isLink?: boolean;
/** Instances of `Card.Header`, `Card.Content`, `Card.Footer` or other React nodes like `Divider` */
children: ReactNode;
} & HTMLAttributes<HTMLDivElement>;
/**
* Card component to present content in a structured way.
* @example
* <Card>
* <Card.Header>Header</Card.Header>
* <Card.Content>Content</Card.Content>
* <Card.Footer>Footer</Card.Footer>
* </Card>
*/
export const Card = forwardRef<HTMLDivElement, CardProps>(
(
{ isLink = false, asChild = false, color = 'neutral', className, ...rest },
ref,
) => {
const Component = asChild ? Slot : 'div';
return (
<Component
ref={ref}
className={cl(`ds-card`, isLink && `ds-focus`, className)}
data-color={color}
data-link={isLink ? '' : undefined}
{...rest}
/>
);
},
);
Card.displayName = 'Card';