@thangnqdev/ui 0.2.1 → 0.2.3

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 (190) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +144 -142
  3. package/bin/cli.js +125 -125
  4. package/dist/bento/index.cjs.map +1 -1
  5. package/dist/bento/index.js +2 -2
  6. package/dist/buttons/index.cjs.map +1 -1
  7. package/dist/buttons/index.js +3 -3
  8. package/dist/{chunk-EXFR2BFJ.js → chunk-2ANJFOIU.js} +38 -36
  9. package/dist/chunk-2ANJFOIU.js.map +1 -0
  10. package/dist/{chunk-77KTYOMQ.js → chunk-2OXZK6IP.js} +3 -3
  11. package/dist/chunk-2OXZK6IP.js.map +1 -0
  12. package/dist/{chunk-4CRFNALF.js → chunk-4GNFT2ZJ.js} +7 -7
  13. package/dist/chunk-4GNFT2ZJ.js.map +1 -0
  14. package/dist/{chunk-2YJBW4E2.js → chunk-4S6L5V7X.js} +2 -2
  15. package/dist/chunk-4S6L5V7X.js.map +1 -0
  16. package/dist/{chunk-I2FQBMVW.js → chunk-66VWUJEI.js} +3 -3
  17. package/dist/chunk-66VWUJEI.js.map +1 -0
  18. package/dist/{chunk-YOCGBORV.js → chunk-7NMB2Y64.js} +4 -4
  19. package/dist/chunk-7NMB2Y64.js.map +1 -0
  20. package/dist/{chunk-V52JOSDF.js → chunk-A7P3O5Z5.js} +3 -3
  21. package/dist/chunk-A7P3O5Z5.js.map +1 -0
  22. package/dist/{chunk-ME4XILG5.js → chunk-ATYGDTMK.js} +5 -5
  23. package/dist/chunk-ATYGDTMK.js.map +1 -0
  24. package/dist/{chunk-S6XJMYME.js → chunk-C4SUXMI3.js} +3 -3
  25. package/dist/chunk-C4SUXMI3.js.map +1 -0
  26. package/dist/{chunk-I5O2WCGF.js → chunk-EU2LPUYP.js} +3 -3
  27. package/dist/chunk-EU2LPUYP.js.map +1 -0
  28. package/dist/{chunk-D7FB3TCA.js → chunk-GXI2H5XA.js} +3 -3
  29. package/dist/chunk-GXI2H5XA.js.map +1 -0
  30. package/dist/{chunk-ADO3SVUA.js → chunk-IABPUCAQ.js} +2 -2
  31. package/dist/chunk-IABPUCAQ.js.map +1 -0
  32. package/dist/{chunk-PC5SZFZC.js → chunk-JOKEKOP3.js} +8 -8
  33. package/dist/chunk-JOKEKOP3.js.map +1 -0
  34. package/dist/{chunk-GXWB6BSY.js → chunk-KUQWUTZA.js} +4 -4
  35. package/dist/chunk-KUQWUTZA.js.map +1 -0
  36. package/dist/{chunk-ZEDXARXW.js → chunk-U3J4UPV3.js} +2 -2
  37. package/dist/chunk-U3J4UPV3.js.map +1 -0
  38. package/dist/{chunk-DSEL7ELZ.js → chunk-VE2PNSDQ.js} +4 -4
  39. package/dist/chunk-VE2PNSDQ.js.map +1 -0
  40. package/dist/{chunk-YJ64RI7J.js → chunk-WAFHC4DQ.js} +3 -3
  41. package/dist/chunk-WAFHC4DQ.js.map +1 -0
  42. package/dist/{chunk-W5WNWTQC.js → chunk-YJ67WYVW.js} +5 -5
  43. package/dist/chunk-YJ67WYVW.js.map +1 -0
  44. package/dist/{chunk-4MS6ZHFQ.js → chunk-Z427NPMU.js} +7 -7
  45. package/dist/chunk-Z427NPMU.js.map +1 -0
  46. package/dist/core/index.cjs +34 -32
  47. package/dist/core/index.cjs.map +1 -1
  48. package/dist/core/index.js +2 -2
  49. package/dist/data-display/index.cjs.map +1 -1
  50. package/dist/data-display/index.js +5 -5
  51. package/dist/feedback/index.cjs.map +1 -1
  52. package/dist/feedback/index.js +2 -2
  53. package/dist/forms/index.cjs.map +1 -1
  54. package/dist/forms/index.js +8 -8
  55. package/dist/glass/index.cjs.map +1 -1
  56. package/dist/glass/index.js +2 -2
  57. package/dist/index.cjs +34 -32
  58. package/dist/index.cjs.map +1 -1
  59. package/dist/index.js +19 -19
  60. package/dist/layout/index.cjs.map +1 -1
  61. package/dist/layout/index.js +2 -2
  62. package/dist/navigation/index.cjs.map +1 -1
  63. package/dist/navigation/index.js +6 -6
  64. package/dist/overlays/index.cjs.map +1 -1
  65. package/dist/overlays/index.js +7 -7
  66. package/dist/reset.css +45 -45
  67. package/dist/tokens.css +11 -11
  68. package/dist/typography/index.cjs.map +1 -1
  69. package/dist/typography/index.js +4 -4
  70. package/llms.txt +3 -3
  71. package/package.json +165 -165
  72. package/scripts/postinstall.js +125 -125
  73. package/src/bento/BentoCard.tsx +140 -140
  74. package/src/bento/BentoGrid.tsx +50 -50
  75. package/src/bento/index.ts +2 -2
  76. package/src/bento/tokens.css +46 -46
  77. package/src/buttons/Button.tsx +104 -104
  78. package/src/buttons/ButtonGroup.tsx +43 -43
  79. package/src/buttons/IconButton.tsx +79 -79
  80. package/src/buttons/SplitButton.tsx +186 -186
  81. package/src/buttons/ToggleButton.tsx +157 -157
  82. package/src/buttons/index.ts +5 -5
  83. package/src/buttons/tokens.css +6 -6
  84. package/src/core/ThemeProvider.tsx +124 -106
  85. package/src/core/index.ts +2 -2
  86. package/src/core/tokens.css +134 -134
  87. package/src/data-display/Accordion.tsx +147 -147
  88. package/src/data-display/Avatar.tsx +134 -134
  89. package/src/data-display/Card.tsx +112 -112
  90. package/src/data-display/Chip.tsx +74 -74
  91. package/src/data-display/DataTablePro.tsx +534 -534
  92. package/src/data-display/StatCard.tsx +60 -60
  93. package/src/data-display/Table.tsx +74 -74
  94. package/src/data-display/Timeline.tsx +62 -62
  95. package/src/data-display/TreeView.tsx +279 -279
  96. package/src/data-display/tokens.css +4 -4
  97. package/src/feedback/Alert.tsx +80 -80
  98. package/src/feedback/EmptyState.tsx +45 -45
  99. package/src/feedback/Skeleton.tsx +66 -66
  100. package/src/feedback/Spinner.tsx +65 -65
  101. package/src/feedback/index.ts +5 -5
  102. package/src/feedback/tokens.css +4 -4
  103. package/src/forms/Checkbox.tsx +149 -149
  104. package/src/forms/CheckboxGroup.tsx +76 -76
  105. package/src/forms/Combobox.tsx +512 -512
  106. package/src/forms/DatePicker.tsx +784 -784
  107. package/src/forms/FileUpload.tsx +266 -266
  108. package/src/forms/FormField.tsx +115 -115
  109. package/src/forms/Input.tsx +151 -151
  110. package/src/forms/NumberInput.tsx +262 -262
  111. package/src/forms/PasswordInput.tsx +35 -35
  112. package/src/forms/PinInput.tsx +139 -139
  113. package/src/forms/Radio.tsx +142 -142
  114. package/src/forms/RangeSlider.tsx +237 -237
  115. package/src/forms/SearchInput.tsx +34 -34
  116. package/src/forms/Select.tsx +103 -103
  117. package/src/forms/Slider.tsx +85 -85
  118. package/src/forms/Textarea.tsx +114 -114
  119. package/src/forms/tokens.css +6 -6
  120. package/src/glass/GlassButton.tsx +59 -59
  121. package/src/glass/GlassCard.tsx +71 -71
  122. package/src/glass/index.ts +3 -3
  123. package/src/glass/tokens.css +81 -81
  124. package/src/index.ts +26 -26
  125. package/src/layout/AspectRatio.tsx +39 -39
  126. package/src/layout/Container.tsx +53 -53
  127. package/src/layout/Divider.tsx +61 -61
  128. package/src/layout/Flex.tsx +79 -79
  129. package/src/layout/Grid.tsx +124 -124
  130. package/src/layout/PageLayout.tsx +59 -59
  131. package/src/layout/Section.tsx +47 -47
  132. package/src/layout/Spacer.tsx +30 -30
  133. package/src/layout/Stack.tsx +88 -88
  134. package/src/layout/tokens.css +8 -8
  135. package/src/navigation/Breadcrumb.tsx +73 -73
  136. package/src/navigation/CommandPalette.tsx +142 -142
  137. package/src/navigation/DropdownMenu.tsx +244 -244
  138. package/src/navigation/Pagination.tsx +114 -114
  139. package/src/navigation/Stepper.tsx +93 -93
  140. package/src/navigation/Tabs.tsx +265 -265
  141. package/src/navigation/index.ts +6 -6
  142. package/src/navigation/tokens.css +4 -4
  143. package/src/overlays/AlertDialog.tsx +63 -63
  144. package/src/overlays/BottomSheet.tsx +143 -143
  145. package/src/overlays/ContextMenu.tsx +161 -161
  146. package/src/overlays/Drawer.tsx +160 -160
  147. package/src/overlays/FocusTrap.tsx +122 -122
  148. package/src/overlays/Modal.tsx +296 -296
  149. package/src/overlays/Popover.tsx +156 -156
  150. package/src/overlays/Portal.tsx +23 -23
  151. package/src/overlays/Toast.tsx +175 -175
  152. package/src/overlays/Tooltip.tsx +125 -125
  153. package/src/overlays/tokens.css +8 -8
  154. package/src/registry/components.ts +1368 -1368
  155. package/src/styles/components.css +39 -39
  156. package/src/styles/index.css +5 -5
  157. package/src/styles/reset.css +45 -45
  158. package/src/styles/tokens.css +11 -11
  159. package/src/typography/Blockquote.tsx +32 -32
  160. package/src/typography/Code.tsx +89 -89
  161. package/src/typography/Heading.tsx +56 -56
  162. package/src/typography/Kbd.tsx +25 -25
  163. package/src/typography/Label.tsx +47 -47
  164. package/src/typography/Link.tsx +56 -56
  165. package/src/typography/Text.tsx +62 -62
  166. package/src/typography/index.ts +7 -7
  167. package/src/typography/tokens.css +5 -5
  168. package/src/utils/cn.ts +6 -6
  169. package/src/utils/scroll-lock.ts +19 -19
  170. package/src/utils/useControllableState.ts +54 -54
  171. package/ui-contract.json +1 -1
  172. package/dist/chunk-2YJBW4E2.js.map +0 -1
  173. package/dist/chunk-4CRFNALF.js.map +0 -1
  174. package/dist/chunk-4MS6ZHFQ.js.map +0 -1
  175. package/dist/chunk-77KTYOMQ.js.map +0 -1
  176. package/dist/chunk-ADO3SVUA.js.map +0 -1
  177. package/dist/chunk-D7FB3TCA.js.map +0 -1
  178. package/dist/chunk-DSEL7ELZ.js.map +0 -1
  179. package/dist/chunk-EXFR2BFJ.js.map +0 -1
  180. package/dist/chunk-GXWB6BSY.js.map +0 -1
  181. package/dist/chunk-I2FQBMVW.js.map +0 -1
  182. package/dist/chunk-I5O2WCGF.js.map +0 -1
  183. package/dist/chunk-ME4XILG5.js.map +0 -1
  184. package/dist/chunk-PC5SZFZC.js.map +0 -1
  185. package/dist/chunk-S6XJMYME.js.map +0 -1
  186. package/dist/chunk-V52JOSDF.js.map +0 -1
  187. package/dist/chunk-W5WNWTQC.js.map +0 -1
  188. package/dist/chunk-YJ64RI7J.js.map +0 -1
  189. package/dist/chunk-YOCGBORV.js.map +0 -1
  190. package/dist/chunk-ZEDXARXW.js.map +0 -1
@@ -1,161 +1,161 @@
1
- import React, { useState, useEffect, useRef, forwardRef } from 'react';
2
- import { cn } from '../utils/cn';
3
- import { Portal } from './Portal';
4
- import { Kbd } from '../typography/Kbd';
5
-
6
- export interface ContextMenuItemProps extends React.HTMLAttributes<HTMLDivElement> {
7
- icon?: React.ReactNode;
8
- shortcut?: string;
9
- disabled?: boolean;
10
- destructive?: boolean;
11
- onSelect?: () => void;
12
- }
13
-
14
- export const ContextMenuItem: React.FC<ContextMenuItemProps> = ({
15
- icon,
16
- shortcut,
17
- disabled = false,
18
- destructive = false,
19
- onSelect,
20
- children,
21
- className,
22
- ...props
23
- }) => {
24
- return (
25
- <div
26
- role="menuitem"
27
- tabIndex={disabled ? -1 : 0}
28
- aria-disabled={disabled}
29
- onClick={() => {
30
- if (!disabled) onSelect?.();
31
- }}
32
- onKeyDown={(e) => {
33
- if (!disabled && (e.key === 'Enter' || e.key === ' ')) {
34
- e.preventDefault();
35
- onSelect?.();
36
- }
37
- }}
38
- className={cn(
39
- 'flex items-center justify-between px-3 py-1.5 rounded-xl text-xs font-medium cursor-pointer transition-colors select-none focus:outline-none focus:bg-[var(--ui-bg-tertiary)]',
40
- disabled && 'opacity-40 cursor-not-allowed pointer-events-none',
41
- destructive
42
- ? 'text-rose-500 hover:bg-rose-500/10 focus:bg-rose-500/10'
43
- : 'text-[var(--ui-text-primary)] hover:bg-[var(--ui-bg-tertiary)]',
44
- className
45
- )}
46
- {...props}
47
- >
48
- <div className="flex items-center gap-2 truncate">
49
- {icon && <span className="w-4 h-4 shrink-0">{icon}</span>}
50
- <span className="truncate">{children}</span>
51
- </div>
52
-
53
- {shortcut && <Kbd className="text-[10px] py-0 px-1">{shortcut}</Kbd>}
54
- </div>
55
- );
56
- };
57
-
58
- export const ContextMenuSeparator: React.FC = () => (
59
- <div className="h-px my-1 bg-[var(--ui-border-subtle)]" role="separator" />
60
- );
61
-
62
- export interface ContextMenuProps {
63
- children: React.ReactNode;
64
- menuContent: React.ReactNode;
65
- className?: string;
66
- }
67
-
68
- export const ContextMenu = forwardRef<HTMLDivElement, ContextMenuProps>(
69
- ({ children, menuContent, className }, ref) => {
70
- const [isOpen, setIsOpen] = useState(false);
71
- const [position, setPosition] = useState<{ x: number; y: number }>({ x: 0, y: 0 });
72
- const menuRef = useRef<HTMLDivElement | null>(null);
73
-
74
- const handleContextMenu = (e: React.MouseEvent) => {
75
- e.preventDefault();
76
- const x = Math.min(window.innerWidth - 220, e.clientX);
77
- const y = Math.min(window.innerHeight - 260, e.clientY);
78
- setPosition({ x, y });
79
- setIsOpen(true);
80
- };
81
-
82
- useEffect(() => {
83
- if (!isOpen) return;
84
-
85
- const timer = setTimeout(() => {
86
- const firstItem = menuRef.current?.querySelector<HTMLElement>('[role="menuitem"]:not([aria-disabled="true"])');
87
- firstItem?.focus();
88
- }, 10);
89
-
90
- const handleClickOutside = (e: MouseEvent) => {
91
- if (menuRef.current && !menuRef.current.contains(e.target as Node)) {
92
- setIsOpen(false);
93
- }
94
- };
95
-
96
- const handleKeyDown = (e: KeyboardEvent) => {
97
- if (!menuRef.current) return;
98
- const items = Array.from(
99
- menuRef.current.querySelectorAll<HTMLElement>('[role="menuitem"]:not([aria-disabled="true"])')
100
- );
101
- if (items.length === 0) return;
102
-
103
- const currentIndex = items.indexOf(document.activeElement as HTMLElement);
104
-
105
- if (e.key === 'ArrowDown') {
106
- e.preventDefault();
107
- const nextIndex = currentIndex === -1 ? 0 : (currentIndex + 1) % items.length;
108
- items[nextIndex]?.focus();
109
- } else if (e.key === 'ArrowUp') {
110
- e.preventDefault();
111
- const prevIndex = currentIndex === -1 ? items.length - 1 : (currentIndex - 1 + items.length) % items.length;
112
- items[prevIndex]?.focus();
113
- } else if (e.key === 'Home') {
114
- e.preventDefault();
115
- items[0]?.focus();
116
- } else if (e.key === 'End') {
117
- e.preventDefault();
118
- items[items.length - 1]?.focus();
119
- } else if (e.key === 'Escape') {
120
- e.preventDefault();
121
- setIsOpen(false);
122
- }
123
- };
124
-
125
- window.addEventListener('click', handleClickOutside);
126
- window.addEventListener('contextmenu', handleClickOutside);
127
- window.addEventListener('keydown', handleKeyDown);
128
-
129
- return () => {
130
- clearTimeout(timer);
131
- window.removeEventListener('click', handleClickOutside);
132
- window.removeEventListener('contextmenu', handleClickOutside);
133
- window.removeEventListener('keydown', handleKeyDown);
134
- };
135
- }, [isOpen]);
136
-
137
- return (
138
- <>
139
- <div ref={ref} onContextMenu={handleContextMenu} className={className}>
140
- {children}
141
- </div>
142
-
143
- {isOpen && (
144
- <Portal>
145
- <div
146
- ref={menuRef}
147
- role="menu"
148
- tabIndex={-1}
149
- style={{ top: `${position.y}px`, left: `${position.x}px` }}
150
- onClick={() => setIsOpen(false)}
151
- className="fixed z-50 min-w-48 p-1.5 rounded-2xl bg-[var(--ui-bg-surface)]/90 backdrop-blur-3xl border border-[var(--ui-border-default)] shadow-2xl space-y-0.5 animate-in fade-in zoom-in-95 duration-150 focus:outline-none"
152
- >
153
- {menuContent}
154
- </div>
155
- </Portal>
156
- )}
157
- </>
158
- );
159
- }
160
- );
161
- ContextMenu.displayName = 'ContextMenu';
1
+ import React, { useState, useEffect, useRef, forwardRef } from 'react';
2
+ import { cn } from '../utils/cn';
3
+ import { Portal } from './Portal';
4
+ import { Kbd } from '../typography/Kbd';
5
+
6
+ export interface ContextMenuItemProps extends React.HTMLAttributes<HTMLDivElement> {
7
+ icon?: React.ReactNode;
8
+ shortcut?: string;
9
+ disabled?: boolean;
10
+ destructive?: boolean;
11
+ onSelect?: () => void;
12
+ }
13
+
14
+ export const ContextMenuItem: React.FC<ContextMenuItemProps> = ({
15
+ icon,
16
+ shortcut,
17
+ disabled = false,
18
+ destructive = false,
19
+ onSelect,
20
+ children,
21
+ className,
22
+ ...props
23
+ }) => {
24
+ return (
25
+ <div
26
+ role="menuitem"
27
+ tabIndex={disabled ? -1 : 0}
28
+ aria-disabled={disabled}
29
+ onClick={() => {
30
+ if (!disabled) onSelect?.();
31
+ }}
32
+ onKeyDown={(e) => {
33
+ if (!disabled && (e.key === 'Enter' || e.key === ' ')) {
34
+ e.preventDefault();
35
+ onSelect?.();
36
+ }
37
+ }}
38
+ className={cn(
39
+ 'flex items-center justify-between px-3 py-1.5 rounded-xl text-xs font-medium cursor-pointer transition-colors select-none focus:outline-none focus:bg-[var(--ui-bg-tertiary)]',
40
+ disabled && 'opacity-40 cursor-not-allowed pointer-events-none',
41
+ destructive
42
+ ? 'text-rose-500 hover:bg-rose-500/10 focus:bg-rose-500/10'
43
+ : 'text-[var(--ui-text-primary)] hover:bg-[var(--ui-bg-tertiary)]',
44
+ className
45
+ )}
46
+ {...props}
47
+ >
48
+ <div className="flex items-center gap-2 truncate">
49
+ {icon && <span className="w-4 h-4 shrink-0">{icon}</span>}
50
+ <span className="truncate">{children}</span>
51
+ </div>
52
+
53
+ {shortcut && <Kbd className="text-[10px] py-0 px-1">{shortcut}</Kbd>}
54
+ </div>
55
+ );
56
+ };
57
+
58
+ export const ContextMenuSeparator: React.FC = () => (
59
+ <div className="h-px my-1 bg-[var(--ui-border-subtle)]" role="separator" />
60
+ );
61
+
62
+ export interface ContextMenuProps {
63
+ children: React.ReactNode;
64
+ menuContent: React.ReactNode;
65
+ className?: string;
66
+ }
67
+
68
+ export const ContextMenu = forwardRef<HTMLDivElement, ContextMenuProps>(
69
+ ({ children, menuContent, className }, ref) => {
70
+ const [isOpen, setIsOpen] = useState(false);
71
+ const [position, setPosition] = useState<{ x: number; y: number }>({ x: 0, y: 0 });
72
+ const menuRef = useRef<HTMLDivElement | null>(null);
73
+
74
+ const handleContextMenu = (e: React.MouseEvent) => {
75
+ e.preventDefault();
76
+ const x = Math.min(window.innerWidth - 220, e.clientX);
77
+ const y = Math.min(window.innerHeight - 260, e.clientY);
78
+ setPosition({ x, y });
79
+ setIsOpen(true);
80
+ };
81
+
82
+ useEffect(() => {
83
+ if (!isOpen) return;
84
+
85
+ const timer = setTimeout(() => {
86
+ const firstItem = menuRef.current?.querySelector<HTMLElement>('[role="menuitem"]:not([aria-disabled="true"])');
87
+ firstItem?.focus();
88
+ }, 10);
89
+
90
+ const handleClickOutside = (e: MouseEvent) => {
91
+ if (menuRef.current && !menuRef.current.contains(e.target as Node)) {
92
+ setIsOpen(false);
93
+ }
94
+ };
95
+
96
+ const handleKeyDown = (e: KeyboardEvent) => {
97
+ if (!menuRef.current) return;
98
+ const items = Array.from(
99
+ menuRef.current.querySelectorAll<HTMLElement>('[role="menuitem"]:not([aria-disabled="true"])')
100
+ );
101
+ if (items.length === 0) return;
102
+
103
+ const currentIndex = items.indexOf(document.activeElement as HTMLElement);
104
+
105
+ if (e.key === 'ArrowDown') {
106
+ e.preventDefault();
107
+ const nextIndex = currentIndex === -1 ? 0 : (currentIndex + 1) % items.length;
108
+ items[nextIndex]?.focus();
109
+ } else if (e.key === 'ArrowUp') {
110
+ e.preventDefault();
111
+ const prevIndex = currentIndex === -1 ? items.length - 1 : (currentIndex - 1 + items.length) % items.length;
112
+ items[prevIndex]?.focus();
113
+ } else if (e.key === 'Home') {
114
+ e.preventDefault();
115
+ items[0]?.focus();
116
+ } else if (e.key === 'End') {
117
+ e.preventDefault();
118
+ items[items.length - 1]?.focus();
119
+ } else if (e.key === 'Escape') {
120
+ e.preventDefault();
121
+ setIsOpen(false);
122
+ }
123
+ };
124
+
125
+ window.addEventListener('click', handleClickOutside);
126
+ window.addEventListener('contextmenu', handleClickOutside);
127
+ window.addEventListener('keydown', handleKeyDown);
128
+
129
+ return () => {
130
+ clearTimeout(timer);
131
+ window.removeEventListener('click', handleClickOutside);
132
+ window.removeEventListener('contextmenu', handleClickOutside);
133
+ window.removeEventListener('keydown', handleKeyDown);
134
+ };
135
+ }, [isOpen]);
136
+
137
+ return (
138
+ <>
139
+ <div ref={ref} onContextMenu={handleContextMenu} className={className}>
140
+ {children}
141
+ </div>
142
+
143
+ {isOpen && (
144
+ <Portal>
145
+ <div
146
+ ref={menuRef}
147
+ role="menu"
148
+ tabIndex={-1}
149
+ style={{ top: `${position.y}px`, left: `${position.x}px` }}
150
+ onClick={() => setIsOpen(false)}
151
+ className="fixed z-50 min-w-48 p-1.5 rounded-2xl bg-[var(--ui-bg-surface)]/90 backdrop-blur-3xl border border-[var(--ui-border-default)] shadow-2xl space-y-0.5 animate-in fade-in zoom-in-95 duration-150 focus:outline-none"
152
+ >
153
+ {menuContent}
154
+ </div>
155
+ </Portal>
156
+ )}
157
+ </>
158
+ );
159
+ }
160
+ );
161
+ ContextMenu.displayName = 'ContextMenu';
@@ -1,160 +1,160 @@
1
- import React, { forwardRef, createContext, useContext, useEffect, useId } from 'react';
2
- import { cva, type VariantProps } from 'class-variance-authority';
3
- import { X } from 'lucide-react';
4
- import { Portal } from './Portal';
5
- import { FocusTrap } from './FocusTrap';
6
- import { lockBodyScroll, unlockBodyScroll } from '../utils/scroll-lock';
7
- import { cn } from '../utils/cn';
8
-
9
- interface DrawerContextType {
10
- isOpen: boolean;
11
- onClose: () => void;
12
- titleId: string;
13
- }
14
-
15
- const DrawerContext = createContext<DrawerContextType | null>(null);
16
-
17
- export function useDrawer() {
18
- const context = useContext(DrawerContext);
19
- if (!context) {
20
- throw new Error('Drawer compound components must be used within a <Drawer />');
21
- }
22
- return context;
23
- }
24
-
25
- export const drawerVariants = cva(
26
- 'fixed z-50 bg-[var(--ui-bg-surface)] text-[var(--ui-text-primary)] border-[var(--ui-border-default)] shadow-2xl transition-transform duration-300 ease-in-out flex flex-col',
27
- {
28
- variants: {
29
- placement: {
30
- right: 'inset-y-0 right-0 h-full w-full sm:max-w-md border-l animate-in slide-in-from-right',
31
- left: 'inset-y-0 left-0 h-full w-full sm:max-w-md border-r animate-in slide-in-from-left',
32
- top: 'inset-x-0 top-0 w-full max-h-[80vh] border-b animate-in slide-in-from-top',
33
- bottom: 'inset-x-0 bottom-0 w-full max-h-[80vh] border-t rounded-t-[var(--ui-radius-xl)] animate-in slide-in-from-bottom',
34
- },
35
- },
36
- defaultVariants: {
37
- placement: 'right',
38
- },
39
- }
40
- );
41
-
42
- export interface DrawerProps extends VariantProps<typeof drawerVariants> {
43
- isOpen: boolean;
44
- onClose: () => void;
45
- children: React.ReactNode;
46
- closeOnEsc?: boolean;
47
- 'aria-label'?: string;
48
- 'aria-labelledby'?: string;
49
- }
50
-
51
- export function Drawer({
52
- isOpen,
53
- onClose,
54
- placement = 'right',
55
- children,
56
- closeOnEsc = true,
57
- 'aria-label': ariaLabel,
58
- 'aria-labelledby': customLabelledBy,
59
- }: DrawerProps) {
60
- const generatedId = useId();
61
- const titleId = customLabelledBy || `drawer-title-${generatedId}`;
62
-
63
- useEffect(() => {
64
- if (!isOpen) return;
65
-
66
- lockBodyScroll();
67
-
68
- const handleKeyDown = (e: KeyboardEvent) => {
69
- if (closeOnEsc && e.key === 'Escape') {
70
- onClose();
71
- }
72
- };
73
-
74
- window.addEventListener('keydown', handleKeyDown);
75
- return () => {
76
- window.removeEventListener('keydown', handleKeyDown);
77
- unlockBodyScroll();
78
- };
79
- }, [isOpen, closeOnEsc, onClose]);
80
-
81
- if (!isOpen) return null;
82
-
83
- return (
84
- <Portal>
85
- <DrawerContext.Provider value={{ isOpen, onClose, titleId }}>
86
- <FocusTrap active={isOpen} restoreFocus={true}>
87
- <div
88
- className="fixed inset-0 z-50 overflow-hidden"
89
- role="dialog"
90
- aria-modal="true"
91
- aria-label={ariaLabel}
92
- aria-labelledby={ariaLabel ? undefined : titleId}
93
- >
94
- {/* Backdrop */}
95
- <div
96
- aria-hidden="true"
97
- onClick={onClose}
98
- className="fixed inset-0 bg-[var(--ui-bg-overlay)] backdrop-blur-sm transition-opacity animate-in fade-in duration-200"
99
- />
100
- {/* Drawer Panel */}
101
- <div className={cn(drawerVariants({ placement }))}>
102
- {children}
103
- </div>
104
- </div>
105
- </FocusTrap>
106
- </DrawerContext.Provider>
107
- </Portal>
108
- );
109
- }
110
-
111
- export const DrawerHeader = forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
112
- ({ className, children, id, ...props }, ref) => {
113
- const { onClose, titleId } = useDrawer();
114
- return (
115
- <div
116
- ref={ref}
117
- id={id || titleId}
118
- className={cn('flex items-center justify-between p-5 border-b border-[var(--ui-border-subtle)]', className)}
119
- {...props}
120
- >
121
- <div className="flex-1 font-semibold text-base text-[var(--ui-text-primary)]">{children}</div>
122
- <button
123
- type="button"
124
- onClick={onClose}
125
- aria-label="Close drawer"
126
- className="p-1.5 rounded-full text-[var(--ui-text-muted)] hover:text-[var(--ui-text-primary)] hover:bg-[var(--ui-bg-tertiary)] transition-colors ml-4 cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--ui-primary)]"
127
- >
128
- <X className="w-4 h-4" />
129
- </button>
130
- </div>
131
- );
132
- }
133
- );
134
- DrawerHeader.displayName = 'DrawerHeader';
135
-
136
- export const DrawerBody = forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
137
- ({ className, children, ...props }, ref) => {
138
- return (
139
- <div ref={ref} className={cn('flex-1 p-5 overflow-y-auto', className)} {...props}>
140
- {children}
141
- </div>
142
- );
143
- }
144
- );
145
- DrawerBody.displayName = 'DrawerBody';
146
-
147
- export const DrawerFooter = forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
148
- ({ className, children, ...props }, ref) => {
149
- return (
150
- <div
151
- ref={ref}
152
- className={cn('p-4 border-t border-[var(--ui-border-subtle)] bg-[var(--ui-bg-secondary)] flex items-center justify-end gap-3', className)}
153
- {...props}
154
- >
155
- {children}
156
- </div>
157
- );
158
- }
159
- );
160
- DrawerFooter.displayName = 'DrawerFooter';
1
+ import React, { forwardRef, createContext, useContext, useEffect, useId } from 'react';
2
+ import { cva, type VariantProps } from 'class-variance-authority';
3
+ import { X } from 'lucide-react';
4
+ import { Portal } from './Portal';
5
+ import { FocusTrap } from './FocusTrap';
6
+ import { lockBodyScroll, unlockBodyScroll } from '../utils/scroll-lock';
7
+ import { cn } from '../utils/cn';
8
+
9
+ interface DrawerContextType {
10
+ isOpen: boolean;
11
+ onClose: () => void;
12
+ titleId: string;
13
+ }
14
+
15
+ const DrawerContext = createContext<DrawerContextType | null>(null);
16
+
17
+ export function useDrawer() {
18
+ const context = useContext(DrawerContext);
19
+ if (!context) {
20
+ throw new Error('Drawer compound components must be used within a <Drawer />');
21
+ }
22
+ return context;
23
+ }
24
+
25
+ export const drawerVariants = cva(
26
+ 'fixed z-50 bg-[var(--ui-bg-surface)] text-[var(--ui-text-primary)] border-[var(--ui-border-default)] shadow-2xl transition-transform duration-300 ease-in-out flex flex-col',
27
+ {
28
+ variants: {
29
+ placement: {
30
+ right: 'inset-y-0 right-0 h-full w-full sm:max-w-md border-l animate-in slide-in-from-right',
31
+ left: 'inset-y-0 left-0 h-full w-full sm:max-w-md border-r animate-in slide-in-from-left',
32
+ top: 'inset-x-0 top-0 w-full max-h-[80vh] border-b animate-in slide-in-from-top',
33
+ bottom: 'inset-x-0 bottom-0 w-full max-h-[80vh] border-t rounded-t-[var(--ui-radius-xl)] animate-in slide-in-from-bottom',
34
+ },
35
+ },
36
+ defaultVariants: {
37
+ placement: 'right',
38
+ },
39
+ }
40
+ );
41
+
42
+ export interface DrawerProps extends VariantProps<typeof drawerVariants> {
43
+ isOpen: boolean;
44
+ onClose: () => void;
45
+ children: React.ReactNode;
46
+ closeOnEsc?: boolean;
47
+ 'aria-label'?: string;
48
+ 'aria-labelledby'?: string;
49
+ }
50
+
51
+ export function Drawer({
52
+ isOpen,
53
+ onClose,
54
+ placement = 'right',
55
+ children,
56
+ closeOnEsc = true,
57
+ 'aria-label': ariaLabel,
58
+ 'aria-labelledby': customLabelledBy,
59
+ }: DrawerProps) {
60
+ const generatedId = useId();
61
+ const titleId = customLabelledBy || `drawer-title-${generatedId}`;
62
+
63
+ useEffect(() => {
64
+ if (!isOpen) return;
65
+
66
+ lockBodyScroll();
67
+
68
+ const handleKeyDown = (e: KeyboardEvent) => {
69
+ if (closeOnEsc && e.key === 'Escape') {
70
+ onClose();
71
+ }
72
+ };
73
+
74
+ window.addEventListener('keydown', handleKeyDown);
75
+ return () => {
76
+ window.removeEventListener('keydown', handleKeyDown);
77
+ unlockBodyScroll();
78
+ };
79
+ }, [isOpen, closeOnEsc, onClose]);
80
+
81
+ if (!isOpen) return null;
82
+
83
+ return (
84
+ <Portal>
85
+ <DrawerContext.Provider value={{ isOpen, onClose, titleId }}>
86
+ <FocusTrap active={isOpen} restoreFocus={true}>
87
+ <div
88
+ className="fixed inset-0 z-50 overflow-hidden"
89
+ role="dialog"
90
+ aria-modal="true"
91
+ aria-label={ariaLabel}
92
+ aria-labelledby={ariaLabel ? undefined : titleId}
93
+ >
94
+ {/* Backdrop */}
95
+ <div
96
+ aria-hidden="true"
97
+ onClick={onClose}
98
+ className="fixed inset-0 bg-[var(--ui-bg-overlay)] backdrop-blur-sm transition-opacity animate-in fade-in duration-200"
99
+ />
100
+ {/* Drawer Panel */}
101
+ <div className={cn(drawerVariants({ placement }))}>
102
+ {children}
103
+ </div>
104
+ </div>
105
+ </FocusTrap>
106
+ </DrawerContext.Provider>
107
+ </Portal>
108
+ );
109
+ }
110
+
111
+ export const DrawerHeader = forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
112
+ ({ className, children, id, ...props }, ref) => {
113
+ const { onClose, titleId } = useDrawer();
114
+ return (
115
+ <div
116
+ ref={ref}
117
+ id={id || titleId}
118
+ className={cn('flex items-center justify-between p-5 border-b border-[var(--ui-border-subtle)]', className)}
119
+ {...props}
120
+ >
121
+ <div className="flex-1 font-semibold text-base text-[var(--ui-text-primary)]">{children}</div>
122
+ <button
123
+ type="button"
124
+ onClick={onClose}
125
+ aria-label="Close drawer"
126
+ className="p-1.5 rounded-full text-[var(--ui-text-muted)] hover:text-[var(--ui-text-primary)] hover:bg-[var(--ui-bg-tertiary)] transition-colors ml-4 cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--ui-primary)]"
127
+ >
128
+ <X className="w-4 h-4" />
129
+ </button>
130
+ </div>
131
+ );
132
+ }
133
+ );
134
+ DrawerHeader.displayName = 'DrawerHeader';
135
+
136
+ export const DrawerBody = forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
137
+ ({ className, children, ...props }, ref) => {
138
+ return (
139
+ <div ref={ref} className={cn('flex-1 p-5 overflow-y-auto', className)} {...props}>
140
+ {children}
141
+ </div>
142
+ );
143
+ }
144
+ );
145
+ DrawerBody.displayName = 'DrawerBody';
146
+
147
+ export const DrawerFooter = forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
148
+ ({ className, children, ...props }, ref) => {
149
+ return (
150
+ <div
151
+ ref={ref}
152
+ className={cn('p-4 border-t border-[var(--ui-border-subtle)] bg-[var(--ui-bg-secondary)] flex items-center justify-end gap-3', className)}
153
+ {...props}
154
+ >
155
+ {children}
156
+ </div>
157
+ );
158
+ }
159
+ );
160
+ DrawerFooter.displayName = 'DrawerFooter';