@speles7172/controls 0.2.0 → 0.3.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/README.md +36 -2
- package/dist/.tsbuildinfo +1 -1
- package/dist/Badge.d.ts +45 -0
- package/dist/Badge.d.ts.map +1 -0
- package/dist/Badge.js +51 -0
- package/dist/Badge.js.map +1 -0
- package/dist/Card.d.ts +52 -0
- package/dist/Card.d.ts.map +1 -0
- package/dist/Card.js +25 -0
- package/dist/Card.js.map +1 -0
- package/dist/DataTable.d.ts +99 -0
- package/dist/DataTable.d.ts.map +1 -0
- package/dist/DataTable.js +93 -0
- package/dist/DataTable.js.map +1 -0
- package/dist/KeyValueList.d.ts.map +1 -1
- package/dist/KeyValueList.js +2 -1
- package/dist/KeyValueList.js.map +1 -1
- package/dist/Modal.d.ts +48 -0
- package/dist/Modal.d.ts.map +1 -0
- package/dist/Modal.js +160 -0
- package/dist/Modal.js.map +1 -0
- package/dist/PageHeader.d.ts +36 -0
- package/dist/PageHeader.d.ts.map +1 -0
- package/dist/PageHeader.js +24 -0
- package/dist/PageHeader.js.map +1 -0
- package/dist/ProgressBar.d.ts +36 -0
- package/dist/ProgressBar.d.ts.map +1 -0
- package/dist/ProgressBar.js +34 -0
- package/dist/ProgressBar.js.map +1 -0
- package/dist/SearchableMultiSelect.d.ts.map +1 -1
- package/dist/SearchableMultiSelect.js +3 -2
- package/dist/SearchableMultiSelect.js.map +1 -1
- package/dist/Section.d.ts +34 -0
- package/dist/Section.d.ts.map +1 -0
- package/dist/Section.js +21 -0
- package/dist/Section.js.map +1 -0
- package/dist/Tabs.d.ts +37 -0
- package/dist/Tabs.d.ts.map +1 -0
- package/dist/Tabs.js +55 -0
- package/dist/Tabs.js.map +1 -0
- package/dist/icons.d.ts +37 -0
- package/dist/icons.d.ts.map +1 -0
- package/dist/icons.js +45 -0
- package/dist/icons.js.map +1 -0
- package/dist/index.d.ts +29 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +29 -4
- package/dist/index.js.map +1 -1
- package/dist/states.d.ts +65 -0
- package/dist/states.d.ts.map +1 -0
- package/dist/states.js +38 -0
- package/dist/states.js.map +1 -0
- package/dist/styles.css +879 -21
- package/package.json +4 -3
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { SortAscendingIcon, SortDescendingIcon, SortableIcon } from './icons.js';
|
|
3
|
+
/** Everything that handles its own click, for a row that also handles clicks. */
|
|
4
|
+
const INTERACTIVE = 'button, a[href], input, select, textarea, label, [role="button"]';
|
|
5
|
+
/** Whether an event landed on a control inside the row rather than on the row. */
|
|
6
|
+
function interactive(target) {
|
|
7
|
+
return target instanceof Element && target.closest(INTERACTIVE) !== null;
|
|
8
|
+
}
|
|
9
|
+
const ALIGN = {
|
|
10
|
+
left: '',
|
|
11
|
+
right: ' ctl-align-right',
|
|
12
|
+
center: ' ctl-align-center',
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* A sortable column head.
|
|
16
|
+
*
|
|
17
|
+
* Exported because a table with a `leadingHeader` or `trailingHeader` of its own
|
|
18
|
+
* still wants those to look like the rest of the row.
|
|
19
|
+
*/
|
|
20
|
+
export function SortableColumn({ label, sortKey, activeKey, direction = 'asc', onSort, className, }) {
|
|
21
|
+
const active = activeKey === sortKey;
|
|
22
|
+
const Icon = !active ? SortableIcon : direction === 'asc' ? SortAscendingIcon : SortDescendingIcon;
|
|
23
|
+
return (_jsx("th", { scope: "col", className: `ctl-th${className === undefined ? '' : ` ${className}`}`, "aria-sort": !active ? 'none' : direction === 'asc' ? 'ascending' : 'descending', children: _jsxs("button", { type: "button", className: "ctl-th-button", onClick: () => onSort(sortKey), children: [label, _jsx("span", { className: `ctl-th-icon${active ? ' ctl-th-icon-active' : ''}`, "aria-hidden": "true", children: _jsx(Icon, { size: 12 }) })] }) }));
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The table every list view is.
|
|
27
|
+
*
|
|
28
|
+
* Here rather than in each console for the reason this package exists: a table
|
|
29
|
+
* written eight times is eight row heights, eight header treatments and eight
|
|
30
|
+
* empty states — and the empty one is the state that gets skipped. The column
|
|
31
|
+
* definitions are data, so a console that shows a different set of columns when
|
|
32
|
+
* it is embedded in a record's page (see `docs/UI.md`) is one array, not a
|
|
33
|
+
* second component.
|
|
34
|
+
*
|
|
35
|
+
* It renders the markup and takes no view of where the rows came from: sorting
|
|
36
|
+
* and paging are the caller's, because a console paging server-side over a
|
|
37
|
+
* keyset (`log-console`) and one sorting an array in memory need the same
|
|
38
|
+
* table and nothing else the same.
|
|
39
|
+
*
|
|
40
|
+
* ```tsx
|
|
41
|
+
* <DataTable
|
|
42
|
+
* columns={[
|
|
43
|
+
* { key: 'name', label: 'Name', render: (r) => r.name },
|
|
44
|
+
* { key: 'rows', label: 'Rows', align: 'right', render: (r) => r.rows.toLocaleString() },
|
|
45
|
+
* ]}
|
|
46
|
+
* rows={runs}
|
|
47
|
+
* rowKey={(r) => r.id}
|
|
48
|
+
* sortKey={sort.key}
|
|
49
|
+
* sortDirection={sort.direction}
|
|
50
|
+
* onSort={sort.toggle}
|
|
51
|
+
* onRowClick={open}
|
|
52
|
+
* />
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export function DataTable({ columns, rows, rowKey, sortKey = null, sortDirection = 'asc', onSort, onRowClick, rowClassName, isSelected, rowHeader, leadingHeader, leadingCell, trailingHeader, trailingCell, empty = 'Nothing to show.', label, className, theme = 'light', }) {
|
|
56
|
+
const span = columns.length + (leadingHeader === undefined ? 0 : 1) + (trailingHeader === undefined ? 0 : 1);
|
|
57
|
+
return (_jsx("div", { className: `ctl ctl-table-wrap${className === undefined ? '' : ` ${className}`}`, "data-ctl-theme": theme, children: _jsxs("table", { className: "ctl-table", "aria-label": label, children: [_jsx("thead", { children: _jsxs("tr", { children: [leadingHeader, columns.map((column) => {
|
|
58
|
+
const align = ALIGN[column.align ?? 'left'] ?? '';
|
|
59
|
+
const head = `${align}${column.headerClassName === undefined ? '' : ` ${column.headerClassName}`}`;
|
|
60
|
+
return column.sortable !== false && onSort !== undefined ? (_jsx(SortableColumn, { label: column.label, sortKey: column.key, activeKey: sortKey, direction: sortDirection, onSort: onSort, className: head.trim() }, column.key)) : (_jsx("th", { scope: "col", className: `ctl-th${head}`, children: column.label }, column.key));
|
|
61
|
+
}), trailingHeader] }) }), _jsx("tbody", { children: rows.length === 0 ? (_jsx("tr", { children: _jsx("td", { className: "ctl-td ctl-table-empty", colSpan: span === 0 ? 1 : span, children: empty }) })) : (rows.map((item, index) => {
|
|
62
|
+
const extra = rowClassName?.(item);
|
|
63
|
+
return (_jsxs("tr", { className: `ctl-row${onRowClick === undefined ? '' : ' ctl-row-clickable'}${isSelected?.(item) === true ? ' ctl-row-selected' : ''}${extra === undefined || extra === '' ? '' : ` ${extra}`}`,
|
|
64
|
+
// A clickable row is reachable by keyboard, or the whole table
|
|
65
|
+
// is mouse-only — which is how a "click the row for detail"
|
|
66
|
+
// console ends up with no way to open a record at all.
|
|
67
|
+
tabIndex: onRowClick === undefined ? undefined : 0, onClick: onRowClick === undefined
|
|
68
|
+
? undefined
|
|
69
|
+
: (event) => {
|
|
70
|
+
// A control inside a cell is its own: without this,
|
|
71
|
+
// the delete button in the action column also opens
|
|
72
|
+
// the record it just deleted.
|
|
73
|
+
if (interactive(event.target))
|
|
74
|
+
return;
|
|
75
|
+
onRowClick(item);
|
|
76
|
+
}, onKeyDown: onRowClick === undefined
|
|
77
|
+
? undefined
|
|
78
|
+
: (event) => {
|
|
79
|
+
if (event.key !== 'Enter' && event.key !== ' ')
|
|
80
|
+
return;
|
|
81
|
+
// Space scrolls the page otherwise, and Enter inside a
|
|
82
|
+
// cell's own button must stay that button's.
|
|
83
|
+
if (event.target !== event.currentTarget)
|
|
84
|
+
return;
|
|
85
|
+
event.preventDefault();
|
|
86
|
+
onRowClick(item);
|
|
87
|
+
}, children: [leadingCell?.(item, index), columns.map((column) => {
|
|
88
|
+
const Cell = column.key === rowHeader ? 'th' : 'td';
|
|
89
|
+
return (_jsx(Cell, { scope: column.key === rowHeader ? 'row' : undefined, className: `ctl-td${ALIGN[column.align ?? 'left'] ?? ''}${column.className === undefined ? '' : ` ${column.className}`}`, children: column.render(item, index) }, column.key));
|
|
90
|
+
}), trailingCell?.(item, index)] }, rowKey(item, index)));
|
|
91
|
+
})) })] }) }));
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=DataTable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DataTable.js","sourceRoot":"","sources":["../src/DataTable.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAiEjF,iFAAiF;AACjF,MAAM,WAAW,GAAG,kEAAkE,CAAC;AAEvF,kFAAkF;AAClF,SAAS,WAAW,CAAC,MAA0B;IAC7C,OAAO,MAAM,YAAY,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;AAC3E,CAAC;AAED,MAAM,KAAK,GAA2B;IACpC,IAAI,EAAE,EAAE;IACR,KAAK,EAAE,kBAAkB;IACzB,MAAM,EAAE,mBAAmB;CAC5B,CAAC;AAEF;;;;;GAKG;AACH,MAAM,UAAU,cAAc,CAAC,EAC7B,KAAK,EACL,OAAO,EACP,SAAS,EACT,SAAS,GAAG,KAAK,EACjB,MAAM,EACN,SAAS,GAQV;IACC,MAAM,MAAM,GAAG,SAAS,KAAK,OAAO,CAAC;IACrC,MAAM,IAAI,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,SAAS,KAAK,KAAK,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,kBAAkB,CAAC;IAEnG,OAAO,CACL,aACE,KAAK,EAAC,KAAK,EACX,SAAS,EAAE,SAAS,SAAS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AM,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;oCACpD,OAAO,CACL,KAAC,IAAI,IAEH,KAAK,EAAE,MAAM,CAAC,GAAG,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,EACnD,SAAS,EAAE,SAAS,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,MAAM,CAAC,IAAI,EAAE,GACrD,MAAM,CAAC,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,SAAS,EAC5D,EAAE,YAED,MAAM,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IANtB,MAAM,CAAC,GAAG,CAOV,CACR,CAAC;gCACJ,CAAC,CAAC,EACD,YAAY,EAAE,CAAC,IAAI,EAAE,KAAK,CAAC,KA/CvB,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,CAgDrB,CACN,CAAC;oBACJ,CAAC,CAAC,CACH,GACK,IACF,GACJ,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KeyValueList.d.ts","sourceRoot":"","sources":["../src/KeyValueList.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"KeyValueList.d.ts","sourceRoot":"","sources":["../src/KeyValueList.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,sCAAsC;AACtC,MAAM,MAAM,gBAAgB,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;AAE7D;;;;;;;GAOG;AACH,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,gBAAgB,CAAC;CACzB;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,SAAS,YAAY,EAAE,CAAC;IAC/B,QAAQ,CAAC,KAAK,EAAE,YAAY,EAAE,GAAG,IAAI,CAAC;IAEtC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sEAAsE;IACtE,QAAQ,CAAC,EAAE,gBAAgB,CAAC;IAC5B,+EAA+E;IAC/E,QAAQ,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;IACzD,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAID;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,YAAY,CAAC,EAC3B,KAAK,EACL,QAAQ,EACR,KAAK,EACL,QAAiB,EACjB,QAA2B,EAC3B,QAAqB,EACrB,QAAQ,EACR,QAAQ,EACR,UAA4B,EAC5B,SAAS,EACT,KAAe,EACf,aAAa,EAAE,MAAM,GACtB,EAAE,iBAAiB,+BAkJnB"}
|
package/dist/KeyValueList.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useId } from 'react';
|
|
3
|
+
import { CloseIcon, MoveDownIcon, MoveUpIcon, ICON_SIZE } from './icons.js';
|
|
3
4
|
const DEFAULT_HEADINGS = { label: 'Label', key: 'Key', value: 'Value' };
|
|
4
5
|
/**
|
|
5
6
|
* An editable list of labelled entries.
|
|
@@ -48,7 +49,7 @@ export function KeyValueList({ value, onChange, label, itemType = 'text', headin
|
|
|
48
49
|
return (_jsxs("div", { className: `ctl ctl-kv${className === undefined ? '' : ` ${className}`}`, "data-ctl-theme": theme, "data-testid": testId, children: [label !== undefined && (_jsx("span", { className: "ctl-label", id: `${ids}-label`, children: label })), value.length === 0 ? (_jsx("p", { className: "ctl-note ctl-kv-empty", children: emptyLabel })) : (_jsxs("div", { className: "ctl-kv-head", "aria-hidden": "true", children: [_jsx("span", { className: "ctl-kv-cell", children: headings.label }), _jsx("span", { className: "ctl-kv-cell", children: headings.key }), _jsx("span", { className: "ctl-kv-cell", children: headings.value }), _jsx("span", { className: "ctl-kv-actions" })] })), value.map((item, index) => {
|
|
49
50
|
const duplicate = item.key !== '' && (counts.get(item.key) ?? 0) > 1;
|
|
50
51
|
const type = item.type ?? itemType;
|
|
51
|
-
return (_jsxs("div", { className: `ctl-kv-row${duplicate ? ' ctl-kv-duplicate' : ''}`, children: [_jsx("input", { className: "ctl-input ctl-kv-cell", "aria-label": `${headings.label} ${index + 1}`, value: item.label, disabled: locked, onChange: (event) => replace(index, { label: event.target.value }) }), _jsx("input", { className: "ctl-input ctl-kv-cell", "aria-label": `${headings.key} ${index + 1}`, "aria-invalid": duplicate ? true : undefined, value: item.key, disabled: locked, onChange: (event) => replace(index, { key: event.target.value }) }), type === 'boolean' ? (_jsxs("label", { className: "ctl-switch ctl-kv-cell", children: [_jsx("input", { type: "checkbox", className: "ctl-switch-box", "aria-label": `${headings.value} ${index + 1}`, checked: item.value === 'true', disabled: locked, onChange: (event) => replace(index, { value: event.target.checked ? 'true' : 'false' }) }), _jsx("span", { className: "ctl-switch-text", children: item.value === 'true' ? 'On' : 'Off' })] })) : (_jsx("input", { className: "ctl-input ctl-kv-cell", type: type === 'number' ? 'number' : 'text', step: type === 'number' ? 'any' : undefined, "aria-label": `${headings.value} ${index + 1}`, value: item.value, disabled: locked, onChange: (event) => replace(index, { value: event.target.value }) })), _jsxs("span", { className: "ctl-kv-actions", children: [_jsx("button", { type: "button", className: "ctl-icon-button", "aria-label": `Move ${headings.label} ${index + 1} up`, disabled: locked || index === 0, onClick: () => move(index, -1), children: "
|
|
52
|
+
return (_jsxs("div", { className: `ctl-kv-row${duplicate ? ' ctl-kv-duplicate' : ''}`, children: [_jsx("input", { className: "ctl-input ctl-kv-cell", "aria-label": `${headings.label} ${index + 1}`, value: item.label, disabled: locked, onChange: (event) => replace(index, { label: event.target.value }) }), _jsx("input", { className: "ctl-input ctl-kv-cell", "aria-label": `${headings.key} ${index + 1}`, "aria-invalid": duplicate ? true : undefined, value: item.key, disabled: locked, onChange: (event) => replace(index, { key: event.target.value }) }), type === 'boolean' ? (_jsxs("label", { className: "ctl-switch ctl-kv-cell", children: [_jsx("input", { type: "checkbox", className: "ctl-switch-box", "aria-label": `${headings.value} ${index + 1}`, checked: item.value === 'true', disabled: locked, onChange: (event) => replace(index, { value: event.target.checked ? 'true' : 'false' }) }), _jsx("span", { className: "ctl-switch-text", children: item.value === 'true' ? 'On' : 'Off' })] })) : (_jsx("input", { className: "ctl-input ctl-kv-cell", type: type === 'number' ? 'number' : 'text', step: type === 'number' ? 'any' : undefined, "aria-label": `${headings.value} ${index + 1}`, value: item.value, disabled: locked, onChange: (event) => replace(index, { value: event.target.value }) })), _jsxs("span", { className: "ctl-kv-actions", children: [_jsx("button", { type: "button", className: "ctl-icon-button", "aria-label": `Move ${headings.label} ${index + 1} up`, disabled: locked || index === 0, onClick: () => move(index, -1), children: _jsx(MoveUpIcon, { size: ICON_SIZE, "aria-hidden": "true" }) }), _jsx("button", { type: "button", className: "ctl-icon-button", "aria-label": `Move ${headings.label} ${index + 1} down`, disabled: locked || index === value.length - 1, onClick: () => move(index, 1), children: _jsx(MoveDownIcon, { size: ICON_SIZE, "aria-hidden": "true" }) }), _jsx("button", { type: "button", className: "ctl-icon-button", "aria-label": `Remove ${headings.label} ${index + 1}`, disabled: locked, onClick: () => onChange(value.filter((_, position) => position !== index)), children: _jsx(CloseIcon, { size: ICON_SIZE, "aria-hidden": "true" }) })] })] }, `${ids}-${index}`));
|
|
52
53
|
}), [...counts.entries()].some(([key, count]) => key !== '' && count > 1) && (_jsx("p", { className: "ctl-note ctl-error", role: "alert", children: "Two entries share a key. Only one of them will ever be read." })), !locked && (_jsxs("button", { type: "button", className: "ctl-link ctl-kv-add", onClick: add, children: ["+ ", addLabel] }))] }));
|
|
53
54
|
}
|
|
54
55
|
//# sourceMappingURL=KeyValueList.js.map
|
package/dist/KeyValueList.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"KeyValueList.js","sourceRoot":"","sources":["../src/KeyValueList.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"KeyValueList.js","sourceRoot":"","sources":["../src/KeyValueList.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAuC5E,MAAM,gBAAgB,GAAG,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAW,CAAC;AAEjF;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,YAAY,CAAC,EAC3B,KAAK,EACL,QAAQ,EACR,KAAK,EACL,QAAQ,GAAG,MAAM,EACjB,QAAQ,GAAG,gBAAgB,EAC3B,QAAQ,GAAG,UAAU,EACrB,QAAQ,EACR,QAAQ,EACR,UAAU,GAAG,eAAe,EAC5B,SAAS,EACT,KAAK,GAAG,OAAO,EACf,aAAa,EAAE,MAAM,GACH;IAClB,MAAM,GAAG,GAAG,KAAK,EAAE,CAAC;IACpB,MAAM,MAAM,GAAG,QAAQ,KAAK,IAAI,IAAI,QAAQ,KAAK,IAAI,CAAC;IAEtD,MAAM,MAAM,GAAG,IAAI,GAAG,EAAkB,CAAC;IACzC,KAAK,MAAM,IAAI,IAAI,KAAK;QAAE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,CAAC,EAAE,QAAQ,EAAE,EAAE,CAAC,QAAQ,KAAK,KAAK,CAAC,CAAC,YAE1E,KAAC,SAAS,IAAC,IAAI,EAAE,SAAS,iBAAc,MAAM,GAAG,GAC1C,IACJ,KAxEF,GAAG,GAAG,IAAI,KAAK,EAAE,CAyElB,CACP,CAAC;YACJ,CAAC,CAAC,EAED,CAAC,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,KAAK,EAAE,IAAI,KAAK,GAAG,CAAC,CAAC,IAAI,CACxE,YAAG,SAAS,EAAC,oBAAoB,EAAC,IAAI,EAAC,OAAO,6EAE1C,CACL,EAEA,CAAC,MAAM,IAAI,CACV,kBAAQ,IAAI,EAAC,QAAQ,EAAC,SAAS,EAAC,qBAAqB,EAAC,OAAO,EAAE,GAAG,mBAC7D,QAAQ,IACJ,CACV,IACG,CACP,CAAC;AACJ,CAAC"}
|
package/dist/Modal.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { ControlTheme } from './types.js';
|
|
3
|
+
export interface ModalProps {
|
|
4
|
+
/** The heading, and the accessible name when `labelledBy` is not given. */
|
|
5
|
+
title: string;
|
|
6
|
+
onClose(): void;
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
/** A row of actions pinned below the scrolling body. */
|
|
9
|
+
footer?: ReactNode;
|
|
10
|
+
/** Widen the panel for content that is mostly table, picture or stack trace. */
|
|
11
|
+
wide?: boolean;
|
|
12
|
+
/** Id of an element inside the panel that names it, when the title is not enough. */
|
|
13
|
+
labelledBy?: string;
|
|
14
|
+
className?: string;
|
|
15
|
+
theme?: ControlTheme;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The modal shell.
|
|
19
|
+
*
|
|
20
|
+
* Here rather than in each console for the reason this package exists: a dialog
|
|
21
|
+
* written twice is a dialog that behaves differently in two places, and the two
|
|
22
|
+
* differ in exactly the parts nobody reimplements — the focus trap, the focus
|
|
23
|
+
* *restore*, and the scroll lock. `file-console` carries an older `Dialog` of
|
|
24
|
+
* its own that predates this and should be folded in.
|
|
25
|
+
*
|
|
26
|
+
* What it does that a `<div>` does not:
|
|
27
|
+
*
|
|
28
|
+
* - closes on Escape, and on a click on the backdrop rather than on anything
|
|
29
|
+
* that merely bubbles out of the panel;
|
|
30
|
+
* - announces itself as a modal dialog, so a screen reader stops offering the
|
|
31
|
+
* page behind it;
|
|
32
|
+
* - traps `Tab` inside the panel. Without this the third Tab is on a filter
|
|
33
|
+
* box behind the overlay, focus is invisible, and a keyboard user is typing
|
|
34
|
+
* into a page they cannot see;
|
|
35
|
+
* - puts focus back where it came from on close. A record opened from a table
|
|
36
|
+
* row must return focus to that row, or the next `Tab` restarts from the
|
|
37
|
+
* top of the document and the operator loses their place in a long list;
|
|
38
|
+
* - stops the page behind from scrolling, so a wheel over the backdrop does
|
|
39
|
+
* not silently move the list the dialog was opened from.
|
|
40
|
+
*
|
|
41
|
+
* Rendered in place rather than through a portal, deliberately. A console
|
|
42
|
+
* bridges its own palette onto `--ctl-*` with a descendant selector
|
|
43
|
+
* (`.logc .ctl { --ctl-bg: … }`), and a portal to `document.body` escapes it —
|
|
44
|
+
* so a dark console would open a light dialog. `position: fixed` covers the
|
|
45
|
+
* viewport from wherever the element sits.
|
|
46
|
+
*/
|
|
47
|
+
export declare function Modal({ title, onClose, children, footer, wide, labelledBy, className, theme, }: ModalProps): import("react").JSX.Element;
|
|
48
|
+
//# sourceMappingURL=Modal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Modal.d.ts","sourceRoot":"","sources":["../src/Modal.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AACjE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,MAAM,WAAW,UAAU;IACzB,2EAA2E;IAC3E,KAAK,EAAE,MAAM,CAAC;IACd,OAAO,IAAI,IAAI,CAAC;IAChB,QAAQ,EAAE,SAAS,CAAC;IACpB,wDAAwD;IACxD,MAAM,CAAC,EAAE,SAAS,CAAC;IACnB,gFAAgF;IAChF,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,qFAAqF;IACrF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB;AAoCD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AACH,wBAAgB,KAAK,CAAC,EACpB,KAAK,EACL,OAAO,EACP,QAAQ,EACR,MAAM,EACN,IAAY,EACZ,UAAU,EACV,SAAS,EACT,KAAe,GAChB,EAAE,UAAU,+BA0IZ"}
|
package/dist/Modal.js
ADDED
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useId, useRef } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* The modals currently open, in the order they opened.
|
|
5
|
+
*
|
|
6
|
+
* Module scope, because two `<Modal>`s rendered from unrelated trees have no
|
|
7
|
+
* other way to agree about which of them is on top — and both of the things
|
|
8
|
+
* below need that answer:
|
|
9
|
+
*
|
|
10
|
+
* - **Escape.** Both instances listen on `document`, and `stopPropagation()`
|
|
11
|
+
* does not stop other listeners on the *same* node (that is
|
|
12
|
+
* `stopImmediatePropagation`), so one Escape closed both. Only the topmost
|
|
13
|
+
* acts on a key now.
|
|
14
|
+
* - **The scroll lock.** Each instance used to snapshot and restore
|
|
15
|
+
* `body.style.overflow` for itself. Nested, that happens to work; unmounted
|
|
16
|
+
* out of order it does not, and the first one to leave hands the page back
|
|
17
|
+
* its scrollbar while a dialog is still open over it.
|
|
18
|
+
*
|
|
19
|
+
* Kept as a plain array rather than a count so a non-LIFO teardown removes the
|
|
20
|
+
* right entry.
|
|
21
|
+
*/
|
|
22
|
+
const openModals = [];
|
|
23
|
+
/** What `body.style.overflow` was before the first modal took it. */
|
|
24
|
+
let releasedOverflow = '';
|
|
25
|
+
/** Everything a `Tab` can land on, in document order. */
|
|
26
|
+
const FOCUSABLE = [
|
|
27
|
+
'a[href]',
|
|
28
|
+
'button:not([disabled])',
|
|
29
|
+
'input:not([disabled])',
|
|
30
|
+
'select:not([disabled])',
|
|
31
|
+
'textarea:not([disabled])',
|
|
32
|
+
'[tabindex]:not([tabindex="-1"])',
|
|
33
|
+
].join(',');
|
|
34
|
+
/**
|
|
35
|
+
* The modal shell.
|
|
36
|
+
*
|
|
37
|
+
* Here rather than in each console for the reason this package exists: a dialog
|
|
38
|
+
* written twice is a dialog that behaves differently in two places, and the two
|
|
39
|
+
* differ in exactly the parts nobody reimplements — the focus trap, the focus
|
|
40
|
+
* *restore*, and the scroll lock. `file-console` carries an older `Dialog` of
|
|
41
|
+
* its own that predates this and should be folded in.
|
|
42
|
+
*
|
|
43
|
+
* What it does that a `<div>` does not:
|
|
44
|
+
*
|
|
45
|
+
* - closes on Escape, and on a click on the backdrop rather than on anything
|
|
46
|
+
* that merely bubbles out of the panel;
|
|
47
|
+
* - announces itself as a modal dialog, so a screen reader stops offering the
|
|
48
|
+
* page behind it;
|
|
49
|
+
* - traps `Tab` inside the panel. Without this the third Tab is on a filter
|
|
50
|
+
* box behind the overlay, focus is invisible, and a keyboard user is typing
|
|
51
|
+
* into a page they cannot see;
|
|
52
|
+
* - puts focus back where it came from on close. A record opened from a table
|
|
53
|
+
* row must return focus to that row, or the next `Tab` restarts from the
|
|
54
|
+
* top of the document and the operator loses their place in a long list;
|
|
55
|
+
* - stops the page behind from scrolling, so a wheel over the backdrop does
|
|
56
|
+
* not silently move the list the dialog was opened from.
|
|
57
|
+
*
|
|
58
|
+
* Rendered in place rather than through a portal, deliberately. A console
|
|
59
|
+
* bridges its own palette onto `--ctl-*` with a descendant selector
|
|
60
|
+
* (`.logc .ctl { --ctl-bg: … }`), and a portal to `document.body` escapes it —
|
|
61
|
+
* so a dark console would open a light dialog. `position: fixed` covers the
|
|
62
|
+
* viewport from wherever the element sits.
|
|
63
|
+
*/
|
|
64
|
+
export function Modal({ title, onClose, children, footer, wide = false, labelledBy, className, theme = 'light', }) {
|
|
65
|
+
const panel = useRef(null);
|
|
66
|
+
const titleId = useId();
|
|
67
|
+
// A stable identity for this instance, and the only thing `openModals` holds.
|
|
68
|
+
const self = useRef({}).current;
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
// Captured before focus moves into the panel below, which is the only
|
|
71
|
+
// moment the element that opened this dialog is still the active one.
|
|
72
|
+
const opener = document.activeElement;
|
|
73
|
+
// The panel itself, not the first control: focusing a text box scrolls a
|
|
74
|
+
// long dialog to it and reads the wrong thing to a screen reader.
|
|
75
|
+
panel.current?.focus();
|
|
76
|
+
return () => {
|
|
77
|
+
// `isConnected` because the opener is routinely a row in a list the close
|
|
78
|
+
// also removed, and focusing a detached node silently sends focus to
|
|
79
|
+
// `<body>` — the very thing this exists to avoid.
|
|
80
|
+
if (opener instanceof HTMLElement && opener.isConnected)
|
|
81
|
+
opener.focus();
|
|
82
|
+
};
|
|
83
|
+
}, []);
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
const onKeyDown = (event) => {
|
|
86
|
+
// Only the dialog on top responds. Both instances' listeners sit on
|
|
87
|
+
// `document`, so nothing either of them does to the event stops the
|
|
88
|
+
// other from seeing it.
|
|
89
|
+
if (openModals[openModals.length - 1] !== self)
|
|
90
|
+
return;
|
|
91
|
+
if (event.key === 'Escape') {
|
|
92
|
+
// Not what keeps a second dialog from closing — the check above is.
|
|
93
|
+
// This is for a host with its own Escape handler further out: a drawer
|
|
94
|
+
// behind the dialog should not close alongside it.
|
|
95
|
+
event.stopPropagation();
|
|
96
|
+
onClose();
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
if (event.key !== 'Tab' || panel.current === null)
|
|
100
|
+
return;
|
|
101
|
+
const focusable = [...panel.current.querySelectorAll(FOCUSABLE)];
|
|
102
|
+
// Nothing to cycle between: hold focus on the panel rather than letting
|
|
103
|
+
// it escape to the page underneath.
|
|
104
|
+
if (focusable.length === 0) {
|
|
105
|
+
event.preventDefault();
|
|
106
|
+
panel.current.focus();
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
const first = focusable[0];
|
|
110
|
+
const last = focusable[focusable.length - 1];
|
|
111
|
+
const active = document.activeElement;
|
|
112
|
+
// Only the two ends are intercepted. Everything in between is the
|
|
113
|
+
// browser's own tab order, which handles disabled controls, `tabindex`
|
|
114
|
+
// and shadow roots better than a hand-rolled walk ever does.
|
|
115
|
+
if (event.shiftKey && (active === first || active === panel.current)) {
|
|
116
|
+
event.preventDefault();
|
|
117
|
+
last.focus();
|
|
118
|
+
}
|
|
119
|
+
else if (!event.shiftKey && active === last) {
|
|
120
|
+
event.preventDefault();
|
|
121
|
+
first.focus();
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
document.addEventListener('keydown', onKeyDown);
|
|
125
|
+
return () => document.removeEventListener('keydown', onKeyDown);
|
|
126
|
+
}, [onClose]);
|
|
127
|
+
useEffect(() => {
|
|
128
|
+
openModals.push(self);
|
|
129
|
+
// The first one in takes the scrollbar and remembers what it interrupted —
|
|
130
|
+
// whatever was there rather than `''`, since a host that had set its own
|
|
131
|
+
// `overflow` on `<body>` must get that back and not the initial value.
|
|
132
|
+
if (openModals.length === 1) {
|
|
133
|
+
releasedOverflow = document.body.style.overflow;
|
|
134
|
+
document.body.style.overflow = 'hidden';
|
|
135
|
+
}
|
|
136
|
+
return () => {
|
|
137
|
+
const index = openModals.indexOf(self);
|
|
138
|
+
if (index !== -1)
|
|
139
|
+
openModals.splice(index, 1);
|
|
140
|
+
// And the last one out gives it back. Restoring per-instance instead lets
|
|
141
|
+
// the page scroll behind a dialog that is still open, whenever two of
|
|
142
|
+
// them close in the order they opened rather than the reverse.
|
|
143
|
+
if (openModals.length === 0)
|
|
144
|
+
document.body.style.overflow = releasedOverflow;
|
|
145
|
+
};
|
|
146
|
+
// Registration and the lock are one effect on purpose: separating them
|
|
147
|
+
// leaves an ordering between two `useEffect`s that has to stay right, and
|
|
148
|
+
// the failure would be a page that never scrolls again.
|
|
149
|
+
}, [self]);
|
|
150
|
+
return (_jsx("div", { className: "ctl ctl-modal-overlay", "data-ctl-theme": theme,
|
|
151
|
+
// A click on the backdrop, not on anything that happens to bubble out of
|
|
152
|
+
// the panel — `currentTarget` is what separates the two. `mousedown`
|
|
153
|
+
// rather than `click`, or a drag that starts on a text selection inside
|
|
154
|
+
// the panel and ends on the backdrop closes the dialog.
|
|
155
|
+
onMouseDown: (event) => {
|
|
156
|
+
if (event.target === event.currentTarget)
|
|
157
|
+
onClose();
|
|
158
|
+
}, children: _jsxs("div", { className: `ctl-modal${wide ? ' ctl-modal-wide' : ''}${className ? ` ${className}` : ''}`, role: "dialog", "aria-modal": "true", "aria-labelledby": labelledBy ?? titleId, tabIndex: -1, ref: panel, children: [_jsxs("div", { className: "ctl-modal-head", children: [_jsx("h2", { className: "ctl-modal-title", id: titleId, children: title }), _jsx("button", { type: "button", className: "ctl-modal-close", "aria-label": "Close", onClick: onClose, children: _jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: _jsx("path", { d: "M18 6 6 18M6 6l12 12", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" }) }) })] }), _jsx("div", { className: "ctl-modal-body", children: children }), footer !== undefined && _jsx("div", { className: "ctl-modal-foot", children: footer })] }) }));
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=Modal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Modal.js","sourceRoot":"","sources":["../src/Modal.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAkB,MAAM,OAAO,CAAC;AAkBjE;;;;;;;;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AAE,YAAY,IAAI,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,EAAE,GAAG,SAAS,CAAC,CAAC,CAAC,IAAI,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EACzF,IAAI,EAAC,QAAQ,gBACF,MAAM,qBACA,UAAU,IAAI,OAAO,EACtC,QAAQ,EAAE,CAAC,CAAC,EACZ,GAAG,EAAE,KAAK,aAEV,eAAK,SAAS,EAAC,gBAAgB,aAC7B,aAAI,SAAS,EAAC,iBAAiB,EAAC,EAAE,EAAE,OAAO,YACxC,KAAK,GACH,EACL,iBACE,IAAI,EAAC,QAAQ,EACb,SAAS,EAAC,iBAAiB,gBAChB,OAAO,EAClB,OAAO,EAAE,OAAO,YAEhB,cAAK,KAAK,EAAC,IAAI,EAAC,MAAM,EAAC,IAAI,EAAC,OAAO,EAAC,WAAW,EAAC,IAAI,EAAC,MAAM,iBAAa,MAAM,YAC5E,eACE,CAAC,EAAC,sBAAsB,EACxB,MAAM,EAAC,cAAc,EACrB,WAAW,EAAC,GAAG,EACf,aAAa,EAAC,OAAO,GACrB,GACE,GACC,IACL,EACN,cAAK,SAAS,EAAC,gBAAgB,YAAE,QAAQ,GAAO,EAC/C,MAAM,KAAK,SAAS,IAAI,cAAK,SAAS,EAAC,gBAAgB,YAAE,MAAM,GAAO,IACnE,GACF,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
import type { ControlTheme } from './types.js';
|
|
3
|
+
export interface PageHeaderProps {
|
|
4
|
+
/** What this screen is. Rendered at the given heading level. */
|
|
5
|
+
title: ReactNode;
|
|
6
|
+
/** One quiet line saying what you are looking at. */
|
|
7
|
+
lead?: ReactNode;
|
|
8
|
+
/** The number worth knowing, beside the title rather than under it. */
|
|
9
|
+
count?: number;
|
|
10
|
+
/** Buttons and filters that act on the whole screen. */
|
|
11
|
+
actions?: ReactNode;
|
|
12
|
+
/** Heading level. A console embedded in a page is rarely its `<h1>`. */
|
|
13
|
+
level?: 1 | 2 | 3;
|
|
14
|
+
className?: string;
|
|
15
|
+
theme?: ControlTheme;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* The header every screen has.
|
|
19
|
+
*
|
|
20
|
+
* "Every screen states what it is" is the rule this exists to make cheap: a
|
|
21
|
+
* title in medium weight and one muted line under it saying what you are
|
|
22
|
+
* looking at. Written per console it was got wrong per console — a heading with
|
|
23
|
+
* no lead, a lead that repeated the heading, a count buried in a filter bar —
|
|
24
|
+
* which is what a shared component fixes and a written-down rule does not.
|
|
25
|
+
*
|
|
26
|
+
* ```tsx
|
|
27
|
+
* <PageHeader
|
|
28
|
+
* title="Backups"
|
|
29
|
+
* count={runs.length}
|
|
30
|
+
* lead="Every dump and restore, newest first. A run is stored as Parquet in S3 and queryable from Athena."
|
|
31
|
+
* actions={<button onClick={start}>Back up now</button>}
|
|
32
|
+
* />
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare function PageHeader({ title, lead, count, actions, level, className, theme, }: PageHeaderProps): import("react").JSX.Element;
|
|
36
|
+
//# sourceMappingURL=PageHeader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PageHeader.d.ts","sourceRoot":"","sources":["../src/PageHeader.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,MAAM,WAAW,eAAe;IAC9B,gEAAgE;IAChE,KAAK,EAAE,SAAS,CAAC;IACjB,qDAAqD;IACrD,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,uEAAuE;IACvE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,wDAAwD;IACxD,OAAO,CAAC,EAAE,SAAS,CAAC;IACpB,wEAAwE;IACxE,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,YAAY,CAAC;CACtB;AAED;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,UAAU,CAAC,EACzB,KAAK,EACL,IAAI,EACJ,KAAK,EACL,OAAO,EACP,KAAS,EACT,SAAS,EACT,KAAe,GAChB,EAAE,eAAe,+BAoBjB"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* The header every screen has.
|
|
4
|
+
*
|
|
5
|
+
* "Every screen states what it is" is the rule this exists to make cheap: a
|
|
6
|
+
* title in medium weight and one muted line under it saying what you are
|
|
7
|
+
* looking at. Written per console it was got wrong per console — a heading with
|
|
8
|
+
* no lead, a lead that repeated the heading, a count buried in a filter bar —
|
|
9
|
+
* which is what a shared component fixes and a written-down rule does not.
|
|
10
|
+
*
|
|
11
|
+
* ```tsx
|
|
12
|
+
* <PageHeader
|
|
13
|
+
* title="Backups"
|
|
14
|
+
* count={runs.length}
|
|
15
|
+
* lead="Every dump and restore, newest first. A run is stored as Parquet in S3 and queryable from Athena."
|
|
16
|
+
* actions={<button onClick={start}>Back up now</button>}
|
|
17
|
+
* />
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
export function PageHeader({ title, lead, count, actions, level = 2, className, theme = 'light', }) {
|
|
21
|
+
const Heading = `h${level}`;
|
|
22
|
+
return (_jsxs("div", { className: `ctl ctl-page-head${className === undefined ? '' : ` ${className}`}`, "data-ctl-theme": theme, children: [_jsxs("div", { className: "ctl-page-heading", children: [_jsxs(Heading, { className: "ctl-page-title", children: [title, count !== undefined && (_jsx("span", { className: "ctl-page-count", children: count.toLocaleString() }))] }), lead !== undefined && _jsx("p", { className: "ctl-page-lead", children: lead })] }), actions !== undefined && _jsx("div", { className: "ctl-page-actions", children: actions })] }));
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=PageHeader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PageHeader.js","sourceRoot":"","sources":["../src/PageHeader.tsx"],"names":[],"mappings":";AAkBA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,UAAU,CAAC,EACzB,KAAK,EACL,IAAI,EACJ,KAAK,EACL,OAAO,EACP,KAAK,GAAG,CAAC,EACT,SAAS,EACT,KAAK,GAAG,OAAO,GACC;IAChB,MAAM,OAAO,GAAG,IAAI,KAAK,EAAwB,CAAC;IAElD,OAAO,CACL,eACE,SAAS,EAAE,oBAAoB,SAAS,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,SAAS,EAAE,EAAE,oBAC/D,KAAK,aAErB,eAAK,SAAS,EAAC,kBAAkB,aAC/B,MAAC,OAAO,IAAC,SAAS,EAAC,gBAAgB,aAChC,KAAK,EACL,KAAK,KAAK,SAAS,IAAI,CACtB,eAAM,SAAS,EAAC,gBAAgB,YAAE,KAAK,CAAC,cAAc,EAAE,GAAQ,CACjE,IACO,EACT,IAAI,KAAK,SAAS,IAAI,YAAG,SAAS,EAAC,eAAe,YAAE,IAAI,GAAK,IAC1D,EACL,OAAO,KAAK,SAAS,IAAI,cAAK,SAAS,EAAC,kBAAkB,YAAE,OAAO,GAAO,IACvE,CACP,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { ReactNode } from 'react';
|
|
2
|
+
export interface ProgressBarProps {
|
|
3
|
+
/** How far along, in the same unit as `total`. */
|
|
4
|
+
value: number;
|
|
5
|
+
/** The whole. A total of zero or less renders nothing: a bar with no
|
|
6
|
+
* denominator is a shape that means nothing. */
|
|
7
|
+
total: number;
|
|
8
|
+
/** The line above the bar — what the numbers are. */
|
|
9
|
+
label?: ReactNode;
|
|
10
|
+
/**
|
|
11
|
+
* Which direction "more" is.
|
|
12
|
+
*
|
|
13
|
+
* `progress` (the default) is work getting done, so a full bar is good and
|
|
14
|
+
* the ramp runs red → amber → green. `usage` is a budget being spent, so a
|
|
15
|
+
* full bar is bad and the ramp runs the other way. Getting this backwards is
|
|
16
|
+
* how a console shows a project 95% through its budget in reassuring green.
|
|
17
|
+
*/
|
|
18
|
+
meaning?: 'progress' | 'usage' | 'neutral';
|
|
19
|
+
/** Hide the percentage on the right of the meta line. */
|
|
20
|
+
hidePercent?: boolean;
|
|
21
|
+
className?: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A progress bar with a meaning.
|
|
25
|
+
*
|
|
26
|
+
* The reference dashboard colours every bar on one green → amber → red scale,
|
|
27
|
+
* which reads correctly for a goal and backwards for a budget — the two things
|
|
28
|
+
* it puts a bar on. Naming the direction is the fix, and it is the only reason
|
|
29
|
+
* this takes a prop beyond the two numbers.
|
|
30
|
+
*
|
|
31
|
+
* The bar is `<div role="progressbar">` rather than `<progress>`: the native
|
|
32
|
+
* element cannot be themed to the same shape across browsers, which is exactly
|
|
33
|
+
* the sort of "close enough" that makes one screen look unlike the rest.
|
|
34
|
+
*/
|
|
35
|
+
export declare function ProgressBar({ value, total, label, meaning, hidePercent, className, }: ProgressBarProps): import("react").JSX.Element | null;
|
|
36
|
+
//# sourceMappingURL=ProgressBar.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProgressBar.d.ts","sourceRoot":"","sources":["../src/ProgressBar.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,MAAM,WAAW,gBAAgB;IAC/B,kDAAkD;IAClD,KAAK,EAAE,MAAM,CAAC;IACd;qDACiD;IACjD,KAAK,EAAE,MAAM,CAAC;IACd,qDAAqD;IACrD,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,GAAG,SAAS,CAAC;IAC3C,yDAAyD;IACzD,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAYD;;;;;;;;;;;GAWG;AACH,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EACL,KAAK,EACL,KAAK,EACL,OAAoB,EACpB,WAAmB,EACnB,SAAS,GACV,EAAE,gBAAgB,sCAgClB"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/** The tone class for a percentage, given which direction "more" is. */
|
|
3
|
+
function tone(percent, meaning) {
|
|
4
|
+
if (meaning === 'neutral')
|
|
5
|
+
return '';
|
|
6
|
+
const good = meaning === 'progress' ? percent >= 70 : percent < 70;
|
|
7
|
+
const bad = meaning === 'progress' ? percent < 30 : percent >= 90;
|
|
8
|
+
if (bad)
|
|
9
|
+
return ' ctl-progress-danger';
|
|
10
|
+
if (good)
|
|
11
|
+
return ' ctl-progress-ok';
|
|
12
|
+
return ' ctl-progress-warn';
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A progress bar with a meaning.
|
|
16
|
+
*
|
|
17
|
+
* The reference dashboard colours every bar on one green → amber → red scale,
|
|
18
|
+
* which reads correctly for a goal and backwards for a budget — the two things
|
|
19
|
+
* it puts a bar on. Naming the direction is the fix, and it is the only reason
|
|
20
|
+
* this takes a prop beyond the two numbers.
|
|
21
|
+
*
|
|
22
|
+
* The bar is `<div role="progressbar">` rather than `<progress>`: the native
|
|
23
|
+
* element cannot be themed to the same shape across browsers, which is exactly
|
|
24
|
+
* the sort of "close enough" that makes one screen look unlike the rest.
|
|
25
|
+
*/
|
|
26
|
+
export function ProgressBar({ value, total, label, meaning = 'progress', hidePercent = false, className, }) {
|
|
27
|
+
if (!Number.isFinite(total) || total <= 0 || !Number.isFinite(value))
|
|
28
|
+
return null;
|
|
29
|
+
const percent = Math.max(0, (value / total) * 100);
|
|
30
|
+
// The number can exceed the whole — a budget goes over — and the bar cannot.
|
|
31
|
+
const width = Math.min(percent, 100);
|
|
32
|
+
return (_jsxs("div", { className: `ctl-progress${tone(percent, meaning)}${className === undefined ? '' : ` ${className}`}`, children: [(label !== undefined || !hidePercent) && (_jsxs("div", { className: "ctl-progress-meta", children: [_jsx("span", { children: label }), !hidePercent && _jsxs("span", { children: [Math.round(percent), "%"] })] })), _jsx("div", { className: "ctl-progress-track", role: "progressbar", "aria-valuenow": Math.round(width), "aria-valuemin": 0, "aria-valuemax": 100, ...(percent > 100 ? { 'aria-valuetext': `${Math.round(percent)}%` } : {}), children: _jsx("div", { className: "ctl-progress-fill", style: { width: `${width}%` } }) })] }));
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=ProgressBar.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProgressBar.js","sourceRoot":"","sources":["../src/ProgressBar.tsx"],"names":[],"mappings":";AAwBA,wEAAwE;AACxE,SAAS,IAAI,CAAC,OAAe,EAAE,OAAyC;IACtE,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,EAAE,CAAC;IACrC,MAAM,IAAI,GAAG,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC,OAAO,GAAG,EAAE,CAAC;IACnE,MAAM,GAAG,GAAG,OAAO,KAAK,UAAU,CAAC,CAAC,CAAC,OAAO,GAAG,EAAE,CAAC,CAAC,CAAC,OAAO,IAAI,EAAE,CAAC;IAClE,IAAI,GAAG;QAAE,OAAO,sBAAsB,CAAC;IACvC,IAAI,IAAI;QAAE,OAAO,kBAAkB,CAAC;IACpC,OAAO,oBAAoB,CAAC;AAC9B,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,WAAW,CAAC,EAC1B,KAAK,EACL,KAAK,EACL,KAAK,EACL,OAAO,GAAG,UAAU,EACpB,WAAW,GAAG,KAAK,EACnB,SAAS,GACQ;IACjB,IAAI,CAAC,M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],"mappings":"AAAA,OAAO,EAA6D,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"SearchableMultiSelect.d.ts","sourceRoot":"","sources":["../src/SearchableMultiSelect.tsx"],"names":[],"mappings":"AAAA,OAAO,EAA6D,KAAK,SAAS,EAAE,MAAM,OAAO,CAAC;AAGlG,OAAO,EAA2C,KAAK,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC5G,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEvD,MAAM,WAAW,0BAA2B,SAAQ,sBAAsB;IACxE,2EAA2E;IAC3E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sDAAsD;IACtD,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,sCAAsC;IACtC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB;;;;;;OAMG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,YAAY,CAAC;IACrB,8EAA8E;IAC9E,YAAY,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACvD,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,qBAAqB,CAAC,EACpC,KAAK,EACL,WAAmB,EACnB,iBAA6B,EAC7B,KAAK,EACL,IAAI,EACJ,SAAS,EACT,KAAe,EACf,YAAY,EACZ,aAAa,EAAE,MAAM,EACrB,GAAG,OAAO,EACX,EAAE,0BAA0B,+BAkO5B"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { useCallback, useEffect, useId, useRef } from 'react';
|
|
3
3
|
import { groupOptions, highlightParts } from '@speles7172/controls-client/core';
|
|
4
|
+
import { CheckedIcon, ChevronDownIcon, CloseIcon, UncheckedIcon, ICON_SIZE } from './icons.js';
|
|
4
5
|
import { useOptionSelect } from './useOptionSelect.js';
|
|
5
6
|
/**
|
|
6
7
|
* A multi-select you can search.
|
|
@@ -115,7 +116,7 @@ export function SearchableMultiSelect({ label, placeholder = 'All', searchPlaceh
|
|
|
115
116
|
// the popover it just emptied.
|
|
116
117
|
event.stopPropagation();
|
|
117
118
|
state.clear();
|
|
118
|
-
}, children: "
|
|
119
|
+
}, children: _jsx(CloseIcon, { size: 14, "aria-hidden": "true" }) })), _jsx("span", { "aria-hidden": "true", className: "ctl-caret", children: _jsx(ChevronDownIcon, { size: ICON_SIZE }) })] })] }), showChips && state.selected.length > 1 && (_jsx("ul", { className: "ctl-chips", "data-testid": testId === undefined ? undefined : `${testId}-chips`, children: state.selected.map((option) => (_jsxs("li", { className: "ctl-chip", children: [_jsx("span", { className: "ctl-chip-label", title: option.description ?? option.label, children: option.label }), _jsx("button", { type: "button", className: "ctl-chip-remove", "aria-label": `Remove ${option.label}`, disabled: state.disabled, onClick: () => state.toggle(option.value), children: _jsx(CloseIcon, { size: 12, "aria-hidden": "true" }) })] }, option.value))) })), open && (_jsxs("div", { className: "ctl-popover", children: [_jsx("div", { className: "ctl-search", children: _jsx("input", { ref: searchRef, type: "text", className: "ctl-search-input", value: state.term, placeholder: searchPlaceholder, "aria-label": label === undefined ? 'Search options' : `Search ${label}`,
|
|
119
120
|
// The combobox is the search box while the popover is open: it is
|
|
120
121
|
// what has focus, so it is what must own `aria-activedescendant`.
|
|
121
122
|
role: "combobox", "aria-autocomplete": "list", "aria-expanded": true, "aria-controls": `${ids}-list`, "aria-activedescendant": activeIndex >= 0 ? cssId(ids, activeIndex) : undefined, onChange: (event) => state.setTerm(event.target.value), "data-testid": testId === undefined ? undefined : `${testId}-search` }) }), _jsx(OptionList, { state: state, ids: ids, listRef: listRef, renderOption: renderOption, testId: testId }), _jsxs("div", { className: "ctl-popover-footer", children: [state.hasMore && (_jsx("button", { type: "button", className: "ctl-link", onClick: state.showMore, children: "Show more" })), !options.single && state.options.length > 0 && !state.atLimit && (_jsx("button", { type: "button", className: "ctl-link", onClick: state.selectListed, children: "Select these" })), state.selected.length > 0 && state.clearable && (_jsx("button", { type: "button", className: "ctl-link", onClick: state.clear, children: "Clear" }))] })] })), name !== undefined &&
|
|
@@ -155,7 +156,7 @@ function OptionRow({ option, index, ids, state, renderOption, testId, }) {
|
|
|
155
156
|
onMouseMove: () => state.setActiveIndex(index), onClick: () => {
|
|
156
157
|
if (!blocked)
|
|
157
158
|
state.toggle(option.value);
|
|
158
|
-
}, "data-testid": testId === undefined ? undefined : `${testId}-option-${option.value}`, children: [_jsx("span", { className: "ctl-check", "aria-hidden": "true", children: selected ?
|
|
159
|
+
}, "data-testid": testId === undefined ? undefined : `${testId}-option-${option.value}`, children: [_jsx("span", { className: "ctl-check", "aria-hidden": "true", children: selected ? _jsx(CheckedIcon, { size: ICON_SIZE }) : _jsx(UncheckedIcon, { size: ICON_SIZE }) }), _jsx("span", { className: "ctl-option-text", children: renderOption === undefined ? (_jsxs(_Fragment, { children: [_jsx("span", { className: "ctl-option-label", children: highlight(option.label, state.appliedTerm) }), option.description !== undefined && (_jsx("span", { className: "ctl-option-description", children: highlight(option.description, state.appliedTerm) }))] })) : (renderOption(option, state.appliedTerm)) })] }));
|
|
159
160
|
}
|
|
160
161
|
/** The matched run of a label, marked. */
|
|
161
162
|
function highlight(text, term) {
|