@avenue-ticketing/ui 0.4.0 → 0.6.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 (73) hide show
  1. package/dist/react/avatar.d.ts +42 -0
  2. package/dist/react/avatar.js +159 -0
  3. package/dist/react/avatar.js.map +1 -0
  4. package/dist/react/badge.d.ts +12 -0
  5. package/dist/react/badge.js +35 -1
  6. package/dist/react/badge.js.map +1 -1
  7. package/dist/react/button.d.ts +1 -1
  8. package/dist/react/button.js +3 -3
  9. package/dist/react/button.js.map +1 -1
  10. package/dist/react/calendar.d.ts +13 -0
  11. package/dist/react/calendar.js +4639 -0
  12. package/dist/react/calendar.js.map +1 -0
  13. package/dist/react/card.d.ts +11 -0
  14. package/dist/react/card.js +113 -0
  15. package/dist/react/card.js.map +1 -0
  16. package/dist/react/checkbox.d.ts +11 -0
  17. package/dist/react/checkbox.js +129 -0
  18. package/dist/react/checkbox.js.map +1 -0
  19. package/dist/react/datetime-picker.d.ts +21 -0
  20. package/dist/react/datetime-picker.js +6124 -0
  21. package/dist/react/datetime-picker.js.map +1 -0
  22. package/dist/react/dialog.js +1 -1
  23. package/dist/react/dialog.js.map +1 -1
  24. package/dist/react/dropdown.d.ts +34 -9
  25. package/dist/react/dropdown.js +295 -144
  26. package/dist/react/dropdown.js.map +1 -1
  27. package/dist/react/input.d.ts +7 -0
  28. package/dist/react/input.js +15 -2
  29. package/dist/react/input.js.map +1 -1
  30. package/dist/react/pagination.d.ts +28 -0
  31. package/dist/react/pagination.js +262 -0
  32. package/dist/react/pagination.js.map +1 -0
  33. package/dist/react/popover.d.ts +76 -0
  34. package/dist/react/popover.js +564 -0
  35. package/dist/react/popover.js.map +1 -0
  36. package/dist/react/scroll-header.js +13 -1
  37. package/dist/react/scroll-header.js.map +1 -1
  38. package/dist/react/scroll-wheel.d.ts +45 -0
  39. package/dist/react/scroll-wheel.js +557 -0
  40. package/dist/react/scroll-wheel.js.map +1 -0
  41. package/dist/react/select.d.ts +62 -0
  42. package/dist/react/select.js +889 -0
  43. package/dist/react/select.js.map +1 -0
  44. package/dist/react/sheet.js +1 -1
  45. package/dist/react/sheet.js.map +1 -1
  46. package/dist/react/switch.d.ts +38 -0
  47. package/dist/react/switch.js +117 -0
  48. package/dist/react/switch.js.map +1 -0
  49. package/dist/react/table-pagination.d.ts +15 -0
  50. package/dist/react/table-pagination.js +1153 -0
  51. package/dist/react/table-pagination.js.map +1 -0
  52. package/dist/react/table-view/column-menu.d.ts +15 -0
  53. package/dist/react/table-view/column-menu.js +955 -0
  54. package/dist/react/table-view/column-menu.js.map +1 -0
  55. package/dist/react/table-view/index.d.ts +70 -0
  56. package/dist/react/table-view/index.js +2190 -0
  57. package/dist/react/table-view/index.js.map +1 -0
  58. package/dist/react/table.d.ts +86 -0
  59. package/dist/react/table.js +414 -0
  60. package/dist/react/table.js.map +1 -0
  61. package/dist/react/tabs.d.ts +9 -3
  62. package/dist/react/tabs.js +204 -48
  63. package/dist/react/tabs.js.map +1 -1
  64. package/dist/react/textarea.d.ts +6 -0
  65. package/dist/react/textarea.js +33 -0
  66. package/dist/react/textarea.js.map +1 -0
  67. package/dist/react/time-picker.d.ts +22 -0
  68. package/dist/react/time-picker.js +856 -0
  69. package/dist/react/time-picker.js.map +1 -0
  70. package/dist/react/tooltip.d.ts +45 -0
  71. package/dist/react/tooltip.js +540 -0
  72. package/dist/react/tooltip.js.map +1 -0
  73. package/package.json +1 -1
@@ -0,0 +1,955 @@
1
+ import { X, MoreVertical, ArrowLeft, ArrowRight, ChevronUp, ChevronDown, Pin, PinOff, EyeOff } from 'lucide-react';
2
+ import * as React2 from 'react';
3
+ import React2__default, { useCallback, forwardRef, useState, useImperativeHandle, memo, useRef, useMemo, useEffect, useLayoutEffect } from 'react';
4
+ import { clsx } from 'clsx';
5
+ import { twMerge } from 'tailwind-merge';
6
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
7
+ import { createPortal } from 'react-dom';
8
+
9
+ function cn(...inputs) {
10
+ return twMerge(clsx(inputs));
11
+ }
12
+ var sizeClass = {
13
+ xs: "h-8 min-h-8 gap-2 px-4 text-sm has-[>svg]:px-3 [&_svg:not([class*='size-'])]:size-3",
14
+ default: "h-10 min-h-10 gap-2 px-5 text-sm has-[>svg]:px-4 [&_svg:not([class*='size-'])]:size-4",
15
+ lg: "h-11 min-h-11 gap-2 px-6 text-base has-[>svg]:px-5 [&_svg:not([class*='size-'])]:size-5"
16
+ };
17
+ var iconOnlySizeClass = {
18
+ xs: "size-8 min-h-8 min-w-8 gap-0 p-0 [&_svg:not([class*='size-'])]:size-3",
19
+ default: "size-10 min-h-10 min-w-10 gap-0 p-0 [&_svg:not([class*='size-'])]:size-4",
20
+ lg: "size-11 min-h-11 min-w-11 gap-0 p-0 [&_svg:not([class*='size-'])]:size-5"
21
+ };
22
+ var roundedClass = {
23
+ full: "rounded-full",
24
+ lg: "rounded-lg",
25
+ md: "rounded-md"
26
+ };
27
+ var variantClass = {
28
+ primary: "bg-primary text-background border border-transparent hover:bg-primary/90 active:bg-primary/85",
29
+ secondary: "bg-background text-primary border border-primary/10 hover:bg-primary/5",
30
+ destructive: "bg-background text-red-500 border border-red-500/25 hover:bg-red-500/5",
31
+ success: "bg-background text-green-500 border border-green-500/25 hover:bg-green-500/5"
32
+ };
33
+ var Button = React2.forwardRef(
34
+ ({
35
+ className,
36
+ type = "button",
37
+ variant = "secondary",
38
+ rounded: roundedProp,
39
+ size = "default",
40
+ iconOnly = false,
41
+ disabled,
42
+ ...props
43
+ }, ref) => {
44
+ const rounded = roundedProp ?? (iconOnly ? "md" : "full");
45
+ return /* @__PURE__ */ jsx(
46
+ "button",
47
+ {
48
+ type,
49
+ disabled,
50
+ "data-slot": "button",
51
+ "data-icon-only": iconOnly ? "" : void 0,
52
+ className: cn(
53
+ "inline-flex shrink-0 cursor-pointer items-center justify-center whitespace-nowrap outline-none scale-100 transition-[color,background-color,box-shadow,transform] duration-150 ease-out active:scale-[0.98] active:duration-100 active:ease-linear [&_svg]:pointer-events-none [&_svg]:shrink-0",
54
+ "disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50",
55
+ "focus-visible:border-ring font-medium lg:tracking-wide focus-visible:ring-ring/50 focus-visible:ring-[3px]",
56
+ iconOnly ? iconOnlySizeClass[size] : sizeClass[size],
57
+ roundedClass[rounded],
58
+ variantClass[variant],
59
+ className
60
+ ),
61
+ ref,
62
+ ...props
63
+ }
64
+ );
65
+ }
66
+ );
67
+ Button.displayName = "Button";
68
+ var DROPDOWN_PANEL_OPEN_EASING = "cubic-bezier(0,0.55,0.45,1)";
69
+ var DROPDOWN_PANEL_CLOSE_EASING = "cubic-bezier(0.55,0,1,0.45)";
70
+ var DROPDOWN_MENU_MIN_WIDTH_PX = 192;
71
+ var DROPDOWN_MOBILE_SHEET_MAX_PX = 1024;
72
+ var DROPDOWN_MOBILE_SHEET_MOTION_MS = 175;
73
+ var DROPDOWN_MOBILE_SHEET_ENTRY_EASING = "cubic-bezier(0.85, 0, 0.15, 1)";
74
+ var DROPDOWN_MOBILE_SHEET_EXIT_EASING = "cubic-bezier(0.85, 0, 1, 0.15)";
75
+ var DROPDOWN_MOBILE_SHEET_SLIDE_ENTRANCE_OFFSET_DEFAULT_PX = 120;
76
+ function resolveDropdownMobileSheet(mobileOptions) {
77
+ return {
78
+ sheet: mobileOptions?.sheet ?? true,
79
+ title: mobileOptions?.title,
80
+ sheetExtraClassName: mobileOptions?.className,
81
+ contentClassName: mobileOptions?.contentClassName
82
+ };
83
+ }
84
+ var DROPDOWN_SUB_CONTENT_ATTR = "data-dropdown-sub-content";
85
+ var DROPDOWN_PANEL_SHADOW = "shadow-[0_12px_32px_-8px_rgba(0,0,0,0.18),0_2px_6px_-2px_rgba(0,0,0,0.06)] dark:shadow-[0_12px_32px_-8px_rgba(0,0,0,0.55),0_2px_6px_-2px_rgba(0,0,0,0.35)]";
86
+ var DROPDOWN_PANEL_SCROLL = "[&_*]:[scrollbar-width:none] [&_*::-webkit-scrollbar]:hidden [&_*]:overscroll-contain";
87
+ function preventMenuWheelChain(menu, e) {
88
+ let el = e.target;
89
+ while (el && menu.contains(el)) {
90
+ const oy = getComputedStyle(el).overflowY;
91
+ if ((oy === "auto" || oy === "scroll") && el.scrollHeight > el.clientHeight) {
92
+ const atTop = el.scrollTop <= 0;
93
+ const atBottom = el.scrollTop + el.clientHeight >= el.scrollHeight;
94
+ if (e.deltaY < 0 && !atTop || e.deltaY > 0 && !atBottom) return;
95
+ break;
96
+ }
97
+ el = el.parentElement;
98
+ }
99
+ e.preventDefault();
100
+ }
101
+ var DROPDOWN_SHEET_MENU_TEXT = "max-[1024px]:text-base";
102
+ var DROPDOWN_SHEET_MENU_SHORTCUT = "max-[1024px]:text-sm";
103
+ var DROPDOWN_CONTENT_ORIGIN = {
104
+ bottom: "top center",
105
+ top: "bottom center",
106
+ left: "right center",
107
+ right: "left center"
108
+ };
109
+ var DROPDOWN_CONTENT_HIDDEN = {
110
+ bottom: "translateY(-4px) scale(0.97)",
111
+ top: "translateY(4px) scale(0.97)",
112
+ left: "translateX(4px) scale(0.97)",
113
+ right: "translateX(-4px) scale(0.97)"
114
+ };
115
+ function computePos(trigger, menu, side, align, offset, pad) {
116
+ const tr = trigger.getBoundingClientRect();
117
+ const mr = menu.getBoundingClientRect();
118
+ const vw = window.innerWidth;
119
+ const vh = window.innerHeight;
120
+ const sx = window.scrollX;
121
+ const sy = window.scrollY;
122
+ let top = 0;
123
+ let left = 0;
124
+ let effectiveSide = side;
125
+ const calc = (s) => {
126
+ switch (s) {
127
+ case "bottom":
128
+ top = tr.bottom + sy + offset;
129
+ if (align === "start") left = tr.left + sx;
130
+ else if (align === "end") left = tr.right + sx - mr.width;
131
+ else left = tr.left + sx + tr.width / 2 - mr.width / 2;
132
+ break;
133
+ case "top":
134
+ top = tr.top + sy - mr.height - offset;
135
+ if (align === "start") left = tr.left + sx;
136
+ else if (align === "end") left = tr.right + sx - mr.width;
137
+ else left = tr.left + sx + tr.width / 2 - mr.width / 2;
138
+ break;
139
+ case "right":
140
+ left = tr.right + sx + offset;
141
+ if (align === "start") top = tr.top + sy;
142
+ else if (align === "end") top = tr.bottom + sy - mr.height;
143
+ else top = tr.top + sy + tr.height / 2 - mr.height / 2;
144
+ break;
145
+ case "left":
146
+ left = tr.left + sx - mr.width - offset;
147
+ if (align === "start") top = tr.top + sy;
148
+ else if (align === "end") top = tr.bottom + sy - mr.height;
149
+ else top = tr.top + sy + tr.height / 2 - mr.height / 2;
150
+ break;
151
+ }
152
+ };
153
+ calc(side);
154
+ if (side === "bottom" && top + mr.height > vh + sy - pad) {
155
+ const ft = tr.top + sy - mr.height - offset;
156
+ if (ft >= sy + pad) {
157
+ effectiveSide = "top";
158
+ top = ft;
159
+ }
160
+ } else if (side === "top" && top < sy + pad) {
161
+ const ft = tr.bottom + sy + offset;
162
+ if (ft + mr.height <= vh + sy - pad) {
163
+ effectiveSide = "bottom";
164
+ top = ft;
165
+ }
166
+ } else if (side === "right" && left + mr.width > vw + sx - pad) {
167
+ const fl = tr.left + sx - mr.width - offset;
168
+ if (fl >= sx + pad) {
169
+ effectiveSide = "left";
170
+ left = fl;
171
+ }
172
+ } else if (side === "left" && left < sx + pad) {
173
+ const fl = tr.right + sx + offset;
174
+ if (fl + mr.width <= vw + sx - pad) {
175
+ effectiveSide = "right";
176
+ left = fl;
177
+ }
178
+ }
179
+ left = Math.max(sx + pad, Math.min(left, vw + sx - mr.width - pad));
180
+ top = Math.max(sy + pad, Math.min(top, vh + sy - mr.height - pad));
181
+ return { top, left, side: effectiveSide };
182
+ }
183
+ function useIsMobile(breakpoint = 1025) {
184
+ const [isMobile, setIsMobile] = useState(() => {
185
+ if (typeof window === "undefined") return false;
186
+ return window.matchMedia(`(max-width: ${breakpoint - 1}px)`).matches;
187
+ });
188
+ useEffect(() => {
189
+ const mq = window.matchMedia(`(max-width: ${breakpoint - 1}px)`);
190
+ const handler = (e) => setIsMobile(e.matches);
191
+ mq.addEventListener("change", handler);
192
+ return () => mq.removeEventListener("change", handler);
193
+ }, [breakpoint]);
194
+ return isMobile;
195
+ }
196
+ var DropdownContext = React2__default.createContext(void 0);
197
+ function useDropdown() {
198
+ const ctx = React2__default.useContext(DropdownContext);
199
+ if (!ctx)
200
+ throw new Error("Dropdown components must be used within <Dropdown />");
201
+ return ctx;
202
+ }
203
+ React2__default.createContext(void 0);
204
+ var Dropdown = ({
205
+ children,
206
+ open: controlledOpen,
207
+ onOpenChange
208
+ }) => {
209
+ const [internalOpen, setInternalOpen] = useState(false);
210
+ const isControlled = controlledOpen !== void 0;
211
+ const open = isControlled ? controlledOpen : internalOpen;
212
+ const triggerRef = useRef(null);
213
+ const [radioValues, setRadioValues] = useState({});
214
+ const setOpen = useCallback(
215
+ (v) => {
216
+ if (!isControlled) setInternalOpen(v);
217
+ onOpenChange?.(v);
218
+ },
219
+ [isControlled, onOpenChange]
220
+ );
221
+ const setRadioValue = useCallback((group, value) => {
222
+ setRadioValues((prev) => ({ ...prev, [group]: value }));
223
+ }, []);
224
+ const ctx = useMemo(
225
+ () => ({ open, setOpen, triggerRef, radioValues, setRadioValue }),
226
+ [open, setOpen, radioValues, setRadioValue]
227
+ );
228
+ return /* @__PURE__ */ jsx(DropdownContext.Provider, { value: ctx, children });
229
+ };
230
+ function mergeTriggerRef(triggerRef, node, childRef) {
231
+ triggerRef.current = node;
232
+ if (typeof childRef === "function") childRef(node);
233
+ else if (childRef && typeof childRef === "object")
234
+ childRef.current = node;
235
+ }
236
+ var DropdownTrigger = React2__default.forwardRef(
237
+ ({
238
+ children,
239
+ asChild,
240
+ className,
241
+ onClick: onClickProp,
242
+ disabled,
243
+ ...buttonProps
244
+ }, ref) => {
245
+ const { open, setOpen, triggerRef } = useDropdown();
246
+ const handleClick = useCallback(
247
+ (e) => {
248
+ onClickProp?.(e);
249
+ e.stopPropagation();
250
+ if (disabled) return;
251
+ setOpen(!open);
252
+ },
253
+ [disabled, onClickProp, open, setOpen]
254
+ );
255
+ const setButtonRef = useCallback(
256
+ (el) => {
257
+ triggerRef.current = el;
258
+ if (typeof ref === "function") ref(el);
259
+ else if (ref) ref.current = el;
260
+ },
261
+ [ref, triggerRef]
262
+ );
263
+ if (asChild && React2__default.isValidElement(children)) {
264
+ const child = children;
265
+ return React2__default.cloneElement(child, {
266
+ ref: (node) => {
267
+ mergeTriggerRef(
268
+ triggerRef,
269
+ node,
270
+ child.ref
271
+ );
272
+ },
273
+ className: cn("group", child.props.className),
274
+ onClick: (e) => {
275
+ child.props.onClick?.(e);
276
+ handleClick(e);
277
+ },
278
+ "aria-expanded": open,
279
+ "aria-haspopup": "menu",
280
+ "data-state": open ? "open" : "closed",
281
+ ...disabled !== void 0 ? {
282
+ disabled
283
+ } : {}
284
+ });
285
+ }
286
+ return /* @__PURE__ */ jsx(
287
+ Button,
288
+ {
289
+ ref: setButtonRef,
290
+ type: "button",
291
+ ...buttonProps,
292
+ disabled,
293
+ className: cn("group", className),
294
+ "aria-expanded": open,
295
+ "aria-haspopup": "menu",
296
+ "data-state": open ? "open" : "closed",
297
+ onClick: handleClick,
298
+ children
299
+ }
300
+ );
301
+ }
302
+ );
303
+ DropdownTrigger.displayName = "DropdownTrigger";
304
+ var DropdownMobileClose = React2__default.forwardRef(({ className, type = "button", ...props }, ref) => {
305
+ return /* @__PURE__ */ jsxs(
306
+ "button",
307
+ {
308
+ ref,
309
+ type,
310
+ className: cn(
311
+ "z-100 flex size-12 shrink-0 cursor-pointer items-center justify-center rounded-full transition-all hover:bg-secondary-background active:scale-[0.96]",
312
+ className
313
+ ),
314
+ ...props,
315
+ children: [
316
+ /* @__PURE__ */ jsx(X, { className: "size-5.5" }),
317
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: "Close" })
318
+ ]
319
+ }
320
+ );
321
+ });
322
+ DropdownMobileClose.displayName = "DropdownMobileClose";
323
+ function DropdownMobileBottomSheetPortal({
324
+ open,
325
+ isAnimating,
326
+ slideEntrance,
327
+ slideOffsetPx,
328
+ sheetTitle,
329
+ sheetExtraClassName,
330
+ contentClassName,
331
+ onRequestClose,
332
+ menuRef,
333
+ portalZClassName = "z-50",
334
+ isSubPortal = false,
335
+ children,
336
+ className,
337
+ style,
338
+ ...panelProps
339
+ }) {
340
+ const sheetMotion = open ? DROPDOWN_MOBILE_SHEET_ENTRY_EASING : DROPDOWN_MOBILE_SHEET_EXIT_EASING;
341
+ const sheetHiddenTransform = slideEntrance ? `translateY(${slideOffsetPx}px)` : "translateY(100%)";
342
+ return createPortal(
343
+ /* @__PURE__ */ jsxs(
344
+ "div",
345
+ {
346
+ ...isSubPortal ? { [DROPDOWN_SUB_CONTENT_ATTR]: "" } : {},
347
+ className: cn(
348
+ "fixed inset-0 flex items-end justify-center p-0",
349
+ portalZClassName
350
+ ),
351
+ children: [
352
+ /* @__PURE__ */ jsx(
353
+ "div",
354
+ {
355
+ className: cn(
356
+ "fixed inset-0 bg-black/40 dark:bg-black/60",
357
+ isAnimating ? "opacity-100" : "opacity-0"
358
+ ),
359
+ style: {
360
+ transitionProperty: "opacity",
361
+ transitionDuration: `${DROPDOWN_MOBILE_SHEET_MOTION_MS}ms`,
362
+ transitionTimingFunction: sheetMotion
363
+ },
364
+ onClick: onRequestClose
365
+ }
366
+ ),
367
+ /* @__PURE__ */ jsxs(
368
+ "div",
369
+ {
370
+ ...panelProps,
371
+ ref: menuRef,
372
+ className: cn(
373
+ "bg-background border-primary/8 relative z-10 flex w-full max-h-[min(90dvh,calc(100dvh-env(safe-area-inset-bottom,0px)))] flex-col overflow-hidden shadow-2xl outline-none",
374
+ "rounded-t-2xl rounded-b-none border-x-0 border-b-0 border-t",
375
+ DROPDOWN_PANEL_SCROLL,
376
+ sheetExtraClassName,
377
+ className
378
+ ),
379
+ style: {
380
+ transform: isAnimating ? "translateY(0)" : sheetHiddenTransform,
381
+ opacity: isAnimating ? 1 : 0,
382
+ transitionProperty: "transform, opacity",
383
+ transitionDuration: `${DROPDOWN_MOBILE_SHEET_MOTION_MS}ms`,
384
+ transitionTimingFunction: sheetMotion,
385
+ ...style
386
+ },
387
+ children: [
388
+ /* @__PURE__ */ jsxs(
389
+ "div",
390
+ {
391
+ className: cn(
392
+ "flex w-full shrink-0 items-center py-2 pl-4 pr-2",
393
+ sheetTitle ? "justify-between gap-3" : "justify-end"
394
+ ),
395
+ children: [
396
+ sheetTitle ? /* @__PURE__ */ jsx("p", { className: "text-foreground min-w-0 flex-1 truncate text-base font-semibold", children: sheetTitle }) : null,
397
+ /* @__PURE__ */ jsx(
398
+ DropdownMobileClose,
399
+ {
400
+ onClick: (e) => {
401
+ e.stopPropagation();
402
+ onRequestClose();
403
+ }
404
+ }
405
+ )
406
+ ]
407
+ }
408
+ ),
409
+ /* @__PURE__ */ jsx(
410
+ "div",
411
+ {
412
+ className: cn(
413
+ "min-h-0 flex-1 overflow-y-auto pb-[calc(5rem+env(safe-area-inset-bottom,0px))]",
414
+ contentClassName
415
+ ),
416
+ children
417
+ }
418
+ )
419
+ ]
420
+ }
421
+ )
422
+ ]
423
+ }
424
+ ),
425
+ document.body
426
+ );
427
+ }
428
+ var DropdownContent = ({
429
+ children,
430
+ side = "bottom",
431
+ align = "start",
432
+ offset = 10,
433
+ duration = 80,
434
+ viewportPadding = 8,
435
+ closeOnEscape = true,
436
+ minWidth = "trigger",
437
+ loop = true,
438
+ mobileOptions,
439
+ slideEntrance = true,
440
+ slideEntranceOffsetPx: slideEntranceOffsetPxProp,
441
+ className,
442
+ style,
443
+ ...props
444
+ }) => {
445
+ const isMobile = useIsMobile(DROPDOWN_MOBILE_SHEET_MAX_PX + 1);
446
+ const { open, setOpen, triggerRef } = useDropdown();
447
+ const [shouldRender, setShouldRender] = useState(false);
448
+ const [isAnimating, setIsAnimating] = useState(false);
449
+ const [pos, setPos] = useState({ top: -9999, left: -9999, side });
450
+ const [triggerW, setTriggerW] = useState(0);
451
+ const menuRef = useRef(null);
452
+ const resolvedMobile = resolveDropdownMobileSheet(mobileOptions);
453
+ const isMobileSheet = isMobile && resolvedMobile.sheet;
454
+ const slideOffsetPx = slideEntranceOffsetPxProp ?? DROPDOWN_MOBILE_SHEET_SLIDE_ENTRANCE_OFFSET_DEFAULT_PX;
455
+ useEffect(() => {
456
+ if (open) {
457
+ setShouldRender(true);
458
+ return;
459
+ }
460
+ if (!isMobileSheet) {
461
+ setShouldRender(false);
462
+ return;
463
+ }
464
+ setIsAnimating(false);
465
+ const t = setTimeout(
466
+ () => setShouldRender(false),
467
+ DROPDOWN_MOBILE_SHEET_MOTION_MS
468
+ );
469
+ return () => clearTimeout(t);
470
+ }, [open, isMobileSheet]);
471
+ useEffect(() => {
472
+ if (!shouldRender || !open) return;
473
+ let raf2 = 0;
474
+ const raf1 = requestAnimationFrame(() => {
475
+ raf2 = requestAnimationFrame(() => setIsAnimating(true));
476
+ });
477
+ return () => {
478
+ cancelAnimationFrame(raf1);
479
+ if (raf2) cancelAnimationFrame(raf2);
480
+ };
481
+ }, [shouldRender, open]);
482
+ useLayoutEffect(() => {
483
+ if (!shouldRender || !triggerRef.current || !menuRef.current) return;
484
+ const update = () => {
485
+ if (!triggerRef.current || !menuRef.current) return;
486
+ setTriggerW(triggerRef.current.getBoundingClientRect().width);
487
+ setPos(
488
+ computePos(
489
+ triggerRef.current,
490
+ menuRef.current,
491
+ side,
492
+ align,
493
+ offset,
494
+ viewportPadding
495
+ )
496
+ );
497
+ };
498
+ update();
499
+ window.addEventListener("resize", update);
500
+ return () => {
501
+ window.removeEventListener("resize", update);
502
+ };
503
+ }, [shouldRender, side, align, offset, viewportPadding]);
504
+ useEffect(() => {
505
+ if (!open || isMobileSheet) return;
506
+ const isInsideMenu = (t) => t instanceof Node && (!!menuRef.current?.contains(t) || !!triggerRef.current?.contains(t) || t instanceof Element && !!t.closest(`[${DROPDOWN_SUB_CONTENT_ATTR}]`));
507
+ const onScroll = (e) => {
508
+ if (!isInsideMenu(e.target)) setOpen(false);
509
+ };
510
+ window.addEventListener("scroll", onScroll, true);
511
+ return () => window.removeEventListener("scroll", onScroll, true);
512
+ }, [open, isMobileSheet, setOpen, triggerRef]);
513
+ useEffect(() => {
514
+ if (!shouldRender || isMobileSheet) return;
515
+ const menu = menuRef.current;
516
+ if (!menu) return;
517
+ const onWheel = (e) => preventMenuWheelChain(menu, e);
518
+ menu.addEventListener("wheel", onWheel, { passive: false });
519
+ return () => menu.removeEventListener("wheel", onWheel);
520
+ }, [shouldRender, isMobileSheet]);
521
+ useEffect(() => {
522
+ if (isAnimating && menuRef.current) {
523
+ menuRef.current.focus();
524
+ }
525
+ }, [isAnimating]);
526
+ useEffect(() => {
527
+ if (!open) return;
528
+ const handler = (e) => {
529
+ const t = e.target;
530
+ if (menuRef.current?.contains(t) || triggerRef.current?.contains(t))
531
+ return;
532
+ const el = e.target instanceof Element ? e.target : null;
533
+ if (el?.closest?.(`[${DROPDOWN_SUB_CONTENT_ATTR}]`)) return;
534
+ setOpen(false);
535
+ };
536
+ document.addEventListener("mousedown", handler);
537
+ return () => document.removeEventListener("mousedown", handler);
538
+ }, [open, setOpen, triggerRef]);
539
+ useEffect(() => {
540
+ if (!open) return;
541
+ const handler = (e) => {
542
+ const menu = menuRef.current;
543
+ if (!menu) return;
544
+ const focusedEl = document.activeElement;
545
+ if (focusedEl && !menu.contains(focusedEl)) return;
546
+ const items = getItems(menu);
547
+ const idx = items.indexOf(focusedEl);
548
+ switch (e.key) {
549
+ case "Escape":
550
+ if (closeOnEscape) {
551
+ e.preventDefault();
552
+ setOpen(false);
553
+ triggerRef.current?.focus();
554
+ }
555
+ break;
556
+ case "ArrowDown":
557
+ e.preventDefault();
558
+ if (items.length === 0) break;
559
+ if (idx === -1 || idx === items.length - 1 && loop)
560
+ items[0]?.focus();
561
+ else if (idx < items.length - 1) items[idx + 1]?.focus();
562
+ break;
563
+ case "ArrowUp":
564
+ e.preventDefault();
565
+ if (items.length === 0) break;
566
+ if (idx <= 0 && loop) items[items.length - 1]?.focus();
567
+ else if (idx > 0) items[idx - 1]?.focus();
568
+ break;
569
+ case "Home":
570
+ e.preventDefault();
571
+ items[0]?.focus();
572
+ break;
573
+ case "End":
574
+ e.preventDefault();
575
+ items[items.length - 1]?.focus();
576
+ break;
577
+ case "Tab":
578
+ setOpen(false);
579
+ break;
580
+ }
581
+ };
582
+ window.addEventListener("keydown", handler);
583
+ return () => window.removeEventListener("keydown", handler);
584
+ }, [open, closeOnEscape, loop, setOpen, triggerRef]);
585
+ useEffect(() => {
586
+ if (!open || !isMobileSheet) return;
587
+ document.body.style.overflow = "hidden";
588
+ return () => {
589
+ document.body.style.overflow = "";
590
+ };
591
+ }, [open, isMobileSheet]);
592
+ if (!shouldRender || typeof document === "undefined") return null;
593
+ if (isMobileSheet) {
594
+ return /* @__PURE__ */ jsx(
595
+ DropdownMobileBottomSheetPortal,
596
+ {
597
+ ...props,
598
+ open,
599
+ isAnimating,
600
+ slideEntrance,
601
+ slideOffsetPx,
602
+ sheetTitle: resolvedMobile.title,
603
+ sheetExtraClassName: resolvedMobile.sheetExtraClassName,
604
+ contentClassName: resolvedMobile.contentClassName,
605
+ onRequestClose: () => setOpen(false),
606
+ menuRef,
607
+ portalZClassName: "z-50",
608
+ className,
609
+ style,
610
+ role: "menu",
611
+ "aria-orientation": "vertical",
612
+ tabIndex: -1,
613
+ children
614
+ }
615
+ );
616
+ }
617
+ const resolvedMinW = minWidth === "trigger" ? Math.max(triggerW, DROPDOWN_MENU_MIN_WIDTH_PX) : minWidth;
618
+ return createPortal(
619
+ /* @__PURE__ */ jsx(
620
+ "div",
621
+ {
622
+ ...props,
623
+ ref: menuRef,
624
+ role: "menu",
625
+ "aria-orientation": "vertical",
626
+ tabIndex: -1,
627
+ className: cn(
628
+ "bg-background border-primary/8 absolute z-50 overflow-hidden rounded-xl border py-1.5 outline-none",
629
+ DROPDOWN_PANEL_SHADOW,
630
+ DROPDOWN_PANEL_SCROLL,
631
+ className
632
+ ),
633
+ style: {
634
+ position: "absolute",
635
+ top: pos.top,
636
+ left: pos.left,
637
+ minWidth: resolvedMinW,
638
+ transformOrigin: DROPDOWN_CONTENT_ORIGIN[pos.side],
639
+ transform: isAnimating ? "none" : DROPDOWN_CONTENT_HIDDEN[pos.side],
640
+ opacity: isAnimating ? 1 : 0,
641
+ transitionProperty: "opacity, transform",
642
+ transitionDuration: `${duration}ms`,
643
+ transitionTimingFunction: isAnimating ? DROPDOWN_PANEL_OPEN_EASING : DROPDOWN_PANEL_CLOSE_EASING,
644
+ ...style
645
+ },
646
+ children
647
+ }
648
+ ),
649
+ document.body
650
+ );
651
+ };
652
+ function getItems(menu) {
653
+ return Array.from(
654
+ menu.querySelectorAll(
655
+ '[role="menuitem"]:not([aria-disabled="true"]),[role="menuitemcheckbox"]:not([aria-disabled="true"]),[role="menuitemradio"]:not([aria-disabled="true"])'
656
+ )
657
+ );
658
+ }
659
+ var DropdownItem = ({
660
+ children,
661
+ disabled = false,
662
+ destructive = false,
663
+ icon,
664
+ shortcut,
665
+ closeOnSelect = true,
666
+ inset = false,
667
+ className,
668
+ onClick,
669
+ ...props
670
+ }) => {
671
+ const { setOpen } = useDropdown();
672
+ const handleClick = (e) => {
673
+ if (disabled) return;
674
+ onClick?.(e);
675
+ if (closeOnSelect) setOpen(false);
676
+ };
677
+ const handleKeyDown = (e) => {
678
+ if (e.key === "Enter" || e.key === " ") {
679
+ e.preventDefault();
680
+ handleClick(e);
681
+ }
682
+ };
683
+ return /* @__PURE__ */ jsxs(
684
+ "div",
685
+ {
686
+ ...props,
687
+ role: "menuitem",
688
+ tabIndex: disabled ? void 0 : -1,
689
+ "aria-disabled": disabled,
690
+ onClick: handleClick,
691
+ onKeyDown: handleKeyDown,
692
+ className: cn(
693
+ "relative mx-1.5 flex items-center gap-2 rounded-md px-3 py-2 text-sm transition-colors duration-0 outline-none select-none",
694
+ DROPDOWN_SHEET_MENU_TEXT,
695
+ inset && "pl-9",
696
+ !disabled && "cursor-pointer",
697
+ disabled && "lg:cursor-not-allowed",
698
+ !disabled && !destructive && "text-foreground hover:bg-primary/8 focus-visible:bg-primary/8 dark:hover:bg-primary/4 dark:focus-visible:bg-primary/4",
699
+ !disabled && destructive && "text-destructive hover:bg-destructive/10 focus-visible:bg-destructive/10 dark:text-destructive-foreground dark:hover:bg-destructive-foreground/18 dark:focus-visible:bg-destructive-foreground/18",
700
+ disabled && !destructive && "text-foreground/45 dark:text-foreground/50",
701
+ disabled && destructive && "bg-destructive/5 text-destructive/75 dark:bg-destructive-foreground/12 dark:text-destructive-foreground/78",
702
+ className
703
+ ),
704
+ children: [
705
+ icon && /* @__PURE__ */ jsx("span", { className: "flex size-4 shrink-0 items-center justify-center", children: icon }),
706
+ /* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1", children }),
707
+ shortcut ? /* @__PURE__ */ jsx(
708
+ "span",
709
+ {
710
+ className: cn(
711
+ "ml-auto text-xs tracking-widest",
712
+ DROPDOWN_SHEET_MENU_SHORTCUT,
713
+ destructive ? "text-destructive/70 dark:text-destructive-foreground/80" : "opacity-40"
714
+ ),
715
+ children: shortcut
716
+ }
717
+ ) : null
718
+ ]
719
+ }
720
+ );
721
+ };
722
+ var DropdownSeparator = ({ className, ...props }) => /* @__PURE__ */ jsx(
723
+ "div",
724
+ {
725
+ role: "separator",
726
+ className: cn("border-primary/10 my-1.5 border-t", className),
727
+ ...props
728
+ }
729
+ );
730
+ React2__default.createContext(
731
+ void 0
732
+ );
733
+
734
+ // src/react/table-view/helpers.ts
735
+ function getTableLeafColumnOrderList(table) {
736
+ const o = table.getState().columnOrder;
737
+ if (o && o.length > 0) return [...o];
738
+ return table.getVisibleLeafColumns().map((c) => c.id);
739
+ }
740
+ function moveTableColumnOneStep(table, columnId, direction) {
741
+ const list = getTableLeafColumnOrderList(table);
742
+ const i = list.indexOf(columnId);
743
+ if (i < 0) return;
744
+ const next = [...list];
745
+ if (direction === "left" && i > 0) {
746
+ [next[i - 1], next[i]] = [next[i], next[i - 1]];
747
+ } else if (direction === "right" && i < next.length - 1) {
748
+ [next[i + 1], next[i]] = [next[i], next[i + 1]];
749
+ } else {
750
+ return;
751
+ }
752
+ table.setColumnOrder(next);
753
+ }
754
+
755
+ // src/react/table-view/meta.ts
756
+ function getTableViewColumnDisableReorder(column) {
757
+ return Boolean(column.columnDef.meta?.tableView?.disableColumnReorder);
758
+ }
759
+ var ColumnHeaderMenuInner = forwardRef(function ColumnHeaderMenuInner2({ table, header, columnSort, columnReorder }, ref) {
760
+ const [open, setOpen] = useState(false);
761
+ useImperativeHandle(
762
+ ref,
763
+ () => ({
764
+ open: () => {
765
+ setOpen(true);
766
+ }
767
+ }),
768
+ []
769
+ );
770
+ const col = header.column;
771
+ const id = col.id;
772
+ const canPin = col.getCanPin();
773
+ const pin = col.getIsPinned();
774
+ const list = getTableLeafColumnOrderList(table);
775
+ const idx = list.indexOf(id);
776
+ const reorderLocked = getTableViewColumnDisableReorder(col);
777
+ const canMoveLeft = columnReorder && !reorderLocked && idx > 0;
778
+ const canMoveRight = columnReorder && !reorderLocked && idx >= 0 && idx < list.length - 1;
779
+ const canSort = columnSort && col.getCanSort();
780
+ const hasMoveSection = canMoveLeft || canMoveRight;
781
+ const hasSortSection = !!canSort;
782
+ const hasPinSection = canPin;
783
+ const hasHideSection = col.getCanHide();
784
+ if (!hasMoveSection && !hasSortSection && !hasPinSection && !hasHideSection) {
785
+ return null;
786
+ }
787
+ const showSepBeforeHide = hasHideSection && (hasMoveSection || hasSortSection || hasPinSection);
788
+ return /* @__PURE__ */ jsx(
789
+ "div",
790
+ {
791
+ className: cn(
792
+ "flex shrink-0 self-stretch items-center",
793
+ "opacity-0 transition-opacity duration-150 group-hover:opacity-100 group-focus-within:opacity-100 has-[[data-state=open]]:opacity-100"
794
+ ),
795
+ onClick: (e) => e.stopPropagation(),
796
+ children: /* @__PURE__ */ jsxs(Dropdown, { open, onOpenChange: setOpen, children: [
797
+ /* @__PURE__ */ jsx(DropdownTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
798
+ Button,
799
+ {
800
+ type: "button",
801
+ size: "xs",
802
+ iconOnly: true,
803
+ rounded: "full",
804
+ className: "touch-manipulation border-none bg-transparent shadow-none",
805
+ "aria-label": "Column options",
806
+ children: /* @__PURE__ */ jsx(MoreVertical, { className: "size-3.5", strokeWidth: 2.25, "aria-hidden": true })
807
+ }
808
+ ) }),
809
+ /* @__PURE__ */ jsxs(DropdownContent, { align: "end", side: "bottom", offset: 4, children: [
810
+ hasMoveSection ? /* @__PURE__ */ jsxs(Fragment, { children: [
811
+ /* @__PURE__ */ jsx(
812
+ DropdownItem,
813
+ {
814
+ disabled: !canMoveLeft,
815
+ icon: /* @__PURE__ */ jsx(
816
+ ArrowLeft,
817
+ {
818
+ className: "size-3.5",
819
+ strokeWidth: 2.25,
820
+ "aria-hidden": true
821
+ }
822
+ ),
823
+ onClick: () => {
824
+ if (canMoveLeft) moveTableColumnOneStep(table, id, "left");
825
+ },
826
+ children: "Move to the left"
827
+ }
828
+ ),
829
+ /* @__PURE__ */ jsx(
830
+ DropdownItem,
831
+ {
832
+ disabled: !canMoveRight,
833
+ icon: /* @__PURE__ */ jsx(
834
+ ArrowRight,
835
+ {
836
+ className: "size-3.5",
837
+ strokeWidth: 2.25,
838
+ "aria-hidden": true
839
+ }
840
+ ),
841
+ onClick: () => {
842
+ if (canMoveRight) moveTableColumnOneStep(table, id, "right");
843
+ },
844
+ children: "Move to the right"
845
+ }
846
+ )
847
+ ] }) : null,
848
+ hasMoveSection && (hasSortSection || hasPinSection) ? /* @__PURE__ */ jsx(DropdownSeparator, {}) : null,
849
+ hasSortSection ? /* @__PURE__ */ jsxs(Fragment, { children: [
850
+ /* @__PURE__ */ jsx(
851
+ DropdownItem,
852
+ {
853
+ icon: /* @__PURE__ */ jsx(
854
+ ChevronUp,
855
+ {
856
+ className: "size-3.5",
857
+ strokeWidth: 2.25,
858
+ "aria-hidden": true
859
+ }
860
+ ),
861
+ onClick: () => {
862
+ col.toggleSorting(false);
863
+ },
864
+ children: "Sort ascending"
865
+ }
866
+ ),
867
+ /* @__PURE__ */ jsx(
868
+ DropdownItem,
869
+ {
870
+ icon: /* @__PURE__ */ jsx(
871
+ ChevronDown,
872
+ {
873
+ className: "size-3.5",
874
+ strokeWidth: 2.25,
875
+ "aria-hidden": true
876
+ }
877
+ ),
878
+ onClick: () => {
879
+ col.toggleSorting(true);
880
+ },
881
+ children: "Sort descending"
882
+ }
883
+ )
884
+ ] }) : null,
885
+ hasSortSection && hasPinSection ? /* @__PURE__ */ jsx(DropdownSeparator, {}) : null,
886
+ hasPinSection ? /* @__PURE__ */ jsxs(Fragment, { children: [
887
+ pin !== "left" ? /* @__PURE__ */ jsx(
888
+ DropdownItem,
889
+ {
890
+ icon: /* @__PURE__ */ jsx(Pin, { className: "size-3.5", strokeWidth: 2.25, "aria-hidden": true }),
891
+ onClick: () => {
892
+ col.pin("left");
893
+ },
894
+ children: "Pin to the left"
895
+ }
896
+ ) : null,
897
+ pin !== "right" ? /* @__PURE__ */ jsx(
898
+ DropdownItem,
899
+ {
900
+ icon: /* @__PURE__ */ jsx(
901
+ Pin,
902
+ {
903
+ className: "size-3.5 -scale-x-100",
904
+ strokeWidth: 2.25,
905
+ "aria-hidden": true
906
+ }
907
+ ),
908
+ onClick: () => {
909
+ col.pin("right");
910
+ },
911
+ children: "Pin to the right"
912
+ }
913
+ ) : null,
914
+ pin ? /* @__PURE__ */ jsx(
915
+ DropdownItem,
916
+ {
917
+ icon: /* @__PURE__ */ jsx(
918
+ PinOff,
919
+ {
920
+ className: "size-3.5",
921
+ strokeWidth: 2.25,
922
+ "aria-hidden": true
923
+ }
924
+ ),
925
+ onClick: () => {
926
+ col.pin(false);
927
+ },
928
+ children: "Unpin column"
929
+ }
930
+ ) : null
931
+ ] }) : null,
932
+ showSepBeforeHide ? /* @__PURE__ */ jsx(DropdownSeparator, {}) : null,
933
+ hasHideSection ? /* @__PURE__ */ jsx(
934
+ DropdownItem,
935
+ {
936
+ icon: /* @__PURE__ */ jsx(EyeOff, { className: "size-3.5", strokeWidth: 2.25, "aria-hidden": true }),
937
+ onClick: () => {
938
+ col.toggleVisibility(false);
939
+ setOpen(false);
940
+ },
941
+ children: "Hide column"
942
+ }
943
+ ) : null
944
+ ] })
945
+ ] })
946
+ }
947
+ );
948
+ });
949
+ ColumnHeaderMenuInner.displayName = "ColumnHeaderMenuInner";
950
+ var ColumnHeaderMenu = memo(ColumnHeaderMenuInner);
951
+ ColumnHeaderMenu.displayName = "ColumnHeaderMenu";
952
+
953
+ export { ColumnHeaderMenu };
954
+ //# sourceMappingURL=column-menu.js.map
955
+ //# sourceMappingURL=column-menu.js.map