@scalewing/react 1.26.0 → 1.27.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.
Files changed (49) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +87 -1
  3. package/dist/components/ActionBar.d.ts +14 -0
  4. package/dist/components/ActionBar.js +5 -2
  5. package/dist/components/DenominationGrid.d.ts +1 -1
  6. package/dist/components/DenominationGrid.js +3 -0
  7. package/dist/components/Stepper.d.ts +44 -0
  8. package/dist/components/Stepper.js +77 -0
  9. package/dist/components/Steps.d.ts +18 -0
  10. package/dist/components/Steps.js +34 -0
  11. package/dist/components/action-bar/ActionBarSummary.d.ts +22 -0
  12. package/dist/components/action-bar/ActionBarSummary.js +23 -0
  13. package/dist/components/denomination-grid/ColumnHeadText.d.ts +7 -0
  14. package/dist/components/denomination-grid/ColumnHeadText.js +13 -0
  15. package/dist/components/denomination-grid/DenominationStrip.js +3 -7
  16. package/dist/components/denomination-grid/DenominationTiles.js +2 -1
  17. package/dist/components/denomination-grid/EntryCell.d.ts +15 -0
  18. package/dist/components/denomination-grid/EntryCell.js +16 -0
  19. package/dist/components/denomination-grid/RowLabelLine.d.ts +3 -2
  20. package/dist/components/denomination-grid/RowLabelLine.js +5 -3
  21. package/dist/components/denomination-grid/StripRow.d.ts +13 -0
  22. package/dist/components/denomination-grid/StripRow.js +19 -0
  23. package/dist/components/denomination-grid/types.d.ts +44 -1
  24. package/dist/components/denomination-grid/validate-entry.d.ts +15 -0
  25. package/dist/components/denomination-grid/validate-entry.js +78 -0
  26. package/dist/components/steps/Step.d.ts +24 -0
  27. package/dist/components/steps/Step.js +62 -0
  28. package/dist/components/steps/step-status.d.ts +26 -0
  29. package/dist/components/steps/step-status.js +37 -0
  30. package/dist/components/steps/steps-context.d.ts +16 -0
  31. package/dist/components/steps/steps-context.js +3 -0
  32. package/dist/css/css-action-bar-summary.d.ts +2 -0
  33. package/dist/css/css-action-bar-summary.js +48 -0
  34. package/dist/css/css-action-bar.js +4 -0
  35. package/dist/css/css-components.js +7 -0
  36. package/dist/css/css-denomination-entry.d.ts +2 -0
  37. package/dist/css/css-denomination-entry.js +78 -0
  38. package/dist/css/css-denomination-grid.js +4 -0
  39. package/dist/css/css-stepper.d.ts +10 -0
  40. package/dist/css/css-stepper.js +126 -0
  41. package/dist/css/css-steps.d.ts +9 -0
  42. package/dist/css/css-steps.js +203 -0
  43. package/dist/css/stylesheet.js +4 -0
  44. package/dist/index.d.ts +4 -2
  45. package/dist/index.js +3 -1
  46. package/dist/stepper-count.d.ts +37 -0
  47. package/dist/stepper-count.js +50 -0
  48. package/dist/styles.css +324 -0
  49. package/package.json +1 -1
@@ -0,0 +1,126 @@
1
+ import { typographyVariants } from '@scalewing/tokens';
2
+ import { changedTintLayer } from './css-field-changed.js';
3
+ const body = typographyVariants.body;
4
+ const label = typographyVariants.label;
5
+ const title = typographyVariants.title;
6
+ /*
7
+ * The count is a text input, so the canvas already draws it as a control
8
+ * (`[data-theme] :is(input[type='text'], …)`). `input.sw-stepper-input`
9
+ * matches that rule's specificity and comes later in the sheet, so the
10
+ * stepper's own centering and type win while the canvas keeps the surface,
11
+ * the focus ring and the disabled look.
12
+ */
13
+ const input = '[data-theme] input.sw-stepper-input';
14
+ function stateRules() {
15
+ return `[data-theme] .sw-stepper-invalid input.sw-stepper-input {
16
+ border-color: var(--sw-color-danger);
17
+ }
18
+
19
+ [data-theme] .sw-stepper-changed input.sw-stepper-input {
20
+ border-color: var(--sw-color-accent);
21
+ box-shadow: inset 0 0 0 1px var(--sw-color-accent);
22
+ }
23
+
24
+ [data-theme] .sw-stepper-changed input.sw-stepper-input:not(:placeholder-shown) {
25
+ background-image: ${changedTintLayer};
26
+ }
27
+
28
+ /* Read-only: the buttons keep their room, so the count lines up with an editable one. */
29
+ .sw-stepper-readonly .sw-stepper-button { visibility: hidden; }
30
+
31
+ @media (forced-colors: active) {
32
+ .sw-stepper-button { border-color: ButtonText; }
33
+ .sw-stepper-button:disabled { border-color: GrayText; color: GrayText; opacity: 1; }
34
+ [data-theme] .sw-stepper-invalid input.sw-stepper-input { border-color: Mark; }
35
+ [data-theme] .sw-stepper-changed input.sw-stepper-input { border-color: Highlight; box-shadow: inset 0 0 0 1px Highlight; background-image: none; }
36
+ }`;
37
+ }
38
+ /**
39
+ * The web Stepper: a label over a track of − count +. The count is a few
40
+ * digits wide by default, the track at its own width even under a wider label
41
+ * or message (`5ch` plus its padding, so its width never follows
42
+ * its value), or fills its container with `sw-stepper-full`. The buttons are
43
+ * spacing step 6 wide on the subtle fill and every part is the `md` control
44
+ * height.
45
+ */
46
+ export function cssStepperClasses() {
47
+ return `.sw-stepper {
48
+ align-items: flex-start;
49
+ display: inline-flex;
50
+ flex-direction: column;
51
+ gap: var(--sw-space-1);
52
+ min-width: 0;
53
+ /* Holds its hidden label and empty error region, which leave the flow,
54
+ so inside a scroll region they never widen the page. */
55
+ position: relative;
56
+ }
57
+
58
+ .sw-stepper-full { align-items: stretch; display: flex; }
59
+
60
+ .sw-stepper-track {
61
+ display: inline-grid;
62
+ gap: var(--sw-space-1);
63
+ grid-template-columns: var(--sw-space-6) auto var(--sw-space-6);
64
+ }
65
+
66
+ .sw-stepper-full .sw-stepper-track {
67
+ display: grid;
68
+ grid-template-columns: var(--sw-space-6) minmax(0, 1fr) var(--sw-space-6);
69
+ }
70
+
71
+ .sw-stepper-button {
72
+ align-items: center;
73
+ appearance: none;
74
+ background: var(--sw-color-subtle);
75
+ border: 1px solid transparent;
76
+ border-radius: var(--sw-radius-sm);
77
+ color: var(--sw-color-text);
78
+ cursor: pointer;
79
+ display: inline-flex;
80
+ font-family: var(--sw-font-sans);
81
+ font-size: ${title.fontSize}px;
82
+ font-weight: ${title.fontWeight};
83
+ justify-content: center;
84
+ line-height: ${title.lineHeight}px;
85
+ margin: 0;
86
+ min-height: var(--sw-control-md-min-height);
87
+ padding: 0;
88
+ touch-action: manipulation;
89
+ }
90
+
91
+ .sw-stepper-button:hover:not(:disabled) {
92
+ background: var(--sw-color-border);
93
+ }
94
+
95
+ .sw-stepper-button:disabled {
96
+ cursor: not-allowed;
97
+ opacity: var(--sw-disabled-opacity);
98
+ }
99
+
100
+ ${input} {
101
+ font-size: ${body.fontSize}px;
102
+ font-variant-numeric: tabular-nums;
103
+ font-weight: ${label.fontWeight};
104
+ inline-size: calc(5ch + 2 * var(--sw-space-1));
105
+ line-height: ${body.lineHeight}px;
106
+ min-width: 0;
107
+ padding-inline: var(--sw-space-1);
108
+ text-align: center;
109
+ }
110
+
111
+ .sw-stepper-full input.sw-stepper-input { inline-size: 100%; }
112
+
113
+ ${stateRules()}`;
114
+ }
115
+ export function stepperClassCatalog() {
116
+ return [
117
+ 'sw-stepper',
118
+ 'sw-stepper-full',
119
+ 'sw-stepper-track',
120
+ 'sw-stepper-button',
121
+ 'sw-stepper-input',
122
+ 'sw-stepper-invalid',
123
+ 'sw-stepper-changed',
124
+ 'sw-stepper-readonly',
125
+ ];
126
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * The one-page vertical stepper: an ordered list of glass panels a small
3
+ * gap apart. Each has a header line (marker, title, and on a done step its
4
+ * summary and Edit) and, while open (current or error), a body indented to
5
+ * the title. An open step's title is the title variant; a folded one's is
6
+ * body size at label weight, muted ahead of the form or skipped.
7
+ */
8
+ export declare function cssStepsClasses(): string;
9
+ export declare function stepsClassCatalog(): string[];
@@ -0,0 +1,203 @@
1
+ import { typographyVariants } from '@scalewing/tokens';
2
+ const body = typographyVariants.body;
3
+ const caption = typographyVariants.caption;
4
+ const label = typographyVariants.label;
5
+ const title = typographyVariants.title;
6
+ /** The marker's size: the xs control height. */
7
+ const marker = 'var(--sw-control-xs-min-height)';
8
+ /** The marker's look per status: its fill, ring and number color. */
9
+ function markerRules() {
10
+ return `.sw-steps-item-upcoming .sw-steps-marker,
11
+ .sw-steps-item-skipped .sw-steps-marker {
12
+ box-shadow: inset 0 0 0 2px var(--sw-color-border);
13
+ color: var(--sw-color-muted);
14
+ }
15
+
16
+ .sw-steps-item-current .sw-steps-marker {
17
+ background: var(--sw-color-accent);
18
+ color: var(--sw-color-onAccent);
19
+ }
20
+
21
+ .sw-steps-item-error .sw-steps-marker {
22
+ background: var(--sw-color-danger);
23
+ color: var(--sw-color-onDanger);
24
+ }
25
+
26
+ .sw-steps-item-done .sw-steps-marker {
27
+ background: var(--sw-color-success);
28
+ }
29
+
30
+ /* Private chrome: a check drawn with two borders, as Checkbox's. */
31
+ .sw-steps-item-done .sw-steps-marker::after {
32
+ border-bottom: 2px solid var(--sw-color-surface);
33
+ border-right: 2px solid var(--sw-color-surface);
34
+ content: '';
35
+ height: var(--sw-space-3);
36
+ margin-top: calc(-1 * var(--sw-space-1) / 2);
37
+ transform: rotate(45deg);
38
+ width: calc(var(--sw-space-3) / 2);
39
+ }`;
40
+ }
41
+ /*
42
+ * A line from each marker down to the next step's, through the gap between
43
+ * the panels: the success color below a done step, the hairline otherwise.
44
+ */
45
+ function connectorRules() {
46
+ return `.sw-steps-item:not(:last-child)::after {
47
+ background: var(--sw-color-border);
48
+ bottom: calc(-1 * var(--sw-space-2) - 1px);
49
+ content: '';
50
+ inset-inline-start: calc(var(--sw-space-4) + ${marker} / 2 - 1px);
51
+ position: absolute;
52
+ top: calc(var(--sw-steps-padding) + ${marker} + var(--sw-space-1));
53
+ width: 2px;
54
+ }
55
+
56
+ .sw-steps-item-done:not(:last-child)::after {
57
+ background: var(--sw-color-success);
58
+ }`;
59
+ }
60
+ function forcedColorRules() {
61
+ return `@media (forced-colors: active) {
62
+ .sw-steps-marker { border: 2px solid CanvasText; box-shadow: none; }
63
+ .sw-steps-item-current .sw-steps-marker { border-color: Highlight; }
64
+ .sw-steps-item-done .sw-steps-marker::after { border-color: CanvasText; }
65
+ .sw-steps-item:not(:last-child)::after { background: CanvasText; }
66
+ .sw-steps-item-upcoming .sw-steps-title,
67
+ .sw-steps-item-skipped .sw-steps-title { color: GrayText; }
68
+ }`;
69
+ }
70
+ /**
71
+ * The one-page vertical stepper: an ordered list of glass panels a small
72
+ * gap apart. Each has a header line (marker, title, and on a done step its
73
+ * summary and Edit) and, while open (current or error), a body indented to
74
+ * the title. An open step's title is the title variant; a folded one's is
75
+ * body size at label weight, muted ahead of the form or skipped.
76
+ */
77
+ export function cssStepsClasses() {
78
+ return `.sw-steps {
79
+ display: flex;
80
+ flex-direction: column;
81
+ gap: var(--sw-space-2);
82
+ list-style: none;
83
+ margin: 0;
84
+ padding: 0;
85
+ }
86
+
87
+ .sw-steps-item {
88
+ --sw-steps-padding: var(--sw-space-3);
89
+ background: var(--sw-glass-fill);
90
+ border: 1px solid var(--sw-glass-border);
91
+ border-radius: var(--sw-radius-md);
92
+ box-shadow: inset 0 1px 0 var(--sw-glass-specular);
93
+ color: var(--sw-color-text);
94
+ display: flex;
95
+ flex-direction: column;
96
+ gap: var(--sw-space-4);
97
+ padding: var(--sw-steps-padding) var(--sw-space-4);
98
+ position: relative;
99
+ }
100
+
101
+ .sw-steps-item-current,
102
+ .sw-steps-item-error {
103
+ --sw-steps-padding: var(--sw-space-4);
104
+ }
105
+
106
+ /* The marker sits at the top of the header, so the connector always starts
107
+ under it; each line of the header is centred on the marker's height. */
108
+ .sw-steps-header {
109
+ align-items: flex-start;
110
+ display: flex;
111
+ gap: var(--sw-space-3);
112
+ min-height: ${marker};
113
+ min-width: 0;
114
+ }
115
+
116
+ .sw-steps-marker {
117
+ align-items: center;
118
+ border-radius: var(--sw-radius-pill);
119
+ box-sizing: border-box;
120
+ display: inline-flex;
121
+ flex: none;
122
+ font-family: var(--sw-font-sans);
123
+ font-size: ${caption.fontSize}px;
124
+ font-variant-numeric: tabular-nums;
125
+ font-weight: 700;
126
+ height: ${marker};
127
+ justify-content: center;
128
+ line-height: ${caption.lineHeight}px;
129
+ width: ${marker};
130
+ }
131
+
132
+ .sw-steps-title {
133
+ font-family: var(--sw-font-sans);
134
+ font-size: ${body.fontSize}px;
135
+ font-weight: ${label.fontWeight};
136
+ letter-spacing: ${body.letterSpacing}px;
137
+ line-height: ${body.lineHeight}px;
138
+ margin: 0;
139
+ min-width: 0;
140
+ padding-block: calc((${marker} - ${body.lineHeight}px) / 2);
141
+ }
142
+
143
+ .sw-steps-item-current .sw-steps-title,
144
+ .sw-steps-item-error .sw-steps-title {
145
+ font-size: ${title.fontSize}px;
146
+ letter-spacing: ${title.letterSpacing}px;
147
+ line-height: ${title.lineHeight}px;
148
+ padding-block: calc((${marker} - ${title.lineHeight}px) / 2);
149
+ }
150
+
151
+ .sw-steps-item-upcoming .sw-steps-title,
152
+ .sw-steps-item-skipped .sw-steps-title,
153
+ .sw-steps-reason {
154
+ color: var(--sw-color-muted);
155
+ }
156
+
157
+ .sw-steps-summary {
158
+ flex: 1 1 0;
159
+ font-size: ${label.fontSize}px;
160
+ letter-spacing: ${label.letterSpacing}px;
161
+ line-height: ${label.lineHeight}px;
162
+ min-width: 25%;
163
+ overflow: hidden;
164
+ padding-block: calc((${marker} - ${label.lineHeight}px) / 2);
165
+ text-overflow: ellipsis;
166
+ white-space: nowrap;
167
+ }
168
+
169
+ .sw-button.sw-steps-edit {
170
+ flex: none;
171
+ margin-block: calc((${marker} - var(--sw-control-sm-min-height)) / 2);
172
+ margin-inline-start: auto;
173
+ }
174
+
175
+ .sw-steps-body {
176
+ margin-inline-start: calc(${marker} + var(--sw-space-3));
177
+ min-width: 0;
178
+ }
179
+
180
+ ${markerRules()}
181
+
182
+ ${connectorRules()}
183
+
184
+ ${forcedColorRules()}`;
185
+ }
186
+ export function stepsClassCatalog() {
187
+ return [
188
+ 'sw-steps',
189
+ 'sw-steps-item',
190
+ 'sw-steps-item-upcoming',
191
+ 'sw-steps-item-current',
192
+ 'sw-steps-item-done',
193
+ 'sw-steps-item-error',
194
+ 'sw-steps-item-skipped',
195
+ 'sw-steps-header',
196
+ 'sw-steps-marker',
197
+ 'sw-steps-title',
198
+ 'sw-steps-reason',
199
+ 'sw-steps-summary',
200
+ 'sw-steps-edit',
201
+ 'sw-steps-body',
202
+ ];
203
+ }
@@ -22,6 +22,8 @@ import { gridSpanClassCatalog } from './css-grid-span.js';
22
22
  import { denominationGridClassCatalog } from './css-denomination-grid.js';
23
23
  import { scrollRegionClassCatalog } from './css-scroll-region.js';
24
24
  import { fieldClassCatalog } from './css-field.js';
25
+ import { stepperClassCatalog } from './css-stepper.js';
26
+ import { stepsClassCatalog } from './css-steps.js';
25
27
  import { boxBorderClassCatalog } from './css-box-border.js';
26
28
  import { cssComponentClasses } from './css-components.js';
27
29
  import { buttonClassCatalog } from './css-button.js';
@@ -84,6 +86,8 @@ export function utilityClassCatalog() {
84
86
  ...gridSpanClassCatalog(),
85
87
  ...denominationGridClassCatalog(),
86
88
  ...fieldClassCatalog(),
89
+ ...stepperClassCatalog(),
90
+ ...stepsClassCatalog(),
87
91
  ...splitClassCatalog(),
88
92
  ...toastClassCatalog(),
89
93
  ...responsiveClassCatalog(),
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export { ActionMenu, type ActionMenuAlign, type ActionMenuItem, type ActionMenuProps, } from './components/ActionMenu.js';
2
- export { ActionBar, type ActionBarProps } from './components/ActionBar.js';
2
+ export { ActionBar, type ActionBarProps, type ActionBarSummary, type ActionBarSummaryTone, } from './components/ActionBar.js';
3
3
  export { Accordion } from './components/Accordion.js';
4
4
  export type { AccordionProps, AccordionSize } from './components/Accordion.js';
5
5
  export { Switch, type SwitchProps } from './components/Switch.js';
@@ -24,6 +24,8 @@ export { TabPanel, type TabItem, type TabPanelProps, Tabs, type TabsProps, tabId
24
24
  export { Toast, toastTones } from './components/Toast.js';
25
25
  export type { ToastProps, ToastTone } from './components/Toast.js';
26
26
  export { Field, type FieldProps, type FieldSize } from './components/Field.js';
27
+ export { Step, type StepHeadingLevel, type StepProps, Steps, type StepsLabels, type StepsProps, type StepStatus, } from './components/Steps.js';
28
+ export { Stepper, type StepperProps, type StepperWidth, } from './components/Stepper.js';
27
29
  export { Inline, type InlineProps } from './components/Inline.js';
28
30
  export { Split } from './components/Split.js';
29
31
  export type { SplitProps } from './components/Split.js';
@@ -49,6 +51,6 @@ export type { GridColumns, GridProps } from './components/Grid.js';
49
51
  export type { GridColumnSpan } from './css/css-grid-span.js';
50
52
  export type { ColumnSpanProps } from './column-span-classes.js';
51
53
  export { DenominationGrid } from './components/DenominationGrid.js';
52
- export type { DenominationGridColumn, DenominationGridLayout, DenominationGridProps, DenominationGridRow, DenominationGridRowRole, DenominationGridTone, DenominationLabelWidth, } from './components/DenominationGrid.js';
54
+ export type { DenominationGridColumn, DenominationGridEntry, DenominationGridLayout, DenominationGridProps, DenominationGridRow, DenominationGridRowEmphasis, DenominationGridRowRole, DenominationGridTone, DenominationLabelWidth, } from './components/DenominationGrid.js';
53
55
  export { FilterChips } from './components/FilterChips.js';
54
56
  export type { FilterChipOption, FilterChipsProps, } from './components/FilterChips.js';
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  export { ActionMenu, } from './components/ActionMenu.js';
2
- export { ActionBar } from './components/ActionBar.js';
2
+ export { ActionBar, } from './components/ActionBar.js';
3
3
  export { Accordion } from './components/Accordion.js';
4
4
  export { Switch } from './components/Switch.js';
5
5
  export { DateField, } from './components/DateField.js';
@@ -22,6 +22,8 @@ export { StatTile, statTileTones, } from './components/StatTile.js';
22
22
  export { TabPanel, Tabs, tabId, tabPanelId, } from './components/Tabs.js';
23
23
  export { Toast, toastTones } from './components/Toast.js';
24
24
  export { Field } from './components/Field.js';
25
+ export { Step, Steps, } from './components/Steps.js';
26
+ export { Stepper, } from './components/Stepper.js';
25
27
  export { Inline } from './components/Inline.js';
26
28
  export { Split } from './components/Split.js';
27
29
  export { Nav } from './components/Nav.js';
@@ -0,0 +1,37 @@
1
+ /** A web `Stepper`'s bounds: whole numbers, `min <= max`, `step > 0`. */
2
+ export type StepperBounds = {
3
+ min: number;
4
+ max: number;
5
+ step: number;
6
+ };
7
+ /** Where one press of − and of + lands, or null where that button is stopped. */
8
+ export type StepperMoves = {
9
+ down: number | null;
10
+ up: number | null;
11
+ };
12
+ /** A typed text: no count (empty), a whole count, or text the box refuses. */
13
+ export type StepperEntry = {
14
+ kind: 'empty';
15
+ } | {
16
+ kind: 'count';
17
+ value: number;
18
+ } | {
19
+ kind: 'refused';
20
+ };
21
+ /** A consumer bug, not a runtime state: the bounds must describe a range. */
22
+ export declare function assertStepperBounds(bounds: StepperBounds): void;
23
+ /**
24
+ * The counts − and + would move to. An empty box counts as `min`. A count
25
+ * outside the bounds (typed) moves back inside them; a bound stops its own
26
+ * direction, and a locked (disabled or read-only) stepper stops both.
27
+ */
28
+ export declare function stepperMoves(value: number | null, bounds: StepperBounds, locked: boolean): StepperMoves;
29
+ /**
30
+ * Reads what the person typed. Digits make a count, with a leading minus
31
+ * only when the range goes below zero; an empty box, or a lone minus on its
32
+ * way to a negative count, is no count. Anything else, or a count too large
33
+ * to be exact, is refused and the box keeps its last text.
34
+ */
35
+ export declare function readStepperEntry(text: string, allowsNegative: boolean): StepperEntry;
36
+ /** The box's text for a count: the plain number, or empty for none. */
37
+ export declare function stepperText(value: number | null): string;
@@ -0,0 +1,50 @@
1
+ /** A consumer bug, not a runtime state: the bounds must describe a range. */
2
+ export function assertStepperBounds(bounds) {
3
+ const { min, max, step } = bounds;
4
+ if (!Number.isSafeInteger(min) || !Number.isSafeInteger(step))
5
+ throw new RangeError('Stepper min and step must be whole numbers');
6
+ if (max !== Number.POSITIVE_INFINITY && !Number.isSafeInteger(max))
7
+ throw new RangeError('Stepper max must be a whole number');
8
+ if (min > max)
9
+ throw new RangeError(`Stepper min ${min} is greater than max ${max}`);
10
+ if (step <= 0)
11
+ throw new RangeError(`Stepper step ${step} must be greater than zero`);
12
+ }
13
+ function clamp(value, bounds) {
14
+ return Math.min(Math.max(value, bounds.min), bounds.max);
15
+ }
16
+ /**
17
+ * The counts − and + would move to. An empty box counts as `min`. A count
18
+ * outside the bounds (typed) moves back inside them; a bound stops its own
19
+ * direction, and a locked (disabled or read-only) stepper stops both.
20
+ */
21
+ export function stepperMoves(value, bounds, locked) {
22
+ if (locked)
23
+ return { down: null, up: null };
24
+ const base = value ?? bounds.min;
25
+ return {
26
+ down: base > bounds.min ? clamp(base - bounds.step, bounds) : null,
27
+ up: base < bounds.max ? clamp(base + bounds.step, bounds) : null,
28
+ };
29
+ }
30
+ /**
31
+ * Reads what the person typed. Digits make a count, with a leading minus
32
+ * only when the range goes below zero; an empty box, or a lone minus on its
33
+ * way to a negative count, is no count. Anything else, or a count too large
34
+ * to be exact, is refused and the box keeps its last text.
35
+ */
36
+ export function readStepperEntry(text, allowsNegative) {
37
+ if (text === '' || (allowsNegative && text === '-'))
38
+ return { kind: 'empty' };
39
+ const pattern = allowsNegative ? /^-?\d+$/ : /^\d+$/;
40
+ if (!pattern.test(text))
41
+ return { kind: 'refused' };
42
+ const value = Number(text);
43
+ if (!Number.isSafeInteger(value))
44
+ return { kind: 'refused' };
45
+ return { kind: 'count', value: Object.is(value, -0) ? 0 : value };
46
+ }
47
+ /** The box's text for a count: the plain number, or empty for none. */
48
+ export function stepperText(value) {
49
+ return value === null ? '' : String(value);
50
+ }