@thangnqdev/ui 0.1.2 → 0.2.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.
Files changed (231) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +54 -206
  3. package/dist/bento/index.cjs.map +1 -1
  4. package/dist/bento/index.js +2 -2
  5. package/dist/bento/styles.css +2 -46
  6. package/dist/buttons/index.cjs +111 -18
  7. package/dist/buttons/index.cjs.map +1 -1
  8. package/dist/buttons/index.d.cts +1 -1
  9. package/dist/buttons/index.d.ts +1 -1
  10. package/dist/buttons/index.js +3 -3
  11. package/dist/buttons/styles.css +2 -6
  12. package/dist/{chunk-4S6L5V7X.js → chunk-2YJBW4E2.js} +2 -2
  13. package/dist/chunk-2YJBW4E2.js.map +1 -0
  14. package/dist/{chunk-F5Q7BTMH.js → chunk-4CRFNALF.js} +1011 -556
  15. package/dist/chunk-4CRFNALF.js.map +1 -0
  16. package/dist/{chunk-LWFRUJRU.js → chunk-4MS6ZHFQ.js} +225 -41
  17. package/dist/chunk-4MS6ZHFQ.js.map +1 -0
  18. package/dist/{chunk-2OXZK6IP.js → chunk-77KTYOMQ.js} +3 -3
  19. package/dist/chunk-77KTYOMQ.js.map +1 -0
  20. package/dist/{chunk-IABPUCAQ.js → chunk-ADO3SVUA.js} +2 -2
  21. package/dist/chunk-ADO3SVUA.js.map +1 -0
  22. package/dist/{chunk-GXI2H5XA.js → chunk-D7FB3TCA.js} +3 -3
  23. package/dist/chunk-D7FB3TCA.js.map +1 -0
  24. package/dist/chunk-DSEL7ELZ.js +314 -0
  25. package/dist/chunk-DSEL7ELZ.js.map +1 -0
  26. package/dist/{chunk-KJRBRTQE.js → chunk-EXFR2BFJ.js} +37 -28
  27. package/dist/chunk-EXFR2BFJ.js.map +1 -0
  28. package/dist/{chunk-PF4ZHGVW.js → chunk-GXWB6BSY.js} +116 -23
  29. package/dist/chunk-GXWB6BSY.js.map +1 -0
  30. package/dist/{chunk-66VWUJEI.js → chunk-I2FQBMVW.js} +3 -3
  31. package/dist/chunk-I2FQBMVW.js.map +1 -0
  32. package/dist/{chunk-EU2LPUYP.js → chunk-I5O2WCGF.js} +3 -3
  33. package/dist/chunk-I5O2WCGF.js.map +1 -0
  34. package/dist/{chunk-ATYGDTMK.js → chunk-ME4XILG5.js} +5 -5
  35. package/dist/chunk-ME4XILG5.js.map +1 -0
  36. package/dist/{chunk-5FZ6ZFII.js → chunk-PC5SZFZC.js} +373 -150
  37. package/dist/chunk-PC5SZFZC.js.map +1 -0
  38. package/dist/{chunk-C4SUXMI3.js → chunk-S6XJMYME.js} +3 -3
  39. package/dist/chunk-S6XJMYME.js.map +1 -0
  40. package/dist/{chunk-A7P3O5Z5.js → chunk-V52JOSDF.js} +3 -3
  41. package/dist/chunk-V52JOSDF.js.map +1 -0
  42. package/dist/{chunk-NFVONJUK.js → chunk-W5WNWTQC.js} +455 -211
  43. package/dist/chunk-W5WNWTQC.js.map +1 -0
  44. package/dist/{chunk-WAFHC4DQ.js → chunk-YJ64RI7J.js} +3 -3
  45. package/dist/chunk-YJ64RI7J.js.map +1 -0
  46. package/dist/chunk-YOCGBORV.js +155 -0
  47. package/dist/chunk-YOCGBORV.js.map +1 -0
  48. package/dist/chunk-ZEDXARXW.js +96 -0
  49. package/dist/chunk-ZEDXARXW.js.map +1 -0
  50. package/dist/components.css +2 -0
  51. package/dist/core/index.cjs +33 -24
  52. package/dist/core/index.cjs.map +1 -1
  53. package/dist/core/index.js +2 -2
  54. package/dist/core/styles.css +2 -134
  55. package/dist/data-display/index.cjs +770 -247
  56. package/dist/data-display/index.cjs.map +1 -1
  57. package/dist/data-display/index.d.cts +1 -1
  58. package/dist/data-display/index.d.ts +1 -1
  59. package/dist/data-display/index.js +5 -4
  60. package/dist/data-display/styles.css +2 -4
  61. package/dist/feedback/index.cjs.map +1 -1
  62. package/dist/feedback/index.js +2 -2
  63. package/dist/feedback/styles.css +2 -4
  64. package/dist/forms/index.cjs +1211 -459
  65. package/dist/forms/index.cjs.map +1 -1
  66. package/dist/forms/index.d.cts +1 -1
  67. package/dist/forms/index.d.ts +1 -1
  68. package/dist/forms/index.js +8 -8
  69. package/dist/forms/styles.css +2 -6
  70. package/dist/glass/index.cjs.map +1 -1
  71. package/dist/glass/index.js +2 -2
  72. package/dist/glass/styles.css +2 -81
  73. package/dist/{index-D6fE7w-b.d.cts → index-BGt_hecO.d.cts} +1 -0
  74. package/dist/{index-D6fE7w-b.d.ts → index-BGt_hecO.d.ts} +1 -0
  75. package/dist/{index-DzcWh1Hs.d.cts → index-BtDvpZCf.d.cts} +7 -0
  76. package/dist/{index-DzcWh1Hs.d.ts → index-BtDvpZCf.d.ts} +7 -0
  77. package/dist/{index-Cle6QzQl.d.ts → index-COX1sBUN.d.ts} +27 -3
  78. package/dist/{index-BkRqGNG1.d.ts → index-Cg8MuP7u.d.cts} +40 -13
  79. package/dist/{index-BkRqGNG1.d.cts → index-Cg8MuP7u.d.ts} +40 -13
  80. package/dist/{index-CenuF_P2.d.ts → index-DHkPRTvE.d.cts} +39 -8
  81. package/dist/{index-CenuF_P2.d.cts → index-DHkPRTvE.d.ts} +39 -8
  82. package/dist/{index-TyK-Ldpy.d.cts → index-Du_oht9k.d.cts} +27 -3
  83. package/dist/index.cjs +2481 -917
  84. package/dist/index.cjs.map +1 -1
  85. package/dist/index.d.cts +5 -5
  86. package/dist/index.d.ts +5 -5
  87. package/dist/index.js +19 -19
  88. package/dist/layout/index.cjs.map +1 -1
  89. package/dist/layout/index.js +2 -2
  90. package/dist/layout/styles.css +2 -8
  91. package/dist/navigation/index.cjs +288 -48
  92. package/dist/navigation/index.cjs.map +1 -1
  93. package/dist/navigation/index.d.cts +1 -1
  94. package/dist/navigation/index.d.ts +1 -1
  95. package/dist/navigation/index.js +6 -6
  96. package/dist/navigation/styles.css +2 -4
  97. package/dist/overlays/index.cjs +566 -229
  98. package/dist/overlays/index.cjs.map +1 -1
  99. package/dist/overlays/index.d.cts +1 -1
  100. package/dist/overlays/index.d.ts +1 -1
  101. package/dist/overlays/index.js +7 -7
  102. package/dist/overlays/styles.css +2 -8
  103. package/dist/reset.css +45 -0
  104. package/dist/styles.css +1 -1
  105. package/dist/tokens.css +11 -0
  106. package/dist/typography/index.cjs.map +1 -1
  107. package/dist/typography/index.js +4 -4
  108. package/dist/typography/styles.css +2 -5
  109. package/llms.txt +211 -113
  110. package/package.json +160 -116
  111. package/src/bento/BentoCard.tsx +140 -140
  112. package/src/bento/BentoGrid.tsx +50 -50
  113. package/src/bento/index.ts +2 -2
  114. package/src/bento/tokens.css +46 -46
  115. package/src/buttons/Button.tsx +104 -104
  116. package/src/buttons/ButtonGroup.tsx +43 -43
  117. package/src/buttons/IconButton.tsx +79 -79
  118. package/src/buttons/SplitButton.tsx +186 -86
  119. package/src/buttons/ToggleButton.tsx +157 -157
  120. package/src/buttons/index.ts +5 -5
  121. package/src/buttons/tokens.css +6 -6
  122. package/src/core/ThemeProvider.tsx +135 -123
  123. package/src/core/index.ts +2 -2
  124. package/src/core/tokens.css +134 -134
  125. package/src/data-display/Accordion.tsx +147 -147
  126. package/src/data-display/Avatar.tsx +134 -134
  127. package/src/data-display/Card.tsx +112 -112
  128. package/src/data-display/Chip.tsx +74 -74
  129. package/src/data-display/DataTablePro.tsx +299 -121
  130. package/src/data-display/StatCard.tsx +60 -60
  131. package/src/data-display/Table.tsx +74 -74
  132. package/src/data-display/Timeline.tsx +62 -62
  133. package/src/data-display/TreeView.tsx +243 -104
  134. package/src/data-display/tokens.css +4 -4
  135. package/src/feedback/Alert.tsx +80 -80
  136. package/src/feedback/EmptyState.tsx +45 -45
  137. package/src/feedback/Skeleton.tsx +66 -66
  138. package/src/feedback/Spinner.tsx +65 -65
  139. package/src/feedback/index.ts +5 -5
  140. package/src/feedback/tokens.css +4 -4
  141. package/src/forms/Checkbox.tsx +149 -69
  142. package/src/forms/CheckboxGroup.tsx +76 -29
  143. package/src/forms/Combobox.tsx +172 -28
  144. package/src/forms/DatePicker.tsx +385 -81
  145. package/src/forms/FileUpload.tsx +51 -7
  146. package/src/forms/FormField.tsx +115 -115
  147. package/src/forms/Input.tsx +151 -151
  148. package/src/forms/NumberInput.tsx +34 -20
  149. package/src/forms/PasswordInput.tsx +35 -35
  150. package/src/forms/PinInput.tsx +139 -125
  151. package/src/forms/Radio.tsx +142 -142
  152. package/src/forms/RangeSlider.tsx +237 -111
  153. package/src/forms/SearchInput.tsx +34 -34
  154. package/src/forms/Select.tsx +103 -103
  155. package/src/forms/Slider.tsx +85 -85
  156. package/src/forms/Textarea.tsx +114 -114
  157. package/src/forms/tokens.css +6 -6
  158. package/src/glass/GlassButton.tsx +59 -59
  159. package/src/glass/GlassCard.tsx +71 -71
  160. package/src/glass/index.ts +3 -3
  161. package/src/glass/tokens.css +81 -81
  162. package/src/index.ts +26 -26
  163. package/src/layout/AspectRatio.tsx +39 -39
  164. package/src/layout/Container.tsx +53 -53
  165. package/src/layout/Divider.tsx +61 -61
  166. package/src/layout/Flex.tsx +79 -79
  167. package/src/layout/Grid.tsx +124 -124
  168. package/src/layout/PageLayout.tsx +59 -59
  169. package/src/layout/Section.tsx +47 -47
  170. package/src/layout/Spacer.tsx +30 -30
  171. package/src/layout/Stack.tsx +88 -88
  172. package/src/layout/tokens.css +8 -8
  173. package/src/navigation/Breadcrumb.tsx +73 -73
  174. package/src/navigation/CommandPalette.tsx +142 -142
  175. package/src/navigation/DropdownMenu.tsx +244 -160
  176. package/src/navigation/Pagination.tsx +114 -114
  177. package/src/navigation/Stepper.tsx +93 -93
  178. package/src/navigation/Tabs.tsx +265 -133
  179. package/src/navigation/index.ts +6 -6
  180. package/src/navigation/tokens.css +4 -4
  181. package/src/overlays/AlertDialog.tsx +63 -54
  182. package/src/overlays/BottomSheet.tsx +30 -10
  183. package/src/overlays/ContextMenu.tsx +51 -9
  184. package/src/overlays/Drawer.tsx +160 -145
  185. package/src/overlays/FocusTrap.tsx +122 -49
  186. package/src/overlays/Modal.tsx +296 -219
  187. package/src/overlays/Popover.tsx +55 -25
  188. package/src/overlays/Portal.tsx +23 -23
  189. package/src/overlays/Toast.tsx +175 -137
  190. package/src/overlays/Tooltip.tsx +125 -100
  191. package/src/overlays/tokens.css +8 -8
  192. package/src/registry/components.ts +1368 -0
  193. package/src/styles/components.css +39 -0
  194. package/src/styles/index.css +2 -93
  195. package/src/styles/reset.css +45 -0
  196. package/src/styles/tokens.css +11 -2
  197. package/src/typography/Blockquote.tsx +32 -32
  198. package/src/typography/Code.tsx +89 -89
  199. package/src/typography/Heading.tsx +56 -56
  200. package/src/typography/Kbd.tsx +25 -25
  201. package/src/typography/Label.tsx +47 -47
  202. package/src/typography/Link.tsx +56 -56
  203. package/src/typography/Text.tsx +62 -62
  204. package/src/typography/index.ts +7 -7
  205. package/src/typography/tokens.css +5 -5
  206. package/src/utils/cn.ts +6 -6
  207. package/src/utils/scroll-lock.ts +19 -0
  208. package/src/utils/useControllableState.ts +54 -0
  209. package/ui-contract.json +192 -35
  210. package/dist/chunk-2OXZK6IP.js.map +0 -1
  211. package/dist/chunk-4S6L5V7X.js.map +0 -1
  212. package/dist/chunk-5FZ6ZFII.js.map +0 -1
  213. package/dist/chunk-66VWUJEI.js.map +0 -1
  214. package/dist/chunk-A7P3O5Z5.js.map +0 -1
  215. package/dist/chunk-ATYGDTMK.js.map +0 -1
  216. package/dist/chunk-C4SUXMI3.js.map +0 -1
  217. package/dist/chunk-EU2LPUYP.js.map +0 -1
  218. package/dist/chunk-F5Q7BTMH.js.map +0 -1
  219. package/dist/chunk-GXI2H5XA.js.map +0 -1
  220. package/dist/chunk-H3LCNPMC.js +0 -101
  221. package/dist/chunk-H3LCNPMC.js.map +0 -1
  222. package/dist/chunk-IABPUCAQ.js.map +0 -1
  223. package/dist/chunk-KJRBRTQE.js.map +0 -1
  224. package/dist/chunk-LBUBXUYQ.js +0 -40
  225. package/dist/chunk-LBUBXUYQ.js.map +0 -1
  226. package/dist/chunk-LWFRUJRU.js.map +0 -1
  227. package/dist/chunk-NFVONJUK.js.map +0 -1
  228. package/dist/chunk-PF4ZHGVW.js.map +0 -1
  229. package/dist/chunk-WAFHC4DQ.js.map +0 -1
  230. package/dist/chunk-X76KBH4Y.js +0 -71
  231. package/dist/chunk-X76KBH4Y.js.map +0 -1
@@ -1,160 +1,244 @@
1
- import React, { createContext, useContext, useState, useRef, useEffect, forwardRef } from 'react';
2
- import { Portal } from '../overlays/Portal';
3
- import { cn } from '../utils/cn';
4
-
5
- interface DropdownContextType {
6
- isOpen: boolean;
7
- setIsOpen: (val: boolean) => void;
8
- triggerRect: DOMRect | null;
9
- setTriggerRect: (rect: DOMRect | null) => void;
10
- }
11
-
12
- const DropdownContext = createContext<DropdownContextType | null>(null);
13
-
14
- export function useDropdown() {
15
- const context = useContext(DropdownContext);
16
- if (!context) throw new Error('DropdownMenu components must be used within <DropdownMenu />');
17
- return context;
18
- }
19
-
20
- export interface DropdownMenuProps {
21
- children: React.ReactNode;
22
- }
23
-
24
- export function DropdownMenu({ children }: DropdownMenuProps) {
25
- const [isOpen, setIsOpen] = useState(false);
26
- const [triggerRect, setTriggerRect] = useState<DOMRect | null>(null);
27
-
28
- return (
29
- <DropdownContext.Provider value={{ isOpen, setIsOpen, triggerRect, setTriggerRect }}>
30
- <div className="relative inline-block text-left">{children}</div>
31
- </DropdownContext.Provider>
32
- );
33
- }
34
-
35
- export const DropdownMenuTrigger = forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
36
- ({ children, onClick, ...props }, ref) => {
37
- const { isOpen, setIsOpen, setTriggerRect } = useDropdown();
38
- const triggerRef = useRef<HTMLDivElement>(null);
39
-
40
- const handleClick = (e: React.MouseEvent<HTMLDivElement>) => {
41
- if (triggerRef.current) {
42
- setTriggerRect(triggerRef.current.getBoundingClientRect());
43
- }
44
- setIsOpen(!isOpen);
45
- onClick?.(e);
46
- };
47
-
48
- return (
49
- <div ref={triggerRef} onClick={handleClick} className="inline-flex cursor-pointer" {...props}>
50
- {children}
51
- </div>
52
- );
53
- }
54
- );
55
- DropdownMenuTrigger.displayName = 'DropdownMenuTrigger';
56
-
57
- export interface DropdownMenuContentProps extends React.HTMLAttributes<HTMLDivElement> {
58
- align?: 'start' | 'end';
59
- }
60
-
61
- export const DropdownMenuContent = forwardRef<HTMLDivElement, DropdownMenuContentProps>(
62
- ({ className, align = 'start', children, ...props }, ref) => {
63
- const { isOpen, setIsOpen, triggerRect } = useDropdown();
64
- const menuRef = useRef<HTMLDivElement>(null);
65
-
66
- useEffect(() => {
67
- const handleOutside = (e: MouseEvent) => {
68
- if (menuRef.current && !menuRef.current.contains(e.target as Node)) {
69
- setIsOpen(false);
70
- }
71
- };
72
- if (isOpen) {
73
- document.addEventListener('mousedown', handleOutside);
74
- }
75
- return () => document.removeEventListener('mousedown', handleOutside);
76
- }, [isOpen, setIsOpen]);
77
-
78
- if (!isOpen || !triggerRect) return null;
79
-
80
- const top = triggerRect.bottom + window.scrollY + 6;
81
- const left =
82
- align === 'end'
83
- ? triggerRect.right + window.scrollX
84
- : triggerRect.left + window.scrollX;
85
-
86
- return (
87
- <Portal>
88
- <div
89
- ref={menuRef}
90
- style={{
91
- position: 'absolute',
92
- top: `${top}px`,
93
- left: `${left}px`,
94
- }}
95
- className={cn(
96
- 'z-50 min-w-[12rem] overflow-hidden rounded-[var(--ui-radius-lg)] border border-[var(--ui-border-default)] bg-[var(--ui-bg-surface)] p-1 text-[var(--ui-text-primary)] shadow-xl animate-in fade-in zoom-in-95',
97
- align === 'end' && '-translate-x-full',
98
- className
99
- )}
100
- {...props}
101
- >
102
- {children}
103
- </div>
104
- </Portal>
105
- );
106
- }
107
- );
108
- DropdownMenuContent.displayName = 'DropdownMenuContent';
109
-
110
- export interface DropdownMenuItemProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
111
- icon?: React.ReactNode;
112
- shortcut?: string;
113
- destructive?: boolean;
114
- }
115
-
116
- export const DropdownMenuItem = forwardRef<HTMLButtonElement, DropdownMenuItemProps>(
117
- ({ className, icon, shortcut, destructive = false, children, onClick, ...props }, ref) => {
118
- const { setIsOpen } = useDropdown();
119
-
120
- return (
121
- <button
122
- ref={ref}
123
- type="button"
124
- onClick={(e) => {
125
- onClick?.(e);
126
- setIsOpen(false);
127
- }}
128
- className={cn(
129
- 'relative flex w-full cursor-pointer select-none items-center gap-2 rounded-[var(--ui-radius-sm)] px-2.5 py-1.5 text-xs font-medium outline-none transition-colors hover:bg-[var(--ui-bg-tertiary)] disabled:pointer-events-none disabled:opacity-50 text-left',
130
- destructive && 'text-[var(--ui-error)] hover:bg-[var(--ui-error-subtle)]',
131
- className
132
- )}
133
- {...props}
134
- >
135
- {icon && <span className="flex-shrink-0 text-current">{icon}</span>}
136
- <span className="flex-1 truncate">{children}</span>
137
- {shortcut && <span className="ml-auto text-[10px] text-[var(--ui-text-muted)] tracking-widest">{shortcut}</span>}
138
- </button>
139
- );
140
- }
141
- );
142
- DropdownMenuItem.displayName = 'DropdownMenuItem';
143
-
144
- export const DropdownMenuSeparator = forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
145
- ({ className, ...props }, ref) => {
146
- return <div ref={ref} className={cn('-mx-1 my-1 h-px bg-[var(--ui-border-subtle)]', className)} {...props} />;
147
- }
148
- );
149
- DropdownMenuSeparator.displayName = 'DropdownMenuSeparator';
150
-
151
- export const DropdownMenuLabel = forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
152
- ({ className, children, ...props }, ref) => {
153
- return (
154
- <div ref={ref} className={cn('px-2.5 py-1.5 text-[11px] font-semibold text-[var(--ui-text-muted)] uppercase tracking-wider', className)} {...props}>
155
- {children}
156
- </div>
157
- );
158
- }
159
- );
160
- DropdownMenuLabel.displayName = 'DropdownMenuLabel';
1
+ import React, { createContext, useContext, useState, useRef, useEffect, forwardRef, useId } from 'react';
2
+ import { Portal } from '../overlays/Portal';
3
+ import { cn } from '../utils/cn';
4
+
5
+ interface DropdownContextType {
6
+ isOpen: boolean;
7
+ setIsOpen: (val: boolean) => void;
8
+ triggerRect: DOMRect | null;
9
+ setTriggerRect: (rect: DOMRect | null) => void;
10
+ triggerRef: React.RefObject<HTMLDivElement | null>;
11
+ menuId: string;
12
+ }
13
+
14
+ const DropdownContext = createContext<DropdownContextType | null>(null);
15
+
16
+ export function useDropdown() {
17
+ const context = useContext(DropdownContext);
18
+ if (!context) throw new Error('DropdownMenu components must be used within <DropdownMenu />');
19
+ return context;
20
+ }
21
+
22
+ export interface DropdownMenuProps {
23
+ children: React.ReactNode;
24
+ }
25
+
26
+ export function DropdownMenu({ children }: DropdownMenuProps) {
27
+ const [isOpen, setIsOpen] = useState(false);
28
+ const [triggerRect, setTriggerRect] = useState<DOMRect | null>(null);
29
+ const triggerRef = useRef<HTMLDivElement | null>(null);
30
+ const menuId = useId();
31
+
32
+ return (
33
+ <DropdownContext.Provider value={{ isOpen, setIsOpen, triggerRect, setTriggerRect, triggerRef, menuId }}>
34
+ <div className="relative inline-block text-left">{children}</div>
35
+ </DropdownContext.Provider>
36
+ );
37
+ }
38
+
39
+ export const DropdownMenuTrigger = forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
40
+ ({ children, onClick, onKeyDown, ...props }, ref) => {
41
+ const { isOpen, setIsOpen, setTriggerRect, triggerRef, menuId } = useDropdown();
42
+
43
+ const handleClick = (e: React.MouseEvent<HTMLDivElement>) => {
44
+ if (triggerRef.current) {
45
+ setTriggerRect(triggerRef.current.getBoundingClientRect());
46
+ }
47
+ setIsOpen(!isOpen);
48
+ onClick?.(e);
49
+ };
50
+
51
+ const handleKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {
52
+ onKeyDown?.(e);
53
+ if (e.key === 'ArrowDown' || e.key === 'Enter' || e.key === ' ') {
54
+ e.preventDefault();
55
+ if (triggerRef.current) {
56
+ setTriggerRect(triggerRef.current.getBoundingClientRect());
57
+ }
58
+ setIsOpen(true);
59
+ }
60
+ };
61
+
62
+ return (
63
+ <div
64
+ ref={(node) => {
65
+ (triggerRef as any).current = node;
66
+ if (typeof ref === 'function') ref(node);
67
+ else if (ref) (ref as any).current = node;
68
+ }}
69
+ onClick={handleClick}
70
+ onKeyDown={handleKeyDown}
71
+ role="button"
72
+ tabIndex={0}
73
+ aria-haspopup="menu"
74
+ aria-expanded={isOpen}
75
+ aria-controls={isOpen ? `menu-${menuId}` : undefined}
76
+ className="inline-flex cursor-pointer focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[var(--ui-primary)] rounded-[var(--ui-radius-sm)]"
77
+ {...props}
78
+ >
79
+ {children}
80
+ </div>
81
+ );
82
+ }
83
+ );
84
+ DropdownMenuTrigger.displayName = 'DropdownMenuTrigger';
85
+
86
+ export interface DropdownMenuContentProps extends React.HTMLAttributes<HTMLDivElement> {
87
+ align?: 'start' | 'end';
88
+ }
89
+
90
+ export const DropdownMenuContent = forwardRef<HTMLDivElement, DropdownMenuContentProps>(
91
+ ({ className, align = 'start', children, ...props }, ref) => {
92
+ const { isOpen, setIsOpen, triggerRect, triggerRef, menuId } = useDropdown();
93
+ const menuRef = useRef<HTMLDivElement>(null);
94
+
95
+ useEffect(() => {
96
+ if (!isOpen) return;
97
+
98
+ // Auto-focus first menuitem
99
+ const timer = setTimeout(() => {
100
+ const firstItem = menuRef.current?.querySelector<HTMLButtonElement>('[role="menuitem"]:not([disabled])');
101
+ firstItem?.focus();
102
+ }, 10);
103
+
104
+ const handleOutside = (e: MouseEvent) => {
105
+ if (
106
+ menuRef.current &&
107
+ !menuRef.current.contains(e.target as Node) &&
108
+ !triggerRef.current?.contains(e.target as Node)
109
+ ) {
110
+ setIsOpen(false);
111
+ }
112
+ };
113
+
114
+ const handleKeyDown = (e: KeyboardEvent) => {
115
+ if (!menuRef.current) return;
116
+ const items = Array.from(
117
+ menuRef.current.querySelectorAll<HTMLButtonElement>('[role="menuitem"]:not([disabled])')
118
+ );
119
+ if (items.length === 0) return;
120
+
121
+ const currentIndex = items.indexOf(document.activeElement as HTMLButtonElement);
122
+
123
+ if (e.key === 'ArrowDown') {
124
+ e.preventDefault();
125
+ const nextIndex = currentIndex === -1 ? 0 : (currentIndex + 1) % items.length;
126
+ items[nextIndex]?.focus();
127
+ } else if (e.key === 'ArrowUp') {
128
+ e.preventDefault();
129
+ const prevIndex = currentIndex === -1 ? items.length - 1 : (currentIndex - 1 + items.length) % items.length;
130
+ items[prevIndex]?.focus();
131
+ } else if (e.key === 'Home') {
132
+ e.preventDefault();
133
+ items[0]?.focus();
134
+ } else if (e.key === 'End') {
135
+ e.preventDefault();
136
+ items[items.length - 1]?.focus();
137
+ } else if (e.key === 'Escape') {
138
+ e.preventDefault();
139
+ setIsOpen(false);
140
+ triggerRef.current?.focus();
141
+ }
142
+ };
143
+
144
+ document.addEventListener('mousedown', handleOutside);
145
+ window.addEventListener('keydown', handleKeyDown);
146
+
147
+ return () => {
148
+ clearTimeout(timer);
149
+ document.removeEventListener('mousedown', handleOutside);
150
+ window.removeEventListener('keydown', handleKeyDown);
151
+ };
152
+ }, [isOpen, setIsOpen, triggerRef]);
153
+
154
+ if (!isOpen || !triggerRect) return null;
155
+
156
+ const top = triggerRect.bottom + window.scrollY + 6;
157
+ const left =
158
+ align === 'end'
159
+ ? triggerRect.right + window.scrollX
160
+ : triggerRect.left + window.scrollX;
161
+
162
+ return (
163
+ <Portal>
164
+ <div
165
+ ref={(node) => {
166
+ (menuRef as any).current = node;
167
+ if (typeof ref === 'function') ref(node);
168
+ else if (ref) (ref as any).current = node;
169
+ }}
170
+ id={`menu-${menuId}`}
171
+ role="menu"
172
+ tabIndex={-1}
173
+ style={{
174
+ position: 'absolute',
175
+ top: `${top}px`,
176
+ left: `${left}px`,
177
+ }}
178
+ className={cn(
179
+ 'z-50 min-w-[12rem] overflow-hidden rounded-[var(--ui-radius-lg)] border border-[var(--ui-border-default)] bg-[var(--ui-bg-surface)] p-1 text-[var(--ui-text-primary)] shadow-xl animate-in fade-in zoom-in-95 focus:outline-none',
180
+ align === 'end' && '-translate-x-full',
181
+ className
182
+ )}
183
+ {...props}
184
+ >
185
+ {children}
186
+ </div>
187
+ </Portal>
188
+ );
189
+ }
190
+ );
191
+ DropdownMenuContent.displayName = 'DropdownMenuContent';
192
+
193
+ export interface DropdownMenuItemProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
194
+ icon?: React.ReactNode;
195
+ shortcut?: string;
196
+ destructive?: boolean;
197
+ }
198
+
199
+ export const DropdownMenuItem = forwardRef<HTMLButtonElement, DropdownMenuItemProps>(
200
+ ({ className, icon, shortcut, destructive = false, children, onClick, ...props }, ref) => {
201
+ const { setIsOpen } = useDropdown();
202
+
203
+ return (
204
+ <button
205
+ ref={ref}
206
+ role="menuitem"
207
+ type="button"
208
+ onClick={(e) => {
209
+ onClick?.(e);
210
+ setIsOpen(false);
211
+ }}
212
+ className={cn(
213
+ 'relative flex w-full cursor-pointer select-none items-center gap-2 rounded-[var(--ui-radius-sm)] px-2.5 py-1.5 text-xs font-medium outline-none transition-colors hover:bg-[var(--ui-bg-tertiary)] focus:bg-[var(--ui-bg-tertiary)] disabled:pointer-events-none disabled:opacity-50 text-left',
214
+ destructive && 'text-[var(--ui-error)] hover:bg-[var(--ui-error-subtle)] focus:bg-[var(--ui-error-subtle)]',
215
+ className
216
+ )}
217
+ {...props}
218
+ >
219
+ {icon && <span className="flex-shrink-0 text-current">{icon}</span>}
220
+ <span className="flex-1 truncate">{children}</span>
221
+ {shortcut && <span className="ml-auto text-[10px] text-[var(--ui-text-muted)] tracking-widest">{shortcut}</span>}
222
+ </button>
223
+ );
224
+ }
225
+ );
226
+ DropdownMenuItem.displayName = 'DropdownMenuItem';
227
+
228
+ export const DropdownMenuSeparator = forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
229
+ ({ className, ...props }, ref) => {
230
+ return <div ref={ref} role="separator" className={cn('-mx-1 my-1 h-px bg-[var(--ui-border-subtle)]', className)} {...props} />;
231
+ }
232
+ );
233
+ DropdownMenuSeparator.displayName = 'DropdownMenuSeparator';
234
+
235
+ export const DropdownMenuLabel = forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
236
+ ({ className, children, ...props }, ref) => {
237
+ return (
238
+ <div ref={ref} className={cn('px-2.5 py-1.5 text-[11px] font-semibold text-[var(--ui-text-muted)] uppercase tracking-wider', className)} {...props}>
239
+ {children}
240
+ </div>
241
+ );
242
+ }
243
+ );
244
+ DropdownMenuLabel.displayName = 'DropdownMenuLabel';
@@ -1,114 +1,114 @@
1
- import React, { forwardRef } from 'react';
2
- import { ChevronLeft, ChevronRight, MoreHorizontal } from 'lucide-react';
3
- import { Button } from '../buttons/Button';
4
- import { cn } from '../utils/cn';
5
-
6
- export interface PaginationProps extends React.HTMLAttributes<HTMLElement> {
7
- currentPage: number;
8
- totalPages: number;
9
- onPageChange: (page: number) => void;
10
- siblingCount?: number;
11
- }
12
-
13
- export const Pagination = forwardRef<HTMLElement, PaginationProps>(
14
- ({ className, currentPage, totalPages, onPageChange, siblingCount = 1, ...props }, ref) => {
15
- const generatePages = () => {
16
- const totalPageNumbers = siblingCount * 2 + 5;
17
-
18
- if (totalPages <= totalPageNumbers) {
19
- return Array.from({ length: totalPages }, (_, i) => i + 1);
20
- }
21
-
22
- const leftSiblingIndex = Math.max(currentPage - siblingCount, 1);
23
- const rightSiblingIndex = Math.min(currentPage + siblingCount, totalPages);
24
-
25
- const shouldShowLeftDots = leftSiblingIndex > 2;
26
- const shouldShowRightDots = rightSiblingIndex < totalPages - 2;
27
-
28
- if (!shouldShowLeftDots && shouldShowRightDots) {
29
- const leftItemCount = 3 + 2 * siblingCount;
30
- const leftRange = Array.from({ length: leftItemCount }, (_, i) => i + 1);
31
- return [...leftRange, 'DOTS', totalPages];
32
- }
33
-
34
- if (shouldShowLeftDots && !shouldShowRightDots) {
35
- const rightItemCount = 3 + 2 * siblingCount;
36
- const rightRange = Array.from(
37
- { length: rightItemCount },
38
- (_, i) => totalPages - rightItemCount + i + 1
39
- );
40
- return [1, 'DOTS', ...rightRange];
41
- }
42
-
43
- if (shouldShowLeftDots && shouldShowRightDots) {
44
- const middleRange = Array.from(
45
- { length: rightSiblingIndex - leftSiblingIndex + 1 },
46
- (_, i) => leftSiblingIndex + i
47
- );
48
- return [1, 'DOTS', ...middleRange, 'DOTS', totalPages];
49
- }
50
-
51
- return [];
52
- };
53
-
54
- const pages = generatePages();
55
-
56
- return (
57
- <nav
58
- ref={ref}
59
- role="navigation"
60
- aria-label="Pagination"
61
- className={cn('flex items-center justify-center gap-1.5', className)}
62
- {...props}
63
- >
64
- <Button
65
- variant="outline"
66
- size="sm"
67
- disabled={currentPage <= 1}
68
- onClick={() => onPageChange(currentPage - 1)}
69
- aria-label="Go to previous page"
70
- >
71
- <ChevronLeft className="w-4 h-4" />
72
- </Button>
73
-
74
- {pages.map((p, index) => {
75
- if (p === 'DOTS') {
76
- return (
77
- <span key={`dots-${index}`} className="flex items-center justify-center w-8 h-8 text-[var(--ui-text-muted)]">
78
- <MoreHorizontal className="w-4 h-4" />
79
- </span>
80
- );
81
- }
82
-
83
- const pageNum = Number(p);
84
- const isActive = pageNum === currentPage;
85
-
86
- return (
87
- <Button
88
- key={pageNum}
89
- variant={isActive ? 'primary' : 'ghost'}
90
- size="sm"
91
- aria-current={isActive ? 'page' : undefined}
92
- onClick={() => onPageChange(pageNum)}
93
- className="w-8 h-8 p-0 text-xs font-semibold"
94
- >
95
- {pageNum}
96
- </Button>
97
- );
98
- })}
99
-
100
- <Button
101
- variant="outline"
102
- size="sm"
103
- disabled={currentPage >= totalPages}
104
- onClick={() => onPageChange(currentPage + 1)}
105
- aria-label="Go to next page"
106
- >
107
- <ChevronRight className="w-4 h-4" />
108
- </Button>
109
- </nav>
110
- );
111
- }
112
- );
113
-
114
- Pagination.displayName = 'Pagination';
1
+ import React, { forwardRef } from 'react';
2
+ import { ChevronLeft, ChevronRight, MoreHorizontal } from 'lucide-react';
3
+ import { Button } from '../buttons/Button';
4
+ import { cn } from '../utils/cn';
5
+
6
+ export interface PaginationProps extends React.HTMLAttributes<HTMLElement> {
7
+ currentPage: number;
8
+ totalPages: number;
9
+ onPageChange: (page: number) => void;
10
+ siblingCount?: number;
11
+ }
12
+
13
+ export const Pagination = forwardRef<HTMLElement, PaginationProps>(
14
+ ({ className, currentPage, totalPages, onPageChange, siblingCount = 1, ...props }, ref) => {
15
+ const generatePages = () => {
16
+ const totalPageNumbers = siblingCount * 2 + 5;
17
+
18
+ if (totalPages <= totalPageNumbers) {
19
+ return Array.from({ length: totalPages }, (_, i) => i + 1);
20
+ }
21
+
22
+ const leftSiblingIndex = Math.max(currentPage - siblingCount, 1);
23
+ const rightSiblingIndex = Math.min(currentPage + siblingCount, totalPages);
24
+
25
+ const shouldShowLeftDots = leftSiblingIndex > 2;
26
+ const shouldShowRightDots = rightSiblingIndex < totalPages - 2;
27
+
28
+ if (!shouldShowLeftDots && shouldShowRightDots) {
29
+ const leftItemCount = 3 + 2 * siblingCount;
30
+ const leftRange = Array.from({ length: leftItemCount }, (_, i) => i + 1);
31
+ return [...leftRange, 'DOTS', totalPages];
32
+ }
33
+
34
+ if (shouldShowLeftDots && !shouldShowRightDots) {
35
+ const rightItemCount = 3 + 2 * siblingCount;
36
+ const rightRange = Array.from(
37
+ { length: rightItemCount },
38
+ (_, i) => totalPages - rightItemCount + i + 1
39
+ );
40
+ return [1, 'DOTS', ...rightRange];
41
+ }
42
+
43
+ if (shouldShowLeftDots && shouldShowRightDots) {
44
+ const middleRange = Array.from(
45
+ { length: rightSiblingIndex - leftSiblingIndex + 1 },
46
+ (_, i) => leftSiblingIndex + i
47
+ );
48
+ return [1, 'DOTS', ...middleRange, 'DOTS', totalPages];
49
+ }
50
+
51
+ return [];
52
+ };
53
+
54
+ const pages = generatePages();
55
+
56
+ return (
57
+ <nav
58
+ ref={ref}
59
+ role="navigation"
60
+ aria-label="Pagination"
61
+ className={cn('flex items-center justify-center gap-1.5', className)}
62
+ {...props}
63
+ >
64
+ <Button
65
+ variant="outline"
66
+ size="sm"
67
+ disabled={currentPage <= 1}
68
+ onClick={() => onPageChange(currentPage - 1)}
69
+ aria-label="Go to previous page"
70
+ >
71
+ <ChevronLeft className="w-4 h-4" />
72
+ </Button>
73
+
74
+ {pages.map((p, index) => {
75
+ if (p === 'DOTS') {
76
+ return (
77
+ <span key={`dots-${index}`} className="flex items-center justify-center w-8 h-8 text-[var(--ui-text-muted)]">
78
+ <MoreHorizontal className="w-4 h-4" />
79
+ </span>
80
+ );
81
+ }
82
+
83
+ const pageNum = Number(p);
84
+ const isActive = pageNum === currentPage;
85
+
86
+ return (
87
+ <Button
88
+ key={pageNum}
89
+ variant={isActive ? 'primary' : 'ghost'}
90
+ size="sm"
91
+ aria-current={isActive ? 'page' : undefined}
92
+ onClick={() => onPageChange(pageNum)}
93
+ className="w-8 h-8 p-0 text-xs font-semibold"
94
+ >
95
+ {pageNum}
96
+ </Button>
97
+ );
98
+ })}
99
+
100
+ <Button
101
+ variant="outline"
102
+ size="sm"
103
+ disabled={currentPage >= totalPages}
104
+ onClick={() => onPageChange(currentPage + 1)}
105
+ aria-label="Go to next page"
106
+ >
107
+ <ChevronRight className="w-4 h-4" />
108
+ </Button>
109
+ </nav>
110
+ );
111
+ }
112
+ );
113
+
114
+ Pagination.displayName = 'Pagination';