-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathBox.tsx
69 lines (65 loc) · 1.63 KB
/
Box.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import styles from '@digdir/designsystemet-css/box.module.css';
import { Slot } from '@radix-ui/react-slot';
import cl from 'clsx/lite';
import type { HTMLAttributes } from 'react';
import { forwardRef } from 'react';
export type BoxProps = {
/**
* Shadow size of the box
* @default undefined
*/
shadow?: 'xs' | 'sm' | 'md' | 'lg' | 'xl';
/**
* Border color of the box
* @default undefined
*/
borderColor?: 'default' | 'subtle' | 'strong';
/**
* Border radius of the box
* @default undefined
*/
borderRadius?: 'sm' | 'md' | 'lg' | 'xl' | '2xl' | '3xl' | '4xl' | 'full';
/**
* Background color of the box
* @default 'default'
*/
background?: 'default' | 'subtle';
/**
* Change the default rendered element for the one passed as a child, merging their props and behavior.
* @default false
*/
asChild?: boolean;
} & HTMLAttributes<HTMLDivElement>;
export const Box = forwardRef<HTMLDivElement, BoxProps>(
(
{
shadow,
borderColor,
borderRadius,
background = 'default',
children,
asChild = false,
className,
...rest
},
ref,
) => {
const Component = asChild ? Slot : 'div';
return (
<Component
ref={ref}
className={cl(
shadow && styles[`ds-box--${shadow}-shadow`],
borderColor && styles[`ds-box--${borderColor}-border-color`],
borderRadius && styles[`ds-box--${borderRadius}-border-radius`],
styles[`ds-box--${background}-background`],
className,
)}
{...rest}
>
{children}
</Component>
);
},
);
Box.displayName = 'Box';