@aereamart/design-system 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Accordion.d.ts +10 -0
- package/dist/Accordion.js +12 -0
- package/dist/AlertBanner.d.ts +9 -0
- package/dist/AlertBanner.js +21 -0
- package/dist/AppBar.d.ts +7 -0
- package/dist/AppBar.js +5 -0
- package/dist/Avatar.d.ts +6 -0
- package/dist/Avatar.js +20 -0
- package/dist/Badge.js +4 -4
- package/dist/BottomSheet.d.ts +8 -0
- package/dist/BottomSheet.js +24 -0
- package/dist/Breadcrumb.d.ts +8 -0
- package/dist/Breadcrumb.js +9 -0
- package/dist/Button.js +3 -3
- package/dist/Card.d.ts +7 -0
- package/dist/Card.js +6 -0
- package/dist/Checkbox.d.ts +5 -0
- package/dist/Checkbox.js +5 -0
- package/dist/Chip.d.ts +7 -0
- package/dist/Chip.js +15 -0
- package/dist/DataTable.d.ts +15 -0
- package/dist/DataTable.js +7 -0
- package/dist/DatePicker.d.ts +5 -0
- package/dist/DatePicker.js +11 -0
- package/dist/Divider.d.ts +5 -0
- package/dist/Divider.js +11 -0
- package/dist/Drawer.d.ts +10 -0
- package/dist/Drawer.js +24 -0
- package/dist/EmptyState.d.ts +7 -0
- package/dist/EmptyState.js +6 -0
- package/dist/Input.js +3 -3
- package/dist/Link.d.ts +4 -0
- package/dist/Link.js +6 -0
- package/dist/Menu.d.ts +14 -0
- package/dist/Menu.js +29 -0
- package/dist/Modal.js +1 -1
- package/dist/NavigationBar.d.ts +14 -0
- package/dist/NavigationBar.js +22 -0
- package/dist/Pagination.d.ts +7 -0
- package/dist/Pagination.js +24 -0
- package/dist/Popover.d.ts +7 -0
- package/dist/Popover.js +9 -0
- package/dist/Progress.d.ts +8 -0
- package/dist/Progress.js +15 -0
- package/dist/Radio.d.ts +15 -0
- package/dist/Radio.js +8 -0
- package/dist/SegmentedControl.d.ts +13 -0
- package/dist/SegmentedControl.js +18 -0
- package/dist/Select.js +3 -3
- package/dist/Sidebar.d.ts +16 -0
- package/dist/Sidebar.js +19 -0
- package/dist/Slider.d.ts +5 -0
- package/dist/Slider.js +5 -0
- package/dist/Snackbar.d.ts +12 -0
- package/dist/Snackbar.js +20 -0
- package/dist/Switch.d.ts +4 -0
- package/dist/Switch.js +5 -0
- package/dist/Tabs.d.ts +14 -0
- package/dist/Tabs.js +24 -0
- package/dist/Tag.d.ts +6 -0
- package/dist/Tag.js +11 -0
- package/dist/Textarea.js +3 -3
- package/dist/Tooltip.d.ts +7 -0
- package/dist/Tooltip.js +5 -0
- package/dist/TreeView.d.ts +12 -0
- package/dist/TreeView.js +34 -0
- package/dist/index.d.ts +32 -2
- package/dist/index.js +32 -2
- package/package.json +1 -1
- package/src/Accordion.tsx +58 -0
- package/src/AlertBanner.tsx +62 -0
- package/src/AppBar.tsx +29 -0
- package/src/Avatar.tsx +42 -0
- package/src/Badge.tsx +4 -4
- package/src/BottomSheet.tsx +60 -0
- package/src/Breadcrumb.tsx +48 -0
- package/src/Button.tsx +3 -3
- package/src/Card.tsx +39 -0
- package/src/Checkbox.tsx +31 -0
- package/src/Chip.tsx +44 -0
- package/src/DataTable.tsx +64 -0
- package/src/DatePicker.tsx +44 -0
- package/src/Divider.tsx +33 -0
- package/src/Drawer.tsx +71 -0
- package/src/EmptyState.tsx +37 -0
- package/src/Input.tsx +4 -4
- package/src/Link.tsx +22 -0
- package/src/Menu.tsx +73 -0
- package/src/Modal.tsx +3 -3
- package/src/NavigationBar.tsx +68 -0
- package/src/Pagination.tsx +69 -0
- package/src/Popover.tsx +34 -0
- package/src/Progress.tsx +53 -0
- package/src/Radio.tsx +49 -0
- package/src/SegmentedControl.tsx +63 -0
- package/src/Select.tsx +4 -4
- package/src/Sidebar.tsx +73 -0
- package/src/Slider.tsx +33 -0
- package/src/Snackbar.tsx +72 -0
- package/src/Switch.tsx +40 -0
- package/src/Tabs.tsx +77 -0
- package/src/Tag.tsx +29 -0
- package/src/Textarea.tsx +4 -4
- package/src/Tooltip.tsx +25 -0
- package/src/TreeView.tsx +105 -0
- package/src/index.ts +38 -8
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { cn } from './cn';
|
|
3
|
+
|
|
4
|
+
export interface NavItem {
|
|
5
|
+
value: string;
|
|
6
|
+
label: string;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface NavigationBarProps {
|
|
11
|
+
items: NavItem[];
|
|
12
|
+
value?: string;
|
|
13
|
+
defaultValue?: string;
|
|
14
|
+
onChange?: (value: string) => void;
|
|
15
|
+
variant?: 'pills' | 'links';
|
|
16
|
+
className?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function NavigationBar({
|
|
20
|
+
items,
|
|
21
|
+
value,
|
|
22
|
+
defaultValue,
|
|
23
|
+
onChange,
|
|
24
|
+
variant = 'links',
|
|
25
|
+
className,
|
|
26
|
+
}: NavigationBarProps) {
|
|
27
|
+
const isControlled = value !== undefined;
|
|
28
|
+
const [inner, setInner] = useState<string | undefined>(defaultValue);
|
|
29
|
+
const active = isControlled ? value : inner;
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<nav aria-label="Primary" className={cn('flex items-center gap-1', className)}>
|
|
33
|
+
{items.map(item => {
|
|
34
|
+
const selected = active === item.value;
|
|
35
|
+
return (
|
|
36
|
+
<button
|
|
37
|
+
key={item.value}
|
|
38
|
+
type="button"
|
|
39
|
+
aria-current={selected ? 'page' : undefined}
|
|
40
|
+
disabled={item.disabled}
|
|
41
|
+
onClick={() => {
|
|
42
|
+
if (!isControlled) setInner(item.value);
|
|
43
|
+
onChange?.(item.value);
|
|
44
|
+
}}
|
|
45
|
+
className={cn(
|
|
46
|
+
'px-4 py-2 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-lime-500/40 disabled:opacity-50',
|
|
47
|
+
variant === 'pills'
|
|
48
|
+
? cn(
|
|
49
|
+
'rounded-lg',
|
|
50
|
+
selected
|
|
51
|
+
? 'bg-lime-600 text-white'
|
|
52
|
+
: 'text-slate-600 hover:bg-slate-100 hover:text-slate-900'
|
|
53
|
+
)
|
|
54
|
+
: cn(
|
|
55
|
+
'border-b-2',
|
|
56
|
+
selected
|
|
57
|
+
? 'border-lime-600 text-lime-700'
|
|
58
|
+
: 'border-transparent text-slate-500 hover:text-slate-900'
|
|
59
|
+
)
|
|
60
|
+
)}
|
|
61
|
+
>
|
|
62
|
+
{item.label}
|
|
63
|
+
</button>
|
|
64
|
+
);
|
|
65
|
+
})}
|
|
66
|
+
</nav>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { ChevronLeft, ChevronRight } from 'lucide-react';
|
|
2
|
+
import { cn } from './cn';
|
|
3
|
+
import { Button } from './Button';
|
|
4
|
+
|
|
5
|
+
export interface PaginationProps {
|
|
6
|
+
page: number;
|
|
7
|
+
totalPages: number;
|
|
8
|
+
onChange: (page: number) => void;
|
|
9
|
+
className?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function pageList(page: number, total: number): (number | '…')[] {
|
|
13
|
+
if (total <= 7) return Array.from({ length: total }, (_, i) => i + 1);
|
|
14
|
+
const pages: (number | '…')[] = [1];
|
|
15
|
+
const start = Math.max(2, page - 1);
|
|
16
|
+
const end = Math.min(total - 1, page + 1);
|
|
17
|
+
if (start > 2) pages.push('…');
|
|
18
|
+
for (let i = start; i <= end; i++) pages.push(i);
|
|
19
|
+
if (end < total - 1) pages.push('…');
|
|
20
|
+
pages.push(total);
|
|
21
|
+
return pages;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function Pagination({ page, totalPages, onChange, className }: PaginationProps) {
|
|
25
|
+
return (
|
|
26
|
+
<nav aria-label="Pagination" className={cn('flex items-center gap-1', className)}>
|
|
27
|
+
<Button
|
|
28
|
+
variant="ghost"
|
|
29
|
+
size="sm"
|
|
30
|
+
disabled={page <= 1}
|
|
31
|
+
onClick={() => onChange(page - 1)}
|
|
32
|
+
aria-label="Previous page"
|
|
33
|
+
>
|
|
34
|
+
<ChevronLeft className="h-4 w-4" />
|
|
35
|
+
</Button>
|
|
36
|
+
{pageList(page, totalPages).map((p, i) =>
|
|
37
|
+
p === '…' ? (
|
|
38
|
+
<span key={`e-${i}`} className="px-1.5 text-sm text-slate-400">
|
|
39
|
+
…
|
|
40
|
+
</span>
|
|
41
|
+
) : (
|
|
42
|
+
<button
|
|
43
|
+
key={p}
|
|
44
|
+
type="button"
|
|
45
|
+
onClick={() => onChange(p)}
|
|
46
|
+
aria-current={p === page ? 'page' : undefined}
|
|
47
|
+
className={cn(
|
|
48
|
+
'h-8 min-w-8 rounded-lg px-2 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-lime-500/40',
|
|
49
|
+
p === page
|
|
50
|
+
? 'bg-lime-600 text-white'
|
|
51
|
+
: 'text-slate-600 hover:bg-slate-100 hover:text-slate-900'
|
|
52
|
+
)}
|
|
53
|
+
>
|
|
54
|
+
{p}
|
|
55
|
+
</button>
|
|
56
|
+
)
|
|
57
|
+
)}
|
|
58
|
+
<Button
|
|
59
|
+
variant="ghost"
|
|
60
|
+
size="sm"
|
|
61
|
+
disabled={page >= totalPages}
|
|
62
|
+
onClick={() => onChange(page + 1)}
|
|
63
|
+
aria-label="Next page"
|
|
64
|
+
>
|
|
65
|
+
<ChevronRight className="h-4 w-4" />
|
|
66
|
+
</Button>
|
|
67
|
+
</nav>
|
|
68
|
+
);
|
|
69
|
+
}
|
package/src/Popover.tsx
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { cn } from './cn';
|
|
2
|
+
|
|
3
|
+
export interface PopoverProps {
|
|
4
|
+
trigger: React.ReactNode;
|
|
5
|
+
content: React.ReactNode;
|
|
6
|
+
side?: 'top' | 'bottom' | 'left' | 'right';
|
|
7
|
+
className?: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function Popover({ trigger, content, side = 'bottom', className }: PopoverProps) {
|
|
11
|
+
const isTop = side === 'top';
|
|
12
|
+
const isBottom = side === 'bottom';
|
|
13
|
+
const isLeft = side === 'left';
|
|
14
|
+
const isRight = side === 'right';
|
|
15
|
+
|
|
16
|
+
return (
|
|
17
|
+
<span className="group relative inline-flex">
|
|
18
|
+
{trigger}
|
|
19
|
+
<span
|
|
20
|
+
role="tooltip"
|
|
21
|
+
className={cn(
|
|
22
|
+
'pointer-events-none absolute z-50 w-64 rounded-xl border border-slate-200 bg-white p-4 text-sm text-slate-700 opacity-0 shadow-lg transition-opacity duration-200 group-hover:opacity-100 group-focus-within:opacity-100',
|
|
23
|
+
isBottom && 'left-1/2 top-full mt-2 -translate-x-1/2',
|
|
24
|
+
isTop && 'bottom-full left-1/2 mb-2 -translate-x-1/2',
|
|
25
|
+
isLeft && 'right-full top-1/2 mr-2 -translate-y-1/2',
|
|
26
|
+
isRight && 'left-full top-1/2 ml-2 -translate-y-1/2',
|
|
27
|
+
className
|
|
28
|
+
)}
|
|
29
|
+
>
|
|
30
|
+
{content}
|
|
31
|
+
</span>
|
|
32
|
+
</span>
|
|
33
|
+
);
|
|
34
|
+
}
|
package/src/Progress.tsx
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { cn } from './cn';
|
|
2
|
+
|
|
3
|
+
export interface ProgressProps extends React.HTMLAttributes<HTMLDivElement> {
|
|
4
|
+
value: number;
|
|
5
|
+
max?: number;
|
|
6
|
+
size?: 'sm' | 'md';
|
|
7
|
+
tone?: 'primary' | 'accent' | 'danger';
|
|
8
|
+
showLabel?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const track: Record<NonNullable<ProgressProps['size']>, string> = {
|
|
12
|
+
sm: 'h-1.5',
|
|
13
|
+
md: 'h-2.5',
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const fill: Record<NonNullable<ProgressProps['tone']>, string> = {
|
|
17
|
+
primary: 'bg-lime-600',
|
|
18
|
+
accent: 'bg-purple-600',
|
|
19
|
+
danger: 'bg-red-600',
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export function Progress({
|
|
23
|
+
value,
|
|
24
|
+
max = 100,
|
|
25
|
+
size = 'md',
|
|
26
|
+
tone = 'primary',
|
|
27
|
+
showLabel = false,
|
|
28
|
+
className,
|
|
29
|
+
...props
|
|
30
|
+
}: ProgressProps) {
|
|
31
|
+
const pct = max > 0 ? Math.min(100, Math.max(0, (value / max) * 100)) : 0;
|
|
32
|
+
return (
|
|
33
|
+
<div className={cn('flex items-center gap-3', className)} {...props}>
|
|
34
|
+
<div
|
|
35
|
+
role="progressbar"
|
|
36
|
+
aria-valuenow={value}
|
|
37
|
+
aria-valuemin={0}
|
|
38
|
+
aria-valuemax={max}
|
|
39
|
+
className={cn('w-full overflow-hidden rounded-full bg-slate-200', track[size])}
|
|
40
|
+
>
|
|
41
|
+
<div
|
|
42
|
+
className={cn('h-full rounded-full transition-all duration-300', fill[tone])}
|
|
43
|
+
style={{ width: `${pct}%` }}
|
|
44
|
+
/>
|
|
45
|
+
</div>
|
|
46
|
+
{showLabel && (
|
|
47
|
+
<span className="w-10 shrink-0 text-right text-xs font-semibold tabular-nums text-slate-600">
|
|
48
|
+
{Math.round(pct)}%
|
|
49
|
+
</span>
|
|
50
|
+
)}
|
|
51
|
+
</div>
|
|
52
|
+
);
|
|
53
|
+
}
|
package/src/Radio.tsx
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { cn } from './cn';
|
|
2
|
+
|
|
3
|
+
export interface RadioProps
|
|
4
|
+
extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'type'> {
|
|
5
|
+
label?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function Radio({ label, id, className, ...props }: RadioProps) {
|
|
9
|
+
return (
|
|
10
|
+
<label
|
|
11
|
+
htmlFor={id}
|
|
12
|
+
className={cn('inline-flex cursor-pointer items-center gap-2.5 text-sm', className)}
|
|
13
|
+
>
|
|
14
|
+
<input
|
|
15
|
+
id={id}
|
|
16
|
+
type="radio"
|
|
17
|
+
className="h-4 w-4 shrink-0 cursor-pointer accent-lime-600 focus:outline-none focus:ring-2 focus:ring-lime-500/40"
|
|
18
|
+
{...props}
|
|
19
|
+
/>
|
|
20
|
+
{label && <span className="font-medium text-slate-700">{label}</span>}
|
|
21
|
+
</label>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export interface RadioGroupProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onChange'> {
|
|
26
|
+
name: string;
|
|
27
|
+
value?: string | number;
|
|
28
|
+
onChange?: (value: string) => void;
|
|
29
|
+
options: { value: string; label: string; disabled?: boolean }[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function RadioGroup({ name, value, onChange, options, className, ...props }: RadioGroupProps) {
|
|
33
|
+
return (
|
|
34
|
+
<div className={cn('flex flex-wrap gap-x-5 gap-y-2.5', className)} {...props}>
|
|
35
|
+
{options.map(opt => (
|
|
36
|
+
<Radio
|
|
37
|
+
key={opt.value}
|
|
38
|
+
id={`${name}-${opt.value}`}
|
|
39
|
+
name={name}
|
|
40
|
+
value={opt.value}
|
|
41
|
+
label={opt.label}
|
|
42
|
+
checked={value === opt.value}
|
|
43
|
+
disabled={opt.disabled}
|
|
44
|
+
onChange={e => onChange?.(e.target.value)}
|
|
45
|
+
/>
|
|
46
|
+
))}
|
|
47
|
+
</div>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { cn } from './cn';
|
|
3
|
+
|
|
4
|
+
export interface SegmentedOption<T extends string | number> {
|
|
5
|
+
value: T;
|
|
6
|
+
label: string;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface SegmentedControlProps<T extends string | number> {
|
|
11
|
+
options: SegmentedOption<T>[];
|
|
12
|
+
value?: T;
|
|
13
|
+
defaultValue?: T;
|
|
14
|
+
onChange?: (value: T) => void;
|
|
15
|
+
className?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function SegmentedControl<T extends string | number>({
|
|
19
|
+
options,
|
|
20
|
+
value,
|
|
21
|
+
defaultValue,
|
|
22
|
+
onChange,
|
|
23
|
+
className,
|
|
24
|
+
}: SegmentedControlProps<T>) {
|
|
25
|
+
const isControlled = value !== undefined;
|
|
26
|
+
const [inner, setInner] = useState<T | undefined>(defaultValue);
|
|
27
|
+
const active = isControlled ? value : inner;
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<div
|
|
31
|
+
role="tablist"
|
|
32
|
+
className={cn(
|
|
33
|
+
'inline-flex items-center gap-1 rounded-lg border border-slate-200 bg-white p-1',
|
|
34
|
+
className
|
|
35
|
+
)}
|
|
36
|
+
>
|
|
37
|
+
{options.map(opt => {
|
|
38
|
+
const selected = active === opt.value;
|
|
39
|
+
return (
|
|
40
|
+
<button
|
|
41
|
+
key={String(opt.value)}
|
|
42
|
+
type="button"
|
|
43
|
+
role="tab"
|
|
44
|
+
aria-selected={selected}
|
|
45
|
+
disabled={opt.disabled}
|
|
46
|
+
onClick={() => {
|
|
47
|
+
if (!isControlled) setInner(opt.value);
|
|
48
|
+
onChange?.(opt.value);
|
|
49
|
+
}}
|
|
50
|
+
className={cn(
|
|
51
|
+
'rounded-md px-4 py-1.5 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-lime-500/40 disabled:opacity-50',
|
|
52
|
+
selected
|
|
53
|
+
? 'bg-lime-600 text-white'
|
|
54
|
+
: 'text-slate-600 hover:bg-slate-100 hover:text-slate-900'
|
|
55
|
+
)}
|
|
56
|
+
>
|
|
57
|
+
{opt.label}
|
|
58
|
+
</button>
|
|
59
|
+
);
|
|
60
|
+
})}
|
|
61
|
+
</div>
|
|
62
|
+
);
|
|
63
|
+
}
|
package/src/Select.tsx
CHANGED
|
@@ -9,17 +9,17 @@ export function Select({ label, error, className, id, children, ...props }: Sele
|
|
|
9
9
|
return (
|
|
10
10
|
<div className="w-full">
|
|
11
11
|
{label && (
|
|
12
|
-
<label htmlFor={id} className="mb-1 block text-sm font-medium text-
|
|
12
|
+
<label htmlFor={id} className="mb-1 block text-sm font-medium text-slate-700">
|
|
13
13
|
{label}
|
|
14
14
|
</label>
|
|
15
15
|
)}
|
|
16
16
|
<select
|
|
17
17
|
id={id}
|
|
18
18
|
className={cn(
|
|
19
|
-
'w-full rounded-lg border bg-white px-3 py-2.5 text-sm text-
|
|
19
|
+
'w-full rounded-lg border bg-white px-3 py-2.5 text-sm text-slate-900 focus:outline-none focus:ring-2',
|
|
20
20
|
error
|
|
21
|
-
? 'border-red-
|
|
22
|
-
: 'border-
|
|
21
|
+
? 'border-red-600 focus:border-red-600 focus:ring-red-500/30'
|
|
22
|
+
: 'border-slate-500 focus:border-lime-600 focus:ring-lime-500/30',
|
|
23
23
|
className
|
|
24
24
|
)}
|
|
25
25
|
{...props}
|
package/src/Sidebar.tsx
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { cn } from './cn';
|
|
3
|
+
|
|
4
|
+
export interface SidebarItem {
|
|
5
|
+
value: string;
|
|
6
|
+
label: string;
|
|
7
|
+
icon?: React.ReactNode;
|
|
8
|
+
badge?: React.ReactNode;
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface SidebarProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onChange'> {
|
|
13
|
+
items: SidebarItem[];
|
|
14
|
+
value?: string;
|
|
15
|
+
defaultValue?: string;
|
|
16
|
+
onChange?: (value: string) => void;
|
|
17
|
+
header?: React.ReactNode;
|
|
18
|
+
footer?: React.ReactNode;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function Sidebar({
|
|
22
|
+
items,
|
|
23
|
+
value,
|
|
24
|
+
defaultValue,
|
|
25
|
+
onChange,
|
|
26
|
+
header,
|
|
27
|
+
footer,
|
|
28
|
+
className,
|
|
29
|
+
...props
|
|
30
|
+
}: SidebarProps) {
|
|
31
|
+
const controlled = value !== undefined;
|
|
32
|
+
const [active, setActive] = useState(defaultValue);
|
|
33
|
+
|
|
34
|
+
return (
|
|
35
|
+
<nav
|
|
36
|
+
className={cn('flex w-64 flex-col gap-2 rounded-xl border border-slate-200 bg-white p-3', className)}
|
|
37
|
+
{...props}
|
|
38
|
+
>
|
|
39
|
+
{header && <div className="border-b border-slate-100 pb-2">{header}</div>}
|
|
40
|
+
<ul className="flex-1 space-y-0.5">
|
|
41
|
+
{items.map(item => {
|
|
42
|
+
const isActive = controlled ? value === item.value : active === item.value;
|
|
43
|
+
return (
|
|
44
|
+
<li key={item.value}>
|
|
45
|
+
<button
|
|
46
|
+
type="button"
|
|
47
|
+
disabled={item.disabled}
|
|
48
|
+
onClick={() => {
|
|
49
|
+
if (!controlled) setActive(item.value);
|
|
50
|
+
onChange?.(item.value);
|
|
51
|
+
}}
|
|
52
|
+
className={cn(
|
|
53
|
+
'flex w-full items-center gap-2.5 rounded-lg px-3 py-2 text-left text-sm font-medium transition-colors',
|
|
54
|
+
'focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-lime-500/40 disabled:cursor-not-allowed',
|
|
55
|
+
item.disabled
|
|
56
|
+
? 'cursor-not-allowed text-slate-300'
|
|
57
|
+
: isActive
|
|
58
|
+
? 'bg-lime-600 text-white'
|
|
59
|
+
: 'text-slate-700 hover:bg-lime-50 hover:text-lime-800'
|
|
60
|
+
)}
|
|
61
|
+
>
|
|
62
|
+
{item.icon}
|
|
63
|
+
<span className="flex-1 truncate">{item.label}</span>
|
|
64
|
+
{item.badge}
|
|
65
|
+
</button>
|
|
66
|
+
</li>
|
|
67
|
+
);
|
|
68
|
+
})}
|
|
69
|
+
</ul>
|
|
70
|
+
{footer && <div className="border-t border-slate-100 pt-2">{footer}</div>}
|
|
71
|
+
</nav>
|
|
72
|
+
);
|
|
73
|
+
}
|
package/src/Slider.tsx
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { cn } from './cn';
|
|
2
|
+
|
|
3
|
+
export interface SliderProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'type'> {
|
|
4
|
+
label?: string;
|
|
5
|
+
valueLabel?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function Slider({ label, valueLabel, id, className, ...props }: SliderProps) {
|
|
9
|
+
return (
|
|
10
|
+
<div className={cn('w-full max-w-md', className)}>
|
|
11
|
+
{(label || valueLabel) && (
|
|
12
|
+
<div className="mb-2 flex items-center justify-between">
|
|
13
|
+
{label && (
|
|
14
|
+
<label htmlFor={id} className="text-sm font-medium text-slate-700">
|
|
15
|
+
{label}
|
|
16
|
+
</label>
|
|
17
|
+
)}
|
|
18
|
+
{valueLabel && (
|
|
19
|
+
<span className="text-sm font-semibold tabular-nums text-slate-600">
|
|
20
|
+
{valueLabel}
|
|
21
|
+
</span>
|
|
22
|
+
)}
|
|
23
|
+
</div>
|
|
24
|
+
)}
|
|
25
|
+
<input
|
|
26
|
+
id={id}
|
|
27
|
+
type="range"
|
|
28
|
+
className="h-2 w-full cursor-pointer appearance-none rounded-full bg-slate-200 accent-lime-600 focus:outline-none focus:ring-2 focus:ring-lime-500/40"
|
|
29
|
+
{...props}
|
|
30
|
+
/>
|
|
31
|
+
</div>
|
|
32
|
+
);
|
|
33
|
+
}
|
package/src/Snackbar.tsx
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { CheckCircle2, XCircle, AlertTriangle, Info, X } from 'lucide-react';
|
|
2
|
+
import { cn } from './cn';
|
|
3
|
+
|
|
4
|
+
type SnackbarTone = 'success' | 'error' | 'warning' | 'info';
|
|
5
|
+
|
|
6
|
+
export interface SnackbarProps {
|
|
7
|
+
open?: boolean;
|
|
8
|
+
tone?: SnackbarTone;
|
|
9
|
+
message: string;
|
|
10
|
+
actionLabel?: string;
|
|
11
|
+
onAction?: () => void;
|
|
12
|
+
onClose?: () => void;
|
|
13
|
+
className?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const toneIcon: Record<SnackbarTone, React.ReactNode> = {
|
|
17
|
+
success: <CheckCircle2 className="h-5 w-5 shrink-0" />,
|
|
18
|
+
error: <XCircle className="h-5 w-5 shrink-0" />,
|
|
19
|
+
warning: <AlertTriangle className="h-5 w-5 shrink-0" />,
|
|
20
|
+
info: <Info className="h-5 w-5 shrink-0" />,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const toneText: Record<SnackbarTone, string> = {
|
|
24
|
+
success: 'text-lime-600',
|
|
25
|
+
error: 'text-red-600',
|
|
26
|
+
warning: 'text-purple-600',
|
|
27
|
+
info: 'text-sky-600',
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export function Snackbar({
|
|
31
|
+
open = true,
|
|
32
|
+
tone = 'info',
|
|
33
|
+
message,
|
|
34
|
+
actionLabel,
|
|
35
|
+
onAction,
|
|
36
|
+
onClose,
|
|
37
|
+
className,
|
|
38
|
+
}: SnackbarProps) {
|
|
39
|
+
if (!open) return null;
|
|
40
|
+
return (
|
|
41
|
+
<div
|
|
42
|
+
role="status"
|
|
43
|
+
aria-live="polite"
|
|
44
|
+
className={cn(
|
|
45
|
+
'pointer-events-auto flex items-center gap-3 rounded-xl border border-slate-200 bg-white px-4 py-3 shadow-lg',
|
|
46
|
+
className
|
|
47
|
+
)}
|
|
48
|
+
>
|
|
49
|
+
<span className={toneText[tone]}>{toneIcon[tone]}</span>
|
|
50
|
+
<p className="min-w-0 flex-1 text-sm font-medium text-slate-800">{message}</p>
|
|
51
|
+
{actionLabel && (
|
|
52
|
+
<button
|
|
53
|
+
type="button"
|
|
54
|
+
onClick={onAction}
|
|
55
|
+
className="shrink-0 text-sm font-semibold text-lime-700 hover:text-lime-800 hover:underline"
|
|
56
|
+
>
|
|
57
|
+
{actionLabel}
|
|
58
|
+
</button>
|
|
59
|
+
)}
|
|
60
|
+
{onClose && (
|
|
61
|
+
<button
|
|
62
|
+
type="button"
|
|
63
|
+
aria-label="Close"
|
|
64
|
+
onClick={onClose}
|
|
65
|
+
className="shrink-0 rounded-full p-1 text-slate-400 hover:bg-slate-100"
|
|
66
|
+
>
|
|
67
|
+
<X className="h-4 w-4" />
|
|
68
|
+
</button>
|
|
69
|
+
)}
|
|
70
|
+
</div>
|
|
71
|
+
);
|
|
72
|
+
}
|
package/src/Switch.tsx
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { cn } from './cn';
|
|
2
|
+
|
|
3
|
+
export interface SwitchProps
|
|
4
|
+
extends Omit<React.InputHTMLAttributes<HTMLInputElement>, 'type'> {
|
|
5
|
+
label?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function Switch({ label, id, className, checked, onChange, ...props }: SwitchProps) {
|
|
9
|
+
return (
|
|
10
|
+
<label
|
|
11
|
+
htmlFor={id}
|
|
12
|
+
className={cn('inline-flex cursor-pointer items-center gap-3', className)}
|
|
13
|
+
>
|
|
14
|
+
<input
|
|
15
|
+
id={id}
|
|
16
|
+
type="checkbox"
|
|
17
|
+
role="switch"
|
|
18
|
+
checked={checked}
|
|
19
|
+
onChange={onChange}
|
|
20
|
+
className="sr-only"
|
|
21
|
+
{...props}
|
|
22
|
+
/>
|
|
23
|
+
<span
|
|
24
|
+
aria-hidden="true"
|
|
25
|
+
className={cn(
|
|
26
|
+
'relative inline-flex h-6 w-11 shrink-0 items-center rounded-full transition-colors',
|
|
27
|
+
checked ? 'bg-lime-600' : 'bg-slate-300'
|
|
28
|
+
)}
|
|
29
|
+
>
|
|
30
|
+
<span
|
|
31
|
+
className={cn(
|
|
32
|
+
'inline-block h-4 w-4 transform rounded-full bg-white shadow transition-transform',
|
|
33
|
+
checked ? 'translate-x-6' : 'translate-x-1'
|
|
34
|
+
)}
|
|
35
|
+
/>
|
|
36
|
+
</span>
|
|
37
|
+
{label && <span className="text-sm font-medium text-slate-700">{label}</span>}
|
|
38
|
+
</label>
|
|
39
|
+
);
|
|
40
|
+
}
|
package/src/Tabs.tsx
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { cn } from './cn';
|
|
3
|
+
|
|
4
|
+
export interface Tab<T extends string | number> {
|
|
5
|
+
value: T;
|
|
6
|
+
label: string;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface TabsProps<T extends string | number> {
|
|
11
|
+
tabs: Tab<T>[];
|
|
12
|
+
value?: T;
|
|
13
|
+
defaultValue?: T;
|
|
14
|
+
onChange?: (value: T) => void;
|
|
15
|
+
variant?: 'underline' | 'pill';
|
|
16
|
+
className?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function Tabs<T extends string | number>({
|
|
20
|
+
tabs,
|
|
21
|
+
value,
|
|
22
|
+
defaultValue,
|
|
23
|
+
onChange,
|
|
24
|
+
variant = 'underline',
|
|
25
|
+
className,
|
|
26
|
+
}: TabsProps<T>) {
|
|
27
|
+
const isControlled = value !== undefined;
|
|
28
|
+
const [inner, setInner] = useState<T | undefined>(defaultValue);
|
|
29
|
+
const active = isControlled ? value : inner;
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<div
|
|
33
|
+
role="tablist"
|
|
34
|
+
className={cn(
|
|
35
|
+
variant === 'underline'
|
|
36
|
+
? 'flex gap-1 border-b border-slate-200'
|
|
37
|
+
: 'inline-flex items-center gap-1 rounded-lg border border-slate-200 bg-white p-1',
|
|
38
|
+
className
|
|
39
|
+
)}
|
|
40
|
+
>
|
|
41
|
+
{tabs.map(tab => {
|
|
42
|
+
const selected = active === tab.value;
|
|
43
|
+
return (
|
|
44
|
+
<button
|
|
45
|
+
key={String(tab.value)}
|
|
46
|
+
type="button"
|
|
47
|
+
role="tab"
|
|
48
|
+
aria-selected={selected}
|
|
49
|
+
disabled={tab.disabled}
|
|
50
|
+
onClick={() => {
|
|
51
|
+
if (!isControlled) setInner(tab.value);
|
|
52
|
+
onChange?.(tab.value);
|
|
53
|
+
}}
|
|
54
|
+
className={cn(
|
|
55
|
+
'px-4 py-2 text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-lime-500/40 disabled:opacity-50',
|
|
56
|
+
variant === 'underline'
|
|
57
|
+
? cn(
|
|
58
|
+
'-mb-px border-b-2',
|
|
59
|
+
selected
|
|
60
|
+
? 'border-lime-600 text-lime-700'
|
|
61
|
+
: 'border-transparent text-slate-500 hover:border-slate-300 hover:text-slate-900'
|
|
62
|
+
)
|
|
63
|
+
: cn(
|
|
64
|
+
'rounded-md',
|
|
65
|
+
selected
|
|
66
|
+
? 'bg-lime-600 text-white'
|
|
67
|
+
: 'text-slate-600 hover:bg-slate-100 hover:text-slate-900'
|
|
68
|
+
)
|
|
69
|
+
)}
|
|
70
|
+
>
|
|
71
|
+
{tab.label}
|
|
72
|
+
</button>
|
|
73
|
+
);
|
|
74
|
+
})}
|
|
75
|
+
</div>
|
|
76
|
+
);
|
|
77
|
+
}
|
package/src/Tag.tsx
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { cn } from './cn';
|
|
2
|
+
|
|
3
|
+
type TagTone = 'primary' | 'accent' | 'neutral' | 'danger';
|
|
4
|
+
|
|
5
|
+
export interface TagProps extends React.HTMLAttributes<HTMLSpanElement> {
|
|
6
|
+
tone?: TagTone;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const toneClasses: Record<TagTone, string> = {
|
|
10
|
+
primary: 'border-lime-300 bg-white text-lime-800',
|
|
11
|
+
accent: 'border-purple-300 bg-white text-purple-900',
|
|
12
|
+
neutral: 'border-slate-300 bg-white text-slate-700',
|
|
13
|
+
danger: 'border-red-300 bg-white text-red-800',
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export function Tag({ tone = 'neutral', className, children, ...props }: TagProps) {
|
|
17
|
+
return (
|
|
18
|
+
<span
|
|
19
|
+
className={cn(
|
|
20
|
+
'inline-flex items-center gap-1 rounded-md border px-2 py-0.5 text-xs font-semibold',
|
|
21
|
+
toneClasses[tone],
|
|
22
|
+
className
|
|
23
|
+
)}
|
|
24
|
+
{...props}
|
|
25
|
+
>
|
|
26
|
+
{children}
|
|
27
|
+
</span>
|
|
28
|
+
);
|
|
29
|
+
}
|