@robert-stackflow/oneui 0.5.2 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -12
- package/README.md +169 -149
- package/components/AppShell.d.ts +6 -13
- package/components/AppShell.js +28 -17
- package/components/AppShell.module.css +0 -20
- package/components/AuthLayout.d.ts +8 -0
- package/components/AuthLayout.js +25 -0
- package/components/AuthLayout.module.css +36 -0
- package/components/Badge.d.ts +2 -2
- package/components/Badge.js +4 -2
- package/components/BarChart.d.ts +8 -0
- package/components/BarChart.js +37 -0
- package/components/BarChart.module.css +34 -0
- package/components/Button.d.ts +1 -1
- package/components/Button.module.css +3 -6
- package/components/ContributionCalendar.js +2 -2
- package/components/ContributionCalendar.module.css +3 -0
- package/components/CopyButton.d.ts +9 -0
- package/components/CopyButton.js +23 -0
- package/components/Dialog.module.css +0 -9
- package/components/Drawer.module.css +0 -9
- package/components/Layout.d.ts +81 -0
- package/components/Layout.js +271 -0
- package/components/Layout.module.css +66 -0
- package/components/Menu.d.ts +4 -1
- package/components/Menu.js +10 -4
- package/components/MultiSelect.d.ts +1 -2
- package/components/MultiSelect.js +13 -82
- package/components/MultiSelect.module.css +0 -6
- package/components/NumberInput.d.ts +1 -0
- package/components/NumberInput.js +4 -0
- package/components/NumberInput.module.css +11 -0
- package/components/Page.d.ts +7 -1
- package/components/Page.js +15 -8
- package/components/Page.module.css +1 -11
- package/components/Pagination.d.ts +2 -1
- package/components/Pagination.js +3 -2
- package/components/ResourceCard.d.ts +12 -0
- package/components/ResourceCard.js +24 -0
- package/components/ResourceCard.module.css +13 -0
- package/components/SidebarNavigation.d.ts +29 -0
- package/components/SidebarNavigation.js +139 -0
- package/components/SidebarNavigation.module.css +109 -0
- package/components/Table.module.css +2 -2
- package/components/TableMarkup.d.ts +23 -0
- package/components/TableMarkup.js +41 -0
- package/components/Tooltip.d.ts +2 -1
- package/components/Tooltip.js +3 -1
- package/components/index.d.ts +12 -2
- package/components/index.js +42 -1
- package/package.json +42 -2
|
@@ -4,7 +4,7 @@ import { fieldTriggerProps, useFieldControl } from "./field.js";
|
|
|
4
4
|
import { MenuItem } from "./MenuItem.js";
|
|
5
5
|
import { SelectTrigger } from "./SelectTrigger.js";
|
|
6
6
|
import { useEffect, useId, useRef, useState } from "react";
|
|
7
|
-
import {
|
|
7
|
+
import { Search } from "lucide-react";
|
|
8
8
|
import { Popover } from "./Popover.js";
|
|
9
9
|
import { usePopover } from "./usePopover.js";
|
|
10
10
|
import { Button } from "./Button.js";
|
|
@@ -28,7 +28,6 @@ function MultiSelect({
|
|
|
28
28
|
clearable = true,
|
|
29
29
|
placeholder = "\u8BF7\u9009\u62E9",
|
|
30
30
|
display = "summary",
|
|
31
|
-
onCreate,
|
|
32
31
|
...aria
|
|
33
32
|
}) {
|
|
34
33
|
const field = useFieldControl({
|
|
@@ -44,78 +43,31 @@ function MultiSelect({
|
|
|
44
43
|
});
|
|
45
44
|
const pop = usePopover(
|
|
46
45
|
field.disabled || field.readOnly
|
|
47
|
-
), [query, setQuery] = useState(""),
|
|
46
|
+
), [query, setQuery] = useState(""), list = useRef(null), search = useRef(null), id = useId();
|
|
48
47
|
const { disabled: triggerDisabled, ...tagField } = fieldTriggerProps(field);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const available = [
|
|
52
|
-
...options,
|
|
53
|
-
...created.filter(
|
|
54
|
-
(item) => !options.some((option) => option.value === item.value)
|
|
55
|
-
)
|
|
56
|
-
];
|
|
57
|
-
const reserveIcon = available.some((option) => !!option.icon);
|
|
58
|
-
const filtered = available.filter(
|
|
48
|
+
const reserveIcon = options.some((option) => !!option.icon);
|
|
49
|
+
const filtered = options.filter(
|
|
59
50
|
(item) => item.label.toLowerCase().includes(query.toLowerCase())
|
|
60
51
|
);
|
|
61
52
|
const toggle = (option) => {
|
|
62
|
-
if (!
|
|
53
|
+
if (!field.disabled && !field.readOnly && !option.disabled && (value.includes(option.value) || value.length < maxSelected))
|
|
63
54
|
onChange(
|
|
64
55
|
value.includes(option.value) ? value.filter((v) => v !== option.value) : [...value, option.value]
|
|
65
56
|
);
|
|
66
57
|
};
|
|
67
|
-
const candidate = query.trim();
|
|
68
|
-
const canCreate = !!onCreate && !!candidate && !available.some(
|
|
69
|
-
(option) => option.label.toLowerCase() === candidate.toLowerCase()
|
|
70
|
-
);
|
|
71
|
-
const create = async () => {
|
|
72
|
-
if (!onCreate || !canCreate || creating || field.disabled || field.readOnly || value.length >= maxSelected)
|
|
73
|
-
return;
|
|
74
|
-
const revision = generation.current;
|
|
75
|
-
setCreating(true);
|
|
76
|
-
setCreateError("");
|
|
77
|
-
try {
|
|
78
|
-
const id2 = await onCreate(candidate) || candidate;
|
|
79
|
-
if (!open.current || revision !== generation.current) return;
|
|
80
|
-
setCreated(
|
|
81
|
-
(previous) => previous.some((option) => option.value === id2) ? previous : [...previous, { value: id2, label: candidate }]
|
|
82
|
-
);
|
|
83
|
-
if (!selected.current.includes(id2)) onChange([...selected.current, id2]);
|
|
84
|
-
setQuery("");
|
|
85
|
-
requestAnimationFrame(() => {
|
|
86
|
-
if (open.current) search.current?.focus();
|
|
87
|
-
});
|
|
88
|
-
} catch (failure) {
|
|
89
|
-
if (open.current && revision === generation.current)
|
|
90
|
-
setCreateError(
|
|
91
|
-
failure instanceof Error ? failure.message : "\u521B\u5EFA\u5931\u8D25\uFF0C\u8BF7\u91CD\u8BD5\u3002"
|
|
92
|
-
);
|
|
93
|
-
} finally {
|
|
94
|
-
if (revision === generation.current) setCreating(false);
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
useEffect(
|
|
98
|
-
() => () => {
|
|
99
|
-
generation.current++;
|
|
100
|
-
},
|
|
101
|
-
[]
|
|
102
|
-
);
|
|
103
58
|
useEffect(() => {
|
|
104
|
-
generation.current++;
|
|
105
|
-
setCreating(false);
|
|
106
|
-
setCreateError("");
|
|
107
59
|
if (pop.open) {
|
|
108
60
|
setQuery("");
|
|
109
61
|
search.current?.focus();
|
|
110
62
|
}
|
|
111
63
|
}, [pop.open]);
|
|
112
64
|
const remove = (id2) => {
|
|
113
|
-
if (
|
|
65
|
+
if (field.disabled || field.readOnly || options.find((option) => option.value === id2)?.disabled)
|
|
114
66
|
return;
|
|
115
67
|
onChange(value.filter((v) => v !== id2));
|
|
116
68
|
pop.anchor.current?.focus();
|
|
117
69
|
};
|
|
118
|
-
const summary = value.length ?
|
|
70
|
+
const summary = value.length ? options.filter((item) => value.includes(item.value)).map((item) => item.label).slice(0, 2).join("\u3001") + (value.length > 2 ? ` +${value.length - 2}` : "") : placeholder;
|
|
119
71
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
120
72
|
display === "tags" ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
121
73
|
/* @__PURE__ */ jsxs(
|
|
@@ -148,13 +100,13 @@ function MultiSelect({
|
|
|
148
100
|
},
|
|
149
101
|
children: [
|
|
150
102
|
value.map((id2) => {
|
|
151
|
-
const option =
|
|
103
|
+
const option = options.find((option2) => option2.value === id2);
|
|
152
104
|
return /* @__PURE__ */ jsx(
|
|
153
105
|
SelectionTag,
|
|
154
106
|
{
|
|
155
107
|
label: option?.label || id2,
|
|
156
108
|
icon: option?.icon,
|
|
157
|
-
disabled: field.disabled ||
|
|
109
|
+
disabled: field.disabled || option?.disabled,
|
|
158
110
|
onRemove: field.readOnly ? void 0 : () => remove(id2),
|
|
159
111
|
removeLabel: "\u79FB\u9664 " + (option?.label || id2)
|
|
160
112
|
},
|
|
@@ -211,18 +163,7 @@ function MultiSelect({
|
|
|
211
163
|
"aria-label": `\u641C\u7D22${label}`,
|
|
212
164
|
placeholder: "\u641C\u7D22\u9009\u9879\u2026",
|
|
213
165
|
value: query,
|
|
214
|
-
|
|
215
|
-
onChange: (e) => {
|
|
216
|
-
setQuery(e.target.value);
|
|
217
|
-
setCreateError("");
|
|
218
|
-
},
|
|
219
|
-
onKeyDown: (event) => {
|
|
220
|
-
if (event.key === "Enter" && canCreate) {
|
|
221
|
-
event.preventDefault();
|
|
222
|
-
event.stopPropagation();
|
|
223
|
-
void create();
|
|
224
|
-
}
|
|
225
|
-
}
|
|
166
|
+
onChange: (e) => setQuery(e.target.value)
|
|
226
167
|
}
|
|
227
168
|
)
|
|
228
169
|
] }),
|
|
@@ -247,22 +188,12 @@ function MultiSelect({
|
|
|
247
188
|
selection: "checkbox",
|
|
248
189
|
role: "option",
|
|
249
190
|
"aria-selected": value.includes(option.value),
|
|
250
|
-
disabled:
|
|
191
|
+
disabled: option.disabled || !value.includes(option.value) && value.length >= maxSelected,
|
|
251
192
|
onClick: () => toggle(option)
|
|
252
193
|
},
|
|
253
194
|
option.value
|
|
254
195
|
)),
|
|
255
|
-
|
|
256
|
-
MenuItem,
|
|
257
|
-
{
|
|
258
|
-
label: creating ? "\u6B63\u5728\u521B\u5EFA\u2026" : "\u521B\u5EFA\u201C" + candidate + "\u201D",
|
|
259
|
-
icon: /* @__PURE__ */ jsx(Plus, { size: 16 }),
|
|
260
|
-
disabled: creating || value.length >= maxSelected,
|
|
261
|
-
onClick: () => void create()
|
|
262
|
-
}
|
|
263
|
-
),
|
|
264
|
-
!filtered.length && !canCreate && /* @__PURE__ */ jsx("p", { className: s.noResults, children: "\u6CA1\u6709\u5339\u914D\u7684\u9009\u9879" }),
|
|
265
|
-
createError && /* @__PURE__ */ jsx("p", { className: s.createError, role: "alert", children: createError })
|
|
196
|
+
!filtered.length && /* @__PURE__ */ jsx("p", { className: s.noResults, children: "\u6CA1\u6709\u5339\u914D\u7684\u9009\u9879" })
|
|
266
197
|
]
|
|
267
198
|
}
|
|
268
199
|
),
|
|
@@ -272,7 +203,7 @@ function MultiSelect({
|
|
|
272
203
|
{
|
|
273
204
|
variant: "ghost",
|
|
274
205
|
size: "small",
|
|
275
|
-
disabled:
|
|
206
|
+
disabled: !value.length,
|
|
276
207
|
onClick: () => onChange([]),
|
|
277
208
|
children: "\u6E05\u7A7A"
|
|
278
209
|
}
|
|
@@ -15,6 +15,7 @@ function NumberInput(props) {
|
|
|
15
15
|
invalid = false,
|
|
16
16
|
nullable = false,
|
|
17
17
|
placeholder,
|
|
18
|
+
unit,
|
|
18
19
|
...options
|
|
19
20
|
} = props;
|
|
20
21
|
const onChange = (next) => {
|
|
@@ -59,6 +60,7 @@ function NumberInput(props) {
|
|
|
59
60
|
"div",
|
|
60
61
|
{
|
|
61
62
|
className: s.number,
|
|
63
|
+
"data-unit": unit ? true : void 0,
|
|
62
64
|
"data-disabled": disabled,
|
|
63
65
|
"data-readonly": readOnly || void 0,
|
|
64
66
|
"aria-invalid": field.invalid || invalid,
|
|
@@ -85,6 +87,7 @@ function NumberInput(props) {
|
|
|
85
87
|
"aria-invalid": field.invalid || invalid,
|
|
86
88
|
"aria-label": label,
|
|
87
89
|
"aria-valuenow": value ?? void 0,
|
|
90
|
+
"aria-valuetext": unit && value !== null ? `${value} ${unit}` : void 0,
|
|
88
91
|
placeholder,
|
|
89
92
|
"aria-valuemin": Number.isFinite(min) ? min : void 0,
|
|
90
93
|
"aria-valuemax": Number.isFinite(max) ? max : void 0,
|
|
@@ -115,6 +118,7 @@ function NumberInput(props) {
|
|
|
115
118
|
}
|
|
116
119
|
}
|
|
117
120
|
),
|
|
121
|
+
unit && /* @__PURE__ */ jsx("span", { className: s.unit, children: unit }),
|
|
118
122
|
/* @__PURE__ */ jsx(
|
|
119
123
|
"button",
|
|
120
124
|
{
|
|
@@ -16,6 +16,17 @@
|
|
|
16
16
|
padding: 0;
|
|
17
17
|
font-variant-numeric: tabular-nums;
|
|
18
18
|
}
|
|
19
|
+
.number[data-unit] {
|
|
20
|
+
width: 180px;
|
|
21
|
+
grid-template-columns: 30px minmax(0, 1fr) auto 30px;
|
|
22
|
+
}
|
|
23
|
+
.unit {
|
|
24
|
+
align-self: center;
|
|
25
|
+
padding-right: 6px;
|
|
26
|
+
color: var(--muted);
|
|
27
|
+
font-size: 12px;
|
|
28
|
+
white-space: nowrap;
|
|
29
|
+
}
|
|
19
30
|
.number button {
|
|
20
31
|
display: grid;
|
|
21
32
|
place-items: center;
|
package/components/Page.d.ts
CHANGED
|
@@ -1,6 +1,12 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
+
export declare function PageHeading({ title, description, actions, titleExtra }: {
|
|
3
|
+
title: string;
|
|
4
|
+
description?: string;
|
|
5
|
+
actions?: ReactNode;
|
|
6
|
+
titleExtra?: ReactNode;
|
|
7
|
+
}): import("react").JSX.Element;
|
|
2
8
|
export declare function Page({ title, description, actions, children, }: {
|
|
3
|
-
title
|
|
9
|
+
title: string;
|
|
4
10
|
description?: string;
|
|
5
11
|
actions?: ReactNode;
|
|
6
12
|
children: ReactNode;
|
package/components/Page.js
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import s from "./Page.module.css";
|
|
3
|
+
function PageHeading({ title, description, actions, titleExtra }) {
|
|
4
|
+
return /* @__PURE__ */ jsxs("header", { className: s.heading, children: [
|
|
5
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
6
|
+
/* @__PURE__ */ jsxs("div", { className: s.title, children: [
|
|
7
|
+
/* @__PURE__ */ jsx("h1", { children: title }),
|
|
8
|
+
titleExtra
|
|
9
|
+
] }),
|
|
10
|
+
description && /* @__PURE__ */ jsx("p", { children: description })
|
|
11
|
+
] }),
|
|
12
|
+
actions && /* @__PURE__ */ jsx("div", { className: s.actions, children: actions })
|
|
13
|
+
] });
|
|
14
|
+
}
|
|
3
15
|
function Page({
|
|
4
16
|
title,
|
|
5
17
|
description,
|
|
@@ -7,16 +19,11 @@ function Page({
|
|
|
7
19
|
children
|
|
8
20
|
}) {
|
|
9
21
|
return /* @__PURE__ */ jsxs("div", { className: s.page, children: [
|
|
10
|
-
|
|
11
|
-
/* @__PURE__ */ jsxs("div", { children: [
|
|
12
|
-
title && /* @__PURE__ */ jsx("h1", { children: title }),
|
|
13
|
-
description && /* @__PURE__ */ jsx("p", { children: description })
|
|
14
|
-
] }),
|
|
15
|
-
actions && /* @__PURE__ */ jsx("div", { className: s.actions, children: actions })
|
|
16
|
-
] }),
|
|
22
|
+
/* @__PURE__ */ jsx(PageHeading, { title, description, actions }),
|
|
17
23
|
children
|
|
18
24
|
] });
|
|
19
25
|
}
|
|
20
26
|
export {
|
|
21
|
-
Page
|
|
27
|
+
Page,
|
|
28
|
+
PageHeading
|
|
22
29
|
};
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
display: flex;
|
|
21
21
|
gap: 8px;
|
|
22
22
|
}
|
|
23
|
+
.title { display:flex; align-items:center; flex-wrap:wrap; gap:12px; }
|
|
23
24
|
|
|
24
25
|
.heading h1 {
|
|
25
26
|
font-size: var(--page-title-size);
|
|
@@ -42,14 +43,3 @@
|
|
|
42
43
|
flex-wrap: wrap;
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
|
-
|
|
46
|
-
@keyframes page-enter {
|
|
47
|
-
from {
|
|
48
|
-
opacity: 0;
|
|
49
|
-
translate: 0 5px;
|
|
50
|
-
}
|
|
51
|
-
to {
|
|
52
|
-
opacity: 1;
|
|
53
|
-
translate: 0 0;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
|
-
export declare function Pagination({ page, pageSize, total, onPageChange, onPageSizeChange, pageSizes, summary, resetPageOnSizeChange, compact, size: controlSize, className, }: {
|
|
2
|
+
export declare function Pagination({ page, pageSize, total, onPageChange, onPageSizeChange, pageSizes, summary, resetPageOnSizeChange, compact, size: controlSize, className, showSummary, }: {
|
|
3
3
|
page: number;
|
|
4
4
|
pageSize: number;
|
|
5
5
|
total: number;
|
|
@@ -12,4 +12,5 @@ export declare function Pagination({ page, pageSize, total, onPageChange, onPage
|
|
|
12
12
|
compact?: boolean;
|
|
13
13
|
size?: "default" | "small";
|
|
14
14
|
className?: string;
|
|
15
|
+
showSummary?: boolean;
|
|
15
16
|
}): import("react").JSX.Element;
|
package/components/Pagination.js
CHANGED
|
@@ -21,7 +21,8 @@ function Pagination({
|
|
|
21
21
|
resetPageOnSizeChange = true,
|
|
22
22
|
compact = false,
|
|
23
23
|
size: controlSize = "default",
|
|
24
|
-
className = ""
|
|
24
|
+
className = "",
|
|
25
|
+
showSummary = true
|
|
25
26
|
}) {
|
|
26
27
|
const size = Math.max(1, pageSize), pages = Math.max(1, Math.ceil(total / size)), current = Math.min(pages, Math.max(1, page)), id = useId(), [draft, setDraft] = useState(String(current));
|
|
27
28
|
useEffect(() => setDraft(String(current)), [current]);
|
|
@@ -50,7 +51,7 @@ function Pagination({
|
|
|
50
51
|
className: `${s.pagination} ${compact ? s.compact : ""} ${controlSize === "small" ? s.small : ""} ${className}`,
|
|
51
52
|
"aria-label": "\u5206\u9875",
|
|
52
53
|
children: [
|
|
53
|
-
/* @__PURE__ */ jsxs("span", { className: s.summary, children: [
|
|
54
|
+
showSummary && /* @__PURE__ */ jsxs("span", { className: s.summary, children: [
|
|
54
55
|
total ? (current - 1) * size + 1 + "\u2013" + Math.min(current * size, total) : 0,
|
|
55
56
|
" ",
|
|
56
57
|
"/ ",
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { MouseEventHandler, ReactNode } from "react";
|
|
2
|
+
/** A linked resource with a stable heading, status and compact facts. */
|
|
3
|
+
export declare function ResourceCard({ title, icon, status, description, subtitle, metadata, href, onClick }: {
|
|
4
|
+
title: string;
|
|
5
|
+
icon: ReactNode;
|
|
6
|
+
status?: ReactNode;
|
|
7
|
+
description?: string;
|
|
8
|
+
subtitle?: string;
|
|
9
|
+
metadata?: ReactNode[];
|
|
10
|
+
href: string;
|
|
11
|
+
onClick?: MouseEventHandler<HTMLAnchorElement>;
|
|
12
|
+
}): import("react").JSX.Element;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { ArrowUpRight } from "lucide-react";
|
|
3
|
+
import card from "./Card.module.css";
|
|
4
|
+
import s from "./ResourceCard.module.css";
|
|
5
|
+
function ResourceCard({ title, icon, status, description, subtitle, metadata, href, onClick }) {
|
|
6
|
+
return /* @__PURE__ */ jsxs("a", { href, onClick, className: `${card.card} ${s.card}`, children: [
|
|
7
|
+
/* @__PURE__ */ jsxs("div", { className: s.header, children: [
|
|
8
|
+
/* @__PURE__ */ jsx("span", { className: s.icon, children: icon }),
|
|
9
|
+
/* @__PURE__ */ jsxs("div", { className: s.heading, children: [
|
|
10
|
+
/* @__PURE__ */ jsx("h3", { children: title }),
|
|
11
|
+
subtitle && /* @__PURE__ */ jsx("p", { children: subtitle })
|
|
12
|
+
] }),
|
|
13
|
+
status
|
|
14
|
+
] }),
|
|
15
|
+
description && /* @__PURE__ */ jsx("p", { className: s.description, children: description }),
|
|
16
|
+
/* @__PURE__ */ jsxs("div", { className: s.footer, children: [
|
|
17
|
+
/* @__PURE__ */ jsx("div", { className: s.facts, children: metadata?.map((item, index) => /* @__PURE__ */ jsx("span", { children: item }, index)) }),
|
|
18
|
+
/* @__PURE__ */ jsx(ArrowUpRight, { size: 16, "aria-hidden": "true" })
|
|
19
|
+
] })
|
|
20
|
+
] });
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
ResourceCard
|
|
24
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
.card {display:flex;flex-direction:column;padding:24px;color:var(--fg);text-decoration:none;transition:border-color var(--motion-hover),box-shadow var(--motion-hover);}
|
|
2
|
+
.card:hover {border-color:color-mix(in srgb,var(--accent) 35%,var(--line));box-shadow:var(--shadow);}
|
|
3
|
+
.header {display:flex;align-items:center;gap:12px;min-width:0;}
|
|
4
|
+
.icon {width:40px;height:40px;flex:none;border-radius:var(--radius);display:grid;place-items:center;background:var(--selected);color:var(--accent);}
|
|
5
|
+
.icon svg {width:20px;height:20px;}
|
|
6
|
+
.heading {flex:1;min-width:0;}
|
|
7
|
+
.heading h3 {font-size:15px;font-weight:600;color:var(--fg);overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
|
|
8
|
+
.heading p {font-size:12px;color:var(--muted);margin-top:3px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;}
|
|
9
|
+
.description {font-size:13px;line-height:1.7;margin:18px 0 0;color:var(--muted);display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;}
|
|
10
|
+
.footer {display:flex;align-items:center;justify-content:space-between;gap:12px;margin-top:auto;padding-top:20px;color:var(--muted);}
|
|
11
|
+
.facts {display:flex;align-items:center;flex-wrap:wrap;gap:6px 14px;font-size:12px;}
|
|
12
|
+
.facts > span + span {padding-left:14px;border-left:1px solid var(--line);}
|
|
13
|
+
@media(max-width:600px){.card{padding:18px;}.header{gap:10px;}.facts{gap:6px 10px;}.facts > span + span{padding-left:10px;}}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type ReactNode, type ButtonHTMLAttributes } from "react";
|
|
2
|
+
export interface NavigationItem {
|
|
3
|
+
/** Stable across refreshes; expansion is keyed by id rather than position. */
|
|
4
|
+
id: string;
|
|
5
|
+
path: string;
|
|
6
|
+
label: string;
|
|
7
|
+
icon: ReactNode;
|
|
8
|
+
children?: readonly NavigationItem[];
|
|
9
|
+
/** Loading, empty or error UI for lazily loaded children. */
|
|
10
|
+
content?: ReactNode;
|
|
11
|
+
expandable?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare function NavigationButton({ label, icon, active, className, ...props }: ButtonHTMLAttributes<HTMLButtonElement> & {
|
|
14
|
+
label: string;
|
|
15
|
+
icon?: ReactNode;
|
|
16
|
+
active?: boolean;
|
|
17
|
+
}): import("react").JSX.Element;
|
|
18
|
+
export interface SidebarNavigationProps {
|
|
19
|
+
items: readonly NavigationItem[];
|
|
20
|
+
active: string;
|
|
21
|
+
onNavigate(path: string): void;
|
|
22
|
+
basePath?: string;
|
|
23
|
+
compact?: boolean;
|
|
24
|
+
expandedIds?: readonly string[];
|
|
25
|
+
defaultExpandedIds?: readonly string[];
|
|
26
|
+
onExpandedChange?(ids: string[]): void;
|
|
27
|
+
}
|
|
28
|
+
/** Links and disclosure buttons are siblings, preserving native link behavior. */
|
|
29
|
+
export declare function SidebarNavigation({ items, active, onNavigate, basePath, compact, expandedIds, defaultExpandedIds, onExpandedChange, }: SidebarNavigationProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
|
+
import {
|
|
3
|
+
useId,
|
|
4
|
+
useState
|
|
5
|
+
} from "react";
|
|
6
|
+
import { ChevronRight } from "lucide-react";
|
|
7
|
+
import s from "./SidebarNavigation.module.css";
|
|
8
|
+
function NavigationButton({
|
|
9
|
+
label,
|
|
10
|
+
icon,
|
|
11
|
+
active,
|
|
12
|
+
className = "",
|
|
13
|
+
...props
|
|
14
|
+
}) {
|
|
15
|
+
return /* @__PURE__ */ jsxs(
|
|
16
|
+
"button",
|
|
17
|
+
{
|
|
18
|
+
...props,
|
|
19
|
+
type: "button",
|
|
20
|
+
className: `${s.navigationButton} ${className}`,
|
|
21
|
+
"aria-current": active ? "page" : void 0,
|
|
22
|
+
children: [
|
|
23
|
+
icon,
|
|
24
|
+
/* @__PURE__ */ jsx("span", { children: label })
|
|
25
|
+
]
|
|
26
|
+
}
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
function SidebarNavigation({
|
|
30
|
+
items,
|
|
31
|
+
active,
|
|
32
|
+
onNavigate,
|
|
33
|
+
basePath = "",
|
|
34
|
+
compact = false,
|
|
35
|
+
expandedIds,
|
|
36
|
+
defaultExpandedIds = [],
|
|
37
|
+
onExpandedChange
|
|
38
|
+
}) {
|
|
39
|
+
const [internal, setInternal] = useState(defaultExpandedIds);
|
|
40
|
+
const expanded = expandedIds ?? internal;
|
|
41
|
+
const toggle = (id) => {
|
|
42
|
+
const next = expanded.includes(id) ? expanded.filter((value) => value !== id) : [...expanded, id];
|
|
43
|
+
if (expandedIds === void 0) setInternal(next);
|
|
44
|
+
onExpandedChange?.(next);
|
|
45
|
+
};
|
|
46
|
+
const base = basePath.replace(/^\/+|\/+$/g, "");
|
|
47
|
+
const href = (path) => (base ? "/" + base : "") + (path.startsWith("/") ? path : "/" + path);
|
|
48
|
+
const navigate = (event, path) => {
|
|
49
|
+
if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey)
|
|
50
|
+
return;
|
|
51
|
+
event.preventDefault();
|
|
52
|
+
onNavigate(path);
|
|
53
|
+
};
|
|
54
|
+
return /* @__PURE__ */ jsx("div", { className: s.tree, "data-compact": compact || void 0, children: items.map((item) => /* @__PURE__ */ jsx(
|
|
55
|
+
Branch,
|
|
56
|
+
{
|
|
57
|
+
item,
|
|
58
|
+
active,
|
|
59
|
+
expanded,
|
|
60
|
+
toggle,
|
|
61
|
+
compact,
|
|
62
|
+
href,
|
|
63
|
+
navigate
|
|
64
|
+
},
|
|
65
|
+
item.id
|
|
66
|
+
)) });
|
|
67
|
+
}
|
|
68
|
+
function Branch({
|
|
69
|
+
item,
|
|
70
|
+
active,
|
|
71
|
+
expanded,
|
|
72
|
+
toggle,
|
|
73
|
+
compact,
|
|
74
|
+
href,
|
|
75
|
+
navigate
|
|
76
|
+
}) {
|
|
77
|
+
const id = useId();
|
|
78
|
+
const hasChildren = item.expandable ?? Boolean(item.children?.length || item.content);
|
|
79
|
+
const open = expanded.includes(item.id) && !compact;
|
|
80
|
+
return /* @__PURE__ */ jsxs("div", { className: s.branch, children: [
|
|
81
|
+
/* @__PURE__ */ jsxs("div", { className: s.row, children: [
|
|
82
|
+
/* @__PURE__ */ jsxs(
|
|
83
|
+
"a",
|
|
84
|
+
{
|
|
85
|
+
href: href(item.path),
|
|
86
|
+
"aria-current": active === item.id ? "page" : void 0,
|
|
87
|
+
title: item.label,
|
|
88
|
+
onClick: (event) => navigate(event, item.path),
|
|
89
|
+
children: [
|
|
90
|
+
item.icon,
|
|
91
|
+
/* @__PURE__ */ jsx("span", { className: s.label, children: item.label })
|
|
92
|
+
]
|
|
93
|
+
}
|
|
94
|
+
),
|
|
95
|
+
hasChildren && !compact && /* @__PURE__ */ jsx(
|
|
96
|
+
"button",
|
|
97
|
+
{
|
|
98
|
+
type: "button",
|
|
99
|
+
className: s.disclosure,
|
|
100
|
+
"aria-label": `${open ? "\u6536\u8D77" : "\u5C55\u5F00"}${item.label}`,
|
|
101
|
+
"aria-expanded": open,
|
|
102
|
+
"aria-controls": id,
|
|
103
|
+
onClick: () => toggle(item.id),
|
|
104
|
+
children: /* @__PURE__ */ jsx(ChevronRight, { size: 14, "aria-hidden": "true" })
|
|
105
|
+
}
|
|
106
|
+
)
|
|
107
|
+
] }),
|
|
108
|
+
hasChildren && /* @__PURE__ */ jsxs(
|
|
109
|
+
"div",
|
|
110
|
+
{
|
|
111
|
+
id,
|
|
112
|
+
className: s.children,
|
|
113
|
+
role: "group",
|
|
114
|
+
"aria-label": item.label,
|
|
115
|
+
hidden: !open,
|
|
116
|
+
children: [
|
|
117
|
+
item.content,
|
|
118
|
+
item.children?.map((child) => /* @__PURE__ */ jsx(
|
|
119
|
+
Branch,
|
|
120
|
+
{
|
|
121
|
+
item: child,
|
|
122
|
+
active,
|
|
123
|
+
expanded,
|
|
124
|
+
toggle,
|
|
125
|
+
compact,
|
|
126
|
+
href,
|
|
127
|
+
navigate
|
|
128
|
+
},
|
|
129
|
+
child.id
|
|
130
|
+
))
|
|
131
|
+
]
|
|
132
|
+
}
|
|
133
|
+
)
|
|
134
|
+
] });
|
|
135
|
+
}
|
|
136
|
+
export {
|
|
137
|
+
NavigationButton,
|
|
138
|
+
SidebarNavigation
|
|
139
|
+
};
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
.tree {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
gap: 4px;
|
|
5
|
+
}
|
|
6
|
+
.branch {
|
|
7
|
+
min-width: 0;
|
|
8
|
+
}
|
|
9
|
+
.row {
|
|
10
|
+
position: relative;
|
|
11
|
+
display: flex;
|
|
12
|
+
align-items: center;
|
|
13
|
+
gap: 0;
|
|
14
|
+
min-width: 0;
|
|
15
|
+
border-radius: 8px;
|
|
16
|
+
transition: background var(--motion-hover);
|
|
17
|
+
}
|
|
18
|
+
.row:hover { background:var(--hover); }
|
|
19
|
+
.row:has(> a[aria-current="page"]) { background:var(--selected); }
|
|
20
|
+
.row:has(> .disclosure) > a { padding-right:40px; }
|
|
21
|
+
.row > a,
|
|
22
|
+
.navigationButton {
|
|
23
|
+
display: flex;
|
|
24
|
+
align-items: center;
|
|
25
|
+
gap: 11px;
|
|
26
|
+
flex: 1;
|
|
27
|
+
min-width: 0;
|
|
28
|
+
min-height: 40px;
|
|
29
|
+
padding: 9px 12px;
|
|
30
|
+
border-radius: 8px;
|
|
31
|
+
color: var(--muted);
|
|
32
|
+
font-size: 13px;
|
|
33
|
+
text-decoration: none;
|
|
34
|
+
text-align: left;
|
|
35
|
+
}
|
|
36
|
+
.navigationButton {
|
|
37
|
+
width: 100%;
|
|
38
|
+
border: 0;
|
|
39
|
+
background: transparent;
|
|
40
|
+
cursor: pointer;
|
|
41
|
+
font-family: inherit;
|
|
42
|
+
}
|
|
43
|
+
.row > a > svg {
|
|
44
|
+
flex-shrink: 0;
|
|
45
|
+
}
|
|
46
|
+
.row > a:hover { color:var(--fg); }
|
|
47
|
+
.navigationButton:hover {
|
|
48
|
+
color: var(--fg);
|
|
49
|
+
background: var(--hover);
|
|
50
|
+
}
|
|
51
|
+
.row > a[aria-current="page"] { color:var(--navigation-active-color, var(--accent)); }
|
|
52
|
+
.navigationButton[aria-current="page"] {
|
|
53
|
+
color: var(--navigation-active-color, var(--accent));
|
|
54
|
+
background: var(--selected);
|
|
55
|
+
}
|
|
56
|
+
.label {
|
|
57
|
+
overflow: hidden;
|
|
58
|
+
text-overflow: ellipsis;
|
|
59
|
+
white-space: nowrap;
|
|
60
|
+
}
|
|
61
|
+
.disclosure {
|
|
62
|
+
position: absolute;
|
|
63
|
+
right: 6px;
|
|
64
|
+
display: grid;
|
|
65
|
+
place-items: center;
|
|
66
|
+
flex: 0 0 28px;
|
|
67
|
+
width: 28px;
|
|
68
|
+
height: 28px;
|
|
69
|
+
border: 0;
|
|
70
|
+
border-radius: 6px;
|
|
71
|
+
background: transparent;
|
|
72
|
+
color: var(--muted);
|
|
73
|
+
cursor: pointer;
|
|
74
|
+
}
|
|
75
|
+
.disclosure:hover {
|
|
76
|
+
background: var(--hover);
|
|
77
|
+
color: var(--fg);
|
|
78
|
+
}
|
|
79
|
+
.disclosure:focus-visible {
|
|
80
|
+
outline: 2px solid var(--accent);
|
|
81
|
+
outline-offset: 1px;
|
|
82
|
+
}
|
|
83
|
+
.disclosure svg {
|
|
84
|
+
transition: transform var(--motion-chevron, 180ms) var(--ease);
|
|
85
|
+
}
|
|
86
|
+
.disclosure[aria-expanded="true"] svg {
|
|
87
|
+
transform: rotate(90deg);
|
|
88
|
+
}
|
|
89
|
+
.children {
|
|
90
|
+
margin: 4px 0 4px 16px;
|
|
91
|
+
}
|
|
92
|
+
.children .row > a {min-height:36px;padding-block:7px;gap:9px;font-size:12px;}
|
|
93
|
+
.row > a > svg {width:18px;height:18px;}
|
|
94
|
+
.children .row > a > svg {width:16px;height:16px;}
|
|
95
|
+
.children[hidden] {
|
|
96
|
+
display: none;
|
|
97
|
+
}
|
|
98
|
+
.tree[data-compact] .label {
|
|
99
|
+
display: none;
|
|
100
|
+
}
|
|
101
|
+
.tree[data-compact] .row > a {
|
|
102
|
+
justify-content: center;
|
|
103
|
+
padding-inline: 0;
|
|
104
|
+
}
|
|
105
|
+
@media (prefers-reduced-motion: reduce) {
|
|
106
|
+
.disclosure svg {
|
|
107
|
+
transition: none;
|
|
108
|
+
}
|
|
109
|
+
}
|