@bigpixelrocket/uiok 0.0.0-stage → 0.1.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 +42 -0
- package/LICENSE +21 -0
- package/NOTICE +569 -0
- package/README.md +44 -2
- package/dist/VisuallyHidden.d.ts +13 -0
- package/dist/VisuallyHidden.js +13 -0
- package/dist/activity/ActivityBar.d.ts +29 -0
- package/dist/activity/ActivityBar.js +21 -0
- package/dist/activity/activity.css +43 -0
- package/dist/activity/index.d.ts +2 -0
- package/dist/activity/index.js +2 -0
- package/dist/button/Button.d.ts +26 -0
- package/dist/button/Button.js +14 -0
- package/dist/button/IconButton.d.ts +18 -0
- package/dist/button/IconButton.js +14 -0
- package/dist/button/button.css +95 -0
- package/dist/button/index.d.ts +3 -0
- package/dist/button/index.js +3 -0
- package/dist/charts/Drawing.d.ts +27 -0
- package/dist/charts/Drawing.js +117 -0
- package/dist/charts/Drawing.logic.d.ts +2 -0
- package/dist/charts/Drawing.logic.js +22 -0
- package/dist/charts/Line.logic.d.ts +33 -0
- package/dist/charts/Line.logic.js +72 -0
- package/dist/charts/LineChart.d.ts +34 -0
- package/dist/charts/LineChart.js +100 -0
- package/dist/charts/Pie.logic.d.ts +16 -0
- package/dist/charts/Pie.logic.js +28 -0
- package/dist/charts/PieChart.d.ts +20 -0
- package/dist/charts/PieChart.js +16 -0
- package/dist/charts/ResultChart.d.ts +47 -0
- package/dist/charts/ResultChart.js +175 -0
- package/dist/charts/ResultChart.logic.d.ts +42 -0
- package/dist/charts/ResultChart.logic.js +165 -0
- package/dist/charts/Scatter.logic.d.ts +55 -0
- package/dist/charts/Scatter.logic.js +134 -0
- package/dist/charts/ScatterChart.d.ts +36 -0
- package/dist/charts/ScatterChart.js +99 -0
- package/dist/charts/charts.css +310 -0
- package/dist/charts/index.d.ts +14 -0
- package/dist/charts/index.js +11 -0
- package/dist/charts/seriesColour.d.ts +2 -0
- package/dist/charts/seriesColour.js +8 -0
- package/dist/clock/index.d.ts +2 -0
- package/dist/clock/index.js +2 -0
- package/dist/clock/useClock.d.ts +14 -0
- package/dist/clock/useClock.js +57 -0
- package/dist/datetime/DateTimePicker.d.ts +50 -0
- package/dist/datetime/DateTimePicker.js +98 -0
- package/dist/datetime/DateTimePicker.logic.d.ts +59 -0
- package/dist/datetime/DateTimePicker.logic.js +103 -0
- package/dist/datetime/datetime.css +115 -0
- package/dist/datetime/index.d.ts +7 -0
- package/dist/datetime/index.js +7 -0
- package/dist/dialog/ConfirmDialog.d.ts +73 -0
- package/dist/dialog/ConfirmDialog.js +30 -0
- package/dist/dialog/DialogLegend.d.ts +21 -0
- package/dist/dialog/DialogLegend.js +28 -0
- package/dist/dialog/DialogLegend.logic.d.ts +145 -0
- package/dist/dialog/DialogLegend.logic.js +71 -0
- package/dist/dialog/ModalDialog.d.ts +101 -0
- package/dist/dialog/ModalDialog.js +184 -0
- package/dist/dialog/dialog.css +283 -0
- package/dist/dialog/index.d.ts +8 -0
- package/dist/dialog/index.js +8 -0
- package/dist/filter/FilterEscape.d.ts +16 -0
- package/dist/filter/FilterEscape.js +15 -0
- package/dist/filter/FilterIcon.d.ts +8 -0
- package/dist/filter/FilterIcon.js +11 -0
- package/dist/filter/filter.css +42 -0
- package/dist/filter/index.d.ts +3 -0
- package/dist/filter/index.js +3 -0
- package/dist/grid/DataGrid.d.ts +149 -0
- package/dist/grid/DataGrid.js +373 -0
- package/dist/grid/DataGrid.logic.d.ts +57 -0
- package/dist/grid/DataGrid.logic.js +121 -0
- package/dist/grid/grid.css +206 -0
- package/dist/grid/index.d.ts +7 -0
- package/dist/grid/index.js +7 -0
- package/dist/index.d.ts +32 -0
- package/dist/index.js +32 -0
- package/dist/keyboard/BrowserKeys.d.ts +15 -0
- package/dist/keyboard/BrowserKeys.js +28 -0
- package/dist/keyboard/KeyChord.logic.d.ts +25 -0
- package/dist/keyboard/KeyChord.logic.js +50 -0
- package/dist/keyboard/Keyboard.logic.d.ts +84 -0
- package/dist/keyboard/Keyboard.logic.js +137 -0
- package/dist/keyboard/OverlayWatch.d.ts +28 -0
- package/dist/keyboard/OverlayWatch.js +119 -0
- package/dist/keyboard/PageSelectAll.d.ts +14 -0
- package/dist/keyboard/PageSelectAll.js +22 -0
- package/dist/keyboard/index.d.ts +9 -0
- package/dist/keyboard/index.js +9 -0
- package/dist/keychord/KeyChord.d.ts +16 -0
- package/dist/keychord/KeyChord.js +55 -0
- package/dist/keychord/index.d.ts +2 -0
- package/dist/keychord/index.js +2 -0
- package/dist/keychord/keychord.css +41 -0
- package/dist/labels/UiokLabels.d.ts +41 -0
- package/dist/labels/UiokLabels.js +31 -0
- package/dist/labels/UiokProvider.d.ts +44 -0
- package/dist/labels/UiokProvider.js +54 -0
- package/dist/labels/charts.d.ts +34 -0
- package/dist/labels/charts.js +15 -0
- package/dist/labels/dateTime.d.ts +32 -0
- package/dist/labels/dateTime.js +14 -0
- package/dist/labels/dialog.d.ts +18 -0
- package/dist/labels/dialog.js +6 -0
- package/dist/labels/index.d.ts +13 -0
- package/dist/labels/index.js +13 -0
- package/dist/labels/keys.d.ts +28 -0
- package/dist/labels/keys.js +53 -0
- package/dist/labels/legend.d.ts +21 -0
- package/dist/labels/legend.js +7 -0
- package/dist/labels/listing.d.ts +16 -0
- package/dist/labels/listing.js +8 -0
- package/dist/labels/pager.d.ts +32 -0
- package/dist/labels/pager.js +20 -0
- package/dist/labels/palette.d.ts +17 -0
- package/dist/labels/palette.js +6 -0
- package/dist/labels/selectAll.d.ts +15 -0
- package/dist/labels/selectAll.js +6 -0
- package/dist/labels/terminal.d.ts +25 -0
- package/dist/labels/terminal.js +9 -0
- package/dist/legend/KeyLegend.logic.d.ts +84 -0
- package/dist/legend/KeyLegend.logic.js +109 -0
- package/dist/legend/KeyLegendStrip.d.ts +36 -0
- package/dist/legend/KeyLegendStrip.js +82 -0
- package/dist/legend/index.d.ts +3 -0
- package/dist/legend/index.js +3 -0
- package/dist/legend/legend.css +148 -0
- package/dist/listing/CurrentDot.d.ts +15 -0
- package/dist/listing/CurrentDot.js +13 -0
- package/dist/listing/Listing.d.ts +230 -0
- package/dist/listing/Listing.js +265 -0
- package/dist/listing/PathParts.logic.d.ts +17 -0
- package/dist/listing/PathParts.logic.js +18 -0
- package/dist/listing/index.d.ts +10 -0
- package/dist/listing/index.js +10 -0
- package/dist/listing/listing.css +867 -0
- package/dist/menu/MenuQuery.logic.d.ts +69 -0
- package/dist/menu/MenuQuery.logic.js +75 -0
- package/dist/menu/fuzzyMatch.d.ts +31 -0
- package/dist/menu/fuzzyMatch.js +296 -0
- package/dist/menu/index.d.ts +9 -0
- package/dist/menu/index.js +9 -0
- package/dist/menu/menu.css +203 -0
- package/dist/menu/useBellBeat.d.ts +8 -0
- package/dist/menu/useBellBeat.js +26 -0
- package/dist/namecut/NameCut.d.ts +22 -0
- package/dist/namecut/NameCut.js +28 -0
- package/dist/namecut/NameCut.logic.d.ts +51 -0
- package/dist/namecut/NameCut.logic.js +120 -0
- package/dist/namecut/index.d.ts +3 -0
- package/dist/namecut/index.js +3 -0
- package/dist/namecut/namecut.css +67 -0
- package/dist/pager/Pager.d.ts +37 -0
- package/dist/pager/Pager.js +38 -0
- package/dist/pager/Pager.logic.d.ts +13 -0
- package/dist/pager/Pager.logic.js +63 -0
- package/dist/pager/index.d.ts +7 -0
- package/dist/pager/index.js +7 -0
- package/dist/pager/pager.css +62 -0
- package/dist/palette/Palette.d.ts +79 -0
- package/dist/palette/Palette.js +60 -0
- package/dist/palette/index.d.ts +6 -0
- package/dist/palette/index.js +6 -0
- package/dist/palette/palette.css +159 -0
- package/dist/pane/PaneActions.d.ts +104 -0
- package/dist/pane/PaneActions.js +62 -0
- package/dist/pane/PaneFrame.d.ts +51 -0
- package/dist/pane/PaneFrame.js +28 -0
- package/dist/pane/PaneKeys.d.ts +41 -0
- package/dist/pane/PaneKeys.js +104 -0
- package/dist/pane/PaneKeys.logic.d.ts +95 -0
- package/dist/pane/PaneKeys.logic.js +109 -0
- package/dist/pane/index.d.ts +11 -0
- package/dist/pane/index.js +11 -0
- package/dist/pane/usePaneKeys.d.ts +141 -0
- package/dist/pane/usePaneKeys.js +313 -0
- package/dist/run/RunHeader.d.ts +50 -0
- package/dist/run/RunHeader.js +31 -0
- package/dist/run/RunProgress.logic.d.ts +29 -0
- package/dist/run/RunProgress.logic.js +34 -0
- package/dist/run/index.d.ts +3 -0
- package/dist/run/index.js +3 -0
- package/dist/run/run.css +190 -0
- package/dist/segmented/SegmentedChoice.d.ts +22 -0
- package/dist/segmented/SegmentedChoice.js +31 -0
- package/dist/segmented/index.d.ts +2 -0
- package/dist/segmented/index.js +2 -0
- package/dist/segmented/segmented.css +49 -0
- package/dist/selectall/CheckRange.logic.d.ts +8 -0
- package/dist/selectall/CheckRange.logic.js +23 -0
- package/dist/selectall/SelectAllBar.d.ts +25 -0
- package/dist/selectall/SelectAllBar.js +24 -0
- package/dist/selectall/index.d.ts +7 -0
- package/dist/selectall/index.js +7 -0
- package/dist/selectall/selectall.css +31 -0
- package/dist/store/KeepUnchanged.logic.d.ts +19 -0
- package/dist/store/KeepUnchanged.logic.js +33 -0
- package/dist/store/SameProps.d.ts +15 -0
- package/dist/store/SameProps.js +46 -0
- package/dist/store/ValueStore.d.ts +17 -0
- package/dist/store/ValueStore.js +23 -0
- package/dist/store/index.d.ts +8 -0
- package/dist/store/index.js +8 -0
- package/dist/store/useStableHandlers.d.ts +13 -0
- package/dist/store/useStableHandlers.js +22 -0
- package/dist/styles.css +85 -0
- package/dist/tabs/PageTabs.d.ts +38 -0
- package/dist/tabs/PageTabs.js +33 -0
- package/dist/tabs/index.d.ts +2 -0
- package/dist/tabs/index.js +2 -0
- package/dist/tabs/tabs.css +64 -0
- package/dist/terminal/Terminal.d.ts +104 -0
- package/dist/terminal/Terminal.js +309 -0
- package/dist/terminal/Terminal.logic.d.ts +66 -0
- package/dist/terminal/Terminal.logic.js +156 -0
- package/dist/terminal/TerminalMenu.d.ts +36 -0
- package/dist/terminal/TerminalMenu.js +87 -0
- package/dist/terminal/TerminalMenu.logic.d.ts +78 -0
- package/dist/terminal/TerminalMenu.logic.js +68 -0
- package/dist/terminal/TerminalScrollback.d.ts +10 -0
- package/dist/terminal/TerminalScrollback.js +11 -0
- package/dist/terminal/ghostty/LICENSE +21 -0
- package/dist/terminal/ghostty/core.d.ts +315 -0
- package/dist/terminal/ghostty/core.js +1189 -0
- package/dist/terminal/ghostty/fallbackColors.d.ts +12 -0
- package/dist/terminal/ghostty/fallbackColors.js +23 -0
- package/dist/terminal/ghostty/fonts/LICENSE +21 -0
- package/dist/terminal/ghostty/fonts/SymbolsNerdFontMono-Regular.woff2 +0 -0
- package/dist/terminal/ghostty/keyCodes.logic.d.ts +20 -0
- package/dist/terminal/ghostty/keyCodes.logic.js +249 -0
- package/dist/terminal/ghostty/links.logic.d.ts +39 -0
- package/dist/terminal/ghostty/links.logic.js +84 -0
- package/dist/terminal/ghostty/renderer.d.ts +98 -0
- package/dist/terminal/ghostty/renderer.js +481 -0
- package/dist/terminal/ghostty/runtime.d.ts +126 -0
- package/dist/terminal/ghostty/runtime.js +346 -0
- package/dist/terminal/ghostty/spriteGlyphs.logic.d.ts +64 -0
- package/dist/terminal/ghostty/spriteGlyphs.logic.js +546 -0
- package/dist/terminal/ghostty/surface.d.ts +285 -0
- package/dist/terminal/ghostty/surface.js +1565 -0
- package/dist/terminal/ghostty/surface.logic.d.ts +181 -0
- package/dist/terminal/ghostty/surface.logic.js +392 -0
- package/dist/terminal/ghostty/vendor/LICENSE +21 -0
- package/dist/terminal/ghostty/vendor/ghostty-effects.wasm +0 -0
- package/dist/terminal/ghostty/vendor/ghostty-vt.wasm +0 -0
- package/dist/terminal/index.d.ts +12 -0
- package/dist/terminal/index.js +12 -0
- package/dist/terminal/terminal.css +169 -0
- package/dist/text/MarkedText.d.ts +14 -0
- package/dist/text/MarkedText.js +11 -0
- package/dist/text/highlightSegments.d.ts +13 -0
- package/dist/text/highlightSegments.js +29 -0
- package/dist/text/index.d.ts +3 -0
- package/dist/text/index.js +3 -0
- package/dist/text/text.css +11 -0
- package/dist/themes/attributes.d.ts +21 -0
- package/dist/themes/attributes.js +41 -0
- package/dist/themes/catalog.d.ts +125 -0
- package/dist/themes/catalog.js +940 -0
- package/dist/themes/color.d.ts +29 -0
- package/dist/themes/color.js +52 -0
- package/dist/themes/ids.d.ts +139 -0
- package/dist/themes/ids.js +59 -0
- package/dist/themes/index.d.ts +12 -0
- package/dist/themes/index.js +12 -0
- package/dist/themes/themes.generated.css +1830 -0
- package/dist/themes/tokens.d.ts +189 -0
- package/dist/themes/tokens.js +462 -0
- package/dist/tooltip/Tooltip.d.ts +21 -0
- package/dist/tooltip/Tooltip.js +105 -0
- package/dist/tooltip/Tooltip.logic.d.ts +49 -0
- package/dist/tooltip/Tooltip.logic.js +50 -0
- package/dist/tooltip/index.d.ts +3 -0
- package/dist/tooltip/index.js +3 -0
- package/dist/tooltip/tooltip.css +45 -0
- package/package.json +91 -4
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode } from 'react';
|
|
2
|
+
/** Props for {@link SegmentedChoice}, over the type of its choices. */
|
|
3
|
+
export interface SegmentedChoiceProps<T extends string | number | null> {
|
|
4
|
+
/** The id of the element that names the group, for `aria-labelledby`. */
|
|
5
|
+
readonly labelId: string;
|
|
6
|
+
/** Every choice, in the order the segments are drawn; each must be distinct. */
|
|
7
|
+
readonly choices: readonly T[];
|
|
8
|
+
/** The chosen one, which must be among `choices`. */
|
|
9
|
+
readonly value: T;
|
|
10
|
+
/** Called with the new choice; never for the one already chosen. */
|
|
11
|
+
readonly onChange: (value: T) => void;
|
|
12
|
+
/** What a segment shows for a choice: its words, an icon, or both. */
|
|
13
|
+
readonly render: (choice: T) => ReactNode;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* One choice of several, drawn as a segmented control and announced as a
|
|
17
|
+
* radio group: one Tab stop (the checked segment), and the arrow keys move
|
|
18
|
+
* the choice, wrapping at the ends, with the focus following it. Its look is
|
|
19
|
+
* its own (`.segmented-choice` in `@bigpixelrocket/uiok/styles.css`), so it draws the same
|
|
20
|
+
* in a dialog and on a page.
|
|
21
|
+
*/
|
|
22
|
+
export declare function SegmentedChoice<T extends string | number | null>({ labelId, choices, value, onChange, render }: SegmentedChoiceProps<T>): ReactElement;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useRef } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* One choice of several, drawn as a segmented control and announced as a
|
|
5
|
+
* radio group: one Tab stop (the checked segment), and the arrow keys move
|
|
6
|
+
* the choice, wrapping at the ends, with the focus following it. Its look is
|
|
7
|
+
* its own (`.segmented-choice` in `@bigpixelrocket/uiok/styles.css`), so it draws the same
|
|
8
|
+
* in a dialog and on a page.
|
|
9
|
+
*/
|
|
10
|
+
export function SegmentedChoice({ labelId, choices, value, onChange, render }) {
|
|
11
|
+
const group = useRef(null);
|
|
12
|
+
const step = (event, delta) => {
|
|
13
|
+
event.preventDefault();
|
|
14
|
+
const index = (choices.indexOf(value) + delta + choices.length) % choices.length;
|
|
15
|
+
onChange(choices[index]);
|
|
16
|
+
group.current?.querySelectorAll('[role="radio"]')[index]?.focus();
|
|
17
|
+
};
|
|
18
|
+
return (_jsx("div", { "aria-labelledby": labelId, className: "segmented-choice", onKeyDown: (event) => {
|
|
19
|
+
if (event.key === 'ArrowRight' || event.key === 'ArrowDown') {
|
|
20
|
+
step(event, 1);
|
|
21
|
+
}
|
|
22
|
+
else if (event.key === 'ArrowLeft' || event.key === 'ArrowUp') {
|
|
23
|
+
step(event, -1);
|
|
24
|
+
}
|
|
25
|
+
}, ref: group, role: "radiogroup", children: choices.map((choice) => (_jsx("button", { "aria-checked": choice === value, className: "segmented-choice-option", onClick: () => {
|
|
26
|
+
// The chosen segment again changes nothing, so it reads nothing.
|
|
27
|
+
if (choice !== value) {
|
|
28
|
+
onChange(choice);
|
|
29
|
+
}
|
|
30
|
+
}, role: "radio", tabIndex: choice === value ? 0 : -1, type: "button", children: render(choice) }, String(choice)))) }));
|
|
31
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/* ---- Segmented choice (SegmentedChoice) ----
|
|
2
|
+
|
|
3
|
+
One choice of several: a tinted track with the chosen segment raised, each
|
|
4
|
+
segment as wide as its words. It carries its whole look, so it draws the
|
|
5
|
+
same in a dialog and on a page. */
|
|
6
|
+
.segmented-choice {
|
|
7
|
+
box-sizing: border-box;
|
|
8
|
+
display: inline-flex;
|
|
9
|
+
flex: none;
|
|
10
|
+
gap: 2px;
|
|
11
|
+
margin: 0;
|
|
12
|
+
padding: 2px;
|
|
13
|
+
border-radius: 7px;
|
|
14
|
+
background: color-mix(in srgb, var(--text) 7%, transparent);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.segmented-choice-option {
|
|
18
|
+
box-sizing: border-box;
|
|
19
|
+
flex: none;
|
|
20
|
+
height: 22px;
|
|
21
|
+
padding: 0 12px;
|
|
22
|
+
border: none;
|
|
23
|
+
border-radius: 5px;
|
|
24
|
+
background: transparent;
|
|
25
|
+
color: var(--text-dim);
|
|
26
|
+
font-family: var(--font-ui);
|
|
27
|
+
font-size: 11.5px;
|
|
28
|
+
white-space: nowrap;
|
|
29
|
+
cursor: pointer;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
.segmented-choice-option:hover:enabled:not([aria-disabled='true']) {
|
|
33
|
+
color: var(--text);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.segmented-choice-option[aria-checked='true'] {
|
|
37
|
+
background: linear-gradient(var(--hover-wash), transparent), var(--surface);
|
|
38
|
+
box-shadow:
|
|
39
|
+
inset 0 1px 0 var(--glass-edge),
|
|
40
|
+
0 0 0 0.5px var(--border-strong),
|
|
41
|
+
var(--shadow-segment);
|
|
42
|
+
color: var(--text);
|
|
43
|
+
font-weight: 600;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.segmented-choice-option:focus-visible {
|
|
47
|
+
outline: 2px solid var(--accent);
|
|
48
|
+
outline-offset: -2px;
|
|
49
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a click on a row's checkbox leaves checked: a plain click turns its
|
|
3
|
+
* row alone; a Shift-click turns every row from the one clicked last
|
|
4
|
+
* (`anchor`) to this one, in the list's `order`, to the state the clicked row
|
|
5
|
+
* takes. A Shift-click with no anchor, or one the list no longer shows, turns
|
|
6
|
+
* the row alone.
|
|
7
|
+
*/
|
|
8
|
+
export declare function checkedAfterClick<K>(checked: ReadonlySet<K>, order: readonly K[], anchor: K | null, clicked: K, shift: boolean): Set<K>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What a click on a row's checkbox leaves checked: a plain click turns its
|
|
3
|
+
* row alone; a Shift-click turns every row from the one clicked last
|
|
4
|
+
* (`anchor`) to this one, in the list's `order`, to the state the clicked row
|
|
5
|
+
* takes. A Shift-click with no anchor, or one the list no longer shows, turns
|
|
6
|
+
* the row alone.
|
|
7
|
+
*/
|
|
8
|
+
export function checkedAfterClick(checked, order, anchor, clicked, shift) {
|
|
9
|
+
const next = new Set(checked);
|
|
10
|
+
const on = !checked.has(clicked);
|
|
11
|
+
const from = anchor === null ? -1 : order.indexOf(anchor);
|
|
12
|
+
const to = order.indexOf(clicked);
|
|
13
|
+
const range = shift && from >= 0 && to >= 0
|
|
14
|
+
? order.slice(Math.min(from, to), Math.max(from, to) + 1)
|
|
15
|
+
: [clicked];
|
|
16
|
+
for (const key of range) {
|
|
17
|
+
if (on)
|
|
18
|
+
next.add(key);
|
|
19
|
+
else
|
|
20
|
+
next.delete(key);
|
|
21
|
+
}
|
|
22
|
+
return next;
|
|
23
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode } from 'react';
|
|
2
|
+
/** Props for {@link SelectAllBar}. */
|
|
3
|
+
export interface SelectAllBarProps {
|
|
4
|
+
/** The toolbar's accessible name; the `selectAll` label's "With selected" unless given. */
|
|
5
|
+
readonly label?: string;
|
|
6
|
+
/** How many rows the list offers to check. */
|
|
7
|
+
readonly total: number;
|
|
8
|
+
/** How many of those are checked. */
|
|
9
|
+
readonly checked: number;
|
|
10
|
+
/** Checks every offered row (true), or clears them all (false). */
|
|
11
|
+
readonly onCheckAll: (on: boolean) => void;
|
|
12
|
+
/** The bulk actions after "With selected:". */
|
|
13
|
+
readonly children: ReactNode;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* The select-all footer of a list whose rows have checkboxes: Check all,
|
|
17
|
+
* which checks or clears every row the list offers (its filter's
|
|
18
|
+
* survivors, never a row it disables), then "With selected:" and the
|
|
19
|
+
* list's bulk actions. The checkbox is ticked when every row is, ticked
|
|
20
|
+
* and mixed when some are, and clear when none are, and follows each row's
|
|
21
|
+
* change. A list with no row to check draws it disabled. Its words come
|
|
22
|
+
* from the `selectAll` labels; pair it with `checkedAfterClick` for the
|
|
23
|
+
* rows' own Shift-click ranges.
|
|
24
|
+
*/
|
|
25
|
+
export declare function SelectAllBar({ label, total, checked, onCheckAll, children }: SelectAllBarProps): ReactElement;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef } from 'react';
|
|
3
|
+
import { useLabels } from '../labels/UiokProvider.js';
|
|
4
|
+
/**
|
|
5
|
+
* The select-all footer of a list whose rows have checkboxes: Check all,
|
|
6
|
+
* which checks or clears every row the list offers (its filter's
|
|
7
|
+
* survivors, never a row it disables), then "With selected:" and the
|
|
8
|
+
* list's bulk actions. The checkbox is ticked when every row is, ticked
|
|
9
|
+
* and mixed when some are, and clear when none are, and follows each row's
|
|
10
|
+
* change. A list with no row to check draws it disabled. Its words come
|
|
11
|
+
* from the `selectAll` labels; pair it with `checkedAfterClick` for the
|
|
12
|
+
* rows' own Shift-click ranges.
|
|
13
|
+
*/
|
|
14
|
+
export function SelectAllBar({ label, total, checked, onCheckAll, children }) {
|
|
15
|
+
const labels = useLabels().selectAll;
|
|
16
|
+
const box = useRef(null);
|
|
17
|
+
const all = total > 0 && checked >= total;
|
|
18
|
+
const some = checked > 0 && !all;
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (box.current !== null)
|
|
21
|
+
box.current.indeterminate = some;
|
|
22
|
+
}, [some]);
|
|
23
|
+
return (_jsxs("div", { "aria-label": label ?? labels.label, className: "select-all-bar", role: "toolbar", children: [_jsxs("label", { className: "select-all-check", children: [_jsx("input", { checked: all || some, disabled: total === 0, onChange: () => onCheckAll(!all), ref: box, type: "checkbox" }), labels.checkAll] }), _jsx("span", { className: "select-all-with", children: labels.withSelected }), children] }));
|
|
24
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `SelectAllBar`: the Check all footer of a list with row checkboxes and
|
|
3
|
+
* its bulk actions; plus `checkedAfterClick`, the Shift-click range rule
|
|
4
|
+
* for the rows themselves.
|
|
5
|
+
*/
|
|
6
|
+
export { checkedAfterClick } from './CheckRange.logic.js';
|
|
7
|
+
export { SelectAllBar, type SelectAllBarProps } from './SelectAllBar.js';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `SelectAllBar`: the Check all footer of a list with row checkboxes and
|
|
3
|
+
* its bulk actions; plus `checkedAfterClick`, the Shift-click range rule
|
|
4
|
+
* for the rows themselves.
|
|
5
|
+
*/
|
|
6
|
+
export { checkedAfterClick } from './CheckRange.logic.js';
|
|
7
|
+
export { SelectAllBar } from './SelectAllBar.js';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/* ---- Select-all bar (SelectAllBar) ----
|
|
2
|
+
|
|
3
|
+
Check all, then "With selected:" in italics and the bulk actions, on one
|
|
4
|
+
wrapping row. */
|
|
5
|
+
.select-all-bar {
|
|
6
|
+
display: flex;
|
|
7
|
+
flex-wrap: wrap;
|
|
8
|
+
align-items: center;
|
|
9
|
+
gap: 6px 10px;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.select-all-check {
|
|
13
|
+
display: inline-flex;
|
|
14
|
+
gap: 7px;
|
|
15
|
+
align-items: center;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.select-all-check input {
|
|
19
|
+
margin: 0;
|
|
20
|
+
accent-color: var(--accent);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.select-all-check input:focus-visible {
|
|
24
|
+
outline: 2px solid var(--accent);
|
|
25
|
+
outline-offset: 1px;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.select-all-with {
|
|
29
|
+
color: var(--text-dim);
|
|
30
|
+
font-style: italic;
|
|
31
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `next` with each item that holds the same data (`sameData`) as the item
|
|
3
|
+
* of the same id in `previous` replaced by that earlier object, and
|
|
4
|
+
* `previous` itself when every item is kept in the same order. A snapshot
|
|
5
|
+
* that arrives from a server or another process is all fresh objects;
|
|
6
|
+
* keeping the unchanged ones lets memoized rows, and memos keyed by them,
|
|
7
|
+
* skip an update that did not touch them.
|
|
8
|
+
*/
|
|
9
|
+
export declare function keepUnchangedById<Item extends {
|
|
10
|
+
readonly id: string;
|
|
11
|
+
}>(previous: readonly Item[] | null, next: readonly Item[]): readonly Item[];
|
|
12
|
+
/**
|
|
13
|
+
* `keepUnchangedById` for items known by another field (`idOf`): a list
|
|
14
|
+
* built afresh from what the page holds, such as a tree's rows, keeps each
|
|
15
|
+
* row a rebuild left alike. `alike` says when an earlier
|
|
16
|
+
* item may stand for the new one: the same data by default, or a looser
|
|
17
|
+
* test for a list that draws only part of what its items hold.
|
|
18
|
+
*/
|
|
19
|
+
export declare function keepUnchangedBy<Item>(previous: readonly Item[] | null, next: readonly Item[], idOf: (item: Item) => string, alike?: (earlier: Item, item: Item) => boolean): readonly Item[];
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { sameData } from './SameProps.js';
|
|
2
|
+
/**
|
|
3
|
+
* `next` with each item that holds the same data (`sameData`) as the item
|
|
4
|
+
* of the same id in `previous` replaced by that earlier object, and
|
|
5
|
+
* `previous` itself when every item is kept in the same order. A snapshot
|
|
6
|
+
* that arrives from a server or another process is all fresh objects;
|
|
7
|
+
* keeping the unchanged ones lets memoized rows, and memos keyed by them,
|
|
8
|
+
* skip an update that did not touch them.
|
|
9
|
+
*/
|
|
10
|
+
export function keepUnchangedById(previous, next) {
|
|
11
|
+
return keepUnchangedBy(previous, next, (item) => item.id);
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* `keepUnchangedById` for items known by another field (`idOf`): a list
|
|
15
|
+
* built afresh from what the page holds, such as a tree's rows, keeps each
|
|
16
|
+
* row a rebuild left alike. `alike` says when an earlier
|
|
17
|
+
* item may stand for the new one: the same data by default, or a looser
|
|
18
|
+
* test for a list that draws only part of what its items hold.
|
|
19
|
+
*/
|
|
20
|
+
export function keepUnchangedBy(previous, next, idOf, alike = sameData) {
|
|
21
|
+
if (previous === null || previous.length === 0)
|
|
22
|
+
return next;
|
|
23
|
+
const before = new Map(previous.map((item) => [idOf(item), item]));
|
|
24
|
+
let whole = previous.length === next.length;
|
|
25
|
+
const kept = next.map((item, index) => {
|
|
26
|
+
const earlier = before.get(idOf(item));
|
|
27
|
+
const keep = earlier !== undefined && alike(earlier, item) ? earlier : item;
|
|
28
|
+
if (keep !== previous[index])
|
|
29
|
+
whole = false;
|
|
30
|
+
return keep;
|
|
31
|
+
});
|
|
32
|
+
return whole ? previous : kept;
|
|
33
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether two values hold the same data: the same value, React elements of
|
|
3
|
+
* one type and key whose props hold the same data, or arrays and objects of
|
|
4
|
+
* no class whose items or fields do. Anything else (a function, a Set, a
|
|
5
|
+
* DOM node, a class instance) is the same only as itself, so the test never
|
|
6
|
+
* calls two things equal that a component could tell apart.
|
|
7
|
+
*/
|
|
8
|
+
export declare function sameData(a: unknown, b: unknown): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* A `memo` comparison that renders a component again only when its props
|
|
11
|
+
* hold other data (`sameData`), so a parent may build its arrays, records,
|
|
12
|
+
* and elements afresh on every render. Its function props must keep their
|
|
13
|
+
* identities (`useStableHandlers`) for the comparison to hold.
|
|
14
|
+
*/
|
|
15
|
+
export declare const sameProps: <Props extends object>(previous: Props, next: Props) => boolean;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { isValidElement } from 'react';
|
|
2
|
+
/** Whether `value` is an array or an object of no class: data a component reads field by field. */
|
|
3
|
+
const isPlainData = (value) => {
|
|
4
|
+
if (Array.isArray(value)) {
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
const prototype = Object.getPrototypeOf(value);
|
|
8
|
+
return prototype === Object.prototype || prototype === null;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Whether two values hold the same data: the same value, React elements of
|
|
12
|
+
* one type and key whose props hold the same data, or arrays and objects of
|
|
13
|
+
* no class whose items or fields do. Anything else (a function, a Set, a
|
|
14
|
+
* DOM node, a class instance) is the same only as itself, so the test never
|
|
15
|
+
* calls two things equal that a component could tell apart.
|
|
16
|
+
*/
|
|
17
|
+
export function sameData(a, b) {
|
|
18
|
+
if (Object.is(a, b)) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
if (typeof a !== 'object' || typeof b !== 'object' || a === null || b === null) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
if (isValidElement(a) || isValidElement(b)) {
|
|
25
|
+
return (isValidElement(a) &&
|
|
26
|
+
isValidElement(b) &&
|
|
27
|
+
a.type === b.type &&
|
|
28
|
+
a.key === b.key &&
|
|
29
|
+
sameData(a.props, b.props));
|
|
30
|
+
}
|
|
31
|
+
if (!isPlainData(a) || !isPlainData(b) || Array.isArray(a) !== Array.isArray(b)) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
const first = a;
|
|
35
|
+
const second = b;
|
|
36
|
+
const fields = Object.keys(first);
|
|
37
|
+
return (fields.length === Object.keys(second).length &&
|
|
38
|
+
fields.every((field) => Object.prototype.hasOwnProperty.call(second, field) && sameData(first[field], second[field])));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* A `memo` comparison that renders a component again only when its props
|
|
42
|
+
* hold other data (`sameData`), so a parent may build its arrays, records,
|
|
43
|
+
* and elements afresh on every render. Its function props must keep their
|
|
44
|
+
* identities (`useStableHandlers`) for the comparison to hold.
|
|
45
|
+
*/
|
|
46
|
+
export const sameProps = (previous, next) => sameData(previous, next);
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One value held outside React state, which the components that show it
|
|
3
|
+
* follow on their own through `useSyncExternalStore`: a change draws those
|
|
4
|
+
* components alone, never the one that holds the store, nor the page
|
|
5
|
+
* around them. No React here.
|
|
6
|
+
*/
|
|
7
|
+
export interface ValueStore<T> {
|
|
8
|
+
readonly get: () => T;
|
|
9
|
+
/** Replaces the value and tells every listener, unless it is the same value (`Object.is`). */
|
|
10
|
+
readonly set: (next: T) => void;
|
|
11
|
+
/** Adds a listener; returns its removal. */
|
|
12
|
+
readonly subscribe: (listener: () => void) => () => void;
|
|
13
|
+
}
|
|
14
|
+
/** A subscription that hears nothing, for `useSyncExternalStore` while there is nothing to follow. */
|
|
15
|
+
export declare const unheard: () => (() => void);
|
|
16
|
+
/** A store holding `initial` until its first `set`. */
|
|
17
|
+
export declare function createValueStore<T>(initial: T): ValueStore<T>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** A subscription that hears nothing, for `useSyncExternalStore` while there is nothing to follow. */
|
|
2
|
+
export const unheard = () => () => undefined;
|
|
3
|
+
/** A store holding `initial` until its first `set`. */
|
|
4
|
+
export function createValueStore(initial) {
|
|
5
|
+
let value = initial;
|
|
6
|
+
const listeners = new Set();
|
|
7
|
+
return {
|
|
8
|
+
get: () => value,
|
|
9
|
+
set: (next) => {
|
|
10
|
+
if (Object.is(next, value))
|
|
11
|
+
return;
|
|
12
|
+
value = next;
|
|
13
|
+
for (const listener of [...listeners])
|
|
14
|
+
listener();
|
|
15
|
+
},
|
|
16
|
+
subscribe: (listener) => {
|
|
17
|
+
listeners.add(listener);
|
|
18
|
+
return () => {
|
|
19
|
+
listeners.delete(listener);
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Render economy: an external value store for `useSyncExternalStore`, data
|
|
3
|
+
* equality for `memo`, stable handler identities, and kept list items.
|
|
4
|
+
*/
|
|
5
|
+
export { keepUnchangedBy, keepUnchangedById } from './KeepUnchanged.logic.js';
|
|
6
|
+
export { sameData, sameProps } from './SameProps.js';
|
|
7
|
+
export { useStableHandlers } from './useStableHandlers.js';
|
|
8
|
+
export { createValueStore, unheard, type ValueStore } from './ValueStore.js';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Render economy: an external value store for `useSyncExternalStore`, data
|
|
3
|
+
* equality for `memo`, stable handler identities, and kept list items.
|
|
4
|
+
*/
|
|
5
|
+
export { keepUnchangedBy, keepUnchangedById } from './KeepUnchanged.logic.js';
|
|
6
|
+
export { sameData, sameProps } from './SameProps.js';
|
|
7
|
+
export { useStableHandlers } from './useStableHandlers.js';
|
|
8
|
+
export { createValueStore, unheard } from './ValueStore.js';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Event handlers whose identities never change, each calling the version of
|
|
3
|
+
* its handler from the latest commit, so a memoized component handed them
|
|
4
|
+
* renders again only when its data changes, not because its parent made new
|
|
5
|
+
* closures.
|
|
6
|
+
*
|
|
7
|
+
* The record must name the same handlers on every render. They are for
|
|
8
|
+
* events only: the latest versions are taken at commit (layout timing), so a
|
|
9
|
+
* call during render would reach the previous commit's.
|
|
10
|
+
*/
|
|
11
|
+
export declare function useStableHandlers<T extends {
|
|
12
|
+
readonly [Name in keyof T]: (...args: never[]) => unknown;
|
|
13
|
+
}>(handlers: T): T;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useLayoutEffect, useRef, useState } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* Event handlers whose identities never change, each calling the version of
|
|
4
|
+
* its handler from the latest commit, so a memoized component handed them
|
|
5
|
+
* renders again only when its data changes, not because its parent made new
|
|
6
|
+
* closures.
|
|
7
|
+
*
|
|
8
|
+
* The record must name the same handlers on every render. They are for
|
|
9
|
+
* events only: the latest versions are taken at commit (layout timing), so a
|
|
10
|
+
* call during render would reach the previous commit's.
|
|
11
|
+
*/
|
|
12
|
+
export function useStableHandlers(handlers) {
|
|
13
|
+
const latest = useRef(handlers);
|
|
14
|
+
useLayoutEffect(() => {
|
|
15
|
+
latest.current = handlers;
|
|
16
|
+
});
|
|
17
|
+
const [stable] = useState(() => Object.fromEntries(Object.keys(handlers).map((name) => [
|
|
18
|
+
name,
|
|
19
|
+
(...args) => latest.current[name](...args)
|
|
20
|
+
])));
|
|
21
|
+
return stable;
|
|
22
|
+
}
|
package/dist/styles.css
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/* UIOK's base stylesheet: the theme tokens, the tokens no theme changes, and
|
|
2
|
+
the utilities every component may rely on. It names no colour itself;
|
|
3
|
+
colours are theme tokens, which themes.generated.css defines (docs/themes.md).
|
|
4
|
+
Import it once, before any stylesheet of the app's own. */
|
|
5
|
+
@import './themes/themes.generated.css';
|
|
6
|
+
|
|
7
|
+
/* Component stylesheets, each beside its component. */
|
|
8
|
+
@import './button/button.css';
|
|
9
|
+
@import './tooltip/tooltip.css';
|
|
10
|
+
@import './activity/activity.css';
|
|
11
|
+
@import './segmented/segmented.css';
|
|
12
|
+
@import './keychord/keychord.css';
|
|
13
|
+
@import './listing/listing.css';
|
|
14
|
+
@import './filter/filter.css';
|
|
15
|
+
@import './legend/legend.css';
|
|
16
|
+
@import './dialog/dialog.css';
|
|
17
|
+
@import './run/run.css';
|
|
18
|
+
@import './namecut/namecut.css';
|
|
19
|
+
@import './text/text.css';
|
|
20
|
+
@import './grid/grid.css';
|
|
21
|
+
@import './datetime/datetime.css';
|
|
22
|
+
@import './pager/pager.css';
|
|
23
|
+
@import './tabs/tabs.css';
|
|
24
|
+
@import './selectall/selectall.css';
|
|
25
|
+
@import './menu/menu.css';
|
|
26
|
+
@import './palette/palette.css';
|
|
27
|
+
@import './charts/charts.css';
|
|
28
|
+
@import './terminal/terminal.css';
|
|
29
|
+
|
|
30
|
+
:root {
|
|
31
|
+
/* Surfaces that float over other content (sticky headers, cards,
|
|
32
|
+
overlays) add --frost as a backdrop-filter so what scrolls under a
|
|
33
|
+
translucent layer blurs. */
|
|
34
|
+
--frost: blur(24px) saturate(160%);
|
|
35
|
+
--font-mono: 'SF Mono', ui-monospace, Menlo, monospace;
|
|
36
|
+
--font-ui: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
|
37
|
+
|
|
38
|
+
/* Z-index scale. Overlay layering is decided here once, not with
|
|
39
|
+
per-component magic numbers:
|
|
40
|
+
- --z-panel: floating panels inside a page;
|
|
41
|
+
- --z-dialog: modal dialogs and their backdrops, above every panel;
|
|
42
|
+
- --z-tooltip: the hover tooltip, above a dialog whose controls it names. */
|
|
43
|
+
--z-panel: 10;
|
|
44
|
+
--z-dialog: 20;
|
|
45
|
+
--z-tooltip: 30;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/* Kept in the accessibility tree but off screen, for text that only assistive
|
|
49
|
+
technology should read. */
|
|
50
|
+
.visually-hidden {
|
|
51
|
+
position: absolute;
|
|
52
|
+
width: 1px;
|
|
53
|
+
height: 1px;
|
|
54
|
+
margin: -1px;
|
|
55
|
+
padding: 0;
|
|
56
|
+
overflow: hidden;
|
|
57
|
+
clip-path: inset(50%);
|
|
58
|
+
white-space: nowrap;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/* A control that cannot act right now: a disabled field or button, a menu
|
|
62
|
+
row or an option marked aria-disabled, a label whose checkbox or field is
|
|
63
|
+
disabled. It keeps its place and its words, faded whole (words, icon, and
|
|
64
|
+
fill) to --disabled-opacity, and the pointer stays an arrow over it. Inside
|
|
65
|
+
one already faded it fades no further. :root weighs it over a page's own
|
|
66
|
+
cursor and opacity for a control; a control that hides its native input (a
|
|
67
|
+
switch, a radio row) keeps the input hidden with a heavier rule and fades
|
|
68
|
+
what it draws instead. A hover or cursor-row highlight leaves out a
|
|
69
|
+
disabled control in its own rule (:enabled, :not([aria-disabled='true'])). */
|
|
70
|
+
:root
|
|
71
|
+
:is(
|
|
72
|
+
:is(button, input, select, textarea):disabled,
|
|
73
|
+
:is(button, [role^='menuitem'], [role='option'])[aria-disabled='true'],
|
|
74
|
+
label:is([data-disabled], :has(> :is(input, select, textarea):disabled))
|
|
75
|
+
):not(
|
|
76
|
+
:where(
|
|
77
|
+
:is(button, input, select, textarea):disabled,
|
|
78
|
+
[aria-disabled='true'],
|
|
79
|
+
label:is([data-disabled], :has(> :is(input, select, textarea):disabled))
|
|
80
|
+
)
|
|
81
|
+
*
|
|
82
|
+
) {
|
|
83
|
+
cursor: default;
|
|
84
|
+
opacity: var(--disabled-opacity);
|
|
85
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { LucideIcon } from 'lucide-react';
|
|
2
|
+
import { type ReactElement } from 'react';
|
|
3
|
+
import type { LinkLook } from '../pane/PaneActions.js';
|
|
4
|
+
/** One tab of a page's strip. */
|
|
5
|
+
export interface PageTab<Id extends string> {
|
|
6
|
+
/** Names the tab to `onSelect`; also its `data-page-tab` attribute. */
|
|
7
|
+
readonly id: Id;
|
|
8
|
+
/** The tab's name. */
|
|
9
|
+
readonly label: string;
|
|
10
|
+
/** The tab's icon. */
|
|
11
|
+
readonly icon: LucideIcon;
|
|
12
|
+
}
|
|
13
|
+
/** Props for {@link PageTabs}, over the type of its tab ids. */
|
|
14
|
+
export interface PageTabsProps<Id extends string> {
|
|
15
|
+
/** The strip's accessible name, what it holds the tabs of ("Project pages"). */
|
|
16
|
+
readonly label: string;
|
|
17
|
+
/** The tabs, in the order they draw. */
|
|
18
|
+
readonly tabs: readonly PageTab<Id>[];
|
|
19
|
+
/** The tab whose page is shown, or null when the page shown is no tab's. */
|
|
20
|
+
readonly current: Id | null;
|
|
21
|
+
/** Called with the tab a click or an arrow key opens. */
|
|
22
|
+
readonly onSelect: (id: Id) => void;
|
|
23
|
+
/** Draws the second, smaller strip a tab's own pages take under the first. */
|
|
24
|
+
readonly pills?: boolean;
|
|
25
|
+
/** How each tab draws: its icon and name (the default), its name alone, or its icon alone, named on hover. */
|
|
26
|
+
readonly look?: LinkLook;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* The tab strip a page draws under its path bar: one tab per page of the
|
|
30
|
+
* level shown, in the order the caller gives, the current one marked. A
|
|
31
|
+
* level's home page that is no tab of its own passes `current` as null, so
|
|
32
|
+
* no tab is marked. A tablist with roving focus: Left and Right move
|
|
33
|
+
* between tabs and open the one they reach, as a native tab bar does, and
|
|
34
|
+
* keep those keys from any listing cursor around it; Tab enters on the
|
|
35
|
+
* current tab. `pills` draws the second, smaller strip a tab's own pages
|
|
36
|
+
* take under the first.
|
|
37
|
+
*/
|
|
38
|
+
export declare function PageTabs<Id extends string>({ label, tabs, current, onSelect, pills, look }: PageTabsProps<Id>): ReactElement;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useRef } from 'react';
|
|
3
|
+
import { tooltip } from '../tooltip/Tooltip.logic.js';
|
|
4
|
+
/**
|
|
5
|
+
* The tab strip a page draws under its path bar: one tab per page of the
|
|
6
|
+
* level shown, in the order the caller gives, the current one marked. A
|
|
7
|
+
* level's home page that is no tab of its own passes `current` as null, so
|
|
8
|
+
* no tab is marked. A tablist with roving focus: Left and Right move
|
|
9
|
+
* between tabs and open the one they reach, as a native tab bar does, and
|
|
10
|
+
* keep those keys from any listing cursor around it; Tab enters on the
|
|
11
|
+
* current tab. `pills` draws the second, smaller strip a tab's own pages
|
|
12
|
+
* take under the first.
|
|
13
|
+
*/
|
|
14
|
+
export function PageTabs({ label, tabs, current, onSelect, pills = false, look = 'both' }) {
|
|
15
|
+
const strip = useRef(null);
|
|
16
|
+
const focusable = current ?? tabs[0]?.id ?? null;
|
|
17
|
+
const onKeyDown = (event) => {
|
|
18
|
+
if (event.key !== 'ArrowLeft' && event.key !== 'ArrowRight')
|
|
19
|
+
return;
|
|
20
|
+
if (event.metaKey || event.altKey || event.ctrlKey || event.shiftKey)
|
|
21
|
+
return;
|
|
22
|
+
const at = tabs.findIndex((tab) => tab.id === event.target.dataset.pageTab);
|
|
23
|
+
const next = tabs[at + (event.key === 'ArrowLeft' ? -1 : 1)];
|
|
24
|
+
event.preventDefault();
|
|
25
|
+
// The tab keeps its arrows from the pane's cursor.
|
|
26
|
+
event.stopPropagation();
|
|
27
|
+
if (next === undefined)
|
|
28
|
+
return;
|
|
29
|
+
onSelect(next.id);
|
|
30
|
+
strip.current?.querySelector(`[data-page-tab="${next.id}"]`)?.focus();
|
|
31
|
+
};
|
|
32
|
+
return (_jsx("div", { "aria-label": label, className: pills ? 'page-tabs pills' : 'page-tabs', onKeyDown: onKeyDown, ref: strip, role: "tablist", children: tabs.map(({ id, label: name, icon: Icon }) => (_jsxs("button", { "aria-label": look === 'icons' ? name : undefined, "aria-selected": id === current, className: "page-tab", "data-page-tab": id, onClick: () => onSelect(id), role: "tab", tabIndex: id === focusable ? 0 : -1, type: "button", ...(look === 'icons' ? tooltip(name) : {}), children: [look !== 'text' && _jsx(Icon, { "aria-hidden": true, size: 13 }), look !== 'icons' && _jsx("span", { children: name })] }, id))) }));
|
|
33
|
+
}
|