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.
- 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/hooks.js +17 -6
- 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 +1032 -778
- 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
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/date-picker.tsx
|
|
4
|
+
import { useEffect, useId, useRef, useState } from "react";
|
|
5
|
+
import { cn } from "../cn.js";
|
|
6
|
+
import { getDefaultLocale } from "../format.js";
|
|
7
|
+
import { Calendar } from "./calendar.js";
|
|
8
|
+
import {
|
|
9
|
+
datePlaceholder,
|
|
10
|
+
formatDateField,
|
|
11
|
+
fullDate,
|
|
12
|
+
inRange,
|
|
13
|
+
parseDateField,
|
|
14
|
+
parseIso,
|
|
15
|
+
resolveLocale
|
|
16
|
+
} from "./calendar-classes.js";
|
|
17
|
+
import { setRef } from "./forms-classes.js";
|
|
18
|
+
import { Popover } from "./popover.js";
|
|
19
|
+
import { CalendarIcon } from "./icons.js";
|
|
20
|
+
import { fieldClass } from "./primitives-classes.js";
|
|
21
|
+
import { useNishConfig, useNishStrings } from "./provider.js";
|
|
22
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
23
|
+
function DatePicker({
|
|
24
|
+
ref,
|
|
25
|
+
value: valueProp,
|
|
26
|
+
defaultValue = null,
|
|
27
|
+
onValueChange,
|
|
28
|
+
min: minProp,
|
|
29
|
+
max: maxProp,
|
|
30
|
+
isDateDisabled,
|
|
31
|
+
locale,
|
|
32
|
+
weekStartsOn,
|
|
33
|
+
captionLayout,
|
|
34
|
+
placeholder,
|
|
35
|
+
"aria-label": ariaLabel,
|
|
36
|
+
"aria-labelledby": ariaLabelledBy,
|
|
37
|
+
"aria-describedby": ariaDescribedBy,
|
|
38
|
+
"aria-invalid": ariaInvalid,
|
|
39
|
+
invalid,
|
|
40
|
+
id,
|
|
41
|
+
name,
|
|
42
|
+
form,
|
|
43
|
+
required,
|
|
44
|
+
disabled = false,
|
|
45
|
+
size = "md",
|
|
46
|
+
calendarLabel,
|
|
47
|
+
className,
|
|
48
|
+
...rest
|
|
49
|
+
}) {
|
|
50
|
+
const strings = useNishStrings();
|
|
51
|
+
const config = useNishConfig();
|
|
52
|
+
const loc = resolveLocale(locale ?? config.locale ?? getDefaultLocale());
|
|
53
|
+
const autoId = useId().replace(/[^a-zA-Z0-9_-]/g, "");
|
|
54
|
+
const inputId = id ?? `nish-dp-${autoId}`;
|
|
55
|
+
const min = parseIso(minProp) ? minProp : null;
|
|
56
|
+
const max = parseIso(maxProp) ? maxProp : null;
|
|
57
|
+
const controlled = valueProp !== void 0;
|
|
58
|
+
const [own, setOwn] = useState(parseIso(defaultValue) ? defaultValue : null);
|
|
59
|
+
const value = controlled ? parseIso(valueProp) ? valueProp : null : own;
|
|
60
|
+
const [open, setOpen] = useState(false);
|
|
61
|
+
const [text, setText] = useState("");
|
|
62
|
+
const [dirty, setDirty] = useState(false);
|
|
63
|
+
const [badText, setBadText] = useState(false);
|
|
64
|
+
const inputRef = useRef(null);
|
|
65
|
+
const buttonRef = useRef(null);
|
|
66
|
+
const shown = dirty ? text : value ? formatDateField(value, loc) : "";
|
|
67
|
+
const isInvalid = invalid === true || ariaInvalid === true || ariaInvalid === "true" || badText;
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
inputRef.current?.setCustomValidity(badText ? strings.invalidDate : "");
|
|
70
|
+
}, [badText, strings.invalidDate]);
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
const f = inputRef.current?.form;
|
|
73
|
+
if (!f || controlled) return;
|
|
74
|
+
const onReset = () => {
|
|
75
|
+
setOwn(parseIso(defaultValue) ? defaultValue : null);
|
|
76
|
+
setDirty(false);
|
|
77
|
+
setBadText(false);
|
|
78
|
+
};
|
|
79
|
+
f.addEventListener("reset", onReset);
|
|
80
|
+
return () => f.removeEventListener("reset", onReset);
|
|
81
|
+
}, [name, form, controlled, defaultValue]);
|
|
82
|
+
const commit = (v) => {
|
|
83
|
+
if (!controlled) setOwn(v);
|
|
84
|
+
onValueChange?.(v);
|
|
85
|
+
};
|
|
86
|
+
const commitText = () => {
|
|
87
|
+
if (!dirty) return;
|
|
88
|
+
if (text.trim() === "") {
|
|
89
|
+
if (value !== null) commit(null);
|
|
90
|
+
setDirty(false);
|
|
91
|
+
setBadText(false);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const iso = parseDateField(text, loc);
|
|
95
|
+
if (iso && inRange(iso, min, max) && isDateDisabled?.(iso) !== true) {
|
|
96
|
+
if (iso !== value) commit(iso);
|
|
97
|
+
setDirty(false);
|
|
98
|
+
setBadText(false);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
setBadText(true);
|
|
102
|
+
};
|
|
103
|
+
const pickFromCalendar = (iso) => {
|
|
104
|
+
commit(iso);
|
|
105
|
+
setDirty(false);
|
|
106
|
+
setBadText(false);
|
|
107
|
+
setOpen(false);
|
|
108
|
+
};
|
|
109
|
+
const onKeyDown = (e) => {
|
|
110
|
+
if (disabled) return;
|
|
111
|
+
if (e.key === "Enter") {
|
|
112
|
+
if (dirty) {
|
|
113
|
+
e.preventDefault();
|
|
114
|
+
commitText();
|
|
115
|
+
}
|
|
116
|
+
} else if (e.key === "ArrowDown" && e.altKey) {
|
|
117
|
+
e.preventDefault();
|
|
118
|
+
setOpen(true);
|
|
119
|
+
} else if (e.key === "Escape" && dirty) {
|
|
120
|
+
e.preventDefault();
|
|
121
|
+
e.stopPropagation();
|
|
122
|
+
setDirty(false);
|
|
123
|
+
setBadText(false);
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
const buttonLabel = calendarLabel ?? (value ? strings.changeDate(fullDate(value, loc)) : strings.chooseDate);
|
|
127
|
+
return /* @__PURE__ */ jsxs(
|
|
128
|
+
"div",
|
|
129
|
+
{
|
|
130
|
+
...rest,
|
|
131
|
+
"data-state": open ? "open" : "closed",
|
|
132
|
+
"data-disabled": disabled ? "" : void 0,
|
|
133
|
+
className: cn("relative w-full min-w-0", className),
|
|
134
|
+
children: [
|
|
135
|
+
/* @__PURE__ */ jsx(
|
|
136
|
+
"input",
|
|
137
|
+
{
|
|
138
|
+
ref: (node) => {
|
|
139
|
+
inputRef.current = node;
|
|
140
|
+
setRef(ref, node);
|
|
141
|
+
},
|
|
142
|
+
id: inputId,
|
|
143
|
+
type: "text",
|
|
144
|
+
inputMode: "numeric",
|
|
145
|
+
autoComplete: "off",
|
|
146
|
+
spellCheck: false,
|
|
147
|
+
value: shown,
|
|
148
|
+
placeholder: placeholder ?? datePlaceholder(loc, {
|
|
149
|
+
day: strings.dayToken,
|
|
150
|
+
month: strings.monthToken,
|
|
151
|
+
year: strings.yearToken
|
|
152
|
+
}),
|
|
153
|
+
disabled,
|
|
154
|
+
required,
|
|
155
|
+
"aria-label": ariaLabel,
|
|
156
|
+
"aria-labelledby": ariaLabelledBy,
|
|
157
|
+
"aria-describedby": ariaDescribedBy,
|
|
158
|
+
"aria-invalid": isInvalid || void 0,
|
|
159
|
+
"aria-required": required || void 0,
|
|
160
|
+
onChange: (e) => {
|
|
161
|
+
setText(e.target.value);
|
|
162
|
+
setDirty(true);
|
|
163
|
+
},
|
|
164
|
+
onBlur: commitText,
|
|
165
|
+
onKeyDown,
|
|
166
|
+
className: fieldClass({
|
|
167
|
+
size,
|
|
168
|
+
invalid: isInvalid,
|
|
169
|
+
className: "pe-11 tabular-nums"
|
|
170
|
+
})
|
|
171
|
+
}
|
|
172
|
+
),
|
|
173
|
+
name != null ? /* @__PURE__ */ jsx("input", { type: "hidden", name, value: value ?? "", form, disabled }) : null,
|
|
174
|
+
/* @__PURE__ */ jsx(
|
|
175
|
+
"button",
|
|
176
|
+
{
|
|
177
|
+
ref: buttonRef,
|
|
178
|
+
type: "button",
|
|
179
|
+
"aria-label": buttonLabel,
|
|
180
|
+
"aria-haspopup": "dialog",
|
|
181
|
+
"aria-expanded": open,
|
|
182
|
+
disabled,
|
|
183
|
+
onClick: () => setOpen((o) => !o),
|
|
184
|
+
className: "absolute inset-y-0 end-0 flex w-11 items-center justify-center text-th-hi3 hover:text-th-hi disabled:pointer-events-none disabled:opacity-50",
|
|
185
|
+
children: /* @__PURE__ */ jsx("span", { className: "flex size-8 items-center justify-center rounded-md hover:bg-th-elevated", children: /* @__PURE__ */ jsx(CalendarIcon, { size: 16 }) })
|
|
186
|
+
}
|
|
187
|
+
),
|
|
188
|
+
/* @__PURE__ */ jsx(Popover, { open, onOpenChange: (o) => setOpen(o), anchor: buttonRef, align: "end", "aria-label": strings.chooseDate, className: "p-3", children: /* @__PURE__ */ jsx(
|
|
189
|
+
Calendar,
|
|
190
|
+
{
|
|
191
|
+
value,
|
|
192
|
+
onValueChange: pickFromCalendar,
|
|
193
|
+
min: minProp,
|
|
194
|
+
max: maxProp,
|
|
195
|
+
isDateDisabled,
|
|
196
|
+
locale: loc,
|
|
197
|
+
weekStartsOn,
|
|
198
|
+
captionLayout,
|
|
199
|
+
autoFocus: true
|
|
200
|
+
}
|
|
201
|
+
) })
|
|
202
|
+
]
|
|
203
|
+
}
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
export {
|
|
207
|
+
DatePicker
|
|
208
|
+
};
|
|
@@ -103,27 +103,24 @@ var LEGEND_FILL = {
|
|
|
103
103
|
loss: "bg-th-loss-fill",
|
|
104
104
|
info: "bg-th-info-fill"
|
|
105
105
|
};
|
|
106
|
-
var
|
|
107
|
-
|
|
108
|
-
CALLOUT_TONE,
|
|
106
|
+
var FORCED_MARK = "forced-colors:forced-color-adjust-none forced-colors:bg-[Highlight] forced-colors:text-[HighlightText]";
|
|
107
|
+
export {
|
|
109
108
|
CALLOUT_CLAMP,
|
|
109
|
+
CALLOUT_TONE,
|
|
110
110
|
DOT_SIZE,
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
STAT_SKELETON,
|
|
114
|
-
STAT_TONE,
|
|
111
|
+
FILL,
|
|
112
|
+
FORCED_MARK,
|
|
115
113
|
GRID_BASE,
|
|
116
114
|
GRID_MD,
|
|
115
|
+
HALO,
|
|
116
|
+
LEGEND_FILL,
|
|
117
117
|
METER_FILL,
|
|
118
118
|
METER_THICK,
|
|
119
119
|
METER_THICK_V,
|
|
120
120
|
SPARK_TONE,
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
export {
|
|
125
|
-
FORCED_MARK,
|
|
126
|
-
displayInternals,
|
|
121
|
+
STAT_SKELETON,
|
|
122
|
+
STAT_TONE,
|
|
123
|
+
STAT_VALUE_SIZE,
|
|
127
124
|
signTone,
|
|
128
125
|
toneFor,
|
|
129
126
|
warnDev
|
|
@@ -13,33 +13,36 @@ import { cn } from "../cn.js";
|
|
|
13
13
|
import { sparklineGeometry } from "../sparkline-path.js";
|
|
14
14
|
import { safeUrl } from "../url.js";
|
|
15
15
|
import { mergeRefs } from "./data-classes.js";
|
|
16
|
-
import {
|
|
17
|
-
import { Skeleton } from "./feedback.js";
|
|
18
|
-
import { AlertTriangleIcon, CheckCircleIcon, ChevronDownIcon, InfoIcon, XIcon } from "./icons.js";
|
|
19
|
-
import { useHeightVar, useStuck } from "./layout-vars.js";
|
|
20
|
-
import { DropdownMenu, Tooltip } from "./overlay.js";
|
|
21
|
-
import { Badge, Button, Card, IconButton } from "./primitives.js";
|
|
22
|
-
import { useNishStrings } from "./provider.js";
|
|
23
|
-
import { ThemeToggle } from "./theme-toggle.js";
|
|
24
|
-
import { signTone, toneFor as toneFor2 } from "./display-classes.js";
|
|
25
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
26
|
-
var {
|
|
27
|
-
FILL,
|
|
28
|
-
CALLOUT_TONE,
|
|
16
|
+
import {
|
|
29
17
|
CALLOUT_CLAMP,
|
|
18
|
+
CALLOUT_TONE,
|
|
30
19
|
DOT_SIZE,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
STAT_SKELETON,
|
|
34
|
-
STAT_TONE,
|
|
20
|
+
FILL,
|
|
21
|
+
FORCED_MARK,
|
|
35
22
|
GRID_BASE,
|
|
36
23
|
GRID_MD,
|
|
24
|
+
HALO,
|
|
25
|
+
LEGEND_FILL,
|
|
37
26
|
METER_FILL,
|
|
38
27
|
METER_THICK,
|
|
39
28
|
METER_THICK_V,
|
|
40
29
|
SPARK_TONE,
|
|
41
|
-
|
|
42
|
-
|
|
30
|
+
STAT_SKELETON,
|
|
31
|
+
STAT_TONE,
|
|
32
|
+
STAT_VALUE_SIZE,
|
|
33
|
+
toneFor,
|
|
34
|
+
warnDev
|
|
35
|
+
} from "./display-classes.js";
|
|
36
|
+
import { Skeleton } from "./feedback.js";
|
|
37
|
+
import { AlertTriangleIcon, CheckCircleIcon, ChevronDownIcon, InfoIcon, XIcon } from "./icons.js";
|
|
38
|
+
import { useHeightVar, useStuck } from "./layout-vars.js";
|
|
39
|
+
import { DropdownMenu } from "./menu.js";
|
|
40
|
+
import { Tooltip } from "./tooltip.js";
|
|
41
|
+
import { Badge, Button, Card, IconButton } from "./primitives.js";
|
|
42
|
+
import { useNishStrings } from "./provider.js";
|
|
43
|
+
import { ThemeToggle } from "./theme-toggle.js";
|
|
44
|
+
import { signTone, toneFor as toneFor2 } from "./display-classes.js";
|
|
45
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
43
46
|
function Svg({ size = 16, children, ...rest }) {
|
|
44
47
|
return /* @__PURE__ */ jsx(
|
|
45
48
|
"svg",
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/components/drawer.tsx
|
|
4
|
+
import { useEffect, useId, useRef } from "react";
|
|
5
|
+
import { cn } from "../cn.js";
|
|
6
|
+
import { XIcon } from "./icons.js";
|
|
7
|
+
import { IconButton } from "./primitives.js";
|
|
8
|
+
import { Portal } from "./portal.js";
|
|
9
|
+
import { useNishStrings } from "./provider.js";
|
|
10
|
+
import { DRAWER_SHEET_HEIGHT, DRAWER_WIDTH } from "./overlay-classes.js";
|
|
11
|
+
import { warnDev, useMergedRef, useScrollable } from "./overlay-core.js";
|
|
12
|
+
import { useDialog, useSheetExit, useSheetSwipe, SheetHandle } from "./overlay-dialog.js";
|
|
13
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
14
|
+
function Drawer({ open, ...props }) {
|
|
15
|
+
if (open === false) return null;
|
|
16
|
+
return /* @__PURE__ */ jsx(Portal, { children: /* @__PURE__ */ jsx(DrawerPanel, { ...props }) });
|
|
17
|
+
}
|
|
18
|
+
function DrawerPanel({
|
|
19
|
+
title,
|
|
20
|
+
subtitle,
|
|
21
|
+
onClose,
|
|
22
|
+
onOpenChange,
|
|
23
|
+
side = "right",
|
|
24
|
+
size = "md",
|
|
25
|
+
actions,
|
|
26
|
+
footer,
|
|
27
|
+
bottomOffset,
|
|
28
|
+
dismissible = true,
|
|
29
|
+
closeOnBack = true,
|
|
30
|
+
canClose,
|
|
31
|
+
"aria-label": ariaLabel,
|
|
32
|
+
"aria-labelledby": ariaLabelledBy,
|
|
33
|
+
children,
|
|
34
|
+
className,
|
|
35
|
+
ref,
|
|
36
|
+
...rest
|
|
37
|
+
}) {
|
|
38
|
+
const strings = useNishStrings();
|
|
39
|
+
const titleId = useId();
|
|
40
|
+
const [panelRef, setPanelRef] = useMergedRef(ref);
|
|
41
|
+
const scrimRef = useRef(null);
|
|
42
|
+
const bodyRef = useRef(null);
|
|
43
|
+
const { closing, requestClose, closeNow, isClosing, allowClose } = useSheetExit(onClose, canClose, onOpenChange);
|
|
44
|
+
useDialog(panelRef, requestClose, closeOnBack);
|
|
45
|
+
const bottom = side === "bottom";
|
|
46
|
+
const swipe = useSheetSwipe(panelRef, scrimRef, () => bottom && dismissible && !isClosing(), closeNow, allowClose);
|
|
47
|
+
const swipeHeader = bottom && dismissible;
|
|
48
|
+
const hasTitle = title !== void 0 && title !== null;
|
|
49
|
+
const named = hasTitle || !!ariaLabel || !!ariaLabelledBy;
|
|
50
|
+
const scrollable = useScrollable(bodyRef);
|
|
51
|
+
const bodyLabel = typeof title === "string" ? title : ariaLabel;
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (!named) warnDev("nish-ui: <Drawer> has no accessible name. Pass `title`, `aria-label` or `aria-labelledby`.");
|
|
54
|
+
}, [named]);
|
|
55
|
+
return /* @__PURE__ */ jsx(
|
|
56
|
+
"div",
|
|
57
|
+
{
|
|
58
|
+
ref: scrimRef,
|
|
59
|
+
"data-nish-layer": "",
|
|
60
|
+
"data-state": closing ? "closed" : "open",
|
|
61
|
+
className: cn(
|
|
62
|
+
"fixed inset-0 z-[var(--nish-z-modal,50)] bg-th-scrim/50",
|
|
63
|
+
closing ? "pointer-events-none animate-[nish-fade-out_200ms_ease-in_forwards]" : "animate-[nish-fade-in_160ms_ease-out]"
|
|
64
|
+
),
|
|
65
|
+
style: bottom && bottomOffset ? { bottom: bottomOffset } : void 0,
|
|
66
|
+
onMouseDown: (e) => {
|
|
67
|
+
if (e.target === e.currentTarget) requestClose();
|
|
68
|
+
},
|
|
69
|
+
children: /* @__PURE__ */ jsxs(
|
|
70
|
+
"div",
|
|
71
|
+
{
|
|
72
|
+
...rest,
|
|
73
|
+
ref: setPanelRef,
|
|
74
|
+
role: "dialog",
|
|
75
|
+
"aria-modal": "true",
|
|
76
|
+
"aria-labelledby": ariaLabelledBy ?? (ariaLabel || !hasTitle ? void 0 : titleId),
|
|
77
|
+
"aria-label": ariaLabel,
|
|
78
|
+
"data-state": closing ? "closed" : "open",
|
|
79
|
+
tabIndex: -1,
|
|
80
|
+
className: cn(
|
|
81
|
+
"absolute flex flex-col border-th-line bg-th-surface shadow-modal outline-none",
|
|
82
|
+
bottom ? cn(
|
|
83
|
+
"inset-x-0 bottom-0 rounded-t-2xl border-t",
|
|
84
|
+
closing ? "animate-[nish-sheet-out_200ms_ease-in_forwards]" : "animate-[nish-sheet-in_240ms_var(--nish-ease-out)]",
|
|
85
|
+
bottomOffset ? "" : "pb-[env(safe-area-inset-bottom)]",
|
|
86
|
+
DRAWER_SHEET_HEIGHT[size]
|
|
87
|
+
) : cn(
|
|
88
|
+
"inset-y-0 w-full pt-[env(safe-area-inset-top)] pb-[env(safe-area-inset-bottom)]",
|
|
89
|
+
DRAWER_WIDTH[size],
|
|
90
|
+
side === "right" ? cn(
|
|
91
|
+
"right-0 border-l pr-[env(safe-area-inset-right)]",
|
|
92
|
+
closing ? "translate-x-full transition-transform duration-200 ease-in" : "animate-[nish-slide-in-right_240ms_var(--nish-ease-out)]"
|
|
93
|
+
) : cn(
|
|
94
|
+
"left-0 border-r pl-[env(safe-area-inset-left)]",
|
|
95
|
+
closing ? "-translate-x-full transition-transform duration-200 ease-in" : "animate-[nish-slide-in-left_240ms_var(--nish-ease-out)]"
|
|
96
|
+
)
|
|
97
|
+
),
|
|
98
|
+
className
|
|
99
|
+
),
|
|
100
|
+
children: [
|
|
101
|
+
swipeHeader ? /* @__PURE__ */ jsx(SheetHandle, { onClose: requestClose, swipe }) : bottom ? /* @__PURE__ */ jsx("div", { className: "h-3 shrink-0", "aria-hidden": "true" }) : null,
|
|
102
|
+
/* @__PURE__ */ jsxs(
|
|
103
|
+
"div",
|
|
104
|
+
{
|
|
105
|
+
className: cn("flex shrink-0 items-start justify-between gap-3 border-b border-th-line px-5 py-3", swipeHeader && "touch-pan-x"),
|
|
106
|
+
...swipeHeader ? swipe : {},
|
|
107
|
+
children: [
|
|
108
|
+
/* @__PURE__ */ jsxs("div", { className: "min-w-0 pt-1", children: [
|
|
109
|
+
hasTitle ? /* @__PURE__ */ jsx("h2", { id: titleId, className: "line-clamp-2 break-words text-base font-semibold leading-snug text-th-hi", children: title }) : null,
|
|
110
|
+
subtitle ? /* @__PURE__ */ jsx("div", { className: "mt-0.5 text-xs text-th-hi3", children: subtitle }) : null
|
|
111
|
+
] }),
|
|
112
|
+
/* @__PURE__ */ jsxs("div", { className: "-me-1.5 flex shrink-0 items-center gap-1", children: [
|
|
113
|
+
actions,
|
|
114
|
+
/* @__PURE__ */ jsx(IconButton, { label: strings.close, onClick: requestClose, children: /* @__PURE__ */ jsx(XIcon, { size: 16 }) })
|
|
115
|
+
] })
|
|
116
|
+
]
|
|
117
|
+
}
|
|
118
|
+
),
|
|
119
|
+
/* @__PURE__ */ jsx(
|
|
120
|
+
"div",
|
|
121
|
+
{
|
|
122
|
+
ref: bodyRef,
|
|
123
|
+
tabIndex: scrollable ? 0 : void 0,
|
|
124
|
+
role: scrollable && bodyLabel ? "region" : void 0,
|
|
125
|
+
"aria-label": scrollable ? bodyLabel : void 0,
|
|
126
|
+
className: "min-h-0 flex-1 overflow-y-auto overscroll-contain px-5 py-4 text-sm text-th-hi2",
|
|
127
|
+
children
|
|
128
|
+
}
|
|
129
|
+
),
|
|
130
|
+
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
|
|
131
|
+
]
|
|
132
|
+
}
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
export {
|
|
138
|
+
Drawer
|
|
139
|
+
};
|
|
@@ -5,7 +5,7 @@ import { useState } from "react";
|
|
|
5
5
|
import { cn } from "../cn.js";
|
|
6
6
|
import { SearchInput } from "./forms.js";
|
|
7
7
|
import { NARROW_QUERY, useMediaQuery } from "./hooks.js";
|
|
8
|
-
import { Drawer } from "./
|
|
8
|
+
import { Drawer } from "./drawer.js";
|
|
9
9
|
import { Badge, Button } from "./primitives.js";
|
|
10
10
|
import { useNishStrings } from "./provider.js";
|
|
11
11
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -12,7 +12,7 @@ import { cn } from "../cn.js";
|
|
|
12
12
|
import { ago } from "../format.js";
|
|
13
13
|
import { useIsoLayoutEffect } from "./client.js";
|
|
14
14
|
import { useMediaQuery, useNow } from "./hooks.js";
|
|
15
|
-
import { Tooltip } from "./
|
|
15
|
+
import { Tooltip } from "./tooltip.js";
|
|
16
16
|
import { Badge } from "./primitives.js";
|
|
17
17
|
import { useNishStrings } from "./provider.js";
|
|
18
18
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
@@ -17,37 +17,48 @@ var queries = /* @__PURE__ */ new Map();
|
|
|
17
17
|
function hasMatchMedia() {
|
|
18
18
|
return typeof window !== "undefined" && typeof window.matchMedia === "function";
|
|
19
19
|
}
|
|
20
|
-
function
|
|
21
|
-
if (!hasMatchMedia()) return () => {
|
|
22
|
-
};
|
|
20
|
+
function entryFor(query) {
|
|
23
21
|
let entry = queries.get(query);
|
|
24
22
|
if (!entry) {
|
|
25
23
|
const mql = window.matchMedia(query);
|
|
26
24
|
const created = {
|
|
27
25
|
mql,
|
|
28
26
|
matches: mql.matches,
|
|
27
|
+
listening: false,
|
|
29
28
|
subs: /* @__PURE__ */ new Set(),
|
|
30
29
|
onChange: () => {
|
|
31
30
|
created.matches = mql.matches;
|
|
32
31
|
created.subs.forEach((fn) => fn());
|
|
33
32
|
}
|
|
34
33
|
};
|
|
35
|
-
mql.addEventListener("change", created.onChange);
|
|
36
34
|
queries.set(query, created);
|
|
37
35
|
entry = created;
|
|
38
36
|
}
|
|
39
|
-
|
|
37
|
+
return entry;
|
|
38
|
+
}
|
|
39
|
+
function subscribeQuery(query, cb) {
|
|
40
|
+
if (!hasMatchMedia()) return () => {
|
|
41
|
+
};
|
|
42
|
+
const owner = entryFor(query);
|
|
43
|
+
if (!owner.listening) {
|
|
44
|
+
owner.listening = true;
|
|
45
|
+
owner.matches = owner.mql.matches;
|
|
46
|
+
owner.mql.addEventListener("change", owner.onChange);
|
|
47
|
+
}
|
|
40
48
|
owner.subs.add(cb);
|
|
41
49
|
return () => {
|
|
42
50
|
owner.subs.delete(cb);
|
|
43
51
|
if (owner.subs.size === 0) {
|
|
52
|
+
owner.listening = false;
|
|
44
53
|
owner.mql.removeEventListener("change", owner.onChange);
|
|
45
54
|
if (queries.get(query) === owner) queries.delete(query);
|
|
46
55
|
}
|
|
47
56
|
};
|
|
48
57
|
}
|
|
49
58
|
function queryMatches(query) {
|
|
50
|
-
|
|
59
|
+
if (!hasMatchMedia()) return false;
|
|
60
|
+
const entry = entryFor(query);
|
|
61
|
+
return entry.listening ? entry.matches : entry.mql.matches;
|
|
51
62
|
}
|
|
52
63
|
function useMediaQuery(query) {
|
|
53
64
|
const subscribe = useCallback((onChange) => subscribeQuery(query, onChange), [query]);
|