@bigpixelrocket/uiok 0.1.3 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +95 -1
- package/README.md +1 -1
- package/dist/activity/ActivityBar.d.ts +21 -8
- package/dist/activity/ActivityBar.js +15 -5
- package/dist/activity/activity.css +53 -6
- package/dist/button/Button.d.ts +10 -6
- package/dist/button/Button.js +6 -1
- package/dist/button/button.css +201 -33
- package/dist/charts/Line.logic.d.ts +6 -0
- package/dist/charts/Line.logic.js +9 -0
- package/dist/charts/LineChart.js +11 -4
- package/dist/charts/Pie.logic.d.ts +89 -1
- package/dist/charts/Pie.logic.js +272 -2
- package/dist/charts/PieChart.d.ts +2 -1
- package/dist/charts/PieChart.js +12 -5
- package/dist/charts/PieFill.d.ts +15 -0
- package/dist/charts/PieFill.js +33 -0
- package/dist/charts/ResultChart.d.ts +2 -2
- package/dist/charts/ResultChart.js +173 -47
- package/dist/charts/ResultChart.logic.d.ts +60 -4
- package/dist/charts/ResultChart.logic.js +105 -6
- package/dist/charts/Scatter.logic.d.ts +18 -4
- package/dist/charts/Scatter.logic.js +98 -22
- package/dist/charts/ScatterChart.js +19 -5
- package/dist/charts/charts.css +233 -116
- package/dist/charts/seriesColour.d.ts +2 -0
- package/dist/charts/seriesColour.js +1 -1
- package/dist/datetime/DateTimePicker.d.ts +12 -2
- package/dist/datetime/DateTimePicker.js +61 -16
- package/dist/datetime/DateTimePicker.logic.d.ts +29 -0
- package/dist/datetime/DateTimePicker.logic.js +25 -0
- package/dist/datetime/datetime.css +89 -49
- package/dist/dialog/ConfirmDialog.d.ts +69 -20
- package/dist/dialog/ConfirmDialog.js +39 -12
- package/dist/dialog/DialogLayer.d.ts +25 -0
- package/dist/dialog/DialogLayer.js +24 -0
- package/dist/dialog/DialogLegend.d.ts +2 -1
- package/dist/dialog/DialogLegend.js +10 -5
- package/dist/dialog/DialogLegend.logic.d.ts +15 -3
- package/dist/dialog/DialogLegend.logic.js +8 -4
- package/dist/dialog/DialogLists.d.ts +157 -0
- package/dist/dialog/DialogLists.js +137 -0
- package/dist/dialog/ModalDialog.d.ts +20 -15
- package/dist/dialog/ModalDialog.js +22 -7
- package/dist/dialog/dialog.css +570 -127
- package/dist/dialog/index.d.ts +7 -1
- package/dist/dialog/index.js +7 -1
- package/dist/field/Check.d.ts +15 -0
- package/dist/field/Check.js +23 -0
- package/dist/field/field.css +812 -0
- package/dist/field/index.d.ts +10 -0
- package/dist/field/index.js +10 -0
- package/dist/field/labelHelp.d.ts +33 -0
- package/dist/field/labelHelp.js +22 -0
- package/dist/filter/FilterIcon.js +2 -1
- package/dist/filter/filter.css +72 -20
- package/dist/grid/DataGrid.d.ts +8 -1
- package/dist/grid/DataGrid.js +115 -40
- package/dist/grid/DataGrid.logic.d.ts +15 -3
- package/dist/grid/DataGrid.logic.js +18 -5
- package/dist/grid/grid.css +481 -56
- package/dist/icon/Spinner.d.ts +16 -0
- package/dist/icon/Spinner.js +13 -0
- package/dist/icon/index.d.ts +5 -0
- package/dist/icon/index.js +5 -0
- package/dist/icon/sizes.d.ts +19 -0
- package/dist/icon/sizes.js +19 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/keychord/KeyChord.d.ts +12 -1
- package/dist/keychord/KeyChord.js +2 -2
- package/dist/keychord/index.d.ts +1 -1
- package/dist/keychord/keychord.css +87 -9
- package/dist/labels/dialog.d.ts +12 -1
- package/dist/labels/dialog.js +3 -1
- package/dist/labels/selectAll.d.ts +4 -4
- package/dist/labels/selectAll.js +1 -1
- package/dist/legend/KeyLegendStrip.js +1 -1
- package/dist/legend/legend.css +82 -57
- package/dist/listing/Listing.d.ts +17 -10
- package/dist/listing/Listing.js +33 -26
- package/dist/listing/listing.css +1665 -237
- package/dist/menu/menu.css +227 -67
- package/dist/menu/useBellBeat.js +2 -2
- package/dist/namecut/NameCut.d.ts +3 -1
- package/dist/namecut/NameCut.js +152 -5
- package/dist/namecut/NameCut.logic.d.ts +5 -3
- package/dist/namecut/NameCut.logic.js +20 -5
- package/dist/namecut/namecut.css +27 -7
- package/dist/pager/Pager.d.ts +12 -4
- package/dist/pager/Pager.js +21 -7
- package/dist/pager/pager.css +41 -30
- package/dist/palette/Palette.js +2 -1
- package/dist/palette/palette.css +121 -60
- package/dist/pane/PaneActions.d.ts +56 -14
- package/dist/pane/PaneActions.js +64 -16
- package/dist/pane/PaneFrame.d.ts +37 -5
- package/dist/pane/PaneFrame.js +246 -11
- package/dist/pane/index.d.ts +4 -2
- package/dist/pane/index.js +4 -2
- package/dist/pane/toolWords.d.ts +14 -0
- package/dist/pane/toolWords.js +26 -0
- package/dist/pane/useToolbarFit.d.ts +25 -0
- package/dist/pane/useToolbarFit.js +95 -0
- package/dist/run/RunHeader.d.ts +5 -3
- package/dist/run/RunHeader.js +11 -8
- package/dist/run/run.css +64 -79
- package/dist/segmented/SegmentedChoice.d.ts +18 -2
- package/dist/segmented/SegmentedChoice.js +18 -7
- package/dist/segmented/segmented.css +62 -22
- package/dist/selectall/SelectAllBar.d.ts +4 -3
- package/dist/selectall/SelectAllBar.js +4 -3
- package/dist/selectall/selectall.css +17 -12
- package/dist/shell/shell.css +1073 -0
- package/dist/styles.css +620 -22
- package/dist/surface/surface.css +154 -0
- package/dist/tabs/PageTabs.d.ts +10 -5
- package/dist/tabs/PageTabs.js +126 -37
- package/dist/tabs/tabs.css +131 -51
- package/dist/terminal/Terminal.js +3 -1
- package/dist/terminal/Terminal.logic.d.ts +5 -4
- package/dist/terminal/Terminal.logic.js +9 -4
- package/dist/terminal/TerminalMenu.d.ts +4 -1
- package/dist/terminal/TerminalMenu.js +12 -5
- package/dist/terminal/ghostty/contrast.logic.d.ts +45 -0
- package/dist/terminal/ghostty/contrast.logic.js +130 -0
- package/dist/terminal/ghostty/core.d.ts +6 -0
- package/dist/terminal/ghostty/renderer.d.ts +9 -2
- package/dist/terminal/ghostty/renderer.js +91 -14
- package/dist/terminal/ghostty/surface.d.ts +8 -0
- package/dist/terminal/ghostty/surface.js +27 -1
- package/dist/terminal/terminal.css +87 -61
- package/dist/text/text.css +16 -7
- package/dist/themes/catalog.js +4 -3
- package/dist/themes/themes.generated.css +1307 -264
- package/dist/themes/tokens.d.ts +69 -14
- package/dist/themes/tokens.js +920 -97
- package/dist/tokens.css +239 -0
- package/dist/tooltip/Tooltip.d.ts +6 -0
- package/dist/tooltip/Tooltip.js +48 -6
- package/dist/tooltip/Tooltip.logic.d.ts +89 -12
- package/dist/tooltip/Tooltip.logic.js +142 -20
- package/dist/tooltip/index.d.ts +1 -1
- package/dist/tooltip/index.js +1 -1
- package/dist/tooltip/tooltip.css +39 -9
- package/package.json +9 -3
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type ReactElement, type ReactNode } from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* The element dialogs mount into under a `DialogLayer`: undefined outside
|
|
4
|
+
* any layer (a dialog renders in place), null while the layer's element is
|
|
5
|
+
* not yet in the document, and the element once it is.
|
|
6
|
+
*/
|
|
7
|
+
export declare const DialogLayerContext: import("react").Context<HTMLElement | null | undefined>;
|
|
8
|
+
/** Props for {@link DialogLayer}. */
|
|
9
|
+
export interface DialogLayerProps {
|
|
10
|
+
/** The content whose dialogs mount into the layer. */
|
|
11
|
+
readonly children: ReactNode;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Where the dialogs of `children` paint: an element drawn after them, so
|
|
15
|
+
* every `ModalDialog` (and `ConfirmDialog`) rendered anywhere inside mounts
|
|
16
|
+
* there instead of in place, above every pane of the content, even one that
|
|
17
|
+
* isolates its own layers. Put it inside the element that carries the
|
|
18
|
+
* content's scoping classes (a space root), so rules written under that
|
|
19
|
+
* root still reach the dialogs, and outside every pane. The layer draws
|
|
20
|
+
* nothing and takes no room (`display: contents`). A dialog keeps its place
|
|
21
|
+
* in the React tree, so context, focus handling, and event bubbling are
|
|
22
|
+
* unchanged; theme tokens follow it because they live on the document's
|
|
23
|
+
* root. A dialog's own `container` prop overrides the layer.
|
|
24
|
+
*/
|
|
25
|
+
export declare function DialogLayer({ children }: DialogLayerProps): ReactElement;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useState } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* The element dialogs mount into under a `DialogLayer`: undefined outside
|
|
5
|
+
* any layer (a dialog renders in place), null while the layer's element is
|
|
6
|
+
* not yet in the document, and the element once it is.
|
|
7
|
+
*/
|
|
8
|
+
export const DialogLayerContext = createContext(undefined);
|
|
9
|
+
/**
|
|
10
|
+
* Where the dialogs of `children` paint: an element drawn after them, so
|
|
11
|
+
* every `ModalDialog` (and `ConfirmDialog`) rendered anywhere inside mounts
|
|
12
|
+
* there instead of in place, above every pane of the content, even one that
|
|
13
|
+
* isolates its own layers. Put it inside the element that carries the
|
|
14
|
+
* content's scoping classes (a space root), so rules written under that
|
|
15
|
+
* root still reach the dialogs, and outside every pane. The layer draws
|
|
16
|
+
* nothing and takes no room (`display: contents`). A dialog keeps its place
|
|
17
|
+
* in the React tree, so context, focus handling, and event bubbling are
|
|
18
|
+
* unchanged; theme tokens follow it because they live on the document's
|
|
19
|
+
* root. A dialog's own `container` prop overrides the layer.
|
|
20
|
+
*/
|
|
21
|
+
export function DialogLayer({ children }) {
|
|
22
|
+
const [layer, setLayer] = useState(null);
|
|
23
|
+
return (_jsxs(_Fragment, { children: [_jsx(DialogLayerContext, { value: layer, children: children }), _jsx("div", { className: "dialog-layer", ref: setLayer })] }));
|
|
24
|
+
}
|
|
@@ -11,7 +11,8 @@ export interface DialogLegendProps {
|
|
|
11
11
|
* A dialog's footer drawn as a key legend: the leave verb on Escape and any
|
|
12
12
|
* secondary verbs line up from the left edge, the primary stands alone at
|
|
13
13
|
* the right edge with its cap lit (in the danger colour inside a
|
|
14
|
-
* destructive dialog), Return's unless it names its own chord.
|
|
14
|
+
* destructive dialog), Return's unless it names its own chord. A secondary
|
|
15
|
+
* verb marked `danger` reads in the danger colour. The slots
|
|
15
16
|
* are the keys' pointer targets; the keys themselves are bound by whatever
|
|
16
17
|
* holds the legend: `ModalDialog`, which renders it as its last child, or a
|
|
17
18
|
* surface without a dialog frame (a palette), which binds them itself with
|
|
@@ -1,21 +1,26 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { KeyChord } from '../keychord/KeyChord.js';
|
|
3
|
+
import { describedTooltip } from '../tooltip/Tooltip.logic.js';
|
|
3
4
|
const ESCAPE = { key: 'Escape' };
|
|
4
5
|
const RETURN = { key: 'Enter' };
|
|
5
6
|
/**
|
|
6
7
|
* One slot: the key cap, then the verb. A real button named by its verb
|
|
7
8
|
* alone (the cap is hidden from assistive technology), outside the Tab
|
|
8
9
|
* order and never taking focus from a press, because its key is the
|
|
9
|
-
* keyboard's way to it.
|
|
10
|
+
* keyboard's way to it. A verb's `help` is its tooltip and description.
|
|
10
11
|
*/
|
|
11
|
-
function LegendSlot({ chord, verb, primary = false, onRun }) {
|
|
12
|
-
|
|
12
|
+
function LegendSlot({ chord, verb, primary = false, danger = false, onRun }) {
|
|
13
|
+
const className = ['legend-slot', primary && 'legend-primary', danger && 'legend-danger']
|
|
14
|
+
.filter(Boolean)
|
|
15
|
+
.join(' ');
|
|
16
|
+
return (_jsxs("button", { className: className, disabled: verb.disabled, onClick: onRun, onMouseDown: (event) => event.preventDefault(), tabIndex: -1, type: "button", ...describedTooltip(verb.help), children: [_jsx("span", { "aria-hidden": true, className: "legend-slot-key", children: _jsx(KeyChord, { chord: chord }) }), verb.label] }));
|
|
13
17
|
}
|
|
14
18
|
/**
|
|
15
19
|
* A dialog's footer drawn as a key legend: the leave verb on Escape and any
|
|
16
20
|
* secondary verbs line up from the left edge, the primary stands alone at
|
|
17
21
|
* the right edge with its cap lit (in the danger colour inside a
|
|
18
|
-
* destructive dialog), Return's unless it names its own chord.
|
|
22
|
+
* destructive dialog), Return's unless it names its own chord. A secondary
|
|
23
|
+
* verb marked `danger` reads in the danger colour. The slots
|
|
19
24
|
* are the keys' pointer targets; the keys themselves are bound by whatever
|
|
20
25
|
* holds the legend: `ModalDialog`, which renders it as its last child, or a
|
|
21
26
|
* surface without a dialog frame (a palette), which binds them itself with
|
|
@@ -24,5 +29,5 @@ function LegendSlot({ chord, verb, primary = false, onRun }) {
|
|
|
24
29
|
*/
|
|
25
30
|
export function DialogLegend({ legend, onLeave }) {
|
|
26
31
|
const { leave, secondary = [], primary } = legend;
|
|
27
|
-
return (_jsxs("div", { className: "dialog-legend", children: [leave && _jsx(LegendSlot, { chord: ESCAPE, onRun: onLeave, verb: leave }), secondary.map((slot) => (_jsx(LegendSlot, { chord: slot.chord, onRun: slot.onRun, verb: slot }, slot.label))), primary && (_jsx(LegendSlot, { chord: primary.chord ?? RETURN, onRun: primary.onRun, primary: true, verb: primary }))] }));
|
|
32
|
+
return (_jsxs("div", { className: "dialog-legend", children: [leave && _jsx(LegendSlot, { chord: ESCAPE, onRun: onLeave, verb: leave }), secondary.map((slot) => (_jsx(LegendSlot, { chord: slot.chord, danger: slot.danger, onRun: slot.onRun, verb: slot }, slot.label))), primary && (_jsx(LegendSlot, { chord: primary.chord ?? RETURN, onRun: primary.onRun, primary: true, verb: primary }))] }));
|
|
28
33
|
}
|
|
@@ -10,6 +10,12 @@ export interface DialogLegendVerb {
|
|
|
10
10
|
readonly label: string;
|
|
11
11
|
/** True while the verb cannot run; its slot stays drawn, dimmed, and its key runs nothing. */
|
|
12
12
|
readonly disabled?: boolean;
|
|
13
|
+
/**
|
|
14
|
+
* What the verb does, when its label does not say it all ("Test checks
|
|
15
|
+
* the connection without saving it"): the slot's tooltip and accessible
|
|
16
|
+
* description, so the dialog's body needs no sentence about its verbs.
|
|
17
|
+
*/
|
|
18
|
+
readonly help?: string;
|
|
13
19
|
}
|
|
14
20
|
/**
|
|
15
21
|
* Escape's verb on a surface with a filter field (a palette, a menu): Clear
|
|
@@ -30,6 +36,12 @@ export interface LegendSecondary extends DialogLegendVerb {
|
|
|
30
36
|
readonly chord: Chord;
|
|
31
37
|
/** What the slot and its chord run. */
|
|
32
38
|
readonly onRun: () => void;
|
|
39
|
+
/**
|
|
40
|
+
* True for a verb that destroys (Delete…): the slot reads in the danger
|
|
41
|
+
* colour so it never passes for a harmless one. The primary takes its
|
|
42
|
+
* colour from the dialog's tone instead.
|
|
43
|
+
*/
|
|
44
|
+
readonly danger?: boolean;
|
|
33
45
|
}
|
|
34
46
|
/** The forward verb at the right edge, on Return unless it names another chord. */
|
|
35
47
|
export interface LegendPrimary extends DialogLegendVerb {
|
|
@@ -37,7 +49,7 @@ export interface LegendPrimary extends DialogLegendVerb {
|
|
|
37
49
|
readonly onRun: () => void;
|
|
38
50
|
/**
|
|
39
51
|
* The primary's key when it is not Return: a delete for good stands on
|
|
40
|
-
* ⌥⌘⌫,
|
|
52
|
+
* ⌥⌘⌫, the Delete Now chord, and Return then runs nothing,
|
|
41
53
|
* so a Return pressed out of habit never deletes anything for good.
|
|
42
54
|
*/
|
|
43
55
|
readonly chord?: Chord;
|
|
@@ -137,8 +149,8 @@ export type LegendKeyAction = {
|
|
|
137
149
|
*/
|
|
138
150
|
export declare function legendKeyAction(legend: DialogLegendModel, stroke: LegendKeyStroke): LegendKeyAction;
|
|
139
151
|
/**
|
|
140
|
-
* What a legend draws, as a string: each slot's label, chord,
|
|
141
|
-
* can run, so two models that draw the same footer compare equal whatever
|
|
152
|
+
* What a legend draws, as a string: each slot's label, chord, whether it
|
|
153
|
+
* can run, and whether it reads as destructive, so two models that draw the same footer compare equal whatever
|
|
142
154
|
* functions they run. A holder that rebuilds its model on every render
|
|
143
155
|
* passes a new one on only when this changes.
|
|
144
156
|
*/
|
|
@@ -54,16 +54,20 @@ export function legendKeyAction(legend, stroke) {
|
|
|
54
54
|
/** A chord as a fixed string for comparison, never for display. */
|
|
55
55
|
const chordText = (chord) => `${chord.ctrl ? '⌃' : ''}${chord.alt ? '⌥' : ''}${chord.shift ? '⇧' : ''}${chord.meta ? '⌘' : ''}${chord.key}`;
|
|
56
56
|
/**
|
|
57
|
-
* What a legend draws, as a string: each slot's label, chord,
|
|
58
|
-
* can run, so two models that draw the same footer compare equal whatever
|
|
57
|
+
* What a legend draws, as a string: each slot's label, chord, whether it
|
|
58
|
+
* can run, and whether it reads as destructive, so two models that draw the same footer compare equal whatever
|
|
59
59
|
* functions they run. A holder that rebuilds its model on every render
|
|
60
60
|
* passes a new one on only when this changes.
|
|
61
61
|
*/
|
|
62
62
|
export function legendSignature(legend) {
|
|
63
|
-
const verb = (slot) => slot === undefined ? null : [slot.label, slot.disabled === true];
|
|
63
|
+
const verb = (slot) => slot === undefined ? null : [slot.label, slot.disabled === true, slot.help ?? ''];
|
|
64
64
|
return JSON.stringify([
|
|
65
65
|
verb(legend.leave),
|
|
66
|
-
(legend.secondary ?? []).map((slot) => [
|
|
66
|
+
(legend.secondary ?? []).map((slot) => [
|
|
67
|
+
...(verb(slot) ?? []),
|
|
68
|
+
chordText(slot.chord),
|
|
69
|
+
slot.danger === true
|
|
70
|
+
]),
|
|
67
71
|
legend.primary === undefined
|
|
68
72
|
? null
|
|
69
73
|
: [...(verb(legend.primary) ?? []), chordText(legend.primary.chord ?? PLAIN_RETURN)]
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import type { LucideIcon } from 'lucide-react';
|
|
2
|
+
import { type ReactElement, type ReactNode } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* One row of a dialog's fact list: what the fact is, and its value, read at
|
|
5
|
+
* a glance ("Terminals", 6, "api, web, worker").
|
|
6
|
+
*/
|
|
7
|
+
export interface DialogFact {
|
|
8
|
+
/** What the row counts or names, in the leading label column: "Terminals". */
|
|
9
|
+
readonly label: string;
|
|
10
|
+
/** A count, in its own column so the counts line up; the host formats it. */
|
|
11
|
+
readonly count?: number | string;
|
|
12
|
+
/**
|
|
13
|
+
* The value: a few names ("api, web, worker"), or the value itself when
|
|
14
|
+
* there is no count. A string value shows its full text in a tooltip
|
|
15
|
+
* while it is cut; a node value passes its own `cutTooltip`.
|
|
16
|
+
*/
|
|
17
|
+
readonly value?: ReactNode;
|
|
18
|
+
/**
|
|
19
|
+
* How many names the value leaves out. The row ends in "+N more"
|
|
20
|
+
* (`dialog.moreItems`) after the value, never cut: a long value gives way
|
|
21
|
+
* with an ellipsis first, so the row always says how many it omits.
|
|
22
|
+
*/
|
|
23
|
+
readonly more?: number;
|
|
24
|
+
}
|
|
25
|
+
/** Props for {@link DialogFacts}. */
|
|
26
|
+
export interface DialogFactsProps {
|
|
27
|
+
/** The rows, in the order they are read. */
|
|
28
|
+
readonly facts: readonly DialogFact[];
|
|
29
|
+
/** The list's accessible name, when the message above does not already say what it lists. */
|
|
30
|
+
readonly label?: string;
|
|
31
|
+
/** The list's id, for a dialog that names it as its description. */
|
|
32
|
+
readonly id?: string;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* A confirmation's or alert's facts as a desktop property list: one line
|
|
36
|
+
* per row, its label in a leading column, then an optional count in a
|
|
37
|
+
* column of its own and the value, so labels, counts, and values each
|
|
38
|
+
* line up. A label keeps to one line; a value wraps (after a separator
|
|
39
|
+
* where it can) up to three lines before it is cut, a cut label or string
|
|
40
|
+
* value carrying its full text in a tooltip; a row's "+N more" (`more`)
|
|
41
|
+
* stays whole after its value. Facts are about the action (where it acts),
|
|
42
|
+
* never the things it acts on, which are `DialogItems`. A list of
|
|
43
|
+
* facts, not sentences: the message above says what they mean. Styled by
|
|
44
|
+
* the `.dialog-facts` rules in `@bigpixelrocket/uiok/styles.css`.
|
|
45
|
+
*/
|
|
46
|
+
export declare function DialogFacts({ facts, label, id }: DialogFactsProps): ReactElement;
|
|
47
|
+
/**
|
|
48
|
+
* One thing a confirmation acts on, as data: its name, an optional dim
|
|
49
|
+
* detail, and its kind's glyph. The dialog draws it as one row of its
|
|
50
|
+
* framed list (`DialogItems`).
|
|
51
|
+
*/
|
|
52
|
+
export interface DialogItem {
|
|
53
|
+
/**
|
|
54
|
+
* What identifies the item ("Production", "deploying.md"), set in
|
|
55
|
+
* monospace. A long name wraps, up to three lines, before it is ever
|
|
56
|
+
* cut, and a name still cut after three lines carries its whole text in
|
|
57
|
+
* a tooltip.
|
|
58
|
+
*/
|
|
59
|
+
readonly name: string;
|
|
60
|
+
/**
|
|
61
|
+
* One dim value at the row's end where the kind has one: a server's
|
|
62
|
+
* host, a file's folder, a size. Leave it out when the kind has none.
|
|
63
|
+
*/
|
|
64
|
+
readonly detail?: string;
|
|
65
|
+
/** This item's glyph, when it differs from its list's `icon` (a folder among files). */
|
|
66
|
+
readonly icon?: LucideIcon;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* One labelled list of a dialog that names several kinds of things (a
|
|
70
|
+
* quit confirmation's running processes and open terminals): a short label
|
|
71
|
+
* and its count above the same framed list.
|
|
72
|
+
*/
|
|
73
|
+
export interface DialogItemGroup {
|
|
74
|
+
/** What the list holds, short, as a heading: "Running processes". */
|
|
75
|
+
readonly label: string;
|
|
76
|
+
/** The items, in the order they are read; only the first five are drawn. */
|
|
77
|
+
readonly items: readonly DialogItem[];
|
|
78
|
+
/** The kind's glyph, drawn on every row whose item names no other. */
|
|
79
|
+
readonly icon?: LucideIcon;
|
|
80
|
+
/**
|
|
81
|
+
* How many there are in all, when the host passes only the first few
|
|
82
|
+
* items; `items.length` unless given. Sets the heading's count and the
|
|
83
|
+
* "+N more" row.
|
|
84
|
+
*/
|
|
85
|
+
readonly count?: number;
|
|
86
|
+
}
|
|
87
|
+
/** Props for {@link DialogItems}. */
|
|
88
|
+
export interface DialogItemsProps {
|
|
89
|
+
/** The items, in the order they are read; only the first five are drawn. */
|
|
90
|
+
readonly items: readonly DialogItem[];
|
|
91
|
+
/** The kind's glyph, drawn on every row whose item names no other. */
|
|
92
|
+
readonly icon?: LucideIcon;
|
|
93
|
+
/**
|
|
94
|
+
* How many there are in all, when the host passes only the first few
|
|
95
|
+
* items; `items.length` unless given. Sets the "+N more" row and the count
|
|
96
|
+
* read with the list.
|
|
97
|
+
*/
|
|
98
|
+
readonly count?: number;
|
|
99
|
+
/**
|
|
100
|
+
* The list's short label, drawn with its count above the frame, for a
|
|
101
|
+
* dialog that names several groups. Without it the count is read by
|
|
102
|
+
* assistive technology only (the dialog's lead already says it).
|
|
103
|
+
*/
|
|
104
|
+
readonly label?: string;
|
|
105
|
+
/** The block's id, for a dialog that names it in its description. */
|
|
106
|
+
readonly id?: string;
|
|
107
|
+
}
|
|
108
|
+
/** How many rows a dialog's item list draws in full before it ends in "+N more". */
|
|
109
|
+
export declare const DIALOG_ITEMS_SHOWN = 5;
|
|
110
|
+
/**
|
|
111
|
+
* Which of `count` items a dialog's list draws, and how many its last row
|
|
112
|
+
* counts as "+N more": every item up to five, else the first five and the
|
|
113
|
+
* rest counted. `count` may exceed `available` (a host that passes only the
|
|
114
|
+
* first few); the list never draws more than it was given.
|
|
115
|
+
*/
|
|
116
|
+
export declare function shownItems(available: number, count?: number): {
|
|
117
|
+
readonly shown: number;
|
|
118
|
+
readonly more: number;
|
|
119
|
+
};
|
|
120
|
+
/**
|
|
121
|
+
* The things a confirmation acts on, as one framed list (a well): one row
|
|
122
|
+
* per item with its kind's glyph, its name in monospace, and its dim detail
|
|
123
|
+
* at the row's end. One item is a list of one row; up to five show in full,
|
|
124
|
+
* and more show the first five and a last row "+N more" (`dialog.moreItems`),
|
|
125
|
+
* so the list is never taller than six rows. A name wraps (up to three
|
|
126
|
+
* lines) before it is cut. With a `label` the list is one of several
|
|
127
|
+
* groups, headed by the label and its count; without one the count
|
|
128
|
+
* (`dialog.itemCount`) is read before the names, so a dialog that names
|
|
129
|
+
* this block in its description reads its lead, the count, then the names.
|
|
130
|
+
* Styled by the `.dialog-items` rules in `@bigpixelrocket/uiok/styles.css`.
|
|
131
|
+
*/
|
|
132
|
+
export declare function DialogItems({ items, icon, count, label, id }: DialogItemsProps): ReactElement;
|
|
133
|
+
/** Props for {@link DialogStatements}. */
|
|
134
|
+
export interface DialogStatementsProps {
|
|
135
|
+
/** What the statements are, short, as the block's heading and accessible name: "SQL". */
|
|
136
|
+
readonly label: string;
|
|
137
|
+
/**
|
|
138
|
+
* Every statement the action runs, in the order it runs them, each whole:
|
|
139
|
+
* the block draws all of them, never a first few, so pass none cut short.
|
|
140
|
+
*/
|
|
141
|
+
readonly lines: readonly string[];
|
|
142
|
+
/** The block's id, for a dialog that names it in its description. */
|
|
143
|
+
readonly id?: string;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* The statements a confirmation runs (a batch of SQL), shown in full so
|
|
147
|
+
* nothing runs that the user could not read first: the label and the count
|
|
148
|
+
* above a framed block in the code face, one statement per line, each
|
|
149
|
+
* wrapping whole under a hanging indent and selectable. The block is
|
|
150
|
+
* capped at about eight lines and scrolls on its own beyond that, never
|
|
151
|
+
* slicing the list or ending in "+N more". It is a region named by the
|
|
152
|
+
* label that Tab reaches, so the arrow keys, Page Up and Page Down, Home
|
|
153
|
+
* and End scroll it, and assistive technology reads it as a list of every
|
|
154
|
+
* statement. Styled by the `.dialog-statements` rules in
|
|
155
|
+
* `@bigpixelrocket/uiok/styles.css`.
|
|
156
|
+
*/
|
|
157
|
+
export declare function DialogStatements({ label, lines, id }: DialogStatementsProps): ReactElement;
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment, useId, useLayoutEffect, useRef } from 'react';
|
|
3
|
+
import { ICON_MD } from '../icon/sizes.js';
|
|
4
|
+
import { useLabels } from '../labels/UiokProvider.js';
|
|
5
|
+
import { cutTooltip } from '../tooltip/Tooltip.logic.js';
|
|
6
|
+
import { VisuallyHidden } from '../VisuallyHidden.js';
|
|
7
|
+
/**
|
|
8
|
+
* A confirmation's or alert's facts as a desktop property list: one line
|
|
9
|
+
* per row, its label in a leading column, then an optional count in a
|
|
10
|
+
* column of its own and the value, so labels, counts, and values each
|
|
11
|
+
* line up. A label keeps to one line; a value wraps (after a separator
|
|
12
|
+
* where it can) up to three lines before it is cut, a cut label or string
|
|
13
|
+
* value carrying its full text in a tooltip; a row's "+N more" (`more`)
|
|
14
|
+
* stays whole after its value. Facts are about the action (where it acts),
|
|
15
|
+
* never the things it acts on, which are `DialogItems`. A list of
|
|
16
|
+
* facts, not sentences: the message above says what they mean. Styled by
|
|
17
|
+
* the `.dialog-facts` rules in `@bigpixelrocket/uiok/styles.css`.
|
|
18
|
+
*/
|
|
19
|
+
export function DialogFacts({ facts, label, id }) {
|
|
20
|
+
const labels = useLabels().dialog;
|
|
21
|
+
return (_jsx("dl", { "aria-label": label, className: "dialog-facts", id: id, children: facts.map((fact) => (_jsxs("div", { className: "dialog-fact", children: [_jsx("dt", { className: "dialog-label", ...cutTooltip(fact.label), children: fact.label }), _jsxs("dd", { children: [fact.count === undefined ? null : (_jsx("span", { className: "dialog-fact-count", children: fact.count })), _jsx(FactValue, { labels: labels, more: fact.more, value: fact.value })] })] }, fact.label))) }));
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A fact's value cell: the value, wrapping before it is cut (a string one
|
|
25
|
+
* carrying its full text in a tooltip while cut), then, when the value
|
|
26
|
+
* leaves names out, "+N more" kept whole after it.
|
|
27
|
+
*/
|
|
28
|
+
function FactValue({ labels, more, value }) {
|
|
29
|
+
const hasValue = value !== undefined && value !== null;
|
|
30
|
+
const rest = more !== undefined && more > 0 ? labels.moreItems(more) : null;
|
|
31
|
+
if (!hasValue && rest === null)
|
|
32
|
+
return null;
|
|
33
|
+
const tooltip = typeof value === 'string' ? cutTooltip(value) : {};
|
|
34
|
+
const shown = typeof value === 'string' ? breakable(value) : value;
|
|
35
|
+
if (rest === null) {
|
|
36
|
+
return (_jsx("span", { className: "dialog-value dialog-fact-value", ...tooltip, children: shown }));
|
|
37
|
+
}
|
|
38
|
+
return (_jsxs("span", { className: "dialog-value dialog-fact-value dialog-fact-value-more", children: [hasValue && (_jsx("span", { className: "dialog-fact-names", ...tooltip, children: shown })), _jsx("span", { className: "dialog-fact-more", children: rest })] }));
|
|
39
|
+
}
|
|
40
|
+
/** How many rows a dialog's item list draws in full before it ends in "+N more". */
|
|
41
|
+
export const DIALOG_ITEMS_SHOWN = 5;
|
|
42
|
+
/**
|
|
43
|
+
* Which of `count` items a dialog's list draws, and how many its last row
|
|
44
|
+
* counts as "+N more": every item up to five, else the first five and the
|
|
45
|
+
* rest counted. `count` may exceed `available` (a host that passes only the
|
|
46
|
+
* first few); the list never draws more than it was given.
|
|
47
|
+
*/
|
|
48
|
+
export function shownItems(available, count = available) {
|
|
49
|
+
const total = Math.max(available, Math.floor(count));
|
|
50
|
+
const shown = Math.min(available, total > DIALOG_ITEMS_SHOWN ? DIALOG_ITEMS_SHOWN : total);
|
|
51
|
+
return { shown, more: total - shown };
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* The things a confirmation acts on, as one framed list (a well): one row
|
|
55
|
+
* per item with its kind's glyph, its name in monospace, and its dim detail
|
|
56
|
+
* at the row's end. One item is a list of one row; up to five show in full,
|
|
57
|
+
* and more show the first five and a last row "+N more" (`dialog.moreItems`),
|
|
58
|
+
* so the list is never taller than six rows. A name wraps (up to three
|
|
59
|
+
* lines) before it is cut. With a `label` the list is one of several
|
|
60
|
+
* groups, headed by the label and its count; without one the count
|
|
61
|
+
* (`dialog.itemCount`) is read before the names, so a dialog that names
|
|
62
|
+
* this block in its description reads its lead, the count, then the names.
|
|
63
|
+
* Styled by the `.dialog-items` rules in `@bigpixelrocket/uiok/styles.css`.
|
|
64
|
+
*/
|
|
65
|
+
export function DialogItems({ items, icon, count, label, id }) {
|
|
66
|
+
const labels = useLabels().dialog;
|
|
67
|
+
const total = Math.max(items.length, Math.floor(count ?? items.length));
|
|
68
|
+
const { shown, more } = shownItems(items.length, total);
|
|
69
|
+
const listRef = useRef(null);
|
|
70
|
+
// A detail too long for its three lines loses its start, not its end, so
|
|
71
|
+
// the folders nearest the item stay; which details are cut depends on
|
|
72
|
+
// layout, so it is read after each layout and on every resize.
|
|
73
|
+
useLayoutEffect(() => {
|
|
74
|
+
const list = listRef.current;
|
|
75
|
+
if (list === null)
|
|
76
|
+
return undefined;
|
|
77
|
+
const mark = () => markCutDetails(list);
|
|
78
|
+
mark();
|
|
79
|
+
if (typeof ResizeObserver === 'undefined')
|
|
80
|
+
return undefined;
|
|
81
|
+
const observer = new ResizeObserver(mark);
|
|
82
|
+
observer.observe(list);
|
|
83
|
+
return () => observer.disconnect();
|
|
84
|
+
}, [items, shown]);
|
|
85
|
+
return (_jsxs("div", { className: "dialog-items-block", id: id, children: [label === undefined ? (_jsx(VisuallyHidden, { children: labels.itemCount(total) })) : (_jsxs("div", { className: "dialog-items-head", children: [_jsx("span", { className: "dialog-label", children: label }), _jsx("span", { className: "dialog-items-count", children: total.toLocaleString() })] })), _jsxs("ul", { "aria-label": label ?? labels.affectedItems(total), className: "dialog-items", ref: listRef, children: [items.slice(0, shown).map((item, index) => {
|
|
86
|
+
const Glyph = item.icon ?? icon;
|
|
87
|
+
return (_jsxs("li", { className: "dialog-item", children: [Glyph === undefined ? (_jsx("span", { "aria-hidden": "true", className: "dialog-item-glyph" })) : (_jsx(Glyph, { "aria-hidden": "true", className: "dialog-item-glyph", size: ICON_MD })), _jsx("span", { className: "dialog-item-name dialog-value", dir: "auto", ...cutTooltip(item.name), children: breakable(item.name) }), item.detail === undefined || item.detail === '' ? null : (_jsx("span", { className: "dialog-item-detail dialog-value", dir: "auto", children: _jsx("span", { className: "dialog-item-detail-text", children: breakable(item.detail) }) }))] }, `${index}:${item.name}`));
|
|
88
|
+
}), more > 0 && _jsx("li", { className: "dialog-item dialog-items-more", children: labels.moreItems(more) })] })] }));
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Marks each detail of `list` whose text runs past its three lines, so
|
|
92
|
+
* cut at its start: `data-cut="start"` (the stylesheet starts its first
|
|
93
|
+
* shown line with an ellipsis, to say more stands before it) and its whole text as
|
|
94
|
+
* a tooltip. A detail that fits loses both.
|
|
95
|
+
*/
|
|
96
|
+
function markCutDetails(list) {
|
|
97
|
+
for (const detail of list.querySelectorAll('.dialog-item-detail')) {
|
|
98
|
+
const text = detail.firstElementChild;
|
|
99
|
+
const cut = text instanceof HTMLElement && text.offsetHeight > detail.clientHeight + 1;
|
|
100
|
+
if (cut) {
|
|
101
|
+
detail.dataset.cut = 'start';
|
|
102
|
+
detail.dataset.tooltip = text.textContent;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
delete detail.dataset.cut;
|
|
106
|
+
delete detail.dataset.tooltip;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* A name or path with a line-break chance after each separator (`/`, `_`,
|
|
112
|
+
* `.`, `:`, `@`), so a wrapped path breaks between its folders and a long
|
|
113
|
+
* identifier between its words before a line breaks inside a word. The text
|
|
114
|
+
* reads and copies exactly as given: `<wbr>` adds no character.
|
|
115
|
+
*/
|
|
116
|
+
function breakable(text) {
|
|
117
|
+
const parts = text.split(/(?<=[/_.:@])(?=.)/u);
|
|
118
|
+
return parts.length === 1
|
|
119
|
+
? text
|
|
120
|
+
: parts.map((part, index) => (_jsxs(Fragment, { children: [index > 0 && _jsx("wbr", {}), part] }, index)));
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* The statements a confirmation runs (a batch of SQL), shown in full so
|
|
124
|
+
* nothing runs that the user could not read first: the label and the count
|
|
125
|
+
* above a framed block in the code face, one statement per line, each
|
|
126
|
+
* wrapping whole under a hanging indent and selectable. The block is
|
|
127
|
+
* capped at about eight lines and scrolls on its own beyond that, never
|
|
128
|
+
* slicing the list or ending in "+N more". It is a region named by the
|
|
129
|
+
* label that Tab reaches, so the arrow keys, Page Up and Page Down, Home
|
|
130
|
+
* and End scroll it, and assistive technology reads it as a list of every
|
|
131
|
+
* statement. Styled by the `.dialog-statements` rules in
|
|
132
|
+
* `@bigpixelrocket/uiok/styles.css`.
|
|
133
|
+
*/
|
|
134
|
+
export function DialogStatements({ label, lines, id }) {
|
|
135
|
+
const labelId = useId();
|
|
136
|
+
return (_jsxs("div", { className: "dialog-statements-block", id: id, children: [_jsxs("div", { className: "dialog-items-head", children: [_jsx("span", { className: "dialog-label", id: labelId, children: label }), _jsx("span", { className: "dialog-items-count", children: lines.length.toLocaleString() })] }), _jsx("div", { className: "dialog-statements-frame", children: _jsx("div", { "aria-labelledby": labelId, className: "dialog-statements scroll-fade", role: "region", tabIndex: 0, children: _jsx("ol", { children: lines.map((line, index) => (_jsx("li", { className: "dialog-statement", children: _jsx("code", { dir: "ltr", children: line }) }, `${index}:${line}`))) }) }) })] }));
|
|
137
|
+
}
|
|
@@ -21,9 +21,11 @@ export declare const containTab: (event: KeyboardEvent<HTMLElement>, container:
|
|
|
21
21
|
/** Props for {@link ModalDialog}; content renders below the title strip. */
|
|
22
22
|
export interface ModalDialogProps {
|
|
23
23
|
/**
|
|
24
|
-
* What the dialog does
|
|
25
|
-
*
|
|
26
|
-
*
|
|
24
|
+
* What the dialog does, in at most five words ("Delete Now?"), never a
|
|
25
|
+
* sentence, and no count, name, or path the body shows: those go in
|
|
26
|
+
* the body. Always one line: a title too long for the strip is cut with
|
|
27
|
+
* an ellipsis, and a string title shows its full text in a tooltip while
|
|
28
|
+
* it is cut.
|
|
27
29
|
*/
|
|
28
30
|
readonly title: ReactNode;
|
|
29
31
|
/** Heading element id, unique per dialog, wired to `aria-labelledby`. */
|
|
@@ -40,13 +42,6 @@ export interface ModalDialogProps {
|
|
|
40
42
|
readonly icon?: LucideIcon;
|
|
41
43
|
/** The title strip's colour; `accent` unless given. */
|
|
42
44
|
readonly tone?: DialogTone;
|
|
43
|
-
/**
|
|
44
|
-
* The strip's context, pushed to its right edge and cut short with an
|
|
45
|
-
* ellipsis: where the dialog acts (`~/Developer/app`, with the home
|
|
46
|
-
* folder as `~`), or the item it asks about. Left out when the dialog has
|
|
47
|
-
* nothing to say there. A string context is also its own tooltip.
|
|
48
|
-
*/
|
|
49
|
-
readonly titleAside?: ReactNode;
|
|
50
45
|
/**
|
|
51
46
|
* Frost the window behind the dialog. Off by default: a dialog that asks
|
|
52
47
|
* about what is on screen (renaming a file, adding a record) is part of
|
|
@@ -78,24 +73,34 @@ export interface ModalDialogProps {
|
|
|
78
73
|
readonly onOutsidePress?: () => void;
|
|
79
74
|
/** The body, between the title strip and the legend. */
|
|
80
75
|
readonly children: ReactNode;
|
|
76
|
+
/**
|
|
77
|
+
* The element the dialog mounts into, for a dialog that must paint above
|
|
78
|
+
* something it is drawn inside (a pane that isolates its layers). Left
|
|
79
|
+
* out, the dialog mounts into the enclosing `DialogLayer`, or in place
|
|
80
|
+
* when there is none. Rules scoped under an element reach the dialog only
|
|
81
|
+
* when the container is inside it.
|
|
82
|
+
*/
|
|
83
|
+
readonly container?: Element;
|
|
81
84
|
}
|
|
82
85
|
/**
|
|
83
86
|
* The modal frame every dialog shares: the backdrop over the whole window
|
|
84
87
|
* that swallows clicks and cancels on an outside press (or runs
|
|
85
88
|
* `onOutsidePress`), Escape-cancels (with or without an esc slot drawn, so
|
|
86
89
|
* a dialog whose primary already does what Escape would still leaves on
|
|
87
|
-
* it), dialog ARIA semantics, Tab focus containment, the title strip (
|
|
88
|
-
*
|
|
90
|
+
* it), dialog ARIA semantics, Tab focus containment, the title strip (the
|
|
91
|
+
* icon and a one-line title, with nothing beside it: context goes in the
|
|
92
|
+
* body's first line), and the key legend footer with its keys. The backdrop is
|
|
89
93
|
* clear unless `frosted` is set, so the page stays in view behind the
|
|
90
94
|
* dialog. Its `aria-modal="true"` is the overlay contract's modal cue
|
|
91
95
|
* (`MODAL_SELECTOR`), which an app shell reads to mute its own chords while
|
|
92
96
|
* the dialog is open. The dialog itself takes focus when it opens with
|
|
93
97
|
* nothing inside focused, so its keys work before any control is chosen.
|
|
94
|
-
* With `pinTop` the box keeps the top edge it opened at.
|
|
95
|
-
*
|
|
98
|
+
* With `pinTop` the box keeps the top edge it opened at. It mounts into
|
|
99
|
+
* `container` when given, else into the enclosing `DialogLayer`, else in
|
|
100
|
+
* place. Dialogs supply only their content and verbs.
|
|
96
101
|
*
|
|
97
102
|
* Styled by the `.dialog-backdrop` and `.dialog` rules in `@bigpixelrocket/uiok/styles.css`
|
|
98
103
|
* (`docs/components/dialog.md`); a caller sets only a dialog's size and its
|
|
99
104
|
* body's layout, through `className`.
|
|
100
105
|
*/
|
|
101
|
-
export declare function ModalDialog({
|
|
106
|
+
export declare function ModalDialog({ container, ...frame }: ModalDialogProps): ReactElement | null;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { createContext, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
3
|
+
import { createPortal } from 'react-dom';
|
|
3
4
|
import { isKeyKept } from '../keyboard/BrowserKeys.js';
|
|
4
5
|
import { isTextEditingTarget } from '../keyboard/Keyboard.logic.js';
|
|
5
|
-
import {
|
|
6
|
+
import { cutTooltip } from '../tooltip/Tooltip.logic.js';
|
|
7
|
+
import { DialogLayerContext } from './DialogLayer.js';
|
|
6
8
|
import { DialogLegend } from './DialogLegend.js';
|
|
7
9
|
import { legendKeyAction } from './DialogLegend.logic.js';
|
|
8
10
|
/** Whether a key comes from a text field holding text, which keeps its deletion chords. */
|
|
@@ -75,21 +77,34 @@ const NestedFocusContext = createContext(null);
|
|
|
75
77
|
* that swallows clicks and cancels on an outside press (or runs
|
|
76
78
|
* `onOutsidePress`), Escape-cancels (with or without an esc slot drawn, so
|
|
77
79
|
* a dialog whose primary already does what Escape would still leaves on
|
|
78
|
-
* it), dialog ARIA semantics, Tab focus containment, the title strip (
|
|
79
|
-
*
|
|
80
|
+
* it), dialog ARIA semantics, Tab focus containment, the title strip (the
|
|
81
|
+
* icon and a one-line title, with nothing beside it: context goes in the
|
|
82
|
+
* body's first line), and the key legend footer with its keys. The backdrop is
|
|
80
83
|
* clear unless `frosted` is set, so the page stays in view behind the
|
|
81
84
|
* dialog. Its `aria-modal="true"` is the overlay contract's modal cue
|
|
82
85
|
* (`MODAL_SELECTOR`), which an app shell reads to mute its own chords while
|
|
83
86
|
* the dialog is open. The dialog itself takes focus when it opens with
|
|
84
87
|
* nothing inside focused, so its keys work before any control is chosen.
|
|
85
|
-
* With `pinTop` the box keeps the top edge it opened at.
|
|
86
|
-
*
|
|
88
|
+
* With `pinTop` the box keeps the top edge it opened at. It mounts into
|
|
89
|
+
* `container` when given, else into the enclosing `DialogLayer`, else in
|
|
90
|
+
* place. Dialogs supply only their content and verbs.
|
|
87
91
|
*
|
|
88
92
|
* Styled by the `.dialog-backdrop` and `.dialog` rules in `@bigpixelrocket/uiok/styles.css`
|
|
89
93
|
* (`docs/components/dialog.md`); a caller sets only a dialog's size and its
|
|
90
94
|
* body's layout, through `className`.
|
|
91
95
|
*/
|
|
92
|
-
export function ModalDialog({
|
|
96
|
+
export function ModalDialog({ container, ...frame }) {
|
|
97
|
+
const layer = useContext(DialogLayerContext);
|
|
98
|
+
const target = container ?? layer;
|
|
99
|
+
// A layer whose element is not in the document yet: the dialog waits one
|
|
100
|
+
// commit for it rather than open in place and move.
|
|
101
|
+
if (target === null) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
return target === undefined ? (_jsx(DialogFrame, { ...frame })) : (createPortal(_jsx(DialogFrame, { ...frame }), target));
|
|
105
|
+
}
|
|
106
|
+
/** The dialog itself, wherever `ModalDialog` mounts it. */
|
|
107
|
+
function DialogFrame({ title, labelId, describedBy, className, icon: Icon, tone = 'accent', frosted = false, pinTop = false, legend, onCancel, onOutsidePress = onCancel, children }) {
|
|
93
108
|
const dialogRef = useRef(null);
|
|
94
109
|
const claimEnclosingFocus = useContext(NestedFocusContext);
|
|
95
110
|
// How many dialogs nested inside this one hold the focus; a count, since
|
|
@@ -180,5 +195,5 @@ export function ModalDialog({ title, labelId, describedBy, className, icon: Icon
|
|
|
180
195
|
}
|
|
181
196
|
}
|
|
182
197
|
containFocus(event);
|
|
183
|
-
}, onMouseDown: (event) => event.stopPropagation(), ref: dialogRef, role: "dialog", style: pinned === null ? undefined : { ['--dialog-top']: `${pinned}px` }, tabIndex: -1, children: [_jsxs("div", { className: "dialog-heading", children: [Icon && _jsx(Icon, { "aria-hidden": true, className: "dialog-icon" }), _jsx("h2", { id: labelId, ...(typeof title === 'string' ?
|
|
198
|
+
}, onMouseDown: (event) => event.stopPropagation(), ref: dialogRef, role: "dialog", style: pinned === null ? undefined : { ['--dialog-top']: `${pinned}px` }, tabIndex: -1, children: [_jsxs("div", { className: "dialog-heading", children: [Icon && _jsx(Icon, { "aria-hidden": true, className: "dialog-icon" }), _jsx("h2", { id: labelId, ...(typeof title === 'string' ? cutTooltip(title) : {}), children: title })] }), _jsx(NestedFocusContext, { value: claimNestedFocus, children: children }), legend && _jsx(DialogLegend, { legend: legend, onLeave: onCancel })] }) }));
|
|
184
199
|
}
|