nish-ui 2.0.2 → 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.
- package/README.md +18 -8
- package/dist/chart.js +1 -1
- package/dist/elements-all.js +13 -13
- package/dist/elements-charts.js +1 -1
- package/dist/elements-data.js +1 -1
- package/dist/elements-forms.js +1 -1
- package/dist/elements.js +3 -3
- package/dist/esm/components/app-shell.js +145 -45
- package/dist/esm/components/breadcrumbs.js +1 -1
- package/dist/esm/components/calendar-classes.js +325 -0
- package/dist/esm/components/calendar.js +263 -0
- package/dist/esm/components/canvas/route.js +56 -20
- package/dist/esm/components/carousel-classes.js +27 -0
- package/dist/esm/components/carousel.js +317 -0
- package/dist/esm/components/command.js +2 -27
- package/dist/esm/components/context-menu.js +199 -0
- package/dist/esm/components/date-picker.js +208 -0
- package/dist/esm/components/display-classes.js +10 -13
- package/dist/esm/components/display.js +22 -19
- package/dist/esm/components/drawer.js +139 -0
- package/dist/esm/components/filters.js +1 -1
- package/dist/esm/components/flow.js +1 -1
- package/dist/esm/components/hover-card.js +221 -0
- package/dist/esm/components/icons.js +17 -0
- package/dist/esm/components/inbox.js +2 -1
- package/dist/esm/components/lazy-module.js +53 -0
- package/dist/esm/components/menu.js +344 -0
- package/dist/esm/components/modal.js +173 -0
- package/dist/esm/components/more-sheet.js +52 -0
- package/dist/esm/components/multi-select.js +420 -0
- package/dist/esm/components/nav-items.js +138 -0
- package/dist/esm/components/nav.js +13 -174
- package/dist/esm/components/navigate.js +33 -0
- package/dist/esm/components/overlay-core.js +221 -0
- package/dist/esm/components/overlay-dialog.js +255 -0
- package/dist/esm/components/overlay-position.js +163 -0
- package/dist/esm/components/overlay.js +7 -1441
- package/dist/esm/components/popover.js +92 -0
- package/dist/esm/components/segmented.js +2 -1
- package/dist/esm/components/split.js +1 -1
- package/dist/esm/components/strings.js +25 -0
- package/dist/esm/components/tooltip.js +177 -0
- package/dist/esm/components/tree-view-classes.js +57 -0
- package/dist/esm/components/tree-view.js +319 -0
- package/dist/esm/components/virtual-table.js +245 -0
- package/dist/esm/components/virtual.js +291 -0
- package/dist/esm/inbox.js +12 -0
- package/dist/esm/index.js +61 -2
- package/dist/esm/runtime.js +1 -1
- package/dist/esm/service-tokens.js +6 -0
- package/dist/esm/theme.js +2 -2
- package/dist/esm/virtual-range.js +73 -0
- package/dist/format.js +1 -1
- package/dist/inbox.d.ts +238 -0
- package/dist/index.d.ts +1030 -777
- package/dist/nish-components.css +2 -0
- package/dist/nish-components.min.css +1 -1
- package/dist/service-tokens.d.ts +60 -0
- package/dist/theme.d.ts +50 -0
- package/dist/theme.global.js +28 -3
- package/dist/theme.js +28 -3
- package/package.json +17 -1
|
@@ -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 {
|
|
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
|
+
};
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/modal.tsx
|
|
4
|
+
import { useCallback, useEffect, useId, useRef } from "react";
|
|
5
|
+
import { cn } from "../cn.js";
|
|
6
|
+
import { XIcon } from "./icons.js";
|
|
7
|
+
import { Button } from "./primitives.js";
|
|
8
|
+
import { useLatest } from "./latest.js";
|
|
9
|
+
import { Portal } from "./portal.js";
|
|
10
|
+
import { useNishStrings } from "./provider.js";
|
|
11
|
+
import { CLOSE_BUTTON, MODAL_SIZE, SHEET_HEIGHT_CLASS } from "./overlay-classes.js";
|
|
12
|
+
import { isPhoneViewport, closeVetoes, warnDev, useMergedRef, useScrollable } from "./overlay-core.js";
|
|
13
|
+
import { useDialog, useSheetExit, useSheetSwipe, SheetHandle } from "./overlay-dialog.js";
|
|
14
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
15
|
+
function Modal({ open, ...props }) {
|
|
16
|
+
if (open === false) return null;
|
|
17
|
+
return /* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsx(ModalPanel, { ...props }) });
|
|
18
|
+
}
|
|
19
|
+
function ModalPanel({
|
|
20
|
+
title,
|
|
21
|
+
onClose,
|
|
22
|
+
onOpenChange,
|
|
23
|
+
children,
|
|
24
|
+
size = "md",
|
|
25
|
+
footer,
|
|
26
|
+
subtitle,
|
|
27
|
+
placement = "center",
|
|
28
|
+
header,
|
|
29
|
+
hideClose = false,
|
|
30
|
+
"aria-label": ariaLabel,
|
|
31
|
+
"aria-labelledby": ariaLabelledBy,
|
|
32
|
+
sheetHeight = "auto",
|
|
33
|
+
dismissible = true,
|
|
34
|
+
closeOnBack = true,
|
|
35
|
+
canClose,
|
|
36
|
+
className,
|
|
37
|
+
role,
|
|
38
|
+
ref,
|
|
39
|
+
...rest
|
|
40
|
+
}) {
|
|
41
|
+
const strings = useNishStrings();
|
|
42
|
+
const titleId = useId();
|
|
43
|
+
const [panelRef, setPanelRef] = useMergedRef(ref);
|
|
44
|
+
const scrimRef = useRef(null);
|
|
45
|
+
const bodyRef = useRef(null);
|
|
46
|
+
const { closing, requestClose, closeNow, isClosing, allowClose } = useSheetExit(onClose, canClose, onOpenChange);
|
|
47
|
+
useDialog(panelRef, requestClose, closeOnBack);
|
|
48
|
+
const swipe = useSheetSwipe(panelRef, scrimRef, () => dismissible && !isClosing() && isPhoneViewport(), closeNow, allowClose);
|
|
49
|
+
const showTitle = header === void 0 && title !== void 0 && title !== null;
|
|
50
|
+
const named = showTitle || !!ariaLabel || !!ariaLabelledBy;
|
|
51
|
+
const scrollable = useScrollable(bodyRef);
|
|
52
|
+
const bodyLabel = typeof title === "string" ? title : ariaLabel;
|
|
53
|
+
useEffect(() => {
|
|
54
|
+
if (!named) warnDev("nish-ui: <Modal> has no accessible name. Pass `title`, `aria-label` or `aria-labelledby`.");
|
|
55
|
+
}, [named]);
|
|
56
|
+
return /* @__PURE__ */ jsx(
|
|
57
|
+
"div",
|
|
58
|
+
{
|
|
59
|
+
ref: scrimRef,
|
|
60
|
+
"data-nish-layer": "",
|
|
61
|
+
"data-state": closing ? "closed" : "open",
|
|
62
|
+
className: cn(
|
|
63
|
+
"fixed inset-0 z-[var(--nish-z-modal,50)] flex items-end justify-center bg-th-scrim/60 sm:p-4",
|
|
64
|
+
closing ? "pointer-events-none animate-[nish-fade-out_200ms_ease-in_forwards]" : "animate-[nish-fade-in_160ms_ease-out]",
|
|
65
|
+
placement === "top" ? "sm:items-start sm:pt-[12vh]" : "sm:items-center"
|
|
66
|
+
),
|
|
67
|
+
onMouseDown: (e) => {
|
|
68
|
+
if (e.target === e.currentTarget) requestClose();
|
|
69
|
+
},
|
|
70
|
+
children: /* @__PURE__ */ jsxs(
|
|
71
|
+
"div",
|
|
72
|
+
{
|
|
73
|
+
...rest,
|
|
74
|
+
ref: setPanelRef,
|
|
75
|
+
role: role ?? "dialog",
|
|
76
|
+
"aria-modal": "true",
|
|
77
|
+
"aria-labelledby": ariaLabelledBy ?? (showTitle && !ariaLabel ? titleId : void 0),
|
|
78
|
+
"aria-label": ariaLabel,
|
|
79
|
+
"data-state": closing ? "closed" : "open",
|
|
80
|
+
tabIndex: -1,
|
|
81
|
+
className: cn(
|
|
82
|
+
"flex w-full flex-col border border-th-line bg-th-surface shadow-modal outline-none",
|
|
83
|
+
"rounded-t-2xl pb-[env(safe-area-inset-bottom)]",
|
|
84
|
+
closing ? "max-sm:animate-[nish-sheet-out_200ms_ease-in_forwards] sm:animate-[nish-fade-out_200ms_ease-in_forwards]" : "animate-[nish-sheet-in_240ms_var(--nish-ease-out)] sm:animate-[nish-rise-in_200ms_var(--nish-ease-out)]",
|
|
85
|
+
"sm:max-h-[85dvh] sm:rounded-2xl sm:pb-0",
|
|
86
|
+
placement === "top" && "sm:max-h-[76dvh]",
|
|
87
|
+
SHEET_HEIGHT_CLASS[sheetHeight],
|
|
88
|
+
MODAL_SIZE[size],
|
|
89
|
+
className
|
|
90
|
+
),
|
|
91
|
+
children: [
|
|
92
|
+
dismissible ? /* @__PURE__ */ jsx(SheetHandle, { onClose: requestClose, swipe, className: "sm:hidden" }) : null,
|
|
93
|
+
header !== void 0 ? /* @__PURE__ */ jsx("div", { className: cn("shrink-0", dismissible && "max-sm:touch-pan-x"), ...dismissible ? swipe : {}, children: header }) : /* @__PURE__ */ jsxs(
|
|
94
|
+
"div",
|
|
95
|
+
{
|
|
96
|
+
className: cn("flex shrink-0 items-start justify-between gap-3 px-5 pb-2 pt-3 sm:pt-4", dismissible && "max-sm:touch-pan-x"),
|
|
97
|
+
...dismissible ? swipe : {},
|
|
98
|
+
children: [
|
|
99
|
+
/* @__PURE__ */ jsx("h2", { id: titleId, className: "min-w-0 line-clamp-2 break-words pt-1 text-base font-semibold leading-snug text-th-hi", children: title }),
|
|
100
|
+
hideClose ? null : /* @__PURE__ */ jsx("button", { type: "button", onClick: requestClose, "aria-label": strings.close, className: CLOSE_BUTTON, children: /* @__PURE__ */ jsx(XIcon, { size: 16 }) })
|
|
101
|
+
]
|
|
102
|
+
}
|
|
103
|
+
),
|
|
104
|
+
subtitle ? /* @__PURE__ */ jsx("div", { className: "shrink-0 border-b border-th-line px-5 pb-3 text-sm text-th-hi2", children: subtitle }) : null,
|
|
105
|
+
/* @__PURE__ */ jsx(
|
|
106
|
+
"div",
|
|
107
|
+
{
|
|
108
|
+
ref: bodyRef,
|
|
109
|
+
tabIndex: scrollable ? 0 : void 0,
|
|
110
|
+
role: scrollable && bodyLabel ? "region" : void 0,
|
|
111
|
+
"aria-label": scrollable ? bodyLabel : void 0,
|
|
112
|
+
className: cn("min-h-0 flex-1 overflow-y-auto overscroll-contain px-5 pb-5 text-sm text-th-hi2", header !== void 0 && "pt-3"),
|
|
113
|
+
children
|
|
114
|
+
}
|
|
115
|
+
),
|
|
116
|
+
footer ? /* @__PURE__ */ jsx("div", { className: "flex shrink-0 flex-wrap items-center justify-end gap-2 border-t border-th-line px-5 py-3", children: footer }) : null
|
|
117
|
+
]
|
|
118
|
+
}
|
|
119
|
+
)
|
|
120
|
+
}
|
|
121
|
+
);
|
|
122
|
+
}
|
|
123
|
+
function ConfirmDialog({
|
|
124
|
+
title,
|
|
125
|
+
body,
|
|
126
|
+
confirmLabel,
|
|
127
|
+
cancelLabel,
|
|
128
|
+
tone = "danger",
|
|
129
|
+
pending = false,
|
|
130
|
+
onConfirm,
|
|
131
|
+
onCancel,
|
|
132
|
+
open,
|
|
133
|
+
onOpenChange
|
|
134
|
+
}) {
|
|
135
|
+
const strings = useNishStrings();
|
|
136
|
+
const bodyId = useId();
|
|
137
|
+
const pendingRef = useLatest(pending);
|
|
138
|
+
const onOpenChangeRef = useLatest(onOpenChange);
|
|
139
|
+
const onCancelRef = useLatest(onCancel);
|
|
140
|
+
const cancel = useCallback(() => {
|
|
141
|
+
if (pendingRef.current) return;
|
|
142
|
+
onCancelRef.current?.();
|
|
143
|
+
onOpenChangeRef.current?.(false);
|
|
144
|
+
}, [onCancelRef, onOpenChangeRef, pendingRef]);
|
|
145
|
+
useEffect(() => {
|
|
146
|
+
closeVetoes.set(cancel, () => pendingRef.current);
|
|
147
|
+
return () => {
|
|
148
|
+
closeVetoes.delete(cancel);
|
|
149
|
+
};
|
|
150
|
+
}, [cancel, pendingRef]);
|
|
151
|
+
const danger = tone === "danger";
|
|
152
|
+
const hasBody = body !== void 0 && body !== null && body !== false;
|
|
153
|
+
return /* @__PURE__ */ jsx(
|
|
154
|
+
Modal,
|
|
155
|
+
{
|
|
156
|
+
open,
|
|
157
|
+
title,
|
|
158
|
+
onClose: cancel,
|
|
159
|
+
size: "md",
|
|
160
|
+
role: "alertdialog",
|
|
161
|
+
"aria-describedby": hasBody ? bodyId : void 0,
|
|
162
|
+
footer: /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
163
|
+
/* @__PURE__ */ jsx(Button, { onClick: cancel, disabled: pending, "data-autofocus": danger ? "" : void 0, children: cancelLabel ?? strings.cancel }),
|
|
164
|
+
/* @__PURE__ */ jsx(Button, { variant: danger ? "danger" : "primary", loading: pending, onClick: onConfirm, "data-autofocus": danger ? void 0 : "", children: confirmLabel })
|
|
165
|
+
] }),
|
|
166
|
+
children: hasBody ? /* @__PURE__ */ jsx("div", { id: bodyId, children: body }) : null
|
|
167
|
+
}
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
export {
|
|
171
|
+
ConfirmDialog,
|
|
172
|
+
Modal
|
|
173
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/more-sheet.tsx
|
|
4
|
+
import { cn } from "../cn.js";
|
|
5
|
+
import { FORCED_MARK } from "./display-classes.js";
|
|
6
|
+
import { Drawer } from "./drawer.js";
|
|
7
|
+
import { FOCUS, NavBadge, renderItem, visibleNavItems } from "./nav-items.js";
|
|
8
|
+
import { useNishStrings } from "./provider.js";
|
|
9
|
+
import { ThemeToggle } from "./theme-toggle.js";
|
|
10
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
11
|
+
function MoreSheet({ open, onClose, items, title, footer, renderLink }) {
|
|
12
|
+
const strings = useNishStrings();
|
|
13
|
+
if (!open) return null;
|
|
14
|
+
const shown = visibleNavItems(items);
|
|
15
|
+
const row = (active) => cn(
|
|
16
|
+
"flex min-h-[52px] w-full items-center gap-3 rounded-lg px-3 text-start transition-colors",
|
|
17
|
+
active ? cn("bg-th-accent-soft text-th-accent", FORCED_MARK) : "text-th-hi hover:bg-th-elevated",
|
|
18
|
+
FOCUS
|
|
19
|
+
);
|
|
20
|
+
return /* @__PURE__ */ jsx(
|
|
21
|
+
Drawer,
|
|
22
|
+
{
|
|
23
|
+
side: "bottom",
|
|
24
|
+
title: title ?? strings.more,
|
|
25
|
+
onClose,
|
|
26
|
+
bottomOffset: "var(--nish-bottom-nav-h, 0px)",
|
|
27
|
+
footer: footer ?? /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-3 px-5 py-3", children: [
|
|
28
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm font-medium text-th-hi", children: strings.theme }),
|
|
29
|
+
/* @__PURE__ */ jsx(ThemeToggle, { phone: "segmented" })
|
|
30
|
+
] }),
|
|
31
|
+
children: /* @__PURE__ */ jsx("ul", { className: "m-0 list-none p-2", children: shown.map((item) => /* @__PURE__ */ jsx("li", { children: renderItem(
|
|
32
|
+
item,
|
|
33
|
+
row(!!item.active),
|
|
34
|
+
/* @__PURE__ */ jsxs(Fragment, { children: [
|
|
35
|
+
/* @__PURE__ */ jsxs("span", { className: "relative inline-flex size-6 shrink-0 items-center justify-center", children: [
|
|
36
|
+
item.icon,
|
|
37
|
+
/* @__PURE__ */ jsx(NavBadge, { value: item.badge })
|
|
38
|
+
] }),
|
|
39
|
+
/* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1", children: [
|
|
40
|
+
/* @__PURE__ */ jsx("span", { className: "block truncate text-sm font-medium", children: item.label }),
|
|
41
|
+
item.hint ? /* @__PURE__ */ jsx("span", { className: cn("block truncate text-xs", item.active ? "text-th-accent/80" : "text-th-hi3"), children: item.hint }) : null
|
|
42
|
+
] })
|
|
43
|
+
] }),
|
|
44
|
+
renderLink,
|
|
45
|
+
onClose
|
|
46
|
+
) }, item.key)) })
|
|
47
|
+
}
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
export {
|
|
51
|
+
MoreSheet
|
|
52
|
+
};
|