@aereamart/design-system 0.2.0 → 0.3.1

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.
Files changed (108) hide show
  1. package/dist/Accordion.d.ts +10 -0
  2. package/dist/Accordion.js +12 -0
  3. package/dist/AlertBanner.d.ts +9 -0
  4. package/dist/AlertBanner.js +21 -0
  5. package/dist/AppBar.d.ts +7 -0
  6. package/dist/AppBar.js +5 -0
  7. package/dist/Avatar.d.ts +6 -0
  8. package/dist/Avatar.js +20 -0
  9. package/dist/Badge.js +4 -4
  10. package/dist/BottomSheet.d.ts +8 -0
  11. package/dist/BottomSheet.js +24 -0
  12. package/dist/Breadcrumb.d.ts +8 -0
  13. package/dist/Breadcrumb.js +9 -0
  14. package/dist/Button.js +3 -3
  15. package/dist/Card.d.ts +7 -0
  16. package/dist/Card.js +6 -0
  17. package/dist/Checkbox.d.ts +5 -0
  18. package/dist/Checkbox.js +5 -0
  19. package/dist/Chip.d.ts +7 -0
  20. package/dist/Chip.js +15 -0
  21. package/dist/DataTable.d.ts +15 -0
  22. package/dist/DataTable.js +7 -0
  23. package/dist/DatePicker.d.ts +5 -0
  24. package/dist/DatePicker.js +11 -0
  25. package/dist/Divider.d.ts +5 -0
  26. package/dist/Divider.js +11 -0
  27. package/dist/Drawer.d.ts +10 -0
  28. package/dist/Drawer.js +24 -0
  29. package/dist/EmptyState.d.ts +7 -0
  30. package/dist/EmptyState.js +6 -0
  31. package/dist/Input.js +3 -3
  32. package/dist/Link.d.ts +4 -0
  33. package/dist/Link.js +6 -0
  34. package/dist/Menu.d.ts +14 -0
  35. package/dist/Menu.js +29 -0
  36. package/dist/Modal.js +1 -1
  37. package/dist/NavigationBar.d.ts +14 -0
  38. package/dist/NavigationBar.js +22 -0
  39. package/dist/Pagination.d.ts +7 -0
  40. package/dist/Pagination.js +24 -0
  41. package/dist/Popover.d.ts +7 -0
  42. package/dist/Popover.js +9 -0
  43. package/dist/Progress.d.ts +8 -0
  44. package/dist/Progress.js +15 -0
  45. package/dist/Radio.d.ts +15 -0
  46. package/dist/Radio.js +8 -0
  47. package/dist/SegmentedControl.d.ts +13 -0
  48. package/dist/SegmentedControl.js +18 -0
  49. package/dist/Select.js +3 -3
  50. package/dist/Sidebar.d.ts +16 -0
  51. package/dist/Sidebar.js +19 -0
  52. package/dist/Slider.d.ts +5 -0
  53. package/dist/Slider.js +5 -0
  54. package/dist/Snackbar.d.ts +12 -0
  55. package/dist/Snackbar.js +20 -0
  56. package/dist/Switch.d.ts +4 -0
  57. package/dist/Switch.js +5 -0
  58. package/dist/Tabs.d.ts +14 -0
  59. package/dist/Tabs.js +24 -0
  60. package/dist/Tag.d.ts +6 -0
  61. package/dist/Tag.js +11 -0
  62. package/dist/Textarea.js +3 -3
  63. package/dist/Tooltip.d.ts +7 -0
  64. package/dist/Tooltip.js +5 -0
  65. package/dist/TreeView.d.ts +12 -0
  66. package/dist/TreeView.js +34 -0
  67. package/dist/index.d.ts +32 -2
  68. package/dist/index.js +32 -2
  69. package/package.json +43 -43
  70. package/src/Accordion.tsx +58 -0
  71. package/src/AlertBanner.tsx +62 -0
  72. package/src/AppBar.tsx +29 -0
  73. package/src/Avatar.tsx +42 -0
  74. package/src/Badge.tsx +27 -27
  75. package/src/BottomSheet.tsx +60 -0
  76. package/src/Breadcrumb.tsx +48 -0
  77. package/src/Button.tsx +54 -54
  78. package/src/Card.tsx +39 -0
  79. package/src/Checkbox.tsx +31 -0
  80. package/src/Chip.tsx +44 -0
  81. package/src/DataTable.tsx +64 -0
  82. package/src/DatePicker.tsx +44 -0
  83. package/src/Divider.tsx +33 -0
  84. package/src/Drawer.tsx +71 -0
  85. package/src/EmptyState.tsx +37 -0
  86. package/src/Input.tsx +30 -30
  87. package/src/Link.tsx +22 -0
  88. package/src/Menu.tsx +73 -0
  89. package/src/Modal.tsx +62 -62
  90. package/src/NavigationBar.tsx +68 -0
  91. package/src/Pagination.tsx +69 -0
  92. package/src/Popover.tsx +34 -0
  93. package/src/Progress.tsx +53 -0
  94. package/src/Radio.tsx +49 -0
  95. package/src/SegmentedControl.tsx +63 -0
  96. package/src/Select.tsx +32 -32
  97. package/src/Sidebar.tsx +73 -0
  98. package/src/Slider.tsx +33 -0
  99. package/src/Snackbar.tsx +72 -0
  100. package/src/Spinner.tsx +19 -19
  101. package/src/Switch.tsx +40 -0
  102. package/src/Tabs.tsx +77 -0
  103. package/src/Tag.tsx +29 -0
  104. package/src/Textarea.tsx +30 -30
  105. package/src/Tooltip.tsx +25 -0
  106. package/src/TreeView.tsx +105 -0
  107. package/src/cn.ts +2 -2
  108. package/src/index.ts +38 -8
@@ -0,0 +1,37 @@
1
+ import { Inbox } from 'lucide-react';
2
+ import { cn } from './cn';
3
+
4
+ export interface EmptyStateProps extends React.HTMLAttributes<HTMLDivElement> {
5
+ title: string;
6
+ description?: string;
7
+ icon?: React.ReactNode;
8
+ action?: React.ReactNode;
9
+ }
10
+
11
+ export function EmptyState({
12
+ title,
13
+ description,
14
+ icon,
15
+ action,
16
+ className,
17
+ ...props
18
+ }: EmptyStateProps) {
19
+ return (
20
+ <div
21
+ className={cn(
22
+ 'flex flex-col items-center justify-center rounded-xl border-2 border-dashed border-slate-200 bg-white px-8 py-12 text-center',
23
+ className
24
+ )}
25
+ {...props}
26
+ >
27
+ <div className="mb-3 rounded-full bg-lime-50 p-3 text-lime-600">
28
+ {icon ?? <Inbox aria-hidden="true" className="h-8 w-8" />}
29
+ </div>
30
+ <h3 className="text-base font-bold text-slate-900">{title}</h3>
31
+ {description && (
32
+ <p className="mt-1 max-w-sm text-sm text-slate-500">{description}</p>
33
+ )}
34
+ {action && <div className="mt-5">{action}</div>}
35
+ </div>
36
+ );
37
+ }
package/src/Input.tsx CHANGED
@@ -1,30 +1,30 @@
1
- import { cn } from './cn';
2
-
3
- export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
4
- label?: string;
5
- error?: string;
6
- }
7
-
8
- export function Input({ label, error, className, id, ...props }: InputProps) {
9
- return (
10
- <div className="w-full">
11
- {label && (
12
- <label htmlFor={id} className="mb-1 block text-sm font-medium text-neutral-700">
13
- {label}
14
- </label>
15
- )}
16
- <input
17
- id={id}
18
- className={cn(
19
- 'w-full rounded-lg border bg-white px-4 py-2.5 text-sm text-neutral-900 placeholder:text-neutral-400 focus:outline-none focus:ring-2',
20
- error
21
- ? 'border-red-500 focus:border-red-500 focus:ring-red-500/30'
22
- : 'border-neutral-300 focus:border-primary-600 focus:ring-primary-500/30',
23
- className
24
- )}
25
- {...props}
26
- />
27
- {error && <p className="mt-1 text-xs text-red-600">{error}</p>}
28
- </div>
29
- );
30
- }
1
+ import { cn } from './cn';
2
+
3
+ export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {
4
+ label?: string;
5
+ error?: string;
6
+ }
7
+
8
+ export function Input({ label, error, className, id, ...props }: InputProps) {
9
+ return (
10
+ <div className="w-full">
11
+ {label && (
12
+ <label htmlFor={id} className="mb-1 block text-sm font-medium text-slate-700">
13
+ {label}
14
+ </label>
15
+ )}
16
+ <input
17
+ id={id}
18
+ className={cn(
19
+ 'w-full rounded-lg border bg-white px-4 py-2.5 text-sm text-slate-900 placeholder:text-slate-500 focus:outline-none focus:ring-2',
20
+ error
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
+ className
24
+ )}
25
+ {...props}
26
+ />
27
+ {error && <p className="mt-1 text-xs text-red-600">{error}</p>}
28
+ </div>
29
+ );
30
+ }
package/src/Link.tsx ADDED
@@ -0,0 +1,22 @@
1
+ import { ExternalLink } from 'lucide-react';
2
+ import { cn } from './cn';
3
+
4
+ export interface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
5
+ external?: boolean;
6
+ }
7
+
8
+ export function Link({ external = false, className, children, ...props }: LinkProps) {
9
+ return (
10
+ <a
11
+ className={cn(
12
+ 'inline-flex items-center gap-1 font-medium text-lime-700 hover:text-lime-800 hover:underline focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-lime-500/40 rounded-sm',
13
+ className
14
+ )}
15
+ {...(external ? { target: '_blank', rel: 'noreferrer' } : {})}
16
+ {...props}
17
+ >
18
+ {children}
19
+ {external && <ExternalLink aria-hidden="true" className="h-3.5 w-3.5" />}
20
+ </a>
21
+ );
22
+ }
package/src/Menu.tsx ADDED
@@ -0,0 +1,73 @@
1
+ import { useEffect, useRef, useState } from 'react';
2
+ import { cn } from './cn';
3
+
4
+ export interface MenuItem {
5
+ label: string;
6
+ onSelect?: () => void;
7
+ danger?: boolean;
8
+ disabled?: boolean;
9
+ icon?: React.ReactNode;
10
+ }
11
+
12
+ export interface MenuProps {
13
+ trigger: React.ReactNode;
14
+ items: MenuItem[];
15
+ align?: 'start' | 'end';
16
+ className?: string;
17
+ }
18
+
19
+ export function Menu({ trigger, items, align = 'end', className }: MenuProps) {
20
+ const [open, setOpen] = useState(false);
21
+ const ref = useRef<HTMLDivElement>(null);
22
+
23
+ useEffect(() => {
24
+ if (!open) return;
25
+ const onDown = (e: MouseEvent) => {
26
+ if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false);
27
+ };
28
+ const onKey = (e: KeyboardEvent) => {
29
+ if (e.key === 'Escape') setOpen(false);
30
+ };
31
+ document.addEventListener('mousedown', onDown);
32
+ document.addEventListener('keydown', onKey);
33
+ return () => {
34
+ document.removeEventListener('mousedown', onDown);
35
+ document.removeEventListener('keydown', onKey);
36
+ };
37
+ }, [open]);
38
+
39
+ return (
40
+ <div ref={ref} className={cn('relative inline-flex', className)}>
41
+ <div onClick={() => setOpen(v => !v)}>{trigger}</div>
42
+ {open && (
43
+ <div
44
+ role="menu"
45
+ className={cn(
46
+ 'absolute z-50 mt-1.5 min-w-40 overflow-hidden rounded-lg border border-slate-200 bg-white py-1 shadow-lg',
47
+ align === 'end' ? 'right-0' : 'left-0'
48
+ )}
49
+ >
50
+ {items.map((item, i) => (
51
+ <button
52
+ key={`${item.label}-${i}`}
53
+ type="button"
54
+ role="menuitem"
55
+ disabled={item.disabled}
56
+ onClick={() => {
57
+ setOpen(false);
58
+ item.onSelect?.();
59
+ }}
60
+ className={cn(
61
+ 'flex w-full items-center gap-2.5 px-4 py-2 text-left text-sm transition-colors disabled:opacity-50 focus-visible:outline-none focus-visible:bg-slate-100',
62
+ item.danger ? 'text-red-700 hover:bg-red-50' : 'text-slate-700 hover:bg-slate-50'
63
+ )}
64
+ >
65
+ {item.icon}
66
+ <span className="flex-1">{item.label}</span>
67
+ </button>
68
+ ))}
69
+ </div>
70
+ )}
71
+ </div>
72
+ );
73
+ }
package/src/Modal.tsx CHANGED
@@ -1,62 +1,62 @@
1
- import { useEffect } from 'react';
2
- import { createPortal } from 'react-dom';
3
- import { X } from 'lucide-react';
4
- import { cn } from './cn';
5
-
6
- export interface ModalProps {
7
- open: boolean;
8
- onClose: () => void;
9
- title?: string;
10
- children?: React.ReactNode;
11
- className?: string;
12
- maxWidth?: string;
13
- }
14
-
15
- export function Modal({
16
- open,
17
- onClose,
18
- title,
19
- children,
20
- className,
21
- maxWidth = 'max-w-md',
22
- }: ModalProps) {
23
- useEffect(() => {
24
- if (!open) return;
25
- const onKey = (e: KeyboardEvent) => {
26
- if (e.key === 'Escape') onClose();
27
- };
28
- document.body.style.overflow = 'hidden';
29
- document.addEventListener('keydown', onKey);
30
- return () => {
31
- document.body.style.overflow = '';
32
- document.removeEventListener('keydown', onKey);
33
- };
34
- }, [open, onClose]);
35
-
36
- if (!open) return null;
37
-
38
- return createPortal(
39
- <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4">
40
- <div
41
- className={cn('w-full rounded-2xl bg-white shadow-xl', maxWidth, className)}
42
- role="dialog"
43
- aria-modal="true"
44
- >
45
- {title && (
46
- <div className="flex items-center justify-between border-b border-neutral-100 px-6 py-4">
47
- <h2 className="text-lg font-bold text-neutral-900">{title}</h2>
48
- <button
49
- onClick={onClose}
50
- className="rounded-lg p-1 text-neutral-400 hover:bg-neutral-100"
51
- aria-label="Close"
52
- >
53
- <X className="h-5 w-5" />
54
- </button>
55
- </div>
56
- )}
57
- {children}
58
- </div>
59
- </div>,
60
- document.body
61
- );
62
- }
1
+ import { useEffect } from 'react';
2
+ import { createPortal } from 'react-dom';
3
+ import { X } from 'lucide-react';
4
+ import { cn } from './cn';
5
+
6
+ export interface ModalProps {
7
+ open: boolean;
8
+ onClose: () => void;
9
+ title?: string;
10
+ children?: React.ReactNode;
11
+ className?: string;
12
+ maxWidth?: string;
13
+ }
14
+
15
+ export function Modal({
16
+ open,
17
+ onClose,
18
+ title,
19
+ children,
20
+ className,
21
+ maxWidth = 'max-w-md',
22
+ }: ModalProps) {
23
+ useEffect(() => {
24
+ if (!open) return;
25
+ const onKey = (e: KeyboardEvent) => {
26
+ if (e.key === 'Escape') onClose();
27
+ };
28
+ document.body.style.overflow = 'hidden';
29
+ document.addEventListener('keydown', onKey);
30
+ return () => {
31
+ document.body.style.overflow = '';
32
+ document.removeEventListener('keydown', onKey);
33
+ };
34
+ }, [open, onClose]);
35
+
36
+ if (!open) return null;
37
+
38
+ return createPortal(
39
+ <div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4">
40
+ <div
41
+ className={cn('w-full rounded-2xl bg-white shadow-xl', maxWidth, className)}
42
+ role="dialog"
43
+ aria-modal="true"
44
+ >
45
+ {title && (
46
+ <div className="flex items-center justify-between border-b border-slate-100 px-6 py-4">
47
+ <h2 className="text-lg font-bold text-slate-900">{title}</h2>
48
+ <button
49
+ onClick={onClose}
50
+ className="rounded-lg p-1 text-slate-400 hover:bg-slate-100"
51
+ aria-label="Close"
52
+ >
53
+ <X className="h-5 w-5" />
54
+ </button>
55
+ </div>
56
+ )}
57
+ {children}
58
+ </div>
59
+ </div>,
60
+ document.body
61
+ );
62
+ }
@@ -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
+ }
@@ -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
+ }
@@ -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
+ }