@crewlethq/ui 0.149.0 → 0.150.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/DataGrid/index.js +2 -1
- package/dist/DurationField/DurationField.d.ts +59 -0
- package/dist/DurationField/index.d.ts +3 -0
- package/dist/DurationField/index.js +32 -0
- package/dist/DurationField-TJFIAUMW.css +23 -0
- package/dist/LinkInterstitial/index.js +2 -2
- package/dist/NumberField/NumberField.d.ts +56 -0
- package/dist/NumberField/index.d.ts +3 -0
- package/dist/NumberField/index.js +29 -0
- package/dist/NumberField-G7H4VNZP.css +30 -0
- package/dist/OrgTable/index.js +4 -3
- package/dist/PresetChips/PresetChips.d.ts +27 -0
- package/dist/PresetChips/index.d.ts +2 -0
- package/dist/PresetChips/index.js +21 -0
- package/dist/RailList/index.js +3 -3
- package/dist/SettingForm/SettingForm.d.ts +50 -0
- package/dist/SettingForm/index.d.ts +3 -0
- package/dist/SettingForm/index.js +20 -0
- package/dist/SettingForm-ODVZZ7JZ.css +30 -0
- package/dist/SettingsTable/SettingsTable.d.ts +47 -34
- package/dist/SettingsTable/index.d.ts +3 -2
- package/dist/SettingsTable/index.js +3 -1
- package/dist/SettingsTable-KAMWVCQB.css +169 -0
- package/dist/SheetColumnEditor/index.js +1 -1
- package/dist/TreeGrid/index.js +3 -2
- package/dist/{chunk-5C7MP4C7.js → chunk-3Q5USPLM.js} +1 -1
- package/dist/chunk-6QWSGM4W.js +21 -0
- package/dist/chunk-BQMDD2FD.js +224 -0
- package/dist/chunk-DDGHRDGV.js +134 -0
- package/dist/chunk-HU56GCZ7.js +198 -0
- package/dist/chunk-NG6GEBSJ.js +53 -0
- package/dist/chunk-OX332RI7.js +127 -0
- package/dist/{chunk-3SUIU2ZO.js → chunk-Q3SHCEXN.js} +5 -194
- package/dist/{chunk-O3CY4MHN.js → chunk-RUKSDKG5.js} +2 -1
- package/dist/generated/index.d.ts +4 -0
- package/dist/generated/index.js +65 -60
- package/dist/index.js +65 -60
- package/dist/styles.css +166 -87
- package/package.json +3 -3
- package/dist/SettingsTable-MTZJTKA6.css +0 -182
- package/dist/chunk-RTMFZLU3.js +0 -94
- package/dist/{chunk-II7TPQ64.js → chunk-2DASEYUG.js} +0 -0
- package/dist/{chunk-UPQ4MDPE.js → chunk-733FZXNS.js} +1 -1
- package/dist/{chunk-3GWCWUSY.js → chunk-ECYA6XZL.js} +1 -1
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* SettingsTable: DataGrid's head, rows, cells, hairlines and hover (its
|
|
3
|
+
* classes), on tracks of its own. Only what is a setting's lives here.
|
|
4
|
+
*
|
|
5
|
+
* THE TRACKS ARE FRACTIONS OF THE TABLE and the controls' track a fixed width,
|
|
6
|
+
* so tables of one width stacked down a page share every column line. Each
|
|
7
|
+
* row is its own grid on them, so one long label never moves another row.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
.crewlet-settings-table {
|
|
11
|
+
/* Two small controls at the row's end: a reset, then the pencil. */
|
|
12
|
+
--crewlet-settings-table-actions: calc(var(--size-control-sm) * 2 + var(--spacing-1));
|
|
13
|
+
|
|
14
|
+
container: crewlet-settings-table / inline-size;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.crewlet-settings-table > .crewlet-data-grid__head,
|
|
18
|
+
.crewlet-settings-table .crewlet-settings-table__row {
|
|
19
|
+
grid-template-columns:
|
|
20
|
+
var(--crewlet-settings-table-columns, minmax(0, 5fr) minmax(0, 3fr) minmax(0, 2fr))
|
|
21
|
+
calc(var(--crewlet-settings-table-actions) + var(--spacing-3) + var(--crewlet-data-grid-edge));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/* A setting's row is read, not opened: no pointer that promises a page. */
|
|
25
|
+
.crewlet-settings-table .crewlet-settings-table__row {
|
|
26
|
+
cursor: auto;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.crewlet-settings-table__head--hidden {
|
|
30
|
+
position: absolute;
|
|
31
|
+
width: 1px;
|
|
32
|
+
height: 1px;
|
|
33
|
+
margin: -1px;
|
|
34
|
+
padding: 0;
|
|
35
|
+
border: 0;
|
|
36
|
+
overflow: hidden;
|
|
37
|
+
clip-path: inset(50%);
|
|
38
|
+
white-space: nowrap;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.crewlet-settings-table__setting {
|
|
42
|
+
gap: var(--spacing-1);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.crewlet-settings-table__label {
|
|
46
|
+
min-width: 0;
|
|
47
|
+
color: var(--color-text-primary);
|
|
48
|
+
line-height: var(--font-line-height-snug);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/* The key's copy control, after the name; its box never sets the row's height. */
|
|
52
|
+
.crewlet-settings-table__key {
|
|
53
|
+
display: inline-flex;
|
|
54
|
+
align-items: center;
|
|
55
|
+
flex-shrink: 0;
|
|
56
|
+
height: calc(1em * var(--font-line-height-snug));
|
|
57
|
+
color: var(--color-text-tertiary);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/* Where a pointer can hover, the key shows with its row, its focus or a copy's outcome. */
|
|
61
|
+
@media (hover: hover) {
|
|
62
|
+
.crewlet-settings-table__key {
|
|
63
|
+
opacity: 0;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
.crewlet-settings-table__row:is(:hover, :focus-within) .crewlet-settings-table__key,
|
|
67
|
+
.crewlet-settings-table__key:not([data-copy='idle']) {
|
|
68
|
+
opacity: 1;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
@media (hover: hover) and (prefers-reduced-motion: no-preference) {
|
|
73
|
+
.crewlet-settings-table__key {
|
|
74
|
+
transition: opacity var(--motion-duration-fast) var(--motion-easing-default);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/* Tabular figures, so a column of numbers reads down its digits. */
|
|
79
|
+
.crewlet-settings-table__value {
|
|
80
|
+
flex-wrap: wrap;
|
|
81
|
+
color: var(--color-text-primary);
|
|
82
|
+
font-weight: var(--font-weight-medium);
|
|
83
|
+
font-variant-numeric: tabular-nums;
|
|
84
|
+
overflow-wrap: anywhere;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
.crewlet-settings-table__source {
|
|
88
|
+
font-size: var(--font-size-xs);
|
|
89
|
+
color: var(--color-text-tertiary);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/* A value that differs from its default is the row a reader came to find. */
|
|
93
|
+
.crewlet-settings-table__source--changed {
|
|
94
|
+
color: var(--color-text-secondary);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/* The controls at the row's end: the pencil last, on one line down the page. */
|
|
98
|
+
.crewlet-settings-table__actions {
|
|
99
|
+
justify-content: flex-end;
|
|
100
|
+
gap: var(--spacing-1);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/* THE RESET'S QUESTION takes the source's and the controls' tracks while it is asked. */
|
|
104
|
+
.crewlet-settings-table__confirm {
|
|
105
|
+
grid-column: 3 / -1;
|
|
106
|
+
justify-content: flex-end;
|
|
107
|
+
gap: var(--spacing-1);
|
|
108
|
+
padding-inline-end: var(--crewlet-data-grid-edge);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.crewlet-settings-table__question {
|
|
112
|
+
margin-inline-end: var(--spacing-1);
|
|
113
|
+
min-width: 0;
|
|
114
|
+
font-size: var(--font-size-xs);
|
|
115
|
+
color: var(--color-text-secondary);
|
|
116
|
+
overflow-wrap: anywhere;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/*
|
|
120
|
+
* NARROW: the name and its controls take the first line, the value and its
|
|
121
|
+
* source the second. Three columns here wrap every name a word to a line.
|
|
122
|
+
*/
|
|
123
|
+
@container crewlet-settings-table (width < 32rem) {
|
|
124
|
+
.crewlet-settings-table > .crewlet-data-grid__head {
|
|
125
|
+
position: absolute;
|
|
126
|
+
width: 1px;
|
|
127
|
+
height: 1px;
|
|
128
|
+
overflow: hidden;
|
|
129
|
+
clip-path: inset(50%);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
.crewlet-settings-table .crewlet-settings-table__row {
|
|
133
|
+
grid-template-columns: minmax(0, 1fr) auto;
|
|
134
|
+
column-gap: var(--spacing-3);
|
|
135
|
+
row-gap: var(--spacing-1);
|
|
136
|
+
padding: var(--spacing-2) var(--crewlet-data-grid-edge);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
.crewlet-settings-table__row > .crewlet-data-grid__cell {
|
|
140
|
+
padding: 0;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
.crewlet-settings-table__setting {
|
|
144
|
+
grid-column: 1;
|
|
145
|
+
grid-row: 1;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
.crewlet-settings-table__actions {
|
|
149
|
+
grid-column: 2;
|
|
150
|
+
grid-row: 1;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.crewlet-settings-table__value {
|
|
154
|
+
grid-column: 1;
|
|
155
|
+
grid-row: 2;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.crewlet-settings-table__source {
|
|
159
|
+
grid-column: 2;
|
|
160
|
+
grid-row: 2;
|
|
161
|
+
justify-content: flex-end;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.crewlet-settings-table__confirm {
|
|
165
|
+
grid-column: 1 / -1;
|
|
166
|
+
grid-row: 3;
|
|
167
|
+
padding: 0;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { SHEET_COLUMN_EDITOR_LABELS, SheetColumnEditor, SheetColumnTypeGlyph } from '../chunk-M4VA76JF.js';
|
|
2
|
-
import '../chunk-657WR3MX.js';
|
|
3
2
|
import '../chunk-FFMCMSJB.js';
|
|
3
|
+
import '../chunk-657WR3MX.js';
|
|
4
4
|
import '../chunk-KW7T23RT.js';
|
|
5
5
|
import '../chunk-LFSIKGRQ.js';
|
|
6
6
|
import '../chunk-Z7JYG5TF.js';
|
package/dist/TreeGrid/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export { TreeGrid } from '../chunk-
|
|
1
|
+
export { TreeGrid } from '../chunk-RUKSDKG5.js';
|
|
2
2
|
import '../chunk-MY374UUD.js';
|
|
3
|
-
import '../chunk-
|
|
3
|
+
import '../chunk-Q3SHCEXN.js';
|
|
4
|
+
import '../chunk-HU56GCZ7.js';
|
|
4
5
|
import '../chunk-CUEPPDBC.js';
|
|
5
6
|
import '../chunk-WFAJYBLX.js';
|
|
6
7
|
import '../chunk-WSIJDWUG.js';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SegmentedControl } from './chunk-GMXOZEF5.js';
|
|
2
|
+
import { cx } from './chunk-ODEQTPFM.js';
|
|
3
|
+
import { jsx } from 'react/jsx-runtime';
|
|
4
|
+
|
|
5
|
+
function PresetChips({ label, options, value, onPick, disabled = false, className }) {
|
|
6
|
+
return /* @__PURE__ */ jsx(
|
|
7
|
+
SegmentedControl,
|
|
8
|
+
{
|
|
9
|
+
semantics: "radio",
|
|
10
|
+
layout: "chips",
|
|
11
|
+
size: "sm",
|
|
12
|
+
label,
|
|
13
|
+
className: cx("crewlet-preset-chips", className),
|
|
14
|
+
options: options.map((option) => ({ value: option.value, label: option.label, disabled })),
|
|
15
|
+
value,
|
|
16
|
+
onValueChange: onPick
|
|
17
|
+
}
|
|
18
|
+
);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export { PresetChips };
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import { GridHeadCell } from './chunk-HU56GCZ7.js';
|
|
2
|
+
import { copyGlyph, CopyStatus } from './chunk-IRGS5FEC.js';
|
|
3
|
+
import { useClipboard } from './chunk-STJ7QBC3.js';
|
|
4
|
+
import { StatusDot } from './chunk-QRE6JCHS.js';
|
|
5
|
+
import { Button } from './chunk-IMF3CPTY.js';
|
|
6
|
+
import { IconButton } from './chunk-KM5OKCW6.js';
|
|
7
|
+
import { returnFocus } from './chunk-4ITETIGZ.js';
|
|
8
|
+
import { cx } from './chunk-ODEQTPFM.js';
|
|
9
|
+
import './DataGrid-XX6ALDIM.css';
|
|
10
|
+
import './SettingsTable-KAMWVCQB.css';
|
|
11
|
+
import { useState, useRef, useLayoutEffect } from 'react';
|
|
12
|
+
import { RotateCcwGlyph } from '@crewlethq/icons/glyphs';
|
|
13
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
14
|
+
|
|
15
|
+
var COLUMNS = {
|
|
16
|
+
setting: "Setting",
|
|
17
|
+
value: "Value",
|
|
18
|
+
source: "Source",
|
|
19
|
+
actions: "Actions"
|
|
20
|
+
};
|
|
21
|
+
var noSort = () => void 0;
|
|
22
|
+
function SettingsTable({ header = true, columns, className, children, ...rest }) {
|
|
23
|
+
const names = { ...COLUMNS, ...columns };
|
|
24
|
+
return /* @__PURE__ */ jsxs("div", { ...rest, role: "table", className: cx("crewlet-data-grid", "crewlet-settings-table", className), children: [
|
|
25
|
+
/* @__PURE__ */ jsxs(
|
|
26
|
+
"div",
|
|
27
|
+
{
|
|
28
|
+
role: "row",
|
|
29
|
+
className: cx(
|
|
30
|
+
"crewlet-data-grid__head",
|
|
31
|
+
"crewlet-settings-table__head",
|
|
32
|
+
!header && "crewlet-settings-table__head--hidden"
|
|
33
|
+
),
|
|
34
|
+
children: [
|
|
35
|
+
/* @__PURE__ */ jsx(GridHeadCell, { column: { key: "setting", header: names.setting }, sort: null, sortable: false, onSort: noSort }),
|
|
36
|
+
/* @__PURE__ */ jsx(GridHeadCell, { column: { key: "value", header: names.value }, sort: null, sortable: false, onSort: noSort }),
|
|
37
|
+
/* @__PURE__ */ jsx(GridHeadCell, { column: { key: "source", header: names.source }, sort: null, sortable: false, onSort: noSort }),
|
|
38
|
+
/* @__PURE__ */ jsx(
|
|
39
|
+
GridHeadCell,
|
|
40
|
+
{
|
|
41
|
+
column: { key: "actions", header: "", action: true, label: names.actions },
|
|
42
|
+
sort: null,
|
|
43
|
+
sortable: false,
|
|
44
|
+
onSort: noSort
|
|
45
|
+
}
|
|
46
|
+
)
|
|
47
|
+
]
|
|
48
|
+
}
|
|
49
|
+
),
|
|
50
|
+
/* @__PURE__ */ jsx("div", { role: "rowgroup", className: "crewlet-data-grid__body crewlet-settings-table__body", children })
|
|
51
|
+
] });
|
|
52
|
+
}
|
|
53
|
+
var SETTINGS_TABLE_ROW_LABELS = {
|
|
54
|
+
reset: "Reset to default",
|
|
55
|
+
confirm: (defaultLabel) => defaultLabel === void 0 || defaultLabel === null ? "Reset to the default?" : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
56
|
+
"Reset to ",
|
|
57
|
+
defaultLabel,
|
|
58
|
+
"?"
|
|
59
|
+
] }),
|
|
60
|
+
confirmReset: "Reset",
|
|
61
|
+
cancel: "Cancel"
|
|
62
|
+
};
|
|
63
|
+
function SettingsTableRow({
|
|
64
|
+
label,
|
|
65
|
+
settingKey,
|
|
66
|
+
source,
|
|
67
|
+
changed = false,
|
|
68
|
+
actions,
|
|
69
|
+
onReset,
|
|
70
|
+
defaultLabel,
|
|
71
|
+
resetHeld,
|
|
72
|
+
labels: overrides,
|
|
73
|
+
className,
|
|
74
|
+
children,
|
|
75
|
+
...rest
|
|
76
|
+
}) {
|
|
77
|
+
const labels = { ...SETTINGS_TABLE_ROW_LABELS, ...overrides };
|
|
78
|
+
const offered = changed && onReset !== void 0;
|
|
79
|
+
const [asking, setAsking] = useState(false);
|
|
80
|
+
const confirming = asking && offered;
|
|
81
|
+
const resetButton = useRef(null);
|
|
82
|
+
const confirmButton = useRef(null);
|
|
83
|
+
const actionsCell = useRef(null);
|
|
84
|
+
const settleFocus = useRef(false);
|
|
85
|
+
const resetHeldFocus = useRef(false);
|
|
86
|
+
useLayoutEffect(() => {
|
|
87
|
+
if (confirming) {
|
|
88
|
+
confirmButton.current?.focus();
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (!settleFocus.current && !(resetHeldFocus.current && !offered)) return;
|
|
92
|
+
settleFocus.current = false;
|
|
93
|
+
resetHeldFocus.current = false;
|
|
94
|
+
returnFocus(resetButton.current ?? actionsCell.current?.querySelector("button") ?? null);
|
|
95
|
+
}, [confirming, offered]);
|
|
96
|
+
const close = (reset) => {
|
|
97
|
+
settleFocus.current = true;
|
|
98
|
+
setAsking(false);
|
|
99
|
+
if (reset) onReset?.();
|
|
100
|
+
};
|
|
101
|
+
const keys = (event) => {
|
|
102
|
+
if (event.key !== "Escape") return;
|
|
103
|
+
event.preventDefault();
|
|
104
|
+
event.stopPropagation();
|
|
105
|
+
close(false);
|
|
106
|
+
};
|
|
107
|
+
const leave = (event) => {
|
|
108
|
+
if (event.relatedTarget instanceof Node && event.currentTarget.contains(event.relatedTarget)) return;
|
|
109
|
+
setAsking(false);
|
|
110
|
+
};
|
|
111
|
+
return /* @__PURE__ */ jsxs(
|
|
112
|
+
"div",
|
|
113
|
+
{
|
|
114
|
+
...rest,
|
|
115
|
+
role: "row",
|
|
116
|
+
"data-changed": changed ? "" : void 0,
|
|
117
|
+
"data-confirming": confirming ? "" : void 0,
|
|
118
|
+
className: cx("crewlet-data-grid__row", "crewlet-settings-table__row", className),
|
|
119
|
+
children: [
|
|
120
|
+
/* @__PURE__ */ jsxs("div", { role: "rowheader", className: "crewlet-data-grid__cell crewlet-settings-table__setting", children: [
|
|
121
|
+
/* @__PURE__ */ jsx("span", { className: "crewlet-settings-table__label", children: label }),
|
|
122
|
+
settingKey === void 0 ? null : /* @__PURE__ */ jsx(SettingKey, { settingKey })
|
|
123
|
+
] }),
|
|
124
|
+
/* @__PURE__ */ jsx("div", { role: "cell", className: "crewlet-data-grid__cell crewlet-settings-table__value", children }),
|
|
125
|
+
confirming ? (
|
|
126
|
+
// The question's own keys and focus: Escape answers no, and leaving it puts it away.
|
|
127
|
+
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
|
|
128
|
+
/* @__PURE__ */ jsxs(
|
|
129
|
+
"div",
|
|
130
|
+
{
|
|
131
|
+
role: "cell",
|
|
132
|
+
className: "crewlet-data-grid__cell crewlet-settings-table__confirm",
|
|
133
|
+
onKeyDown: keys,
|
|
134
|
+
onBlur: leave,
|
|
135
|
+
children: [
|
|
136
|
+
/* @__PURE__ */ jsx("span", { className: "crewlet-settings-table__question", children: labels.confirm(defaultLabel) }),
|
|
137
|
+
/* @__PURE__ */ jsx(Button, { type: "button", size: "small", variant: "ghost", onClick: () => close(false), children: labels.cancel }),
|
|
138
|
+
/* @__PURE__ */ jsx(Button, { ref: confirmButton, type: "button", size: "small", variant: "secondary", onClick: () => close(true), children: labels.confirmReset })
|
|
139
|
+
]
|
|
140
|
+
}
|
|
141
|
+
)
|
|
142
|
+
) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
143
|
+
/* @__PURE__ */ jsxs(
|
|
144
|
+
"div",
|
|
145
|
+
{
|
|
146
|
+
role: "cell",
|
|
147
|
+
className: cx(
|
|
148
|
+
"crewlet-data-grid__cell",
|
|
149
|
+
"crewlet-settings-table__source",
|
|
150
|
+
changed && "crewlet-settings-table__source--changed"
|
|
151
|
+
),
|
|
152
|
+
children: [
|
|
153
|
+
changed ? /* @__PURE__ */ jsx(StatusDot, { tone: "brand" }) : null,
|
|
154
|
+
source
|
|
155
|
+
]
|
|
156
|
+
}
|
|
157
|
+
),
|
|
158
|
+
/* @__PURE__ */ jsxs(
|
|
159
|
+
"div",
|
|
160
|
+
{
|
|
161
|
+
ref: actionsCell,
|
|
162
|
+
role: "cell",
|
|
163
|
+
className: "crewlet-data-grid__cell crewlet-data-grid__cell--action crewlet-settings-table__actions",
|
|
164
|
+
children: [
|
|
165
|
+
offered ? /* @__PURE__ */ jsx(
|
|
166
|
+
IconButton,
|
|
167
|
+
{
|
|
168
|
+
ref: resetButton,
|
|
169
|
+
size: "sm",
|
|
170
|
+
variant: "ghost",
|
|
171
|
+
icon: /* @__PURE__ */ jsx(RotateCcwGlyph, {}),
|
|
172
|
+
label: labels.reset,
|
|
173
|
+
tooltip: true,
|
|
174
|
+
disabledReason: resetHeld,
|
|
175
|
+
onFocus: () => {
|
|
176
|
+
resetHeldFocus.current = true;
|
|
177
|
+
},
|
|
178
|
+
onBlur: () => {
|
|
179
|
+
resetHeldFocus.current = false;
|
|
180
|
+
},
|
|
181
|
+
onClick: () => {
|
|
182
|
+
if (resetHeld === void 0) setAsking(true);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
) : null,
|
|
186
|
+
actions
|
|
187
|
+
]
|
|
188
|
+
}
|
|
189
|
+
)
|
|
190
|
+
] })
|
|
191
|
+
]
|
|
192
|
+
}
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
SettingsTable.Row = SettingsTableRow;
|
|
196
|
+
function SettingKey({ settingKey }) {
|
|
197
|
+
const { state, attempt, copy } = useClipboard({ failedResetMs: null });
|
|
198
|
+
return /* @__PURE__ */ jsxs("span", { className: "crewlet-settings-table__key", "data-copy": state, children: [
|
|
199
|
+
/* @__PURE__ */ jsx(
|
|
200
|
+
IconButton,
|
|
201
|
+
{
|
|
202
|
+
size: "sm",
|
|
203
|
+
variant: "ghost",
|
|
204
|
+
icon: copyGlyph(state),
|
|
205
|
+
label: `Copy the setting's key, ${settingKey}`,
|
|
206
|
+
tooltip: settingKey,
|
|
207
|
+
onClick: () => {
|
|
208
|
+
void copy(settingKey);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
),
|
|
212
|
+
/* @__PURE__ */ jsx(
|
|
213
|
+
CopyStatus,
|
|
214
|
+
{
|
|
215
|
+
state,
|
|
216
|
+
attempt,
|
|
217
|
+
copiedMessage: `${settingKey} copied to the clipboard`,
|
|
218
|
+
failedMessage: "the browser refused the clipboard"
|
|
219
|
+
}
|
|
220
|
+
)
|
|
221
|
+
] });
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export { SETTINGS_TABLE_ROW_LABELS, SettingsTable, SettingsTableRow };
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { PresetChips } from './chunk-6QWSGM4W.js';
|
|
2
|
+
import { Input } from './chunk-XQMRSL7Z.js';
|
|
3
|
+
import { useFieldError } from './chunk-JLKO7PSK.js';
|
|
4
|
+
import { IconButton } from './chunk-KM5OKCW6.js';
|
|
5
|
+
import { cx } from './chunk-ODEQTPFM.js';
|
|
6
|
+
import './NumberField-G7H4VNZP.css';
|
|
7
|
+
import { forwardRef, useRef, useImperativeHandle, useEffect } from 'react';
|
|
8
|
+
import { MinusGlyph, PlusGlyph } from '@crewlethq/icons/glyphs';
|
|
9
|
+
import { jsxs, jsx } from 'react/jsx-runtime';
|
|
10
|
+
|
|
11
|
+
var NUMBER_FIELD_LABELS = {
|
|
12
|
+
decrease: "Decrease",
|
|
13
|
+
increase: "Increase",
|
|
14
|
+
defaultPreset: (value) => `Default (${value})`,
|
|
15
|
+
presets: "Common values"
|
|
16
|
+
};
|
|
17
|
+
function decimals(step) {
|
|
18
|
+
const text = String(step);
|
|
19
|
+
const at = text.indexOf(".");
|
|
20
|
+
return at === -1 ? 0 : text.length - at - 1;
|
|
21
|
+
}
|
|
22
|
+
function typedNumber(value) {
|
|
23
|
+
const text = value.trim();
|
|
24
|
+
if (!/^-?\d+(\.\d+)?$/.test(text)) return null;
|
|
25
|
+
const n = Number(text);
|
|
26
|
+
return Number.isFinite(n) ? n : null;
|
|
27
|
+
}
|
|
28
|
+
function clamp(n, min, max) {
|
|
29
|
+
if (min !== void 0 && n < min) return min;
|
|
30
|
+
if (max !== void 0 && n > max) return max;
|
|
31
|
+
return n;
|
|
32
|
+
}
|
|
33
|
+
var NumberField = forwardRef(function NumberField2({
|
|
34
|
+
id,
|
|
35
|
+
value,
|
|
36
|
+
onValueChange,
|
|
37
|
+
defaultValue,
|
|
38
|
+
min,
|
|
39
|
+
max,
|
|
40
|
+
step = 1,
|
|
41
|
+
unit,
|
|
42
|
+
presets,
|
|
43
|
+
formatValue,
|
|
44
|
+
error: errorProp,
|
|
45
|
+
disabled = false,
|
|
46
|
+
focusOnMount = false,
|
|
47
|
+
labels: overrides,
|
|
48
|
+
className,
|
|
49
|
+
...aria
|
|
50
|
+
}, ref) {
|
|
51
|
+
const labels = { ...NUMBER_FIELD_LABELS, ...overrides };
|
|
52
|
+
const field = useRef(null);
|
|
53
|
+
useImperativeHandle(ref, () => field.current, []);
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
if (focusOnMount) field.current?.focus();
|
|
56
|
+
}, [focusOnMount]);
|
|
57
|
+
const error = useFieldError(errorProp);
|
|
58
|
+
const typed = typedNumber(value);
|
|
59
|
+
const current = value.trim() === "" ? defaultValue : typed ?? void 0;
|
|
60
|
+
const say = formatValue ?? ((n) => n.toLocaleString());
|
|
61
|
+
const places = decimals(step);
|
|
62
|
+
const stepBy = (times) => {
|
|
63
|
+
const from = current ?? defaultValue ?? min ?? 0;
|
|
64
|
+
const next = clamp(Number((from + times * step).toFixed(places)), min, max);
|
|
65
|
+
onValueChange(String(next));
|
|
66
|
+
};
|
|
67
|
+
const atMin = min !== void 0 && current !== void 0 && current <= min;
|
|
68
|
+
const atMax = max !== void 0 && current !== void 0 && current >= max;
|
|
69
|
+
const keys = (event) => {
|
|
70
|
+
const by = event.key === "ArrowUp" ? 1 : event.key === "ArrowDown" ? -1 : event.key === "PageUp" ? 10 : event.key === "PageDown" ? -10 : 0;
|
|
71
|
+
if (by === 0 || disabled) return;
|
|
72
|
+
event.preventDefault();
|
|
73
|
+
stepBy(by);
|
|
74
|
+
};
|
|
75
|
+
const chips = [
|
|
76
|
+
...defaultValue === void 0 ? [] : [{ value: "", label: labels.defaultPreset(say(defaultValue)) }],
|
|
77
|
+
...presets ?? []
|
|
78
|
+
];
|
|
79
|
+
return /* @__PURE__ */ jsxs("div", { className: cx("crewlet-number-field", className), children: [
|
|
80
|
+
/* @__PURE__ */ jsxs("div", { className: "crewlet-number-field__row", children: [
|
|
81
|
+
/* @__PURE__ */ jsx(
|
|
82
|
+
IconButton,
|
|
83
|
+
{
|
|
84
|
+
size: "md",
|
|
85
|
+
variant: "secondary",
|
|
86
|
+
icon: /* @__PURE__ */ jsx(MinusGlyph, {}),
|
|
87
|
+
label: labels.decrease,
|
|
88
|
+
tabIndex: -1,
|
|
89
|
+
disabled: disabled || atMin,
|
|
90
|
+
onClick: () => stepBy(-1)
|
|
91
|
+
}
|
|
92
|
+
),
|
|
93
|
+
/* @__PURE__ */ jsx(
|
|
94
|
+
Input,
|
|
95
|
+
{
|
|
96
|
+
ref: field,
|
|
97
|
+
id,
|
|
98
|
+
role: "spinbutton",
|
|
99
|
+
value,
|
|
100
|
+
placeholder: defaultValue === void 0 ? void 0 : String(defaultValue),
|
|
101
|
+
inputMode: places > 0 || min !== void 0 && min < 0 ? "decimal" : "numeric",
|
|
102
|
+
autoComplete: "off",
|
|
103
|
+
spellCheck: false,
|
|
104
|
+
disabled,
|
|
105
|
+
error,
|
|
106
|
+
"aria-valuemin": min,
|
|
107
|
+
"aria-valuemax": max,
|
|
108
|
+
"aria-valuenow": current,
|
|
109
|
+
"aria-label": aria["aria-label"],
|
|
110
|
+
"aria-describedby": aria["aria-describedby"],
|
|
111
|
+
trailing: unit === void 0 ? void 0 : /* @__PURE__ */ jsx("span", { className: "crewlet-number-field__unit", children: unit }),
|
|
112
|
+
containerClassName: "crewlet-number-field__input",
|
|
113
|
+
onChange: (event) => onValueChange(event.target.value),
|
|
114
|
+
onKeyDown: keys
|
|
115
|
+
}
|
|
116
|
+
),
|
|
117
|
+
/* @__PURE__ */ jsx(
|
|
118
|
+
IconButton,
|
|
119
|
+
{
|
|
120
|
+
size: "md",
|
|
121
|
+
variant: "secondary",
|
|
122
|
+
icon: /* @__PURE__ */ jsx(PlusGlyph, {}),
|
|
123
|
+
label: labels.increase,
|
|
124
|
+
tabIndex: -1,
|
|
125
|
+
disabled: disabled || atMax,
|
|
126
|
+
onClick: () => stepBy(1)
|
|
127
|
+
}
|
|
128
|
+
)
|
|
129
|
+
] }),
|
|
130
|
+
presets !== void 0 && chips.length > 0 ? /* @__PURE__ */ jsx(PresetChips, { label: labels.presets, options: chips, value: value.trim(), disabled, onPick: onValueChange }) : null
|
|
131
|
+
] });
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
export { NUMBER_FIELD_LABELS, NumberField, typedNumber };
|