nish-ui 1.9.0 → 2.0.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 +218 -58
- package/dist/base-tailwind.css +1757 -0
- package/dist/base.css +1590 -1445
- package/dist/chart.d.ts +4 -1
- package/dist/chart.js +122 -49
- package/dist/elements-all.d.ts +8 -0
- package/dist/elements-all.js +178 -0
- package/dist/elements-charts.d.ts +71 -0
- package/dist/elements-charts.js +56 -57
- package/dist/elements-data.d.ts +71 -0
- package/dist/elements-data.js +5 -6
- package/dist/elements-forms.d.ts +71 -0
- package/dist/elements-forms.js +24 -25
- package/dist/elements.d.ts +71 -0
- package/dist/elements.js +4 -5
- package/dist/esm/chart-values.js +58 -0
- package/dist/esm/chart.js +10 -0
- package/dist/esm/cn.js +19 -0
- package/dist/esm/combobox-filter.js +13 -0
- package/dist/esm/components/accordion.js +166 -0
- package/dist/esm/components/app-shell.js +198 -0
- package/dist/esm/components/avatar-classes.js +28 -0
- package/dist/esm/components/avatar.js +113 -0
- package/dist/esm/components/breadcrumbs.js +154 -0
- package/dist/esm/components/canvas/follow-caption.js +32 -0
- package/dist/esm/components/canvas/follow.js +119 -0
- package/dist/esm/components/canvas/icons.js +70 -0
- package/dist/esm/components/canvas/index.js +10 -0
- package/dist/esm/components/canvas/layout.js +258 -0
- package/dist/esm/components/canvas/legend.js +93 -0
- package/dist/esm/components/canvas/minimap.js +127 -0
- package/dist/esm/components/canvas/node.js +87 -0
- package/dist/esm/components/canvas/route.js +262 -0
- package/dist/esm/components/canvas/system-canvas.js +837 -0
- package/dist/esm/components/canvas/types.js +10 -0
- package/dist/esm/components/canvas/view.js +47 -0
- package/dist/esm/components/chart-hooks.js +19 -0
- package/dist/esm/components/charts.js +467 -0
- package/dist/esm/components/client.js +24 -0
- package/dist/esm/components/combobox.js +343 -0
- package/dist/esm/components/command.js +403 -0
- package/dist/esm/components/data-classes.js +159 -0
- package/dist/esm/components/data.js +517 -0
- package/dist/esm/components/display-classes.js +130 -0
- package/dist/esm/components/display.js +755 -0
- package/dist/esm/components/error-boundary.js +64 -0
- package/dist/esm/components/feedback.js +136 -0
- package/dist/esm/components/file-dropzone.js +184 -0
- package/dist/esm/components/filters.js +108 -0
- package/dist/esm/components/flow.js +746 -0
- package/dist/esm/components/forms-classes.js +43 -0
- package/dist/esm/components/forms.js +581 -0
- package/dist/esm/components/hooks-classes.js +9 -0
- package/dist/esm/components/hooks.js +236 -0
- package/dist/esm/components/icons.js +96 -0
- package/dist/esm/components/inbox-classes.js +29 -0
- package/dist/esm/components/inbox.js +257 -0
- package/dist/esm/components/latest.js +13 -0
- package/dist/esm/components/layout-vars.js +96 -0
- package/dist/esm/components/layout.js +272 -0
- package/dist/esm/components/media.js +143 -0
- package/dist/esm/components/nav.js +614 -0
- package/dist/esm/components/overlay-classes.js +66 -0
- package/dist/esm/components/overlay.js +1447 -0
- package/dist/esm/components/pagination-classes.js +29 -0
- package/dist/esm/components/pagination.js +154 -0
- package/dist/esm/components/portal.js +16 -0
- package/dist/esm/components/primitives-classes.js +198 -0
- package/dist/esm/components/primitives.js +268 -0
- package/dist/esm/components/progress.js +77 -0
- package/dist/esm/components/provider.js +32 -0
- package/dist/esm/components/radio-group.js +186 -0
- package/dist/esm/components/resource-classes.js +133 -0
- package/dist/esm/components/resource.js +209 -0
- package/dist/esm/components/segmented.js +178 -0
- package/dist/esm/components/separator.js +38 -0
- package/dist/esm/components/service-tokens.js +221 -0
- package/dist/esm/components/settings.js +301 -0
- package/dist/esm/components/slider.js +262 -0
- package/dist/esm/components/split-classes.js +8 -0
- package/dist/esm/components/split.js +411 -0
- package/dist/esm/components/strings.js +119 -0
- package/dist/esm/components/table.js +144 -0
- package/dist/esm/components/tabs-classes.js +21 -0
- package/dist/esm/components/tabs.js +201 -0
- package/dist/esm/components/tag-input.js +257 -0
- package/dist/esm/components/theme-toggle.js +177 -0
- package/dist/esm/components/toast.js +361 -0
- package/dist/esm/components/url-state.js +118 -0
- package/dist/esm/components/visually-hidden.js +20 -0
- package/dist/esm/format.js +320 -0
- package/dist/esm/inbox-client.js +2 -0
- package/dist/esm/inbox-types.js +2 -0
- package/dist/esm/index.js +320 -0
- package/dist/esm/runtime.js +37 -0
- package/dist/esm/server/inbox/client.js +297 -0
- package/dist/esm/server/inbox/types.js +24 -0
- package/dist/esm/sparkline-path.js +59 -0
- package/dist/esm/split-layout.js +419 -0
- package/dist/esm/system-canvas.js +2 -0
- package/dist/esm/theme.js +804 -0
- package/dist/esm/tokens.mjs +425 -0
- package/dist/esm/url.js +20 -0
- package/dist/files.json +5 -1
- package/dist/fonts/LICENSE-Inter.txt +93 -0
- package/dist/format.d.ts +32 -18
- package/dist/format.js +227 -82
- package/dist/inbox-client.js +3 -1
- package/dist/index.d.ts +1686 -667
- package/dist/nish-components.css +4649 -4506
- package/dist/nish-components.min.css +1 -0
- package/dist/nish.css +1603 -1450
- package/dist/nish.min.css +1 -0
- package/dist/node/eslint.js +29 -14
- package/dist/node/th-check.js +29 -14
- package/dist/node/vite.d.ts +12 -0
- package/dist/node/vite.js +12 -2
- package/dist/server/hono.d.ts +15 -6
- package/dist/server/hono.js +30 -25
- package/dist/server/index.d.ts +3 -10
- package/dist/server/index.js +71 -38
- package/dist/{spa-DuVB5O7S.d.ts → spa-BLlMc0eI.d.ts} +38 -5
- package/dist/system-canvas-BLuWd69H.d.ts +183 -0
- package/dist/system-canvas.d.ts +2 -168
- package/dist/tailwind-core.css +114 -0
- package/dist/tailwind.css +3 -7
- package/dist/theme-init.js +23 -9
- package/dist/theme-init.sha256 +1 -0
- package/dist/theme.d.ts +243 -4
- package/dist/theme.global.js +356 -89
- package/dist/theme.js +337 -67
- package/dist/tokens.css +14 -6
- package/dist/tokens.dtcg.json +1513 -0
- package/dist/tokens.js +29 -14
- package/dist/tokens.json +512 -0
- package/package.json +51 -13
- package/dist/chart.js.map +0 -1
- package/dist/elements-charts.js.map +0 -1
- package/dist/elements-data.js.map +0 -1
- package/dist/elements-forms.js.map +0 -1
- package/dist/elements.js.map +0 -1
- package/dist/format.js.map +0 -1
- package/dist/inbox-client.js.map +0 -1
- package/dist/index.js +0 -10260
- package/dist/index.js.map +0 -1
- package/dist/server/hono.js.map +0 -1
- package/dist/server/index.js.map +0 -1
- package/dist/split-layout.js.map +0 -1
- package/dist/system-canvas.js +0 -2204
- package/dist/system-canvas.js.map +0 -1
- package/dist/theme.global.js.map +0 -1
- package/dist/theme.js.map +0 -1
|
@@ -0,0 +1,614 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/nav.tsx
|
|
4
|
+
import {
|
|
5
|
+
Fragment,
|
|
6
|
+
useEffect,
|
|
7
|
+
useRef,
|
|
8
|
+
useState
|
|
9
|
+
} from "react";
|
|
10
|
+
import { cn } from "../cn.js";
|
|
11
|
+
import { safeUrl } from "../url.js";
|
|
12
|
+
import { isRtl, useIsoLayoutEffect } from "./client.js";
|
|
13
|
+
import { navigateFromLayer } from "./command.js";
|
|
14
|
+
import { mergeRefs } from "./data-classes.js";
|
|
15
|
+
import { FORCED_MARK, warnDev } from "./display-classes.js";
|
|
16
|
+
import { chipClass } from "./forms.js";
|
|
17
|
+
import { useMediaQuery } from "./hooks.js";
|
|
18
|
+
import { PanelLeftCloseIcon, PanelLeftOpenIcon } from "./icons.js";
|
|
19
|
+
import { useHeightVar, useScrollEdges } from "./layout-vars.js";
|
|
20
|
+
import { Drawer, Tooltip } from "./overlay.js";
|
|
21
|
+
import { IconButton } from "./primitives.js";
|
|
22
|
+
import { useNishConfig, useNishStrings } from "./provider.js";
|
|
23
|
+
import { ThemeToggle } from "./theme-toggle.js";
|
|
24
|
+
import { Fragment as Fragment2, jsx, jsxs } from "react/jsx-runtime";
|
|
25
|
+
var MAX_QUERY = {
|
|
26
|
+
md: "(max-width: 767px)",
|
|
27
|
+
lg: "(max-width: 1023px)"
|
|
28
|
+
};
|
|
29
|
+
var HIDE_FROM = { md: "md:hidden", lg: "lg:hidden" };
|
|
30
|
+
var RAIL_SHOW = { sm: "sm:flex", md: "md:flex", lg: "lg:flex" };
|
|
31
|
+
var RAIL_HIDE = { md: "md:hidden", lg: "lg:hidden", xl: "xl:hidden" };
|
|
32
|
+
function visibleNavItems(items) {
|
|
33
|
+
return items.filter((item) => {
|
|
34
|
+
if (item.href == null || safeUrl(item.href) !== null) return true;
|
|
35
|
+
warnDev(`nish-ui: nav item "${item.key}" was not rendered because its href is not safe (${item.href.slice(0, 40)}).`);
|
|
36
|
+
return false;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function useEndSide(ref) {
|
|
40
|
+
const dir = useNishConfig().dir;
|
|
41
|
+
const [rtl, setRtl] = useState(dir === "rtl");
|
|
42
|
+
useIsoLayoutEffect(() => {
|
|
43
|
+
setRtl(dir ? dir === "rtl" : isRtl(ref.current));
|
|
44
|
+
}, [dir, ref]);
|
|
45
|
+
return rtl ? "left" : "right";
|
|
46
|
+
}
|
|
47
|
+
function CountBadge({ value }) {
|
|
48
|
+
const strings = useNishStrings();
|
|
49
|
+
if (value === void 0 || value === false || value === 0) return null;
|
|
50
|
+
if (value === true) {
|
|
51
|
+
return /* @__PURE__ */ jsx(
|
|
52
|
+
"span",
|
|
53
|
+
{
|
|
54
|
+
"aria-hidden": "true",
|
|
55
|
+
className: "absolute -end-0.5 -top-0.5 size-2 rounded-full bg-th-loss ring-2 ring-th-surface forced-colors:forced-color-adjust-none forced-colors:bg-[Highlight]"
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
return /* @__PURE__ */ jsx(
|
|
60
|
+
"span",
|
|
61
|
+
{
|
|
62
|
+
"aria-label": strings.newCount(value),
|
|
63
|
+
className: "absolute -end-2.5 -top-1.5 inline-flex h-4 min-w-4 items-center justify-center rounded-full bg-th-loss px-1 text-3xs font-semibold leading-none tabular-nums text-th-on-loss ring-2 ring-th-surface forced-colors:border forced-colors:border-[CanvasText]",
|
|
64
|
+
children: value > 99 ? "99+" : value
|
|
65
|
+
}
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
var layerOf = () => history.state?.nishLayer;
|
|
69
|
+
function closeAfterRouterLink(onAfter) {
|
|
70
|
+
const layer = layerOf();
|
|
71
|
+
if (typeof window === "undefined" || !layer) {
|
|
72
|
+
onAfter();
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
let decided = false;
|
|
76
|
+
const decide = (routerTookIt) => {
|
|
77
|
+
if (decided) return;
|
|
78
|
+
decided = true;
|
|
79
|
+
window.removeEventListener("click", onWindowClick);
|
|
80
|
+
if (!routerTookIt) {
|
|
81
|
+
onAfter();
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const t0 = Date.now();
|
|
85
|
+
const wait = () => {
|
|
86
|
+
if (layerOf() !== layer || Date.now() - t0 > 3e3) onAfter();
|
|
87
|
+
else window.setTimeout(wait, 16);
|
|
88
|
+
};
|
|
89
|
+
wait();
|
|
90
|
+
};
|
|
91
|
+
const onWindowClick = (e) => decide(e.defaultPrevented);
|
|
92
|
+
window.addEventListener("click", onWindowClick);
|
|
93
|
+
window.setTimeout(() => decide(true), 0);
|
|
94
|
+
}
|
|
95
|
+
function renderItem(item, className, children, renderLink, onAfter) {
|
|
96
|
+
const current = item.active ? "page" : void 0;
|
|
97
|
+
const state = item.active ? "active" : "inactive";
|
|
98
|
+
if (item.href != null) {
|
|
99
|
+
const href = safeUrl(item.href);
|
|
100
|
+
if (href === null) return null;
|
|
101
|
+
if (renderLink) {
|
|
102
|
+
return renderLink(item, {
|
|
103
|
+
className,
|
|
104
|
+
children,
|
|
105
|
+
"aria-current": current,
|
|
106
|
+
"data-state": state,
|
|
107
|
+
...onAfter ? { replace: true } : {},
|
|
108
|
+
onClick: () => {
|
|
109
|
+
item.onSelect?.();
|
|
110
|
+
if (onAfter) closeAfterRouterLink(onAfter);
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
return /* @__PURE__ */ jsx(
|
|
115
|
+
"a",
|
|
116
|
+
{
|
|
117
|
+
href,
|
|
118
|
+
className,
|
|
119
|
+
"aria-current": current,
|
|
120
|
+
"data-state": state,
|
|
121
|
+
onClick: (e) => {
|
|
122
|
+
item.onSelect?.();
|
|
123
|
+
const inLayer = !!history.state?.nishLayer;
|
|
124
|
+
const plain = e.button === 0 && !e.metaKey && !e.ctrlKey && !e.shiftKey && !e.altKey && !e.defaultPrevented;
|
|
125
|
+
if (onAfter && inLayer && plain) {
|
|
126
|
+
e.preventDefault();
|
|
127
|
+
onAfter();
|
|
128
|
+
navigateFromLayer(href);
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
onAfter?.();
|
|
132
|
+
},
|
|
133
|
+
children
|
|
134
|
+
}
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
return /* @__PURE__ */ jsx(
|
|
138
|
+
"button",
|
|
139
|
+
{
|
|
140
|
+
type: "button",
|
|
141
|
+
className,
|
|
142
|
+
"aria-current": current,
|
|
143
|
+
"data-state": state,
|
|
144
|
+
onClick: () => {
|
|
145
|
+
item.onSelect?.();
|
|
146
|
+
onAfter?.();
|
|
147
|
+
},
|
|
148
|
+
children
|
|
149
|
+
}
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
var FOCUS = "focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-th-accent";
|
|
153
|
+
function MoreDots() {
|
|
154
|
+
return /* @__PURE__ */ jsxs("svg", { width: 22, height: 22, viewBox: "0 0 24 24", fill: "currentColor", "aria-hidden": "true", focusable: "false", children: [
|
|
155
|
+
/* @__PURE__ */ jsx("circle", { cx: "5", cy: "12", r: "1.8" }),
|
|
156
|
+
/* @__PURE__ */ jsx("circle", { cx: "12", cy: "12", r: "1.8" }),
|
|
157
|
+
/* @__PURE__ */ jsx("circle", { cx: "19", cy: "12", r: "1.8" })
|
|
158
|
+
] });
|
|
159
|
+
}
|
|
160
|
+
function BottomNav({
|
|
161
|
+
items,
|
|
162
|
+
more,
|
|
163
|
+
trailing,
|
|
164
|
+
hideFrom = "md",
|
|
165
|
+
label,
|
|
166
|
+
renderLink,
|
|
167
|
+
className,
|
|
168
|
+
ref: refProp,
|
|
169
|
+
...rest
|
|
170
|
+
}) {
|
|
171
|
+
const strings = useNishStrings();
|
|
172
|
+
const ref = useRef(null);
|
|
173
|
+
const visible = useMediaQuery(MAX_QUERY[hideFrom]);
|
|
174
|
+
useHeightVar(ref, "--nish-bottom-nav-h", visible);
|
|
175
|
+
const shown = visibleNavItems(items);
|
|
176
|
+
const pill = (active) => cn(
|
|
177
|
+
"flex w-full flex-col items-center gap-0.5 rounded-xl py-1 text-2xs leading-tight transition-colors",
|
|
178
|
+
active ? cn("bg-th-accent-soft font-medium text-th-accent", FORCED_MARK) : "text-th-hi3"
|
|
179
|
+
);
|
|
180
|
+
const cell = cn("flex min-h-14 min-w-0 flex-1 items-center justify-center px-0.5 pointer-coarse:active:scale-[0.97] transition-transform", FOCUS);
|
|
181
|
+
return /* @__PURE__ */ jsxs(
|
|
182
|
+
"nav",
|
|
183
|
+
{
|
|
184
|
+
...rest,
|
|
185
|
+
ref: mergeRefs(ref, refProp),
|
|
186
|
+
"aria-label": label ?? strings.sections,
|
|
187
|
+
"data-nish-bar": "",
|
|
188
|
+
"data-nish-print": "hide",
|
|
189
|
+
className: cn(
|
|
190
|
+
"fixed inset-x-0 bottom-0 z-[var(--nish-z-dropdown,40)] flex items-stretch border-t border-th-line bg-th-surface pb-[env(safe-area-inset-bottom)] pl-[env(safe-area-inset-left)] pr-[env(safe-area-inset-right)]",
|
|
191
|
+
HIDE_FROM[hideFrom],
|
|
192
|
+
className
|
|
193
|
+
),
|
|
194
|
+
children: [
|
|
195
|
+
shown.map((item) => /* @__PURE__ */ jsx(Fragment, { children: renderItem(
|
|
196
|
+
item,
|
|
197
|
+
cell,
|
|
198
|
+
/* @__PURE__ */ jsxs("span", { className: pill(!!item.active), children: [
|
|
199
|
+
/* @__PURE__ */ jsxs("span", { className: "relative inline-flex size-6 items-center justify-center", children: [
|
|
200
|
+
item.icon,
|
|
201
|
+
/* @__PURE__ */ jsx(CountBadge, { value: item.badge })
|
|
202
|
+
] }),
|
|
203
|
+
/* @__PURE__ */ jsx("span", { className: "max-w-full truncate px-1", children: item.label })
|
|
204
|
+
] }),
|
|
205
|
+
renderLink
|
|
206
|
+
) }, item.key)),
|
|
207
|
+
more ? /* @__PURE__ */ jsx(
|
|
208
|
+
"button",
|
|
209
|
+
{
|
|
210
|
+
type: "button",
|
|
211
|
+
"aria-expanded": more.expanded,
|
|
212
|
+
"aria-haspopup": "dialog",
|
|
213
|
+
"data-state": more.expanded ? "open" : "closed",
|
|
214
|
+
onClick: more.onToggle,
|
|
215
|
+
className: cell,
|
|
216
|
+
children: /* @__PURE__ */ jsxs("span", { className: pill(more.active || more.expanded), children: [
|
|
217
|
+
/* @__PURE__ */ jsx("span", { className: "inline-flex size-6 items-center justify-center", children: more.icon ?? /* @__PURE__ */ jsx(MoreDots, {}) }),
|
|
218
|
+
/* @__PURE__ */ jsx("span", { className: "max-w-full truncate px-1", children: more.label ?? strings.more })
|
|
219
|
+
] })
|
|
220
|
+
}
|
|
221
|
+
) : null,
|
|
222
|
+
trailing ? /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
223
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "my-2 w-px shrink-0 bg-th-line" }),
|
|
224
|
+
/* @__PURE__ */ jsx("div", { className: "flex shrink-0 items-center justify-center px-1", children: trailing })
|
|
225
|
+
] }) : null
|
|
226
|
+
]
|
|
227
|
+
}
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
function MoreSheet({ open, onClose, items, title, footer, renderLink }) {
|
|
231
|
+
const strings = useNishStrings();
|
|
232
|
+
if (!open) return null;
|
|
233
|
+
const shown = visibleNavItems(items);
|
|
234
|
+
const row = (active) => cn(
|
|
235
|
+
"flex min-h-[52px] w-full items-center gap-3 rounded-lg px-3 text-start transition-colors",
|
|
236
|
+
active ? cn("bg-th-accent-soft text-th-accent", FORCED_MARK) : "text-th-hi hover:bg-th-elevated",
|
|
237
|
+
FOCUS
|
|
238
|
+
);
|
|
239
|
+
return /* @__PURE__ */ jsx(
|
|
240
|
+
Drawer,
|
|
241
|
+
{
|
|
242
|
+
side: "bottom",
|
|
243
|
+
title: title ?? strings.more,
|
|
244
|
+
onClose,
|
|
245
|
+
bottomOffset: "var(--nish-bottom-nav-h, 0px)",
|
|
246
|
+
footer: footer ?? /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between gap-3 px-5 py-3", children: [
|
|
247
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm font-medium text-th-hi", children: strings.theme }),
|
|
248
|
+
/* @__PURE__ */ jsx(ThemeToggle, { phone: "segmented" })
|
|
249
|
+
] }),
|
|
250
|
+
children: /* @__PURE__ */ jsx("ul", { className: "m-0 list-none p-2", children: shown.map((item) => /* @__PURE__ */ jsx("li", { children: renderItem(
|
|
251
|
+
item,
|
|
252
|
+
row(!!item.active),
|
|
253
|
+
/* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
254
|
+
/* @__PURE__ */ jsxs("span", { className: "relative inline-flex size-6 shrink-0 items-center justify-center", children: [
|
|
255
|
+
item.icon,
|
|
256
|
+
/* @__PURE__ */ jsx(CountBadge, { value: item.badge })
|
|
257
|
+
] }),
|
|
258
|
+
/* @__PURE__ */ jsxs("span", { className: "min-w-0 flex-1", children: [
|
|
259
|
+
/* @__PURE__ */ jsx("span", { className: "block truncate text-sm font-medium", children: item.label }),
|
|
260
|
+
item.hint ? /* @__PURE__ */ jsx("span", { className: cn("block truncate text-xs", item.active ? "text-th-accent/80" : "text-th-hi3"), children: item.hint }) : null
|
|
261
|
+
] })
|
|
262
|
+
] }),
|
|
263
|
+
renderLink,
|
|
264
|
+
onClose
|
|
265
|
+
) }, item.key)) })
|
|
266
|
+
}
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
function NavRail({
|
|
270
|
+
items,
|
|
271
|
+
tools,
|
|
272
|
+
footer,
|
|
273
|
+
showFrom = "md",
|
|
274
|
+
hideFrom = "lg",
|
|
275
|
+
label,
|
|
276
|
+
renderLink,
|
|
277
|
+
className,
|
|
278
|
+
ref: refProp,
|
|
279
|
+
...rest
|
|
280
|
+
}) {
|
|
281
|
+
const strings = useNishStrings();
|
|
282
|
+
const ref = useRef(null);
|
|
283
|
+
const side = useEndSide(ref);
|
|
284
|
+
const shown = visibleNavItems(items);
|
|
285
|
+
return /* @__PURE__ */ jsxs(
|
|
286
|
+
"nav",
|
|
287
|
+
{
|
|
288
|
+
...rest,
|
|
289
|
+
ref: mergeRefs(ref, refProp),
|
|
290
|
+
"aria-label": label ?? strings.sections,
|
|
291
|
+
className: cn(
|
|
292
|
+
"hidden w-[72px] shrink-0 flex-col items-center gap-1 border-e border-th-line bg-th-surface py-3 pl-[env(safe-area-inset-left)]",
|
|
293
|
+
RAIL_SHOW[showFrom],
|
|
294
|
+
hideFrom ? RAIL_HIDE[hideFrom] : null,
|
|
295
|
+
className
|
|
296
|
+
),
|
|
297
|
+
children: [
|
|
298
|
+
shown.map((item) => {
|
|
299
|
+
const node = renderItem(
|
|
300
|
+
item,
|
|
301
|
+
cn("group flex min-h-14 w-full flex-col items-center justify-center gap-0.5 text-2xs leading-tight", FOCUS, item.active ? "font-medium text-th-accent" : "text-th-hi3 hover:text-th-hi"),
|
|
302
|
+
/* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
303
|
+
/* @__PURE__ */ jsxs(
|
|
304
|
+
"span",
|
|
305
|
+
{
|
|
306
|
+
className: cn(
|
|
307
|
+
"relative inline-flex h-8 w-14 items-center justify-center rounded-full transition-colors",
|
|
308
|
+
item.active ? cn("bg-th-accent-soft", FORCED_MARK) : "group-hover:bg-th-elevated"
|
|
309
|
+
),
|
|
310
|
+
children: [
|
|
311
|
+
item.icon,
|
|
312
|
+
/* @__PURE__ */ jsx(CountBadge, { value: item.badge })
|
|
313
|
+
]
|
|
314
|
+
}
|
|
315
|
+
),
|
|
316
|
+
/* @__PURE__ */ jsx("span", { className: "max-w-full truncate px-1", children: item.label })
|
|
317
|
+
] }),
|
|
318
|
+
renderLink
|
|
319
|
+
);
|
|
320
|
+
return item.hint ? /* @__PURE__ */ jsx(Tooltip, { tip: item.hint, side, focusable: false, className: "block w-full", children: node }, item.key) : /* @__PURE__ */ jsx("span", { className: "block w-full", children: node }, item.key);
|
|
321
|
+
}),
|
|
322
|
+
tools ? /* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
323
|
+
/* @__PURE__ */ jsx("span", { "aria-hidden": "true", className: "my-1 h-px w-8 bg-th-line" }),
|
|
324
|
+
tools
|
|
325
|
+
] }) : null,
|
|
326
|
+
footer ? /* @__PURE__ */ jsx("div", { className: "mt-auto flex flex-col items-center gap-2 pt-3", children: footer }) : null
|
|
327
|
+
]
|
|
328
|
+
}
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
function NavSidebar({
|
|
332
|
+
items,
|
|
333
|
+
collapsed,
|
|
334
|
+
onCollapsedChange,
|
|
335
|
+
tools,
|
|
336
|
+
footer,
|
|
337
|
+
label,
|
|
338
|
+
renderLink,
|
|
339
|
+
className,
|
|
340
|
+
ref: refProp,
|
|
341
|
+
...rest
|
|
342
|
+
}) {
|
|
343
|
+
const strings = useNishStrings();
|
|
344
|
+
const ref = useRef(null);
|
|
345
|
+
const side = useEndSide(ref);
|
|
346
|
+
const shown = visibleNavItems(items);
|
|
347
|
+
return /* @__PURE__ */ jsxs(
|
|
348
|
+
"aside",
|
|
349
|
+
{
|
|
350
|
+
"aria-label": strings.sidebar,
|
|
351
|
+
...rest,
|
|
352
|
+
ref: mergeRefs(ref, refProp),
|
|
353
|
+
"data-state": collapsed ? "closed" : "open",
|
|
354
|
+
className: cn(
|
|
355
|
+
"flex h-full shrink-0 flex-col border-e border-th-line bg-th-surface py-3 pl-[env(safe-area-inset-left)] transition-[width] duration-200 motion-reduce:transition-none",
|
|
356
|
+
collapsed ? "w-16" : "w-56",
|
|
357
|
+
className
|
|
358
|
+
),
|
|
359
|
+
children: [
|
|
360
|
+
tools ? /* @__PURE__ */ jsx("div", { className: cn("mb-2 flex gap-1 border-b border-th-line pb-2", collapsed ? "flex-col items-center" : "flex-wrap px-3"), children: tools }) : null,
|
|
361
|
+
/* @__PURE__ */ jsx("nav", { "aria-label": label ?? strings.sections, className: cn("flex min-h-0 flex-1 flex-col gap-1 overflow-y-auto", collapsed ? "items-center px-2" : "px-3"), children: shown.map((item) => {
|
|
362
|
+
const node = renderItem(
|
|
363
|
+
item,
|
|
364
|
+
cn(
|
|
365
|
+
"flex min-h-11 items-center gap-3 rounded-lg border-s-2 text-sm transition-colors",
|
|
366
|
+
FOCUS,
|
|
367
|
+
collapsed ? "w-11 justify-center" : "w-full px-3",
|
|
368
|
+
item.active ? cn("border-th-accent bg-th-accent-soft font-medium text-th-accent", FORCED_MARK) : "border-transparent text-th-hi2 hover:bg-th-elevated hover:text-th-hi"
|
|
369
|
+
),
|
|
370
|
+
/* @__PURE__ */ jsxs(Fragment2, { children: [
|
|
371
|
+
/* @__PURE__ */ jsxs("span", { className: "relative inline-flex size-5 shrink-0 items-center justify-center [&>svg]:size-5", children: [
|
|
372
|
+
item.icon,
|
|
373
|
+
/* @__PURE__ */ jsx(CountBadge, { value: item.badge })
|
|
374
|
+
] }),
|
|
375
|
+
/* @__PURE__ */ jsx("span", { className: collapsed ? "sr-only" : "min-w-0 truncate", children: item.label })
|
|
376
|
+
] }),
|
|
377
|
+
renderLink
|
|
378
|
+
);
|
|
379
|
+
const tip = collapsed ? item.label : item.hint;
|
|
380
|
+
return tip ? /* @__PURE__ */ jsx(Tooltip, { tip, side, focusable: false, className: collapsed ? "block" : "block w-full", children: node }, item.key) : /* @__PURE__ */ jsx("span", { className: "block w-full", children: node }, item.key);
|
|
381
|
+
}) }),
|
|
382
|
+
/* @__PURE__ */ jsxs("div", { className: cn("mt-3 flex gap-2 border-t border-th-line pt-3", collapsed ? "flex-col items-center" : "items-center justify-between px-3"), children: [
|
|
383
|
+
footer,
|
|
384
|
+
/* @__PURE__ */ jsx(IconButton, { label: collapsed ? strings.expandSidebar : strings.collapseSidebar, onClick: () => onCollapsedChange(!collapsed), children: collapsed ? /* @__PURE__ */ jsx(PanelLeftOpenIcon, { size: 18, className: "rtl:-scale-x-100" }) : /* @__PURE__ */ jsx(PanelLeftCloseIcon, { size: 18, className: "rtl:-scale-x-100" }) })
|
|
385
|
+
] })
|
|
386
|
+
]
|
|
387
|
+
}
|
|
388
|
+
);
|
|
389
|
+
}
|
|
390
|
+
function revealInRow(scroller, child) {
|
|
391
|
+
const s = scroller.getBoundingClientRect();
|
|
392
|
+
const c = child.getBoundingClientRect();
|
|
393
|
+
const pad = 8;
|
|
394
|
+
if (c.left < s.left + pad) scroller.scrollLeft += c.left - s.left - pad;
|
|
395
|
+
else if (c.right > s.right - pad) scroller.scrollLeft += c.right - s.right + pad;
|
|
396
|
+
}
|
|
397
|
+
var ACTIVE_SELECTOR = '[aria-pressed="true"],[aria-selected="true"],[aria-current]:not([aria-current="false"]),[aria-checked="true"]';
|
|
398
|
+
function ScrollRow({
|
|
399
|
+
children,
|
|
400
|
+
bleed = false,
|
|
401
|
+
fade = true,
|
|
402
|
+
snap = false,
|
|
403
|
+
as = "div",
|
|
404
|
+
label,
|
|
405
|
+
className,
|
|
406
|
+
ref: refProp,
|
|
407
|
+
...rest
|
|
408
|
+
}) {
|
|
409
|
+
const ref = useRef(null);
|
|
410
|
+
useScrollEdges(ref);
|
|
411
|
+
const lastActive = useRef(null);
|
|
412
|
+
useEffect(() => {
|
|
413
|
+
const active = ref.current?.querySelector(ACTIVE_SELECTOR) ?? null;
|
|
414
|
+
if (active && active !== lastActive.current) {
|
|
415
|
+
revealInRow(ref.current, active);
|
|
416
|
+
}
|
|
417
|
+
lastActive.current = active;
|
|
418
|
+
});
|
|
419
|
+
const Tag = as;
|
|
420
|
+
return /* @__PURE__ */ jsx(
|
|
421
|
+
Tag,
|
|
422
|
+
{
|
|
423
|
+
...rest,
|
|
424
|
+
ref: mergeRefs(ref, refProp),
|
|
425
|
+
"aria-label": label ?? rest["aria-label"],
|
|
426
|
+
className: cn(
|
|
427
|
+
"flex gap-2 overflow-x-auto nish-no-scrollbar",
|
|
428
|
+
fade && "nish-scroll-fade",
|
|
429
|
+
bleed && "-mx-[var(--nish-page-gutter)] px-[var(--nish-page-gutter)]",
|
|
430
|
+
snap && "snap-x snap-mandatory [&>*]:snap-start",
|
|
431
|
+
className
|
|
432
|
+
),
|
|
433
|
+
children
|
|
434
|
+
}
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
function useScrollSpy(ids, { rootMargin = "-45% 0px -50% 0px" } = {}) {
|
|
438
|
+
const [active, setActive] = useState(ids[0] ?? null);
|
|
439
|
+
const key = ids.join("\0");
|
|
440
|
+
useEffect(() => {
|
|
441
|
+
const list = key ? key.split("\0") : [];
|
|
442
|
+
setActive((cur) => cur != null && list.includes(cur) ? cur : list[0] ?? null);
|
|
443
|
+
if (!list.length || typeof IntersectionObserver === "undefined") return;
|
|
444
|
+
const inBand = /* @__PURE__ */ new Set();
|
|
445
|
+
const io = new IntersectionObserver(
|
|
446
|
+
(entries) => {
|
|
447
|
+
let entered = null;
|
|
448
|
+
for (const e of entries) {
|
|
449
|
+
const id = e.target.id;
|
|
450
|
+
if (e.isIntersecting) {
|
|
451
|
+
inBand.add(id);
|
|
452
|
+
entered = id;
|
|
453
|
+
} else {
|
|
454
|
+
inBand.delete(id);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
if (entered) {
|
|
458
|
+
setActive(entered);
|
|
459
|
+
} else {
|
|
460
|
+
setActive((cur) => {
|
|
461
|
+
if (cur != null && inBand.has(cur)) return cur;
|
|
462
|
+
const still = list.filter((id) => inBand.has(id));
|
|
463
|
+
return still.length ? still[still.length - 1] : cur;
|
|
464
|
+
});
|
|
465
|
+
}
|
|
466
|
+
},
|
|
467
|
+
{ rootMargin }
|
|
468
|
+
);
|
|
469
|
+
const seen = /* @__PURE__ */ new Set();
|
|
470
|
+
let mo = null;
|
|
471
|
+
const attach = () => {
|
|
472
|
+
for (const id of list) {
|
|
473
|
+
if (seen.has(id)) continue;
|
|
474
|
+
const el = document.getElementById(id);
|
|
475
|
+
if (el) {
|
|
476
|
+
seen.add(id);
|
|
477
|
+
io.observe(el);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
if (seen.size === list.length && mo) {
|
|
481
|
+
mo.disconnect();
|
|
482
|
+
mo = null;
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
attach();
|
|
486
|
+
if (seen.size < list.length && typeof MutationObserver !== "undefined") {
|
|
487
|
+
mo = new MutationObserver(attach);
|
|
488
|
+
mo.observe(document.body, { childList: true, subtree: true });
|
|
489
|
+
}
|
|
490
|
+
const onScroll = () => {
|
|
491
|
+
if (window.scrollY < 8) setActive(list[0]);
|
|
492
|
+
};
|
|
493
|
+
window.addEventListener("scroll", onScroll, { passive: true });
|
|
494
|
+
return () => {
|
|
495
|
+
io.disconnect();
|
|
496
|
+
mo?.disconnect();
|
|
497
|
+
window.removeEventListener("scroll", onScroll);
|
|
498
|
+
};
|
|
499
|
+
}, [key, rootMargin]);
|
|
500
|
+
return active;
|
|
501
|
+
}
|
|
502
|
+
function SectionNav({
|
|
503
|
+
items,
|
|
504
|
+
sticky = true,
|
|
505
|
+
onSelect,
|
|
506
|
+
updateHash = true,
|
|
507
|
+
label = "On this page",
|
|
508
|
+
className,
|
|
509
|
+
style,
|
|
510
|
+
ref: refProp,
|
|
511
|
+
...rest
|
|
512
|
+
}) {
|
|
513
|
+
const ref = useRef(null);
|
|
514
|
+
const spy = useScrollSpy(items.map((i) => i.id));
|
|
515
|
+
const [locked, setLocked] = useState(null);
|
|
516
|
+
const active = locked ?? spy;
|
|
517
|
+
useEffect(() => {
|
|
518
|
+
if (locked == null) return;
|
|
519
|
+
const release = () => setLocked(null);
|
|
520
|
+
const onKey = (e) => {
|
|
521
|
+
if (["ArrowUp", "ArrowDown", "PageUp", "PageDown", "Home", "End", " "].includes(e.key)) release();
|
|
522
|
+
};
|
|
523
|
+
let settled = false;
|
|
524
|
+
const settle = () => {
|
|
525
|
+
settled = true;
|
|
526
|
+
};
|
|
527
|
+
let t = setTimeout(settle, 400);
|
|
528
|
+
const onScroll = () => {
|
|
529
|
+
if (settled) {
|
|
530
|
+
release();
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
533
|
+
clearTimeout(t);
|
|
534
|
+
t = setTimeout(settle, 200);
|
|
535
|
+
};
|
|
536
|
+
const onScrollEnd = () => {
|
|
537
|
+
clearTimeout(t);
|
|
538
|
+
t = setTimeout(settle, 50);
|
|
539
|
+
};
|
|
540
|
+
window.addEventListener("wheel", release, { passive: true });
|
|
541
|
+
window.addEventListener("touchstart", release, { passive: true });
|
|
542
|
+
window.addEventListener("keydown", onKey);
|
|
543
|
+
window.addEventListener("scroll", onScroll, { passive: true });
|
|
544
|
+
window.addEventListener("scrollend", onScrollEnd);
|
|
545
|
+
return () => {
|
|
546
|
+
clearTimeout(t);
|
|
547
|
+
window.removeEventListener("wheel", release);
|
|
548
|
+
window.removeEventListener("touchstart", release);
|
|
549
|
+
window.removeEventListener("keydown", onKey);
|
|
550
|
+
window.removeEventListener("scroll", onScroll);
|
|
551
|
+
window.removeEventListener("scrollend", onScrollEnd);
|
|
552
|
+
};
|
|
553
|
+
}, [locked]);
|
|
554
|
+
useHeightVar(ref, "--nish-sticky-extra", sticky);
|
|
555
|
+
const go = (id) => {
|
|
556
|
+
const el = document.getElementById(id);
|
|
557
|
+
if (!el) return;
|
|
558
|
+
const reduced = typeof window.matchMedia === "function" && window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
559
|
+
setLocked(id);
|
|
560
|
+
el.scrollIntoView({ block: "start", behavior: reduced ? "auto" : "smooth" });
|
|
561
|
+
if (updateHash) {
|
|
562
|
+
try {
|
|
563
|
+
history.replaceState(history.state, "", `#${id}`);
|
|
564
|
+
} catch {
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
onSelect?.(id);
|
|
568
|
+
};
|
|
569
|
+
return /* @__PURE__ */ jsx(
|
|
570
|
+
"nav",
|
|
571
|
+
{
|
|
572
|
+
...rest,
|
|
573
|
+
ref: mergeRefs(ref, refProp),
|
|
574
|
+
"aria-label": label,
|
|
575
|
+
"data-nish-bar": sticky ? "" : void 0,
|
|
576
|
+
style: sticky ? { top: "var(--nish-header-h, 0px)", ...style } : style,
|
|
577
|
+
className: cn("z-[var(--nish-z-sticky,20)] border-b border-th-line bg-th-bg py-2", sticky && "sticky", className),
|
|
578
|
+
children: /* @__PURE__ */ jsx(ScrollRow, { bleed: true, children: items.map((item) => {
|
|
579
|
+
const on = item.id === active;
|
|
580
|
+
return /* @__PURE__ */ jsxs(
|
|
581
|
+
"button",
|
|
582
|
+
{
|
|
583
|
+
type: "button",
|
|
584
|
+
"aria-current": on ? "true" : void 0,
|
|
585
|
+
"data-state": on ? "active" : "inactive",
|
|
586
|
+
onClick: () => go(item.id),
|
|
587
|
+
className: chipClass({
|
|
588
|
+
pressed: on,
|
|
589
|
+
className: "shrink-0 whitespace-nowrap pointer-coarse:min-h-11 pointer-coarse:min-w-11"
|
|
590
|
+
}),
|
|
591
|
+
children: [
|
|
592
|
+
item.icon,
|
|
593
|
+
item.label,
|
|
594
|
+
item.count != null ? /* @__PURE__ */ jsx("span", { className: "tabular-nums text-th-hi3", children: item.count }) : null
|
|
595
|
+
]
|
|
596
|
+
},
|
|
597
|
+
item.id
|
|
598
|
+
);
|
|
599
|
+
}) })
|
|
600
|
+
}
|
|
601
|
+
);
|
|
602
|
+
}
|
|
603
|
+
export {
|
|
604
|
+
BottomNav,
|
|
605
|
+
MoreSheet,
|
|
606
|
+
NavRail,
|
|
607
|
+
NavSidebar,
|
|
608
|
+
ScrollRow,
|
|
609
|
+
SectionNav,
|
|
610
|
+
revealInRow,
|
|
611
|
+
useScrollEdges,
|
|
612
|
+
useScrollSpy,
|
|
613
|
+
visibleNavItems
|
|
614
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// src/components/overlay-classes.ts
|
|
2
|
+
import { cn } from "../cn.js";
|
|
3
|
+
var MENU_ROW = "flex w-full select-none items-center gap-2 px-3 py-1.5 text-start text-xs outline-none transition-colors pointer-coarse:min-h-11 pointer-coarse:gap-3 pointer-coarse:text-sm forced-colors:focus:outline-solid forced-colors:focus:outline-2 forced-colors:focus:-outline-offset-2";
|
|
4
|
+
function menuItemClass({ active = false, danger = false, disabled = false, className } = {}) {
|
|
5
|
+
return cn(
|
|
6
|
+
MENU_ROW,
|
|
7
|
+
disabled ? "cursor-default text-th-ghost forced-colors:text-[GrayText]" : danger ? "text-th-loss hover:bg-th-loss-soft focus-visible:bg-th-loss-soft" : "text-th-hi2 hover:bg-th-overlay hover:text-th-hi focus-visible:bg-th-overlay focus-visible:text-th-hi",
|
|
8
|
+
active && !disabled && !danger && "bg-th-overlay font-medium text-th-hi forced-colors:underline",
|
|
9
|
+
className
|
|
10
|
+
);
|
|
11
|
+
}
|
|
12
|
+
function keyboardFocused(el) {
|
|
13
|
+
if (typeof document !== "undefined" && document.activeElement !== el) return true;
|
|
14
|
+
try {
|
|
15
|
+
return el.matches(":focus-visible");
|
|
16
|
+
} catch {
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function touchTracker() {
|
|
21
|
+
let touch = false;
|
|
22
|
+
return {
|
|
23
|
+
onPointer: (e) => {
|
|
24
|
+
touch = e.pointerType === "touch";
|
|
25
|
+
},
|
|
26
|
+
recent: () => touch
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
var SHEET_EXIT_MS = 200;
|
|
30
|
+
var PHONE_QUERY = "(max-width: 639px)";
|
|
31
|
+
var CLOSE_BUTTON = "-me-1.5 inline-flex shrink-0 items-center justify-center rounded-lg p-1.5 text-th-hi3 transition-colors hover:bg-th-elevated hover:text-th-hi pointer-coarse:min-h-11 pointer-coarse:min-w-11";
|
|
32
|
+
var SHEET_HEIGHT_CLASS = {
|
|
33
|
+
auto: "max-h-[92dvh]",
|
|
34
|
+
tall: "max-h-[92dvh] max-sm:h-[92dvh]",
|
|
35
|
+
full: "max-h-dvh max-sm:h-dvh max-sm:rounded-t-none max-sm:pt-[env(safe-area-inset-top)]"
|
|
36
|
+
};
|
|
37
|
+
var MODAL_SIZE = {
|
|
38
|
+
md: "sm:max-w-md",
|
|
39
|
+
lg: "sm:max-w-xl",
|
|
40
|
+
xl: "sm:max-w-3xl",
|
|
41
|
+
"2xl": "sm:max-w-6xl",
|
|
42
|
+
full: "sm:max-w-[calc(100vw-2rem)] sm:h-[calc(100dvh-2rem)] sm:max-h-[calc(100dvh-2rem)]"
|
|
43
|
+
};
|
|
44
|
+
var DRAWER_WIDTH = {
|
|
45
|
+
sm: "sm:max-w-sm",
|
|
46
|
+
md: "sm:max-w-md",
|
|
47
|
+
lg: "sm:max-w-2xl"
|
|
48
|
+
};
|
|
49
|
+
var DRAWER_SHEET_HEIGHT = {
|
|
50
|
+
sm: "max-h-[50dvh]",
|
|
51
|
+
md: "max-h-[70dvh]",
|
|
52
|
+
lg: "max-h-[92dvh]"
|
|
53
|
+
};
|
|
54
|
+
export {
|
|
55
|
+
CLOSE_BUTTON,
|
|
56
|
+
DRAWER_SHEET_HEIGHT,
|
|
57
|
+
DRAWER_WIDTH,
|
|
58
|
+
MENU_ROW,
|
|
59
|
+
MODAL_SIZE,
|
|
60
|
+
PHONE_QUERY,
|
|
61
|
+
SHEET_EXIT_MS,
|
|
62
|
+
SHEET_HEIGHT_CLASS,
|
|
63
|
+
keyboardFocused,
|
|
64
|
+
menuItemClass,
|
|
65
|
+
touchTracker
|
|
66
|
+
};
|