nish-ui 2.0.1 → 2.1.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 (63) hide show
  1. package/README.md +18 -8
  2. package/dist/chart.js +1 -1
  3. package/dist/elements-all.js +13 -13
  4. package/dist/elements-charts.js +1 -1
  5. package/dist/elements-data.js +1 -1
  6. package/dist/elements-forms.js +1 -1
  7. package/dist/elements.js +3 -3
  8. package/dist/esm/components/app-shell.js +145 -45
  9. package/dist/esm/components/breadcrumbs.js +1 -1
  10. package/dist/esm/components/calendar-classes.js +325 -0
  11. package/dist/esm/components/calendar.js +263 -0
  12. package/dist/esm/components/canvas/route.js +56 -20
  13. package/dist/esm/components/carousel-classes.js +27 -0
  14. package/dist/esm/components/carousel.js +317 -0
  15. package/dist/esm/components/command.js +2 -27
  16. package/dist/esm/components/context-menu.js +199 -0
  17. package/dist/esm/components/date-picker.js +208 -0
  18. package/dist/esm/components/display-classes.js +10 -13
  19. package/dist/esm/components/display.js +22 -19
  20. package/dist/esm/components/drawer.js +139 -0
  21. package/dist/esm/components/filters.js +1 -1
  22. package/dist/esm/components/flow.js +1 -1
  23. package/dist/esm/components/hooks.js +17 -6
  24. package/dist/esm/components/hover-card.js +221 -0
  25. package/dist/esm/components/icons.js +17 -0
  26. package/dist/esm/components/inbox.js +2 -1
  27. package/dist/esm/components/lazy-module.js +53 -0
  28. package/dist/esm/components/menu.js +344 -0
  29. package/dist/esm/components/modal.js +173 -0
  30. package/dist/esm/components/more-sheet.js +52 -0
  31. package/dist/esm/components/multi-select.js +420 -0
  32. package/dist/esm/components/nav-items.js +138 -0
  33. package/dist/esm/components/nav.js +13 -174
  34. package/dist/esm/components/navigate.js +33 -0
  35. package/dist/esm/components/overlay-core.js +221 -0
  36. package/dist/esm/components/overlay-dialog.js +255 -0
  37. package/dist/esm/components/overlay-position.js +163 -0
  38. package/dist/esm/components/overlay.js +7 -1441
  39. package/dist/esm/components/popover.js +92 -0
  40. package/dist/esm/components/segmented.js +2 -1
  41. package/dist/esm/components/split.js +1 -1
  42. package/dist/esm/components/strings.js +25 -0
  43. package/dist/esm/components/tooltip.js +177 -0
  44. package/dist/esm/components/tree-view-classes.js +57 -0
  45. package/dist/esm/components/tree-view.js +319 -0
  46. package/dist/esm/components/virtual-table.js +245 -0
  47. package/dist/esm/components/virtual.js +291 -0
  48. package/dist/esm/inbox.js +12 -0
  49. package/dist/esm/index.js +61 -2
  50. package/dist/esm/runtime.js +1 -1
  51. package/dist/esm/service-tokens.js +6 -0
  52. package/dist/esm/theme.js +2 -2
  53. package/dist/esm/virtual-range.js +73 -0
  54. package/dist/format.js +1 -1
  55. package/dist/inbox.d.ts +238 -0
  56. package/dist/index.d.ts +1032 -778
  57. package/dist/nish-components.css +2 -0
  58. package/dist/nish-components.min.css +1 -1
  59. package/dist/service-tokens.d.ts +60 -0
  60. package/dist/theme.d.ts +50 -0
  61. package/dist/theme.global.js +28 -3
  62. package/dist/theme.js +28 -3
  63. package/package.json +17 -1
@@ -0,0 +1,221 @@
1
+ "use client";
2
+
3
+ // src/components/hover-card.tsx
4
+ import {
5
+ Children,
6
+ cloneElement,
7
+ isValidElement,
8
+ useCallback,
9
+ useEffect,
10
+ useId,
11
+ useMemo,
12
+ useRef,
13
+ useState
14
+ } from "react";
15
+ import { createPortal } from "react-dom";
16
+ import { cn } from "../cn.js";
17
+ import { shared } from "../runtime.js";
18
+ import { isRtl, useIsClient, useIsoLayoutEffect } from "./client.js";
19
+ import { mergeRefs, warnOnce } from "./data-classes.js";
20
+ import { useLatest } from "./latest.js";
21
+ import { place } from "./overlay-position.js";
22
+ import { keyboardFocused, touchTracker } from "./overlay-classes.js";
23
+ import { useNishConfig } from "./provider.js";
24
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
25
+ var openCard = () => shared("hoverCard", () => ({ close: null }));
26
+ function useCardPosition(anchor, card, open, side, align) {
27
+ const [pos, setPos] = useState(null);
28
+ useIsoLayoutEffect(() => {
29
+ if (!open) {
30
+ setPos(null);
31
+ return;
32
+ }
33
+ const update = () => {
34
+ const a = anchor.current;
35
+ const f = card.current;
36
+ if (!a || !f) return;
37
+ const naturalH = f.scrollHeight + (f.offsetHeight - f.clientHeight);
38
+ const next = place(a.getBoundingClientRect(), f.offsetWidth, Math.max(f.offsetHeight, naturalH), side, align, 8, isRtl(a));
39
+ setPos(
40
+ (prev) => prev && prev.top === next.top && prev.left === next.left && prev.side === next.side && prev.maxHeight === next.maxHeight ? prev : next
41
+ );
42
+ };
43
+ update();
44
+ window.addEventListener("resize", update);
45
+ window.addEventListener("scroll", update, true);
46
+ const ro = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(update);
47
+ if (card.current) ro?.observe(card.current);
48
+ if (anchor.current) ro?.observe(anchor.current);
49
+ return () => {
50
+ window.removeEventListener("resize", update);
51
+ window.removeEventListener("scroll", update, true);
52
+ ro?.disconnect();
53
+ };
54
+ }, [anchor, card, open, side, align]);
55
+ return open ? pos : null;
56
+ }
57
+ function HoverCard({
58
+ children,
59
+ content,
60
+ side = "bottom",
61
+ align = "center",
62
+ openDelay = 500,
63
+ closeDelay = 300,
64
+ open: openProp,
65
+ defaultOpen,
66
+ onOpenChange,
67
+ width = 320,
68
+ className,
69
+ ref,
70
+ style,
71
+ onPointerEnter,
72
+ onPointerLeave,
73
+ ...rest
74
+ }) {
75
+ const [openState, setOpenState] = useState(defaultOpen ?? false);
76
+ const open = openProp ?? openState;
77
+ const config = useNishConfig();
78
+ const isClient = useIsClient();
79
+ const autoId = useId();
80
+ const id = rest.id ?? autoId;
81
+ const wrapperRef = useRef(null);
82
+ const cardRef = useRef(null);
83
+ const timer = useRef(0);
84
+ const latest = useLatest({ open, onOpenChange, controlled: openProp !== void 0 });
85
+ const child = Children.count(children) === 1 && isValidElement(children) ? children : null;
86
+ const valid = child !== null;
87
+ useEffect(() => {
88
+ if (!valid) warnOnce("hovercard-child", "HoverCard: children must be one element, such as a link.");
89
+ }, [valid]);
90
+ const apply = useCallback(
91
+ (next) => {
92
+ const cur = latest.current;
93
+ if (next === cur.open) return;
94
+ if (!cur.controlled) setOpenState(next);
95
+ cur.onOpenChange?.(next);
96
+ },
97
+ [latest]
98
+ );
99
+ const show = useCallback(() => {
100
+ window.clearTimeout(timer.current);
101
+ timer.current = window.setTimeout(() => apply(true), openDelay);
102
+ }, [apply, openDelay]);
103
+ const hide = useCallback(() => {
104
+ window.clearTimeout(timer.current);
105
+ timer.current = window.setTimeout(() => apply(false), closeDelay);
106
+ }, [apply, closeDelay]);
107
+ const stay = useCallback(() => window.clearTimeout(timer.current), []);
108
+ const closeNow = useCallback(() => {
109
+ window.clearTimeout(timer.current);
110
+ apply(false);
111
+ }, [apply]);
112
+ useEffect(() => {
113
+ const el = wrapperRef.current;
114
+ if (!el) return;
115
+ const touch = touchTracker();
116
+ const onPointerEnterTrigger = (e) => touch.onPointer(e);
117
+ const onPointerDown = (e) => {
118
+ touch.onPointer(e);
119
+ if (e.pointerType === "touch") closeNow();
120
+ };
121
+ const onMouseEnter = () => {
122
+ if (!touch.recent()) show();
123
+ };
124
+ const onMouseLeave = (e) => {
125
+ if (e.relatedTarget instanceof Node && cardRef.current?.contains(e.relatedTarget)) return;
126
+ const active = document.activeElement;
127
+ if (active && el.contains(active) && keyboardFocused(active)) return;
128
+ hide();
129
+ };
130
+ const onFocusIn = (e) => {
131
+ if (e.target instanceof Element && keyboardFocused(e.target)) show();
132
+ };
133
+ el.addEventListener("pointerenter", onPointerEnterTrigger);
134
+ el.addEventListener("pointerdown", onPointerDown);
135
+ el.addEventListener("mouseenter", onMouseEnter);
136
+ el.addEventListener("mouseleave", onMouseLeave);
137
+ el.addEventListener("focusin", onFocusIn);
138
+ el.addEventListener("focusout", hide);
139
+ return () => {
140
+ window.clearTimeout(timer.current);
141
+ el.removeEventListener("pointerenter", onPointerEnterTrigger);
142
+ el.removeEventListener("pointerdown", onPointerDown);
143
+ el.removeEventListener("mouseenter", onMouseEnter);
144
+ el.removeEventListener("mouseleave", onMouseLeave);
145
+ el.removeEventListener("focusin", onFocusIn);
146
+ el.removeEventListener("focusout", hide);
147
+ };
148
+ }, [valid, show, hide, closeNow]);
149
+ useEffect(() => {
150
+ if (!open) return;
151
+ const onKey = (e) => {
152
+ if (e.key !== "Escape") return;
153
+ e.stopPropagation();
154
+ closeNow();
155
+ };
156
+ document.addEventListener("keydown", onKey, true);
157
+ return () => document.removeEventListener("keydown", onKey, true);
158
+ }, [open, closeNow]);
159
+ useEffect(() => {
160
+ if (!open) return;
161
+ const slot = openCard();
162
+ if (slot.close && slot.close !== closeNow) slot.close();
163
+ slot.close = closeNow;
164
+ return () => {
165
+ if (slot.close === closeNow) slot.close = null;
166
+ };
167
+ }, [open, closeNow]);
168
+ const [host, setHost] = useState(null);
169
+ useIsoLayoutEffect(() => {
170
+ setHost(open ? wrapperRef.current?.closest("[data-nish-layer]") ?? config.portalContainer ?? document.body : null);
171
+ }, [open, config.portalContainer]);
172
+ const cardRefs = useMemo(() => mergeRefs(cardRef, ref), [ref]);
173
+ const pos = useCardPosition(wrapperRef, cardRef, open && isClient && valid && host !== null, side, align);
174
+ if (!child) return /* @__PURE__ */ jsx(Fragment, { children });
175
+ const existing = child.props["aria-describedby"];
176
+ const describedby = open ? [typeof existing === "string" ? existing : "", id].filter(Boolean).join(" ") : existing;
177
+ const trigger = cloneElement(child, { "aria-describedby": describedby || void 0 });
178
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
179
+ /* @__PURE__ */ jsx("span", { ref: wrapperRef, className: "inline-flex", "data-state": open ? "open" : "closed", children: trigger }),
180
+ open && isClient && host ? createPortal(
181
+ /* @__PURE__ */ jsx(
182
+ "div",
183
+ {
184
+ ...rest,
185
+ ref: cardRefs,
186
+ id,
187
+ "data-side": pos?.side,
188
+ "data-state": "open",
189
+ onPointerEnter: (e) => {
190
+ stay();
191
+ onPointerEnter?.(e);
192
+ },
193
+ onPointerLeave: (e) => {
194
+ hide();
195
+ onPointerLeave?.(e);
196
+ },
197
+ style: {
198
+ ...style,
199
+ position: "fixed",
200
+ top: pos?.top ?? 0,
201
+ left: pos?.left ?? 0,
202
+ visibility: pos ? void 0 : "hidden",
203
+ width,
204
+ maxWidth: "calc(100vw - 1rem)",
205
+ maxHeight: pos?.maxHeight,
206
+ zIndex: "var(--nish-z-tooltip, 100)"
207
+ },
208
+ className: cn(
209
+ "overflow-y-auto overscroll-contain rounded-lg border border-th-line bg-th-elevated p-3 text-sm text-th-hi2 shadow-pop animate-[nish-fade-in_120ms_ease-out] motion-reduce:animate-none",
210
+ className
211
+ ),
212
+ children: content
213
+ }
214
+ ),
215
+ host
216
+ ) : null
217
+ ] });
218
+ }
219
+ export {
220
+ HoverCard
221
+ };
@@ -75,12 +75,27 @@ var PanelLeftOpenIcon = (p) => /* @__PURE__ */ jsxs(Svg, { ...p, children: [
75
75
  /* @__PURE__ */ jsx("path", { d: "M9 3v18" }),
76
76
  /* @__PURE__ */ jsx("path", { d: "m14 9 3 3-3 3" })
77
77
  ] });
78
+ var ChevronLeftIcon = (p) => /* @__PURE__ */ jsx(Svg, { ...p, children: /* @__PURE__ */ jsx("path", { d: "m15 18-6-6 6-6" }) });
79
+ var ChevronRightIcon = (p) => /* @__PURE__ */ jsx(Svg, { ...p, children: /* @__PURE__ */ jsx("path", { d: "m9 18 6-6-6-6" }) });
80
+ var CalendarIcon = (p) => /* @__PURE__ */ jsxs(Svg, { ...p, children: [
81
+ /* @__PURE__ */ jsx("path", { d: "M8 2v4M16 2v4" }),
82
+ /* @__PURE__ */ jsx("rect", { width: "18", height: "18", x: "3", y: "4", rx: "2" }),
83
+ /* @__PURE__ */ jsx("path", { d: "M3 10h18" })
84
+ ] });
85
+ var PauseIcon = (p) => /* @__PURE__ */ jsxs(Svg, { ...p, children: [
86
+ /* @__PURE__ */ jsx("rect", { x: "14", y: "4", width: "4", height: "16", rx: "1" }),
87
+ /* @__PURE__ */ jsx("rect", { x: "6", y: "4", width: "4", height: "16", rx: "1" })
88
+ ] });
89
+ var PlayIcon = (p) => /* @__PURE__ */ jsx(Svg, { ...p, children: /* @__PURE__ */ jsx("polygon", { points: "6 3 20 12 6 21 6 3" }) });
78
90
  export {
79
91
  AlertTriangleIcon,
80
92
  BellIcon,
93
+ CalendarIcon,
81
94
  CheckCircleIcon,
82
95
  CheckIcon,
83
96
  ChevronDownIcon,
97
+ ChevronLeftIcon,
98
+ ChevronRightIcon,
84
99
  ClockIcon,
85
100
  InfoIcon,
86
101
  LoaderIcon,
@@ -89,6 +104,8 @@ export {
89
104
  MoreIcon,
90
105
  PanelLeftCloseIcon,
91
106
  PanelLeftOpenIcon,
107
+ PauseIcon,
108
+ PlayIcon,
92
109
  RotateIcon,
93
110
  SettingsIcon,
94
111
  SunIcon,
@@ -11,7 +11,8 @@ import { StatusDot } from "./display.js";
11
11
  import { EmptyState, ErrorState, SkeletonRows } from "./feedback.js";
12
12
  import { RelativeTime, useMediaQuery } from "./hooks.js";
13
13
  import { CheckIcon, ClockIcon, MoreIcon } from "./icons.js";
14
- import { ConfirmDialog, DropdownMenu, MenuItem, MenuLabel, MenuSeparator } from "./overlay.js";
14
+ import { DropdownMenu, MenuItem, MenuLabel, MenuSeparator } from "./menu.js";
15
+ import { ConfirmDialog } from "./modal.js";
15
16
  import { Button, Card, IconButton } from "./primitives.js";
16
17
  import { useNishStrings } from "./provider.js";
17
18
  import { Tabs } from "./tabs.js";
@@ -0,0 +1,53 @@
1
+ "use client";
2
+
3
+ // src/components/lazy-module.ts
4
+ import { useEffect, useState } from "react";
5
+ import { useLatest } from "./latest.js";
6
+ function lazyModule(importer) {
7
+ let mod = null;
8
+ let pending = null;
9
+ return {
10
+ current: () => mod,
11
+ load: () => pending ??= importer().then(
12
+ (m) => mod = m,
13
+ (e) => {
14
+ pending = null;
15
+ throw e;
16
+ }
17
+ )
18
+ };
19
+ }
20
+ function useLazyModule(m, when, onError) {
21
+ const [, rerender] = useState(0);
22
+ const errorRef = useLatest(onError);
23
+ useEffect(() => {
24
+ if (!when || m.current()) return;
25
+ let live = true;
26
+ m.load().then(
27
+ () => live && rerender((n) => n + 1),
28
+ () => live && errorRef.current?.()
29
+ );
30
+ return () => {
31
+ live = false;
32
+ };
33
+ }, [m, when, errorRef]);
34
+ return m.current();
35
+ }
36
+ function preloadWhenIdle(m) {
37
+ if (typeof window === "undefined" || m.current()) return () => {
38
+ };
39
+ const run = () => {
40
+ m.load().catch(() => void 0);
41
+ };
42
+ if (typeof window.requestIdleCallback === "function") {
43
+ const id2 = window.requestIdleCallback(run, { timeout: 3e3 });
44
+ return () => window.cancelIdleCallback(id2);
45
+ }
46
+ const id = window.setTimeout(run, 1500);
47
+ return () => window.clearTimeout(id);
48
+ }
49
+ export {
50
+ lazyModule,
51
+ preloadWhenIdle,
52
+ useLazyModule
53
+ };
@@ -0,0 +1,344 @@
1
+ "use client";
2
+
3
+ // src/components/menu.tsx
4
+ import { cloneElement, createContext, useCallback, useContext, useEffect, useId, useRef, useState } from "react";
5
+ import { createPortal } from "react-dom";
6
+ import { cn } from "../cn.js";
7
+ import { isRtl } from "./client.js";
8
+ import { useMediaQuery } from "./hooks.js";
9
+ import { useLatest } from "./latest.js";
10
+ import { lazyModule, useLazyModule } from "./lazy-module.js";
11
+ import { useNishConfig, useNishStrings } from "./provider.js";
12
+ import { MENU_ROW, PHONE_QUERY, menuItemClass } from "./overlay-classes.js";
13
+ import { layerHost, setRef, useMergedRef } from "./overlay-core.js";
14
+ import { useAnchoredPosition, floatingStyle, useDismiss, useReturnFocus } from "./overlay-position.js";
15
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
16
+ var MenuContext = /* @__PURE__ */ createContext(null);
17
+ var drawerModule = /* @__PURE__ */ lazyModule(() => import("./drawer.js"));
18
+ var ITEM_SELECTOR = '[role="menuitem"]:not([aria-disabled="true"])';
19
+ function menuItems(menu) {
20
+ return menu ? Array.from(menu.querySelectorAll(ITEM_SELECTOR)) : [];
21
+ }
22
+ function usePhoneViewport(enabled) {
23
+ const phone = useMediaQuery(PHONE_QUERY);
24
+ return enabled && phone;
25
+ }
26
+ function Cloned({ element, ...props }) {
27
+ return cloneElement(element, props);
28
+ }
29
+ function DropdownMenu({
30
+ trigger,
31
+ align = "start",
32
+ side = "bottom",
33
+ children,
34
+ open: openProp,
35
+ onOpenChange,
36
+ defaultOpen = false,
37
+ "aria-label": ariaLabel,
38
+ sheetBelow = false,
39
+ sheetTitle,
40
+ className,
41
+ ref,
42
+ style,
43
+ onKeyDown: userKeyDown,
44
+ ...rest
45
+ }) {
46
+ const strings = useNishStrings();
47
+ const config = useNishConfig();
48
+ const [openState, setOpenState] = useState(defaultOpen);
49
+ const open = openProp ?? openState;
50
+ const triggerRef = useRef(null);
51
+ const [triggerNode, setTriggerNode] = useState(null);
52
+ const triggerPropRef = trigger.props.ref;
53
+ const attachTrigger = useCallback(
54
+ (node) => {
55
+ triggerRef.current = node;
56
+ setTriggerNode(node);
57
+ setRef(triggerPropRef, node);
58
+ },
59
+ [triggerPropRef]
60
+ );
61
+ const shown = open && triggerNode != null;
62
+ const [menuRef, setMenuRef] = useMergedRef(ref);
63
+ const menuId = useId();
64
+ const triggerId = useId();
65
+ const initial = useRef("first");
66
+ const wantSheet = usePhoneViewport(sheetBelow === "sm");
67
+ const drawer = useLazyModule(drawerModule, wantSheet);
68
+ const asSheet = wantSheet && drawer != null;
69
+ const pos = useAnchoredPosition(triggerRef, menuRef, shown && !asSheet, side, align, 4);
70
+ const onOpenChangeRef = useLatest(onOpenChange);
71
+ const setOpen = useCallback(
72
+ (next, reason) => {
73
+ if (openProp === void 0) setOpenState(next);
74
+ onOpenChangeRef.current?.(next, reason);
75
+ },
76
+ [onOpenChangeRef, openProp]
77
+ );
78
+ const close = useCallback(() => setOpen(false), [setOpen]);
79
+ const dismiss = useCallback((reason) => setOpen(false, reason), [setOpen]);
80
+ useDismiss(shown && !asSheet, menuRef, triggerRef, dismiss);
81
+ useReturnFocus(shown, menuRef, triggerRef);
82
+ useEffect(() => {
83
+ if (!shown) return;
84
+ const menu = menuRef.current;
85
+ if (!menu) return;
86
+ const focusInitial = () => {
87
+ const items = menuItems(menu);
88
+ const target = initial.current === "last" ? items[items.length - 1] : initial.current === "menu" ? menu : items[0];
89
+ (target ?? menu).focus();
90
+ };
91
+ const t = window.setTimeout(focusInitial, 0);
92
+ const mo = new MutationObserver(() => {
93
+ if (!menu.contains(document.activeElement) && (document.activeElement === document.body || !document.activeElement)) {
94
+ initial.current = "first";
95
+ focusInitial();
96
+ }
97
+ });
98
+ mo.observe(menu, { childList: true, subtree: true });
99
+ return () => {
100
+ window.clearTimeout(t);
101
+ mo.disconnect();
102
+ };
103
+ }, [shown, asSheet, menuRef]);
104
+ function openWith(where) {
105
+ initial.current = where;
106
+ setOpen(true);
107
+ }
108
+ function onMenuKeyDown(e) {
109
+ userKeyDown?.(e);
110
+ const items = menuItems(menuRef.current);
111
+ const i = items.indexOf(document.activeElement);
112
+ const go = (n) => {
113
+ e.preventDefault();
114
+ items[(n + items.length) % items.length]?.focus();
115
+ };
116
+ switch (e.key) {
117
+ case "ArrowDown":
118
+ return go(i + 1);
119
+ case "ArrowUp":
120
+ return go(i < 0 ? items.length - 1 : i - 1);
121
+ case "Home":
122
+ return go(0);
123
+ case "End":
124
+ return go(items.length - 1);
125
+ case "Tab":
126
+ e.preventDefault();
127
+ dismiss("tab");
128
+ return;
129
+ default:
130
+ if (e.key.length === 1 && /\S/.test(e.key) && !e.ctrlKey && !e.metaKey && !e.altKey) {
131
+ const k = e.key.toLowerCase();
132
+ const order = [...items.slice(i + 1), ...items.slice(0, i + 1)];
133
+ const hit = order.find((el) => (el.textContent ?? "").trim().toLowerCase().startsWith(k));
134
+ if (hit) {
135
+ e.preventDefault();
136
+ hit.focus();
137
+ }
138
+ }
139
+ }
140
+ }
141
+ const tp = trigger.props;
142
+ const triggerEl = /* @__PURE__ */ jsx(
143
+ Cloned,
144
+ {
145
+ element: trigger,
146
+ ref: attachTrigger,
147
+ id: tp.id ?? triggerId,
148
+ "aria-haspopup": "menu",
149
+ "aria-expanded": open,
150
+ "aria-controls": open ? menuId : void 0,
151
+ onClick: (e) => {
152
+ tp.onClick?.(e);
153
+ if (e.defaultPrevented) return;
154
+ if (open) close();
155
+ else openWith(e.detail === 0 ? "first" : "menu");
156
+ },
157
+ onKeyDown: (e) => {
158
+ tp.onKeyDown?.(e);
159
+ if (e.defaultPrevented) return;
160
+ if (e.key === "ArrowDown" || e.key === "ArrowUp") {
161
+ e.preventDefault();
162
+ openWith(e.key === "ArrowDown" ? "first" : "last");
163
+ }
164
+ }
165
+ }
166
+ );
167
+ const menuProps = {
168
+ ...rest,
169
+ ref: setMenuRef,
170
+ id: menuId,
171
+ role: "menu",
172
+ "aria-label": ariaLabel,
173
+ "aria-labelledby": ariaLabel ? void 0 : tp.id ?? triggerId,
174
+ "aria-orientation": "vertical",
175
+ "data-state": "open",
176
+ tabIndex: -1,
177
+ onKeyDown: onMenuKeyDown
178
+ };
179
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
180
+ triggerEl,
181
+ open && asSheet ? /* @__PURE__ */ jsx(MenuContext.Provider, { value: { close }, children: /* @__PURE__ */ jsx(drawer.Drawer, { side: "bottom", size: "md", title: sheetTitle ?? strings.menu, onClose: close, children: /* @__PURE__ */ jsx(
182
+ "div",
183
+ {
184
+ ...menuProps,
185
+ style,
186
+ className: cn(
187
+ "-mx-5 -my-4 py-2 outline-none [&_[role=menuitem]]:min-h-12 [&_[role=menuitem]]:px-5 [&_[role=menuitem]]:text-sm",
188
+ className
189
+ ),
190
+ children
191
+ }
192
+ ) }) }) : shown ? createPortal(
193
+ /* @__PURE__ */ jsx(MenuContext.Provider, { value: { close }, children: /* @__PURE__ */ jsx(
194
+ "div",
195
+ {
196
+ ...menuProps,
197
+ "data-side": pos?.side,
198
+ style: floatingStyle(pos, {
199
+ ...style,
200
+ maxHeight: pos ? Math.min(pos.maxHeight, 384) : void 0,
201
+ zIndex: "var(--nish-z-dropdown, 40)"
202
+ }),
203
+ className: cn(
204
+ "max-h-[min(24rem,calc(100dvh-1rem))] min-w-44 max-w-[calc(100vw-1rem)] overflow-y-auto overscroll-contain",
205
+ "rounded-lg border border-th-line bg-th-elevated py-1 shadow-pop outline-none animate-[nish-fade-in_120ms_ease-out]",
206
+ className
207
+ ),
208
+ children
209
+ }
210
+ ) }),
211
+ layerHost(triggerNode, config.portalContainer)
212
+ ) : null
213
+ ] });
214
+ }
215
+ function MenuItem({
216
+ icon,
217
+ trailing,
218
+ danger = false,
219
+ active = false,
220
+ disabled = false,
221
+ onSelect,
222
+ className,
223
+ children,
224
+ ref,
225
+ onClick,
226
+ onMouseMove,
227
+ ...rest
228
+ }) {
229
+ const ctx = useContext(MenuContext);
230
+ function select() {
231
+ if (disabled) return;
232
+ const ev = new Event("nish-menu-select", { cancelable: true });
233
+ onSelect?.(ev);
234
+ if (!ev.defaultPrevented) ctx?.close();
235
+ }
236
+ return /* @__PURE__ */ jsxs(
237
+ "button",
238
+ {
239
+ ...rest,
240
+ ref,
241
+ type: "button",
242
+ role: "menuitem",
243
+ tabIndex: -1,
244
+ "aria-disabled": disabled || void 0,
245
+ "aria-current": active || void 0,
246
+ "data-disabled": disabled ? "" : void 0,
247
+ onClick: (e) => {
248
+ onClick?.(e);
249
+ if (!e.defaultPrevented) select();
250
+ },
251
+ onMouseMove: (e) => {
252
+ onMouseMove?.(e);
253
+ if (!disabled && document.activeElement !== e.currentTarget) e.currentTarget.focus();
254
+ },
255
+ className: menuItemClass({
256
+ active,
257
+ danger,
258
+ disabled,
259
+ className: cn(!disabled && (danger ? "focus:bg-th-loss-soft" : "focus:bg-th-overlay focus:text-th-hi"), className)
260
+ }),
261
+ children: [
262
+ icon ? /* @__PURE__ */ jsx("span", { className: cn("inline-flex shrink-0", danger || disabled ? "" : "text-th-hi3"), children: icon }) : null,
263
+ /* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 truncate", children }),
264
+ trailing ? /* @__PURE__ */ jsx("span", { className: cn("ms-auto inline-flex shrink-0 items-center", disabled ? "" : "text-th-hi2"), children: trailing }) : null
265
+ ]
266
+ }
267
+ );
268
+ }
269
+ function MenuLabel({
270
+ children,
271
+ className,
272
+ ref,
273
+ ...rest
274
+ }) {
275
+ return /* @__PURE__ */ jsx(
276
+ "div",
277
+ {
278
+ ...rest,
279
+ ref,
280
+ role: "presentation",
281
+ className: cn("px-3 pb-1 pt-2 text-2xs font-semibold uppercase tracking-wider text-th-hi2", className),
282
+ children
283
+ }
284
+ );
285
+ }
286
+ function MenuSeparator({
287
+ className,
288
+ ref,
289
+ ...rest
290
+ }) {
291
+ return /* @__PURE__ */ jsx("div", { ...rest, ref, role: "separator", className: cn("my-1 h-px bg-th-line forced-colors:bg-[CanvasText]", className) });
292
+ }
293
+ function MenuSubHeader({ onBack, children, className, ref, onKeyDown, ...rest }) {
294
+ const strings = useNishStrings();
295
+ return /* @__PURE__ */ jsxs(
296
+ "button",
297
+ {
298
+ ...rest,
299
+ ref,
300
+ type: "button",
301
+ role: "menuitem",
302
+ tabIndex: -1,
303
+ onClick: onBack,
304
+ onKeyDown: (e) => {
305
+ onKeyDown?.(e);
306
+ if (e.key === (isRtl(e.currentTarget) ? "ArrowRight" : "ArrowLeft")) {
307
+ e.preventDefault();
308
+ onBack();
309
+ }
310
+ },
311
+ className: cn(MENU_ROW, "mb-1 border-b border-th-line pb-2 font-semibold text-th-hi hover:bg-th-overlay focus:bg-th-overlay", className),
312
+ children: [
313
+ /* @__PURE__ */ jsx(
314
+ "svg",
315
+ {
316
+ width: 14,
317
+ height: 14,
318
+ viewBox: "0 0 24 24",
319
+ fill: "none",
320
+ stroke: "currentColor",
321
+ strokeWidth: 2,
322
+ strokeLinecap: "round",
323
+ strokeLinejoin: "round",
324
+ "aria-hidden": "true",
325
+ className: "shrink-0 text-th-hi3 rtl:-scale-x-100",
326
+ children: /* @__PURE__ */ jsx("path", { d: "m15 18-6-6 6-6" })
327
+ }
328
+ ),
329
+ /* @__PURE__ */ jsx("span", { className: "sr-only", children: strings.back }),
330
+ /* @__PURE__ */ jsx("span", { className: "min-w-0 flex-1 truncate", children })
331
+ ]
332
+ }
333
+ );
334
+ }
335
+ export {
336
+ DropdownMenu,
337
+ ITEM_SELECTOR,
338
+ MenuContext,
339
+ MenuItem,
340
+ MenuLabel,
341
+ MenuSeparator,
342
+ MenuSubHeader,
343
+ menuItems
344
+ };