@robert-stackflow/oneui 0.5.2 → 0.6.1
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 +78 -69
- package/README.md +188 -149
- package/components/AppShell.d.ts +6 -7
- package/components/AppShell.js +31 -6
- 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 +23 -0
- package/components/ContributionCalendar.js +7 -2
- package/components/ContributionCalendar.module.css +7 -0
- package/components/CopyButton.d.ts +9 -0
- package/components/CopyButton.js +23 -0
- package/components/Layout.d.ts +81 -0
- package/components/Layout.js +271 -0
- package/components/Layout.module.css +82 -0
- package/components/Menu.d.ts +4 -1
- package/components/Menu.js +10 -4
- 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 +6 -0
- package/components/Page.js +21 -8
- package/components/Page.module.css +6 -0
- package/components/Pagination.d.ts +2 -1
- package/components/Pagination.js +3 -2
- package/components/ResourceCard.d.ts +12 -0
- package/components/ResourceCard.js +33 -0
- package/components/ResourceCard.module.css +98 -0
- package/components/SidebarNavigation.d.ts +29 -0
- package/components/SidebarNavigation.js +139 -0
- package/components/SidebarNavigation.module.css +130 -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 +11 -1
- package/components/index.js +42 -1
- package/package.json +42 -2
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
.text {
|
|
2
|
+
margin: 0;
|
|
3
|
+
line-height: 1.65;
|
|
4
|
+
overflow-wrap: anywhere;
|
|
5
|
+
}
|
|
6
|
+
.heading {
|
|
7
|
+
margin: 0;
|
|
8
|
+
line-height: 1.35;
|
|
9
|
+
font-weight: 600;
|
|
10
|
+
letter-spacing: -0.02em;
|
|
11
|
+
overflow-wrap: anywhere;
|
|
12
|
+
}
|
|
13
|
+
.truncate {
|
|
14
|
+
white-space: nowrap;
|
|
15
|
+
overflow: hidden;
|
|
16
|
+
text-overflow: ellipsis;
|
|
17
|
+
}
|
|
18
|
+
.grid {
|
|
19
|
+
display: grid;
|
|
20
|
+
grid-template-columns: repeat(var(--grid-base), minmax(0, 1fr));
|
|
21
|
+
}
|
|
22
|
+
@media (min-width: 768px) {
|
|
23
|
+
.grid {
|
|
24
|
+
grid-template-columns: repeat(var(--grid-sm), minmax(0, 1fr));
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
@media (min-width: 1200px) {
|
|
28
|
+
.grid {
|
|
29
|
+
grid-template-columns: repeat(var(--grid-lg), minmax(0, 1fr));
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
@media (min-width: 1440px) {
|
|
33
|
+
.grid {
|
|
34
|
+
grid-template-columns: repeat(var(--grid-xl), minmax(0, 1fr));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
.code {
|
|
38
|
+
font:
|
|
39
|
+
12px/1.7 Consolas,
|
|
40
|
+
monospace;
|
|
41
|
+
background: var(--soft);
|
|
42
|
+
border-radius: 5px;
|
|
43
|
+
padding: 2px 5px;
|
|
44
|
+
color: var(--fg);
|
|
45
|
+
overflow-wrap: anywhere;
|
|
46
|
+
}
|
|
47
|
+
.codeBlock {
|
|
48
|
+
margin: 0;
|
|
49
|
+
padding: 16px;
|
|
50
|
+
white-space: pre-wrap;
|
|
51
|
+
overflow: auto;
|
|
52
|
+
}
|
|
53
|
+
.icon {
|
|
54
|
+
display: inline-flex;
|
|
55
|
+
align-items: center;
|
|
56
|
+
justify-content: center;
|
|
57
|
+
color: var(--accent);
|
|
58
|
+
background: var(--selected);
|
|
59
|
+
flex-shrink: 0;
|
|
60
|
+
}
|
|
61
|
+
.scroll {
|
|
62
|
+
overflow: auto;
|
|
63
|
+
min-width: 0;
|
|
64
|
+
}
|
|
65
|
+
.interactive {
|
|
66
|
+
text-decoration: none;
|
|
67
|
+
color: inherit;
|
|
68
|
+
transition:
|
|
69
|
+
border-color var(--motion-hover),
|
|
70
|
+
background var(--motion-hover);
|
|
71
|
+
}
|
|
72
|
+
.interactive:hover {
|
|
73
|
+
border-color: var(--accent);
|
|
74
|
+
background: var(--field);
|
|
75
|
+
}
|
|
76
|
+
.mark {
|
|
77
|
+
background: var(--selected);
|
|
78
|
+
color: var(--fg);
|
|
79
|
+
border-radius: 3px;
|
|
80
|
+
padding: 0 1px;
|
|
81
|
+
font-weight: 600;
|
|
82
|
+
}
|
package/components/Menu.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { type ReactNode } from "react";
|
|
2
|
-
export declare function Menu({ label, items, }: {
|
|
2
|
+
export declare function Menu({ label, items, trigger, variant, className, }: {
|
|
3
3
|
label: string;
|
|
4
|
+
trigger?: ReactNode;
|
|
5
|
+
variant?: "primary" | "secondary" | "ghost" | "danger";
|
|
6
|
+
className?: string;
|
|
4
7
|
items: {
|
|
5
8
|
label: string;
|
|
6
9
|
icon?: ReactNode;
|
package/components/Menu.js
CHANGED
|
@@ -7,13 +7,19 @@ import { Popover } from "./Popover.js";
|
|
|
7
7
|
import { usePopover } from "./usePopover.js";
|
|
8
8
|
function Menu({
|
|
9
9
|
label,
|
|
10
|
-
items
|
|
10
|
+
items,
|
|
11
|
+
trigger,
|
|
12
|
+
variant = "secondary",
|
|
13
|
+
className
|
|
11
14
|
}) {
|
|
12
15
|
const pop = usePopover(), id = useId();
|
|
13
16
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
14
|
-
/* @__PURE__ */
|
|
17
|
+
/* @__PURE__ */ jsx(
|
|
15
18
|
Button,
|
|
16
19
|
{
|
|
20
|
+
variant,
|
|
21
|
+
className,
|
|
22
|
+
"aria-label": label,
|
|
17
23
|
ref: pop.anchor,
|
|
18
24
|
"aria-haspopup": "menu",
|
|
19
25
|
"aria-expanded": pop.open,
|
|
@@ -25,10 +31,10 @@ function Menu({
|
|
|
25
31
|
pop.show();
|
|
26
32
|
}
|
|
27
33
|
},
|
|
28
|
-
children: [
|
|
34
|
+
children: trigger ?? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
29
35
|
label,
|
|
30
36
|
/* @__PURE__ */ jsx(ChevronDown, { size: 14 })
|
|
31
|
-
]
|
|
37
|
+
] })
|
|
32
38
|
}
|
|
33
39
|
),
|
|
34
40
|
/* @__PURE__ */ jsx(
|
|
@@ -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,4 +1,10 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
+
export declare function PageHeading({ title, description, actions, titleExtra, }: {
|
|
3
|
+
title?: ReactNode;
|
|
4
|
+
description?: string;
|
|
5
|
+
actions?: ReactNode;
|
|
6
|
+
titleExtra?: ReactNode;
|
|
7
|
+
}): import("react").JSX.Element | null;
|
|
2
8
|
export declare function Page({ title, description, actions, children, }: {
|
|
3
9
|
title?: ReactNode;
|
|
4
10
|
description?: string;
|
package/components/Page.js
CHANGED
|
@@ -1,22 +1,35 @@
|
|
|
1
1
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
2
2
|
import s from "./Page.module.css";
|
|
3
|
-
function
|
|
3
|
+
function PageHeading({
|
|
4
4
|
title,
|
|
5
5
|
description,
|
|
6
6
|
actions,
|
|
7
|
-
|
|
7
|
+
titleExtra
|
|
8
8
|
}) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
if (!title && !description && !actions && !titleExtra) return null;
|
|
10
|
+
return /* @__PURE__ */ jsxs("header", { className: s.heading, children: [
|
|
11
|
+
/* @__PURE__ */ jsxs("div", { children: [
|
|
12
|
+
/* @__PURE__ */ jsxs("div", { className: s.title, children: [
|
|
12
13
|
title && /* @__PURE__ */ jsx("h1", { children: title }),
|
|
13
|
-
|
|
14
|
+
titleExtra
|
|
14
15
|
] }),
|
|
15
|
-
|
|
16
|
+
description && /* @__PURE__ */ jsx("p", { children: description })
|
|
16
17
|
] }),
|
|
18
|
+
actions && /* @__PURE__ */ jsx("div", { className: s.actions, children: actions })
|
|
19
|
+
] });
|
|
20
|
+
}
|
|
21
|
+
function Page({
|
|
22
|
+
title,
|
|
23
|
+
description,
|
|
24
|
+
actions,
|
|
25
|
+
children
|
|
26
|
+
}) {
|
|
27
|
+
return /* @__PURE__ */ jsxs("div", { className: s.page, children: [
|
|
28
|
+
/* @__PURE__ */ jsx(PageHeading, { title, description, actions }),
|
|
17
29
|
children
|
|
18
30
|
] });
|
|
19
31
|
}
|
|
20
32
|
export {
|
|
21
|
-
Page
|
|
33
|
+
Page,
|
|
34
|
+
PageHeading
|
|
22
35
|
};
|
|
@@ -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,33 @@
|
|
|
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({
|
|
6
|
+
title,
|
|
7
|
+
icon,
|
|
8
|
+
status,
|
|
9
|
+
description,
|
|
10
|
+
subtitle,
|
|
11
|
+
metadata,
|
|
12
|
+
href,
|
|
13
|
+
onClick
|
|
14
|
+
}) {
|
|
15
|
+
return /* @__PURE__ */ jsxs("a", { href, onClick, className: `${card.card} ${s.card}`, children: [
|
|
16
|
+
/* @__PURE__ */ jsxs("div", { className: s.header, children: [
|
|
17
|
+
/* @__PURE__ */ jsx("span", { className: s.icon, children: icon }),
|
|
18
|
+
/* @__PURE__ */ jsxs("div", { className: s.heading, children: [
|
|
19
|
+
/* @__PURE__ */ jsx("h3", { children: title }),
|
|
20
|
+
subtitle && /* @__PURE__ */ jsx("p", { children: subtitle })
|
|
21
|
+
] }),
|
|
22
|
+
status
|
|
23
|
+
] }),
|
|
24
|
+
description && /* @__PURE__ */ jsx("p", { className: s.description, children: description }),
|
|
25
|
+
/* @__PURE__ */ jsxs("div", { className: s.footer, children: [
|
|
26
|
+
/* @__PURE__ */ jsx("div", { className: s.facts, children: metadata?.map((item, index) => /* @__PURE__ */ jsx("span", { children: item }, index)) }),
|
|
27
|
+
/* @__PURE__ */ jsx(ArrowUpRight, { size: 16, "aria-hidden": "true" })
|
|
28
|
+
] })
|
|
29
|
+
] });
|
|
30
|
+
}
|
|
31
|
+
export {
|
|
32
|
+
ResourceCard
|
|
33
|
+
};
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
.card {
|
|
2
|
+
display: flex;
|
|
3
|
+
flex-direction: column;
|
|
4
|
+
padding: 24px;
|
|
5
|
+
color: var(--fg);
|
|
6
|
+
text-decoration: none;
|
|
7
|
+
transition:
|
|
8
|
+
border-color var(--motion-hover),
|
|
9
|
+
box-shadow var(--motion-hover);
|
|
10
|
+
}
|
|
11
|
+
.card:hover {
|
|
12
|
+
border-color: color-mix(in srgb, var(--accent) 35%, var(--line));
|
|
13
|
+
box-shadow: var(--shadow);
|
|
14
|
+
}
|
|
15
|
+
.header {
|
|
16
|
+
display: flex;
|
|
17
|
+
align-items: center;
|
|
18
|
+
gap: 12px;
|
|
19
|
+
min-width: 0;
|
|
20
|
+
}
|
|
21
|
+
.icon {
|
|
22
|
+
width: 40px;
|
|
23
|
+
height: 40px;
|
|
24
|
+
flex: none;
|
|
25
|
+
border-radius: var(--radius);
|
|
26
|
+
display: grid;
|
|
27
|
+
place-items: center;
|
|
28
|
+
background: var(--selected);
|
|
29
|
+
color: var(--accent);
|
|
30
|
+
}
|
|
31
|
+
.icon svg {
|
|
32
|
+
width: 20px;
|
|
33
|
+
height: 20px;
|
|
34
|
+
}
|
|
35
|
+
.heading {
|
|
36
|
+
flex: 1;
|
|
37
|
+
min-width: 0;
|
|
38
|
+
}
|
|
39
|
+
.heading h3 {
|
|
40
|
+
font-size: 15px;
|
|
41
|
+
font-weight: 600;
|
|
42
|
+
color: var(--fg);
|
|
43
|
+
overflow: hidden;
|
|
44
|
+
text-overflow: ellipsis;
|
|
45
|
+
white-space: nowrap;
|
|
46
|
+
}
|
|
47
|
+
.heading p {
|
|
48
|
+
font-size: 12px;
|
|
49
|
+
color: var(--muted);
|
|
50
|
+
margin-top: 3px;
|
|
51
|
+
overflow: hidden;
|
|
52
|
+
text-overflow: ellipsis;
|
|
53
|
+
white-space: nowrap;
|
|
54
|
+
}
|
|
55
|
+
.description {
|
|
56
|
+
font-size: 13px;
|
|
57
|
+
line-height: 1.7;
|
|
58
|
+
margin: 18px 0 0;
|
|
59
|
+
color: var(--muted);
|
|
60
|
+
display: -webkit-box;
|
|
61
|
+
-webkit-line-clamp: 2;
|
|
62
|
+
-webkit-box-orient: vertical;
|
|
63
|
+
overflow: hidden;
|
|
64
|
+
}
|
|
65
|
+
.footer {
|
|
66
|
+
display: flex;
|
|
67
|
+
align-items: center;
|
|
68
|
+
justify-content: space-between;
|
|
69
|
+
gap: 12px;
|
|
70
|
+
margin-top: auto;
|
|
71
|
+
padding-top: 20px;
|
|
72
|
+
color: var(--muted);
|
|
73
|
+
}
|
|
74
|
+
.facts {
|
|
75
|
+
display: flex;
|
|
76
|
+
align-items: center;
|
|
77
|
+
flex-wrap: wrap;
|
|
78
|
+
gap: 6px 14px;
|
|
79
|
+
font-size: 12px;
|
|
80
|
+
}
|
|
81
|
+
.facts > span + span {
|
|
82
|
+
padding-left: 14px;
|
|
83
|
+
border-left: 1px solid var(--line);
|
|
84
|
+
}
|
|
85
|
+
@media (max-width: 600px) {
|
|
86
|
+
.card {
|
|
87
|
+
padding: 18px;
|
|
88
|
+
}
|
|
89
|
+
.header {
|
|
90
|
+
gap: 10px;
|
|
91
|
+
}
|
|
92
|
+
.facts {
|
|
93
|
+
gap: 6px 10px;
|
|
94
|
+
}
|
|
95
|
+
.facts > span + span {
|
|
96
|
+
padding-left: 10px;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -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
|
+
};
|