forked from PinSpace-Org/GistPin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDivider.tsx
More file actions
70 lines (62 loc) 路 1.61 KB
/
Copy pathDivider.tsx
File metadata and controls
70 lines (62 loc) 路 1.61 KB
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
70
'use client';
type Orientation = 'horizontal' | 'vertical';
type Color = 'default' | 'light' | 'dark' | 'brand';
type Spacing = 'sm' | 'md' | 'lg';
interface DividerProps {
orientation?: Orientation;
label?: string;
color?: Color;
spacing?: Spacing;
className?: string;
}
const colorClasses: Record<Color, string> = {
default: 'border-gray-200 dark:border-gray-700',
light: 'border-gray-100 dark:border-gray-800',
dark: 'border-gray-400 dark:border-gray-500',
brand: 'border-brand',
};
const spacingH: Record<Spacing, string> = {
sm: 'my-2',
md: 'my-4',
lg: 'my-8',
};
const spacingV: Record<Spacing, string> = {
sm: 'mx-2',
md: 'mx-4',
lg: 'mx-8',
};
export default function Divider({
orientation = 'horizontal',
label,
color = 'default',
spacing = 'md',
className = '',
}: DividerProps) {
if (orientation === 'vertical') {
return (
<div
role="separator"
aria-orientation="vertical"
className={`inline-block self-stretch border-l ${colorClasses[color]} ${spacingV[spacing]} ${className}`}
/>
);
}
if (label) {
return (
<div
role="separator"
className={`flex items-center gap-3 ${spacingH[spacing]} ${className}`}
>
<div className={`flex-1 border-t ${colorClasses[color]}`} />
<span className="text-xs text-gray-500 dark:text-gray-400 whitespace-nowrap">{label}</span>
<div className={`flex-1 border-t ${colorClasses[color]}`} />
</div>
);
}
return (
<hr
role="separator"
className={`border-t ${colorClasses[color]} ${spacingH[spacing]} ${className}`}
/>
);
}