@momoi-labs/kiso-react 0.22.1 → 0.23.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/dist/chart.d.ts +6 -2
- package/dist/chart.js +17 -3
- package/dist/code-block.d.ts +21 -0
- package/dist/code-block.js +148 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/scope-switcher.d.ts +49 -0
- package/dist/scope-switcher.js +297 -0
- package/dist/time-range-calendar.d.ts +12 -0
- package/dist/time-range-calendar.js +102 -0
- package/dist/time-range-control.d.ts +28 -12
- package/dist/time-range-control.js +41 -22
- package/dist/time-range-live.d.ts +18 -0
- package/dist/time-range-live.js +305 -0
- package/dist/time-range-shared.d.ts +91 -0
- package/dist/time-range-shared.js +87 -0
- package/dist/time-range-text.d.ts +13 -0
- package/dist/time-range-text.js +44 -0
- package/dist/time-zone.d.ts +15 -0
- package/dist/time-zone.js +121 -0
- package/package.json +2 -2
package/dist/chart.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ declare const defaultLabels: {
|
|
|
11
11
|
values: string;
|
|
12
12
|
help: string;
|
|
13
13
|
summary: (label: string) => string;
|
|
14
|
-
samples: (label: string) => string;
|
|
14
|
+
samples: (label: string, timeZone: string) => string;
|
|
15
15
|
};
|
|
16
16
|
export type ChartProps = Omit<React.ComponentProps<"figure">, "children"> & {
|
|
17
17
|
data: readonly ChartSample[];
|
|
@@ -31,6 +31,10 @@ export type ChartProps = Omit<React.ComponentProps<"figure">, "children"> & {
|
|
|
31
31
|
/** Panels in a group inspect the same timestamp, not the same array index. */
|
|
32
32
|
syncId?: string;
|
|
33
33
|
formatTime?: (timestamp: number) => string;
|
|
34
|
+
/** IANA time zone for times. With timeZone and locale both omitted, times
|
|
35
|
+
stay UTC ISO strings. */
|
|
36
|
+
timeZone?: string;
|
|
37
|
+
locale?: string;
|
|
34
38
|
formatValue?: (value: number) => string;
|
|
35
39
|
min?: number;
|
|
36
40
|
max?: number;
|
|
@@ -40,4 +44,4 @@ export type ChartProps = Omit<React.ComponentProps<"figure">, "children"> & {
|
|
|
40
44
|
/** Localizes the fixed text. Chart passes the legend's keys on to ChartLegend. */
|
|
41
45
|
labels?: Partial<typeof defaultLabels> & NonNullable<ChartLegendProps["labels"]>;
|
|
42
46
|
} & ChartTreatmentProps;
|
|
43
|
-
export declare function Chart({ data, series, label, variant, layout: layoutProp, legend: legendProp, summary, highlightSeries, onHighlightSeriesChange, height: heightProp, syncId, formatTime, formatValue, min, max, onRangeSelect, labels, chartStyle, chartLine, chartFill, ref, className, onKeyDown, ...props }: ChartProps): React.JSX.Element;
|
|
47
|
+
export declare function Chart({ data, series, label, variant, layout: layoutProp, legend: legendProp, summary, highlightSeries, onHighlightSeriesChange, height: heightProp, syncId, formatTime: formatTimeProp, timeZone, locale, formatValue, min, max, onRangeSelect, labels, chartStyle, chartLine, chartFill, ref, className, onKeyDown, ...props }: ChartProps): React.JSX.Element;
|
package/dist/chart.js
CHANGED
|
@@ -9,16 +9,30 @@ import { ChartDot, ChartPattern, pixelCurve, useChartPresentation, useChartStyle
|
|
|
9
9
|
import { useChartFill } from "./chart-fill.js";
|
|
10
10
|
import { chartPinned, clearChartPin, setChartHover, toggleChartPin, useChartSync } from "./chart-sync.js";
|
|
11
11
|
import { chartColor, chartSlot, formatChartTime, formatChartValue, measured, validateChart } from "./chart-data.js";
|
|
12
|
+
import { dateFormat, validTimeZone } from "./time-zone.js";
|
|
12
13
|
const defaultLabels = {
|
|
13
14
|
notCollected: "Not collected", empty: "No collected samples in this window.",
|
|
14
15
|
timestamp: "Timestamp", values: "View exact values",
|
|
15
16
|
help: "Focus the chart and use Left and Right to inspect samples. Press Enter to mark the inspected sample in every synchronized chart, and Escape to clear it. Select a series in the legend to highlight it. Exact values are available below.",
|
|
16
17
|
summary: (label) => `${label}: summary`,
|
|
17
|
-
samples: (label) => `${label}: collected samples, timestamps in
|
|
18
|
+
samples: (label, timeZone) => `${label}: collected samples, timestamps in ${timeZone}`,
|
|
18
19
|
};
|
|
19
|
-
export function Chart({ data, series, label, variant = "line", layout: layoutProp, legend: legendProp, summary, highlightSeries, onHighlightSeriesChange, height: heightProp, syncId, formatTime
|
|
20
|
+
export function Chart({ data, series, label, variant = "line", layout: layoutProp, legend: legendProp, summary, highlightSeries, onHighlightSeriesChange, height: heightProp, syncId, formatTime: formatTimeProp, timeZone, locale, formatValue = formatChartValue, min, max, onRangeSelect, labels, chartStyle, chartLine, chartFill, ref, className, onKeyDown, ...props }) {
|
|
20
21
|
const id = React.useId();
|
|
21
22
|
const text = { ...defaultLabels, ...labels };
|
|
23
|
+
const zoned = timeZone !== undefined || locale !== undefined;
|
|
24
|
+
const zone = timeZone ?? "UTC";
|
|
25
|
+
if (zoned && !validTimeZone(zone))
|
|
26
|
+
throw new RangeError("Chart time zone must be a valid IANA name.");
|
|
27
|
+
const zonedTime = React.useCallback((timestamp) => dateFormat(locale, { timeZone: zone,
|
|
28
|
+
hour: "2-digit", minute: "2-digit", second: "2-digit" }).format(timestamp), [locale, zone]);
|
|
29
|
+
const formatTime = formatTimeProp ?? (zoned ? zonedTime : formatChartTime);
|
|
30
|
+
// The exact table always names the date, the second, and the offset.
|
|
31
|
+
const fractional = data.some(sample => sample.timestamp % 1000 !== 0);
|
|
32
|
+
const exactTime = zoned ? (timestamp) => dateFormat(locale, { timeZone: zone, year: "numeric",
|
|
33
|
+
month: "2-digit", day: "2-digit", hour: "2-digit", minute: "2-digit", second: "2-digit",
|
|
34
|
+
...(fractional ? { fractionalSecondDigits: 3 } : {}), timeZoneName: "longOffset" }).format(timestamp)
|
|
35
|
+
: formatChartTime;
|
|
22
36
|
const frame = React.useRef(null);
|
|
23
37
|
const { line, fill } = useChartStyle(frame, { chartStyle, chartLine, chartFill });
|
|
24
38
|
const presentation = useChartPresentation(frame, layoutProp, legendProp);
|
|
@@ -193,7 +207,7 @@ export function Chart({ data, series, label, variant = "line", layout: layoutPro
|
|
|
193
207
|
toggleChartPin(group, inspected.current);
|
|
194
208
|
}
|
|
195
209
|
}, children: [_jsx("figcaption", { id: `${id}-title`, className: "t-h3", children: label }), _jsx("p", { id: `${id}-help`, className: "chart-help", children: text.help }), _jsxs("div", { className: "chart-body", children: [_jsx("div", { className: "chart-plots", children: hasData ? layout === "split" ? series.map((item, index) => _jsxs("div", { className: "chart-lane", children: [_jsxs("div", { className: "chart-lane-heading", children: [_jsx(ChartSeriesLabel, { series: item, index: index }), _jsx("span", { children: displayValue(data.at(-1)?.values[item.key]) })] }), renderPlot([index], item)] }, item.key)) : renderPlot(series.map((_, index) => index))
|
|
196
|
-
: _jsx("div", { className: "chart-empty hatch", style: { minHeight: height }, children: text.empty }) }), legend === "sidebar" && legendContent] }), legend !== "sidebar" && legendContent, _jsxs("details", { className: "disclosure chart-values", children: [_jsx("summary", { children: text.values }), _jsx("div", { className: "chart-table-scroll", children: _jsxs("table", { className: "chart-table", children: [_jsx("caption", { children: text.samples(label) }), _jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { scope: "col", children: text.timestamp }), series.map(item => _jsx("th", { scope: "col", children: item.label }, item.key))] }) }), _jsx("tbody", { children: data.map(sample => _jsxs("tr", { children: [_jsx("th", { scope: "row", children:
|
|
210
|
+
: _jsx("div", { className: "chart-empty hatch", style: { minHeight: height }, children: text.empty }) }), legend === "sidebar" && legendContent] }), legend !== "sidebar" && legendContent, _jsxs("details", { className: "disclosure chart-values", children: [_jsx("summary", { children: text.values }), _jsx("div", { className: "chart-table-scroll", children: _jsxs("table", { className: "chart-table", children: [_jsx("caption", { children: text.samples(label, zone) }), _jsx("thead", { children: _jsxs("tr", { children: [_jsx("th", { scope: "col", children: text.timestamp }), series.map(item => _jsx("th", { scope: "col", children: item.label }, item.key))] }) }), _jsx("tbody", { children: data.map(sample => _jsxs("tr", { children: [_jsx("th", { scope: "row", children: exactTime(sample.timestamp) }), series.map(item => _jsx("td", { children: measured(sample.values[item.key]) ? String(sample.values[item.key]) : text.notCollected }, item.key))] }, sample.timestamp)) })] }) })] })] });
|
|
197
211
|
}
|
|
198
212
|
// Observe Recharts' synchronized tooltip state after render. This keeps the
|
|
199
213
|
// sidebar on the same timestamp for mouse, keyboard, touch, and sibling panels.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type ComponentProps, type ReactNode } from "react";
|
|
2
|
+
import type { CodeEditorHighlight } from "./code-editor.js";
|
|
3
|
+
export type CodeBlockProps = Omit<ComponentProps<"figure">, "children" | "title"> & {
|
|
4
|
+
code: string;
|
|
5
|
+
/** Paints the code, as CodeEditor's `highlight`: React nodes or HTML as `{ __html }`. */
|
|
6
|
+
highlight?: CodeEditorHighlight;
|
|
7
|
+
title?: ReactNode;
|
|
8
|
+
/** Marks the block as commands to run in a terminal. */
|
|
9
|
+
terminal?: boolean;
|
|
10
|
+
lineNumbers?: boolean;
|
|
11
|
+
/** Reads the first column as `+`, `-` or a space, marks the line and paints the rest. */
|
|
12
|
+
diff?: boolean;
|
|
13
|
+
/** 1-based line numbers to mark as added or removed. */
|
|
14
|
+
added?: number[];
|
|
15
|
+
removed?: number[];
|
|
16
|
+
/** 1-based, inclusive line ranges that start folded. */
|
|
17
|
+
collapse?: [number, number][];
|
|
18
|
+
/** The value type for the copy action, as in "command". Shows Copy; needs Toasts. */
|
|
19
|
+
copy?: string;
|
|
20
|
+
};
|
|
21
|
+
export declare function CodeBlock({ code, highlight, title, terminal, lineNumbers, diff, added, removed, collapse, copy, className, ...props }: CodeBlockProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { cloneElement, createElement, isValidElement, useState } from "react";
|
|
4
|
+
import { clsx as cn } from "clsx";
|
|
5
|
+
import { Check, Copy } from "lucide-react";
|
|
6
|
+
import { Button } from "./button.js";
|
|
7
|
+
import { TerminalIcon } from "./terminal-icon.js";
|
|
8
|
+
import { useToast } from "./toast.js";
|
|
9
|
+
// A highlight paints the whole value, so a token can span lines. These split
|
|
10
|
+
// the painted value back into lines, reopening any element a newline cuts.
|
|
11
|
+
function splitNode(node) {
|
|
12
|
+
if (node == null || typeof node === "boolean")
|
|
13
|
+
return [[]];
|
|
14
|
+
if (typeof node === "string" || typeof node === "number")
|
|
15
|
+
return String(node).split("\n").map(part => part ? [part] : []);
|
|
16
|
+
if (Array.isArray(node))
|
|
17
|
+
return node.reduce((lines, child) => {
|
|
18
|
+
const [first, ...rest] = splitNode(child);
|
|
19
|
+
lines[lines.length - 1].push(...first);
|
|
20
|
+
return [...lines, ...rest];
|
|
21
|
+
}, [[]]);
|
|
22
|
+
if (isValidElement(node)) {
|
|
23
|
+
return splitNode(node.props.children).map((parts, index) => parts.length ? [cloneElement(node, { key: `${node.key ?? ""}:${index}` }, ...parts)] : []);
|
|
24
|
+
}
|
|
25
|
+
return [[node]];
|
|
26
|
+
}
|
|
27
|
+
// A tag, with `>` allowed inside quoted attribute values, or a run of text.
|
|
28
|
+
const htmlPart = /<\/?[a-z][^>"']*(?:(?:"[^"]*"|'[^']*')[^>"']*)*>|[^<]+|</gi;
|
|
29
|
+
function splitHTML(html) {
|
|
30
|
+
const lines = [""];
|
|
31
|
+
const open = [];
|
|
32
|
+
for (const [part] of html.matchAll(htmlPart)) {
|
|
33
|
+
if (part === "<") {
|
|
34
|
+
lines[lines.length - 1] += "<";
|
|
35
|
+
continue;
|
|
36
|
+
}
|
|
37
|
+
if (part.startsWith("</"))
|
|
38
|
+
open.pop();
|
|
39
|
+
else if (part.startsWith("<") && !part.endsWith("/>"))
|
|
40
|
+
open.push([part, /^<([a-z0-9-]+)/i.exec(part)[1]]);
|
|
41
|
+
if (part.startsWith("<")) {
|
|
42
|
+
lines[lines.length - 1] += part;
|
|
43
|
+
continue;
|
|
44
|
+
}
|
|
45
|
+
part.split("\n").forEach((text, index) => {
|
|
46
|
+
if (index) {
|
|
47
|
+
lines[lines.length - 1] += open.map(([, name]) => `</${name}>`).reverse().join("");
|
|
48
|
+
lines.push(open.map(([tag]) => tag).join(""));
|
|
49
|
+
}
|
|
50
|
+
lines[lines.length - 1] += text;
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return lines;
|
|
54
|
+
}
|
|
55
|
+
const entities = { amp: "&", lt: "<", gt: ">", quot: '"', apos: "'", nbsp: "\u00a0" };
|
|
56
|
+
const htmlText = (html) => html.replace(/<[^>"']*(?:(?:"[^"]*"|'[^']*')[^>"']*)*>/g, "")
|
|
57
|
+
.replace(/&(#x[\da-f]+|#\d+|[a-z]+);/gi, (entity, name) => name[0] !== "#" ? entities[name.toLowerCase()] ?? entity
|
|
58
|
+
: String.fromCodePoint(parseInt(name.slice(name[1].toLowerCase() === "x" ? 2 : 1), name[1].toLowerCase() === "x" ? 16 : 10)));
|
|
59
|
+
// The text a split line will show. A component that takes its text from
|
|
60
|
+
// another prop yields none here, so its line no longer matches the source.
|
|
61
|
+
const nodeText = (node) => node == null || typeof node === "boolean" ? ""
|
|
62
|
+
: typeof node === "string" || typeof node === "number" ? String(node)
|
|
63
|
+
: Array.isArray(node) ? node.map(nodeText).join("")
|
|
64
|
+
: isValidElement(node) ? nodeText(node.props.children) : "";
|
|
65
|
+
// A highlight must keep the value's characters. When the painted lines do not
|
|
66
|
+
// read the same as the source, the block shows the source unpainted.
|
|
67
|
+
function paint(code, highlight) {
|
|
68
|
+
const rows = code.split("\n");
|
|
69
|
+
const painted = highlight?.(code);
|
|
70
|
+
if (painted == null || painted === false || painted === "")
|
|
71
|
+
return rows;
|
|
72
|
+
if (typeof painted === "object" && "__html" in painted) {
|
|
73
|
+
const lines = splitHTML(painted.__html);
|
|
74
|
+
if (lines.length !== rows.length || lines.some((line, index) => htmlText(line) !== rows[index]))
|
|
75
|
+
return rows;
|
|
76
|
+
return lines.map((__html, index) => _jsx("span", { dangerouslySetInnerHTML: { __html } }, index));
|
|
77
|
+
}
|
|
78
|
+
const lines = splitNode(painted);
|
|
79
|
+
if (lines.length !== rows.length || lines.some((parts, index) => nodeText(parts) !== rows[index]))
|
|
80
|
+
return rows;
|
|
81
|
+
return lines.map(parts => createElement("span", null, ...parts));
|
|
82
|
+
}
|
|
83
|
+
// The console also runs on plain HTTP, where the Clipboard API is missing.
|
|
84
|
+
async function writeClipboard(text) {
|
|
85
|
+
if (navigator.clipboard && window.isSecureContext)
|
|
86
|
+
return navigator.clipboard.writeText(text);
|
|
87
|
+
const focused = document.activeElement;
|
|
88
|
+
const area = Object.assign(document.createElement("textarea"), { value: text, readOnly: true });
|
|
89
|
+
area.style.cssText = "position:fixed;inset-block-start:0;opacity:0";
|
|
90
|
+
document.body.append(area);
|
|
91
|
+
area.select();
|
|
92
|
+
let copied = false;
|
|
93
|
+
try {
|
|
94
|
+
copied = document.execCommand("copy");
|
|
95
|
+
}
|
|
96
|
+
finally {
|
|
97
|
+
area.remove();
|
|
98
|
+
focused?.focus();
|
|
99
|
+
}
|
|
100
|
+
if (!copied)
|
|
101
|
+
throw new Error("Copy failed");
|
|
102
|
+
}
|
|
103
|
+
function CopyButton({ code, label }) {
|
|
104
|
+
const notify = useToast();
|
|
105
|
+
const [copied, setCopied] = useState(false);
|
|
106
|
+
const name = label[0].toUpperCase() + label.slice(1);
|
|
107
|
+
return _jsxs(Button, { size: "xs", variant: "ghost", "aria-label": `${copied ? "Copied" : "Copy"} ${label}`, onClick: async () => {
|
|
108
|
+
try {
|
|
109
|
+
await writeClipboard(code);
|
|
110
|
+
notify("success", `${name} copied`);
|
|
111
|
+
setCopied(true);
|
|
112
|
+
setTimeout(() => setCopied(false), 6000);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
notify("error", `${name} was not copied`, "Clipboard access was blocked. Select the value and copy it manually.");
|
|
116
|
+
}
|
|
117
|
+
}, children: [copied ? _jsx(Check, { className: "icon", "aria-hidden": "true" }) : _jsx(Copy, { className: "icon", "aria-hidden": "true" }), copied ? "Copied" : "Copy"] });
|
|
118
|
+
}
|
|
119
|
+
export function CodeBlock({ code, highlight, title, terminal = false, lineNumbers = false, diff = false, added = [], removed = [], collapse = [], copy, className, ...props }) {
|
|
120
|
+
const rows = code.split("\n");
|
|
121
|
+
const changes = rows.map((row, index) => diff
|
|
122
|
+
? (row[0] === "+" ? "added" : row[0] === "-" ? "removed" : undefined)
|
|
123
|
+
: added.includes(index + 1) ? "added" : removed.includes(index + 1) ? "removed" : undefined);
|
|
124
|
+
const source = diff ? rows.map(row => /^[+\- ]/.test(row) ? row.slice(1) : row).join("\n") : code;
|
|
125
|
+
const lines = paint(source, highlight);
|
|
126
|
+
const markers = changes.some(Boolean);
|
|
127
|
+
const [open, setOpen] = useState([]);
|
|
128
|
+
// A title captions the figure; without one, the header holds only controls.
|
|
129
|
+
const Header = title != null ? "figcaption" : "div";
|
|
130
|
+
const line = (index) => _jsxs("span", { className: "code-block-line", "data-change": changes[index], children: [lineNumbers && _jsx("span", { className: "code-block-number", "aria-hidden": "true", children: index + 1 }), markers && _jsx("span", { className: "code-block-marker", "aria-hidden": "true", children: changes[index] === "added" ? "+" : changes[index] === "removed" ? "−" : " " }), changes[index] && _jsx("span", { className: "code-block-change", children: changes[index] === "added" ? "Added line: " : "Removed line: " }), lines[index], "\n"] }, index);
|
|
131
|
+
const body = [];
|
|
132
|
+
for (let index = 0; index < lines.length; index++) {
|
|
133
|
+
const range = collapse.findIndex(([from, to]) => from === index + 1 && to >= from && to <= lines.length);
|
|
134
|
+
if (range === -1) {
|
|
135
|
+
body.push(line(index));
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
const [from, to] = collapse[range];
|
|
139
|
+
const expanded = open.includes(range);
|
|
140
|
+
const count = to - from + 1;
|
|
141
|
+
body.push(_jsxs("span", { className: "code-block-line code-block-fold", children: [_jsx("button", { type: "button", "aria-expanded": expanded, onClick: () => setOpen(current => expanded ? current.filter(item => item !== range) : [...current, range]), children: expanded ? `Hide ${count} lines` : `Show ${count} hidden lines` }), "\n"] }, `fold-${range}`));
|
|
142
|
+
if (expanded)
|
|
143
|
+
for (let folded = from - 1; folded < to; folded++)
|
|
144
|
+
body.push(line(folded));
|
|
145
|
+
index = to - 1;
|
|
146
|
+
}
|
|
147
|
+
return (_jsxs("figure", { className: cn("code-block", className), "data-slot": "code-block", "data-terminal": terminal || undefined, style: { "--code-block-digits": String(lines.length).length }, ...props, children: [(title != null || terminal || copy) && _jsxs(Header, { className: "code-block-header", children: [terminal && _jsx(TerminalIcon, {}), title != null && _jsx("span", { className: "code-block-title", children: title }), copy && _jsx(CopyButton, { code: code, label: copy })] }), _jsx("pre", { children: _jsx("code", { children: body }) })] }));
|
|
148
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,7 @@ export * from "./button.js";
|
|
|
9
9
|
export * from "./card.js";
|
|
10
10
|
export * from "./checkbox.js";
|
|
11
11
|
export * from "./chip-input.js";
|
|
12
|
+
export * from "./code-block.js";
|
|
12
13
|
export * from "./code-editor.js";
|
|
13
14
|
export * from "./filter-input.js";
|
|
14
15
|
export * from "./filter-expression.js";
|
|
@@ -31,6 +32,7 @@ export * from "./navigation.js";
|
|
|
31
32
|
export * from "./page-header.js";
|
|
32
33
|
export * from "./pagination.js";
|
|
33
34
|
export * from "./popover.js";
|
|
35
|
+
export * from "./scope-switcher.js";
|
|
34
36
|
export * from "./search.js";
|
|
35
37
|
export * from "./select.js";
|
|
36
38
|
export * from "./detail-select.js";
|
package/dist/index.js
CHANGED
|
@@ -10,6 +10,7 @@ export * from "./button.js";
|
|
|
10
10
|
export * from "./card.js";
|
|
11
11
|
export * from "./checkbox.js";
|
|
12
12
|
export * from "./chip-input.js";
|
|
13
|
+
export * from "./code-block.js";
|
|
13
14
|
export * from "./code-editor.js";
|
|
14
15
|
export * from "./filter-input.js";
|
|
15
16
|
export * from "./filter-expression.js";
|
|
@@ -32,6 +33,7 @@ export * from "./navigation.js";
|
|
|
32
33
|
export * from "./page-header.js";
|
|
33
34
|
export * from "./pagination.js";
|
|
34
35
|
export * from "./popover.js";
|
|
36
|
+
export * from "./scope-switcher.js";
|
|
35
37
|
export * from "./search.js";
|
|
36
38
|
export * from "./select.js";
|
|
37
39
|
export * from "./detail-select.js";
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
type ScopeOption = {
|
|
3
|
+
value: string;
|
|
4
|
+
label: string;
|
|
5
|
+
description?: string;
|
|
6
|
+
group?: string;
|
|
7
|
+
};
|
|
8
|
+
type ScopeSegmentLabels = {
|
|
9
|
+
/** Popup name. Defaults to "Switch <level>". */
|
|
10
|
+
dialog?: string;
|
|
11
|
+
/** Listbox name. Defaults to the level. */
|
|
12
|
+
list?: string;
|
|
13
|
+
/** Filter name. Defaults to "Filter <list>". */
|
|
14
|
+
filter?: string;
|
|
15
|
+
loading?: string;
|
|
16
|
+
error?: string;
|
|
17
|
+
retry?: string;
|
|
18
|
+
/** Status and trigger text when the level has no choices. */
|
|
19
|
+
empty?: string;
|
|
20
|
+
noMatches?: (query: string) => string;
|
|
21
|
+
/** Trigger name suffix while the current name is unknown. */
|
|
22
|
+
unknown?: string;
|
|
23
|
+
};
|
|
24
|
+
type ScopeSegmentProps = {
|
|
25
|
+
/** Level name, the start of the trigger's accessible name. */
|
|
26
|
+
level: string;
|
|
27
|
+
value?: string;
|
|
28
|
+
options: ScopeOption[];
|
|
29
|
+
all?: {
|
|
30
|
+
value: string;
|
|
31
|
+
label: string;
|
|
32
|
+
};
|
|
33
|
+
/** Current name while options are not loaded, for example from the URL. */
|
|
34
|
+
currentLabel?: string;
|
|
35
|
+
searchable?: boolean;
|
|
36
|
+
status?: "ready" | "loading" | "error";
|
|
37
|
+
onRetry?: () => void;
|
|
38
|
+
onValueChange: (value: string) => void;
|
|
39
|
+
destinations?: React.ReactNode;
|
|
40
|
+
labels?: ScopeSegmentLabels;
|
|
41
|
+
className?: string;
|
|
42
|
+
};
|
|
43
|
+
declare function ScopeSwitcher({ className, children, "aria-label": ariaLabel, ...props }: React.ComponentProps<"nav">): React.JSX.Element;
|
|
44
|
+
declare function ScopeSegment(props: ScopeSegmentProps): React.JSX.Element;
|
|
45
|
+
declare function ScopeDestination({ className, asChild, onClick, ...props }: React.ComponentProps<"a"> & {
|
|
46
|
+
asChild?: boolean;
|
|
47
|
+
}): React.JSX.Element;
|
|
48
|
+
export { ScopeSwitcher, ScopeSegment, ScopeDestination };
|
|
49
|
+
export type { ScopeOption, ScopeSegmentProps, ScopeSegmentLabels };
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { clsx as cn } from "clsx";
|
|
5
|
+
import { Check, ChevronDown, Layers, Search } from "lucide-react";
|
|
6
|
+
import { Popover as PopoverPrimitive, Slot } from "radix-ui";
|
|
7
|
+
import { Button } from "./button.js";
|
|
8
|
+
import { Skeleton } from "./skeleton.js";
|
|
9
|
+
import { Spinner } from "./spinner.js";
|
|
10
|
+
const NARROW = "(max-width: 699px)";
|
|
11
|
+
function subscribe(callback) {
|
|
12
|
+
const query = window.matchMedia(NARROW);
|
|
13
|
+
query.addEventListener("change", callback);
|
|
14
|
+
return () => query.removeEventListener("change", callback);
|
|
15
|
+
}
|
|
16
|
+
function useNarrow() {
|
|
17
|
+
return React.useSyncExternalStore(subscribe, () => window.matchMedia(NARROW).matches, () => false);
|
|
18
|
+
}
|
|
19
|
+
const ScopeContext = React.createContext({ compact: false, closeCompact: () => { }, tabOutCompact: () => { }, levelsRef: null });
|
|
20
|
+
const TABBABLE = 'a[href], button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
21
|
+
function tabbables(root) {
|
|
22
|
+
return Array.from(root.querySelectorAll(TABBABLE))
|
|
23
|
+
.filter((element) => !element.closest("[inert]") && element.getClientRects().length > 0);
|
|
24
|
+
}
|
|
25
|
+
// Focus the first tabbable after `from` in document order, skipping the
|
|
26
|
+
// popup that is closing. Radix portals popups to the end of the document,
|
|
27
|
+
// so plain Tab would leave focus there instead of after the trigger.
|
|
28
|
+
function nextTabbable(from, skip, within = document) {
|
|
29
|
+
if (!from)
|
|
30
|
+
return null;
|
|
31
|
+
const all = tabbables(within).filter((element) => !skip?.contains(element));
|
|
32
|
+
const index = all.indexOf(from);
|
|
33
|
+
return index === -1 ? null : all[index + 1] ?? null;
|
|
34
|
+
}
|
|
35
|
+
// Tab past the last control closes the popup and moves on from the trigger;
|
|
36
|
+
// Shift+Tab before the first closes it and returns to the trigger.
|
|
37
|
+
function boundaryTab(event, content) {
|
|
38
|
+
if (event.key !== "Tab" || !content || !content.contains(event.target))
|
|
39
|
+
return null;
|
|
40
|
+
const focusable = tabbables(content);
|
|
41
|
+
if (!event.shiftKey && document.activeElement === focusable[focusable.length - 1])
|
|
42
|
+
return "forward";
|
|
43
|
+
if (event.shiftKey && document.activeElement === focusable[0])
|
|
44
|
+
return "backward";
|
|
45
|
+
return null;
|
|
46
|
+
}
|
|
47
|
+
const SegmentContext = React.createContext(null);
|
|
48
|
+
function currentName(props) {
|
|
49
|
+
const { value, options, all, currentLabel, status = "ready", labels } = props;
|
|
50
|
+
if (all && value === all.value)
|
|
51
|
+
return all.label;
|
|
52
|
+
const option = options.find((item) => item.value === value);
|
|
53
|
+
if (option)
|
|
54
|
+
return option.label;
|
|
55
|
+
if (currentLabel)
|
|
56
|
+
return currentLabel;
|
|
57
|
+
if (status === "ready" && options.length === 0 && labels?.empty)
|
|
58
|
+
return labels.empty;
|
|
59
|
+
return undefined;
|
|
60
|
+
}
|
|
61
|
+
// Every character outside [A-Za-z0-9-] becomes _<code>_, so two values
|
|
62
|
+
// never share an id, and the -option- prefix keeps clear of the list id.
|
|
63
|
+
function optionId(base, value) {
|
|
64
|
+
return `${base}-option-${value.replace(/[^A-Za-z0-9-]/g, (c) => `_${c.codePointAt(0).toString(16)}_`)}`;
|
|
65
|
+
}
|
|
66
|
+
function matches(option, query) {
|
|
67
|
+
const needle = query.trim().toLocaleLowerCase();
|
|
68
|
+
return !needle
|
|
69
|
+
|| option.label.toLocaleLowerCase().includes(needle)
|
|
70
|
+
|| Boolean(option.description?.toLocaleLowerCase().includes(needle));
|
|
71
|
+
}
|
|
72
|
+
function ScopeSwitcher({ className, children, "aria-label": ariaLabel = "Scope", ...props }) {
|
|
73
|
+
const narrow = useNarrow();
|
|
74
|
+
const [open, setOpen] = React.useState(false);
|
|
75
|
+
const triggerRef = React.useRef(null);
|
|
76
|
+
const levelsRef = React.useRef(null);
|
|
77
|
+
const tabForward = React.useRef(false);
|
|
78
|
+
const tabOutCompact = () => { tabForward.current = true; setOpen(false); };
|
|
79
|
+
const segments = React.Children.toArray(children).filter((child) => React.isValidElement(child) && child.type === ScopeSegment);
|
|
80
|
+
const names = segments.map((segment) => currentName(segment.props) ?? "…");
|
|
81
|
+
const deepest = names[names.length - 1] ?? "";
|
|
82
|
+
if (narrow) {
|
|
83
|
+
return (_jsx("nav", { "data-slot": "scope-switcher", "data-compact": "", "aria-label": ariaLabel, className: cn("scope", className), ...props, children: _jsxs(PopoverPrimitive.Root, { open: open, onOpenChange: setOpen, children: [_jsx(PopoverPrimitive.Trigger, { asChild: true, children: _jsxs(Button, { ref: triggerRef, variant: "ghost", className: "scope-compact", "aria-label": `${ariaLabel}: ${names.join(" / ")}`, children: [_jsx(Layers, { className: "icon icon-sm", "aria-hidden": "true" }), _jsx("span", { className: "scope-name", children: deepest }), _jsx(ChevronDown, { className: "icon icon-sm", "aria-hidden": "true" })] }) }), _jsx(PopoverPrimitive.Portal, { children: _jsx(PopoverPrimitive.Content, { ref: levelsRef, "aria-label": ariaLabel, align: "start", sideOffset: 4, collisionPadding: 16, className: "menu scope-popover kiso-react-floating", onKeyDown: (event) => {
|
|
84
|
+
const edge = boundaryTab(event, levelsRef.current);
|
|
85
|
+
if (!edge)
|
|
86
|
+
return;
|
|
87
|
+
event.preventDefault();
|
|
88
|
+
if (edge === "forward")
|
|
89
|
+
tabOutCompact();
|
|
90
|
+
else
|
|
91
|
+
setOpen(false);
|
|
92
|
+
}, onCloseAutoFocus: (event) => {
|
|
93
|
+
if (!tabForward.current)
|
|
94
|
+
return;
|
|
95
|
+
tabForward.current = false;
|
|
96
|
+
const next = nextTabbable(triggerRef.current, levelsRef.current);
|
|
97
|
+
if (next) {
|
|
98
|
+
event.preventDefault();
|
|
99
|
+
next.focus();
|
|
100
|
+
}
|
|
101
|
+
}, children: _jsx(ScopeContext.Provider, { value: { compact: true, closeCompact: () => setOpen(false), tabOutCompact, levelsRef }, children: _jsx("ol", { className: "scope-levels", children: children }) }) }) })] }) }));
|
|
102
|
+
}
|
|
103
|
+
return (_jsx("nav", { "data-slot": "scope-switcher", "aria-label": ariaLabel, className: cn("scope", className), ...props, children: _jsx(ScopeContext.Provider, { value: { compact: false, closeCompact: () => { }, tabOutCompact: () => { }, levelsRef: null }, children: _jsx("ol", { className: "scope-path", children: segments.map((segment, index) => (_jsxs(React.Fragment, { children: [index > 0 && _jsx("li", { className: "scope-sep", "aria-hidden": "true", children: "/" }), segment] }, segment.key ?? index))) }) }) }));
|
|
104
|
+
}
|
|
105
|
+
function ScopeSegment(props) {
|
|
106
|
+
const { level, value, options, all, searchable = false, status = "ready", onRetry, onValueChange, destinations, labels = {}, className, } = props;
|
|
107
|
+
const { compact, closeCompact, tabOutCompact, levelsRef } = React.useContext(ScopeContext);
|
|
108
|
+
const triggerRef = React.useRef(null);
|
|
109
|
+
const tabForward = React.useRef(false);
|
|
110
|
+
const [open, setOpen] = React.useState(false);
|
|
111
|
+
const [query, setQuery] = React.useState("");
|
|
112
|
+
const [activeValue, setActiveValue] = React.useState(null);
|
|
113
|
+
const base = React.useId();
|
|
114
|
+
const listId = `${base}-list`;
|
|
115
|
+
const statusId = `${base}-status`;
|
|
116
|
+
const contentRef = React.useRef(null);
|
|
117
|
+
const targetRef = React.useRef(null);
|
|
118
|
+
const composing = React.useRef(false);
|
|
119
|
+
const typed = React.useRef({ text: "", at: 0 });
|
|
120
|
+
const leavingCompact = React.useRef(false);
|
|
121
|
+
const listName = labels.list ?? level;
|
|
122
|
+
const name = currentName(props);
|
|
123
|
+
const ready = status === "ready";
|
|
124
|
+
const filtering = searchable && query.trim() !== "";
|
|
125
|
+
const named = ready ? options.filter((option) => matches(option, filtering ? query : "")) : [];
|
|
126
|
+
const showAll = Boolean(all) && ready && options.length > 0 && !filtering;
|
|
127
|
+
// Ungrouped options first, then each group in the order it first appears.
|
|
128
|
+
// Keyboard order follows this rendered order.
|
|
129
|
+
const grouped = [];
|
|
130
|
+
for (const option of named) {
|
|
131
|
+
const bucket = grouped.find((entry) => entry.group === option.group);
|
|
132
|
+
if (bucket)
|
|
133
|
+
bucket.items.push(option);
|
|
134
|
+
else
|
|
135
|
+
grouped.push({ group: option.group, items: [option] });
|
|
136
|
+
}
|
|
137
|
+
grouped.sort((a, b) => Number(a.group !== undefined) - Number(b.group !== undefined));
|
|
138
|
+
const visible = [...(showAll && all ? [all] : []), ...grouped.flatMap((entry) => entry.items)];
|
|
139
|
+
const visibleValues = visible.map((option) => option.value);
|
|
140
|
+
const active = activeValue !== null && visibleValues.includes(activeValue)
|
|
141
|
+
? activeValue
|
|
142
|
+
: value !== undefined && visibleValues.includes(value) ? value : visibleValues[0] ?? null;
|
|
143
|
+
const activeId = active === null ? undefined : optionId(base, active);
|
|
144
|
+
let statusText = "";
|
|
145
|
+
if (status === "loading")
|
|
146
|
+
statusText = labels.loading ?? `Loading ${listName.toLocaleLowerCase()}`;
|
|
147
|
+
else if (status === "error")
|
|
148
|
+
statusText = labels.error ?? `Couldn't load ${listName.toLocaleLowerCase()}.`;
|
|
149
|
+
else if (options.length === 0)
|
|
150
|
+
statusText = labels.empty ?? `No ${listName.toLocaleLowerCase()}.`;
|
|
151
|
+
else if (filtering && named.length === 0)
|
|
152
|
+
statusText = labels.noMatches?.(query.trim()) ?? `No ${listName.toLocaleLowerCase()} match "${query.trim()}"`;
|
|
153
|
+
function changeOpen(next) {
|
|
154
|
+
setOpen(next);
|
|
155
|
+
typed.current = { text: "", at: 0 };
|
|
156
|
+
if (!next) {
|
|
157
|
+
setQuery("");
|
|
158
|
+
setActiveValue(null);
|
|
159
|
+
}
|
|
160
|
+
else
|
|
161
|
+
setActiveValue(value ?? null);
|
|
162
|
+
}
|
|
163
|
+
function focusTarget() {
|
|
164
|
+
targetRef.current?.focus({ preventScroll: true });
|
|
165
|
+
}
|
|
166
|
+
function choose(next) {
|
|
167
|
+
leavingCompact.current = compact;
|
|
168
|
+
changeOpen(false);
|
|
169
|
+
if (next !== value)
|
|
170
|
+
onValueChange(next);
|
|
171
|
+
if (compact)
|
|
172
|
+
closeCompact();
|
|
173
|
+
}
|
|
174
|
+
// Status changes never move focus, but a focused element that disappears
|
|
175
|
+
// (Retry when loading starts) must not drop focus to the page.
|
|
176
|
+
React.useEffect(() => {
|
|
177
|
+
if (!open)
|
|
178
|
+
return;
|
|
179
|
+
const focused = document.activeElement;
|
|
180
|
+
if (!focused || focused === document.body)
|
|
181
|
+
focusTarget();
|
|
182
|
+
}, [open, status, visible.length]);
|
|
183
|
+
React.useEffect(() => {
|
|
184
|
+
if (!open || !activeId)
|
|
185
|
+
return;
|
|
186
|
+
document.getElementById(activeId)?.scrollIntoView({ block: "nearest" });
|
|
187
|
+
}, [open, activeId]);
|
|
188
|
+
function move(step) {
|
|
189
|
+
if (!visible.length)
|
|
190
|
+
return;
|
|
191
|
+
const index = active === null ? -1 : visibleValues.indexOf(active);
|
|
192
|
+
const next = index === -1
|
|
193
|
+
? (step > 0 ? 0 : visible.length - 1)
|
|
194
|
+
: (index + step + visible.length) % visible.length;
|
|
195
|
+
setActiveValue(visibleValues[next]);
|
|
196
|
+
}
|
|
197
|
+
function typeahead(key) {
|
|
198
|
+
const now = Date.now();
|
|
199
|
+
const text = now - typed.current.at > 500 ? key : typed.current.text + key;
|
|
200
|
+
typed.current = { text, at: now };
|
|
201
|
+
const needle = text.toLocaleLowerCase();
|
|
202
|
+
const start = active === null ? 0 : visibleValues.indexOf(active) + (text.length === 1 ? 1 : 0);
|
|
203
|
+
const order = [...visible.slice(start), ...visible.slice(0, start)];
|
|
204
|
+
const found = order.find((option) => option.label.toLocaleLowerCase().startsWith(needle));
|
|
205
|
+
if (found)
|
|
206
|
+
setActiveValue(found.value);
|
|
207
|
+
}
|
|
208
|
+
function onListKeyDown(event, inInput) {
|
|
209
|
+
if (composing.current || event.nativeEvent.isComposing || event.keyCode === 229)
|
|
210
|
+
return;
|
|
211
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
212
|
+
event.preventDefault();
|
|
213
|
+
move(event.key === "ArrowDown" ? 1 : -1);
|
|
214
|
+
}
|
|
215
|
+
else if (!inInput && (event.key === "Home" || event.key === "End")) {
|
|
216
|
+
event.preventDefault();
|
|
217
|
+
if (visible.length)
|
|
218
|
+
setActiveValue(visibleValues[event.key === "Home" ? 0 : visible.length - 1]);
|
|
219
|
+
}
|
|
220
|
+
else if (event.key === "Enter") {
|
|
221
|
+
event.preventDefault();
|
|
222
|
+
if (active !== null)
|
|
223
|
+
choose(active);
|
|
224
|
+
}
|
|
225
|
+
else if (!inInput && event.key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey && event.key !== " ") {
|
|
226
|
+
typeahead(event.key);
|
|
227
|
+
}
|
|
228
|
+
else if (!inInput && event.key === " ") {
|
|
229
|
+
event.preventDefault();
|
|
230
|
+
if (active !== null)
|
|
231
|
+
choose(active);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
function onContentKeyDown(event) {
|
|
235
|
+
const edge = boundaryTab(event, contentRef.current);
|
|
236
|
+
if (!edge)
|
|
237
|
+
return;
|
|
238
|
+
event.preventDefault();
|
|
239
|
+
event.stopPropagation();
|
|
240
|
+
tabForward.current = edge === "forward";
|
|
241
|
+
changeOpen(false);
|
|
242
|
+
}
|
|
243
|
+
function renderOption(option, isAll = false) {
|
|
244
|
+
const id = optionId(base, option.value);
|
|
245
|
+
return (_jsxs("div", { id: id, role: "option", "aria-selected": option.value === value, "data-active": option.value === active ? "" : undefined, "data-all": isAll ? "" : undefined, className: "menu-item scope-option", onPointerMove: () => setActiveValue(option.value), onClick: () => choose(option.value), children: [_jsxs("span", { className: "scope-option-text", children: [_jsx("span", { children: option.label }), option.description && _jsx("span", { className: "scope-option-description", children: option.description })] }), _jsx(Check, { className: "icon icon-sm scope-check", "aria-hidden": "true" })] }, option.value));
|
|
246
|
+
}
|
|
247
|
+
const unknown = name === undefined;
|
|
248
|
+
const trigger = (_jsx(PopoverPrimitive.Trigger, { asChild: true, children: _jsxs(Button, { ref: triggerRef, variant: "ghost", className: "scope-trigger", "aria-label": unknown ? `${level}, ${labels.unknown ?? "loading"}` : `${level} ${name}`, onKeyDown: (event) => {
|
|
249
|
+
if (event.key === "ArrowDown" || event.key === "ArrowUp") {
|
|
250
|
+
event.preventDefault();
|
|
251
|
+
changeOpen(true);
|
|
252
|
+
}
|
|
253
|
+
}, children: [unknown ? _jsx(Skeleton, {}) : _jsx("span", { className: "scope-name", children: name }), _jsx(ChevronDown, { className: "icon icon-sm", "aria-hidden": "true" })] }) }));
|
|
254
|
+
return (_jsx("li", { "data-slot": "scope-segment", className: cn(compact ? "scope-level" : "scope-segment", className), children: _jsxs(PopoverPrimitive.Root, { open: open, onOpenChange: changeOpen, children: [compact && _jsx("span", { className: "scope-level-label", "aria-hidden": "true", children: level }), trigger, _jsx(PopoverPrimitive.Portal, { children: _jsxs(PopoverPrimitive.Content, { ref: contentRef, "data-slot": "scope-segment-content", "aria-label": labels.dialog ?? `Switch ${level.toLocaleLowerCase()}`, align: "start", sideOffset: 4, collisionPadding: 16, className: "menu scope-popover kiso-react-floating", onOpenAutoFocus: (event) => { event.preventDefault(); focusTarget(); }, onCloseAutoFocus: (event) => {
|
|
255
|
+
// A choice made from the compact popup returns focus to the
|
|
256
|
+
// compact trigger, which the outer popover handles.
|
|
257
|
+
if (leavingCompact.current) {
|
|
258
|
+
event.preventDefault();
|
|
259
|
+
leavingCompact.current = false;
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
if (!tabForward.current)
|
|
263
|
+
return;
|
|
264
|
+
tabForward.current = false;
|
|
265
|
+
event.preventDefault();
|
|
266
|
+
// Inside the compact popup, move on to the next level, and
|
|
267
|
+
// past the last one leave the compact popup too.
|
|
268
|
+
const within = compact && levelsRef?.current ? levelsRef.current : document;
|
|
269
|
+
const next = nextTabbable(triggerRef.current, contentRef.current, within);
|
|
270
|
+
if (next)
|
|
271
|
+
next.focus();
|
|
272
|
+
else if (compact) {
|
|
273
|
+
triggerRef.current?.focus();
|
|
274
|
+
tabOutCompact();
|
|
275
|
+
}
|
|
276
|
+
else
|
|
277
|
+
triggerRef.current?.focus();
|
|
278
|
+
}, onEscapeKeyDown: (event) => {
|
|
279
|
+
if (composing.current || event.isComposing || event.keyCode === 229)
|
|
280
|
+
event.preventDefault();
|
|
281
|
+
}, onKeyDown: onContentKeyDown, children: [searchable && (_jsxs("div", { className: "scope-filter", children: [_jsx(Search, { className: "icon icon-sm muted", "aria-hidden": "true" }), _jsx("input", { ref: (element) => { targetRef.current = element; }, role: "combobox", "aria-label": labels.filter ?? `Filter ${listName.toLocaleLowerCase()}`, "aria-expanded": "true", "aria-controls": listId, "aria-autocomplete": "list", "aria-activedescendant": activeId, "aria-describedby": statusText ? statusId : undefined, autoComplete: "off", spellCheck: false, placeholder: labels.filter ?? `Filter ${listName.toLocaleLowerCase()}`, value: query, onChange: (event) => { setQuery(event.target.value); setActiveValue(null); }, onKeyDown: (event) => onListKeyDown(event, true), onCompositionStart: () => { composing.current = true; }, onCompositionEnd: () => { composing.current = false; } })] })), _jsxs("div", { id: listId, ref: searchable ? undefined : (element) => { targetRef.current = element; }, role: "listbox", "aria-label": listName, "aria-busy": status === "loading" || undefined, "aria-activedescendant": searchable ? undefined : activeId, "aria-describedby": !searchable && statusText ? statusId : undefined, tabIndex: searchable ? -1 : 0, className: "scope-list", onKeyDown: searchable ? undefined : (event) => onListKeyDown(event, false), children: [showAll && all && renderOption(all, true), grouped.map((entry, index) => entry.group === undefined
|
|
282
|
+
? entry.items.map((option) => renderOption(option))
|
|
283
|
+
: (_jsxs("div", { role: "group", "aria-labelledby": `${base}-g${index}`, className: "scope-group", children: [_jsx("div", { id: `${base}-g${index}`, role: "presentation", className: "scope-group-label t-caps", children: entry.group }), entry.items.map((option) => renderOption(option))] }, `group-${index}`)))] }), _jsxs("div", { id: statusId, role: "status", className: "scope-status", "data-tone": status === "error" ? "danger" : undefined, children: [status === "loading" && _jsx(Spinner, { size: "sm" }), statusText] }), status === "error" && onRetry && (_jsx(Button, { size: "sm", className: "scope-retry", onClick: () => { focusTarget(); onRetry(); }, children: labels.retry ?? "Retry" })), destinations && (_jsx(SegmentContext.Provider, { value: { close: () => { leavingCompact.current = compact; changeOpen(false); if (compact)
|
|
284
|
+
closeCompact(); } }, children: _jsx("div", { className: "scope-destinations", children: destinations }) }))] }) })] }) }));
|
|
285
|
+
}
|
|
286
|
+
// A page about the level, such as "Manage projects". A real link, so
|
|
287
|
+
// open-in-new-tab works; asChild takes a router link.
|
|
288
|
+
function ScopeDestination({ className, asChild = false, onClick, ...props }) {
|
|
289
|
+
const segment = React.useContext(SegmentContext);
|
|
290
|
+
const Comp = asChild ? Slot.Root : "a";
|
|
291
|
+
return (_jsx(Comp, { "data-slot": "scope-destination", className: cn("menu-item scope-destination", className), onClick: (event) => {
|
|
292
|
+
onClick?.(event);
|
|
293
|
+
if (!event.defaultPrevented && !event.metaKey && !event.ctrlKey && !event.shiftKey && event.button === 0)
|
|
294
|
+
segment?.close();
|
|
295
|
+
}, ...props }));
|
|
296
|
+
}
|
|
297
|
+
export { ScopeSwitcher, ScopeSegment, ScopeDestination };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { TimeRangeControlLabels } from "./time-range-shared.js";
|
|
3
|
+
/** A month grid that picks one day between `min` and `max`, opened from an icon button. */
|
|
4
|
+
export declare function RangeCalendar({ day, min, max, locale, label, text, onPick }: {
|
|
5
|
+
day: string;
|
|
6
|
+
min: string;
|
|
7
|
+
max: string;
|
|
8
|
+
locale: string | undefined;
|
|
9
|
+
label: string;
|
|
10
|
+
text: TimeRangeControlLabels;
|
|
11
|
+
onPick: (day: string) => void;
|
|
12
|
+
}): React.JSX.Element;
|