@zag-js/number-input 2.0.0-next.0 → 2.0.0-next.2
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/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/number-input.connect.js +89 -38
- package/dist/number-input.connect.mjs +91 -40
- package/dist/number-input.machine.js +106 -81
- package/dist/number-input.machine.mjs +95 -69
- package/dist/number-input.translations.d.mts +8 -0
- package/dist/number-input.translations.d.ts +8 -0
- package/dist/number-input.translations.js +33 -0
- package/dist/number-input.translations.mjs +8 -0
- package/dist/number-input.types.d.mts +84 -8
- package/dist/number-input.types.d.ts +84 -8
- package/package.json +12 -9
|
@@ -18,10 +18,12 @@ import {
|
|
|
18
18
|
isValueAtMax,
|
|
19
19
|
isValueAtMin,
|
|
20
20
|
isValueWithinRange,
|
|
21
|
-
snapValueToStep
|
|
21
|
+
snapValueToStep,
|
|
22
|
+
mergeWithDefault
|
|
22
23
|
} from "@zag-js/utils";
|
|
23
24
|
import { recordCursor, restoreCursor } from "./cursor.mjs";
|
|
24
25
|
import * as dom from "./number-input.dom.mjs";
|
|
26
|
+
import { defaultTranslations } from "./number-input.translations.mjs";
|
|
25
27
|
import { createFormatter, createParser, formatValue, getDefaultStep, parseValue } from "./number-input.utils.mjs";
|
|
26
28
|
var { choose, guards, createMachine } = setup();
|
|
27
29
|
var { not, and } = guards;
|
|
@@ -38,8 +40,6 @@ var machine = createMachine({
|
|
|
38
40
|
pattern: "-?[0-9]*(.[0-9]+)?",
|
|
39
41
|
defaultValue: "",
|
|
40
42
|
step,
|
|
41
|
-
largeStep: props.largeStep ?? step * 10,
|
|
42
|
-
smallStep: props.smallStep ?? step * 0.1,
|
|
43
43
|
min: Number.MIN_SAFE_INTEGER,
|
|
44
44
|
max: Number.MAX_SAFE_INTEGER,
|
|
45
45
|
spinOnPress: true,
|
|
@@ -47,17 +47,14 @@ var machine = createMachine({
|
|
|
47
47
|
scrubberDirection: "horizontal",
|
|
48
48
|
snapOnStep: false,
|
|
49
49
|
...props,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
decrementLabel: "decrease value",
|
|
53
|
-
...props.translations
|
|
54
|
-
}
|
|
50
|
+
largeStep: props.largeStep ?? 10 * step,
|
|
51
|
+
smallStep: props.smallStep ?? step / 10
|
|
55
52
|
};
|
|
56
53
|
},
|
|
57
54
|
initialState() {
|
|
58
55
|
return "idle";
|
|
59
56
|
},
|
|
60
|
-
context({ prop, bindable, getComputed }) {
|
|
57
|
+
context({ prop, bindable, getComputed, getEvent }) {
|
|
61
58
|
return {
|
|
62
59
|
value: bindable(() => ({
|
|
63
60
|
defaultValue: prop("defaultValue"),
|
|
@@ -65,7 +62,7 @@ var machine = createMachine({
|
|
|
65
62
|
onChange(value) {
|
|
66
63
|
const computed = getComputed();
|
|
67
64
|
const valueAsNumber = parseValue(value, { computed, prop });
|
|
68
|
-
prop("onValueChange")?.({ value, valueAsNumber });
|
|
65
|
+
prop("onValueChange")?.({ value, valueAsNumber, reason: getEvent().src });
|
|
69
66
|
}
|
|
70
67
|
})),
|
|
71
68
|
hint: bindable(() => ({ defaultValue: null })),
|
|
@@ -92,7 +89,15 @@ var machine = createMachine({
|
|
|
92
89
|
isDisabled: ({ prop, context }) => !!prop("disabled") || context.get("fieldsetDisabled"),
|
|
93
90
|
canIncrement: ({ prop, computed }) => prop("allowOverflow") || !computed("isAtMax"),
|
|
94
91
|
canDecrement: ({ prop, computed }) => prop("allowOverflow") || !computed("isAtMin"),
|
|
95
|
-
|
|
92
|
+
// Only useful when the display differs from `aria-valuenow`, as with currency or percent.
|
|
93
|
+
valueText: ({ prop, context, computed }) => {
|
|
94
|
+
const translations = mergeWithDefault(defaultTranslations, prop("translations"));
|
|
95
|
+
const custom = translations.valueText?.(context.get("value"));
|
|
96
|
+
if (custom) return custom;
|
|
97
|
+
if (computed("isValueEmpty")) return void 0;
|
|
98
|
+
const formatted = computed("formattedValue");
|
|
99
|
+
return formatted === String(computed("valueAsNumber")) ? void 0 : formatted;
|
|
100
|
+
},
|
|
96
101
|
formatter: memo(
|
|
97
102
|
({ prop }) => [prop("locale"), prop("formatOptions")],
|
|
98
103
|
([locale, formatOptions]) => createFormatter(locale, formatOptions)
|
|
@@ -107,6 +112,7 @@ var machine = createMachine({
|
|
|
107
112
|
action(["syncInputElement"]);
|
|
108
113
|
});
|
|
109
114
|
track([() => computed("isOutOfRange")], () => {
|
|
115
|
+
if (!computed("isOutOfRange")) return;
|
|
110
116
|
action(["invokeOnInvalid"]);
|
|
111
117
|
});
|
|
112
118
|
track([() => context.hash("scrubberCursorPoint")], () => {
|
|
@@ -115,32 +121,35 @@ var machine = createMachine({
|
|
|
115
121
|
},
|
|
116
122
|
effects: ["trackFormControl", "detectPointerLock"],
|
|
117
123
|
on: {
|
|
124
|
+
"INPUT.FOCUS": {
|
|
125
|
+
actions: ["invokeOnFocus"]
|
|
126
|
+
},
|
|
118
127
|
"VALUE.SET": {
|
|
119
|
-
actions: ["setRawValue"]
|
|
128
|
+
actions: ["setRawValue", "invokeOnValueCommit"]
|
|
120
129
|
},
|
|
121
130
|
"VALUE.CLEAR": {
|
|
122
|
-
actions: ["clearValue"]
|
|
131
|
+
actions: ["clearValue", "invokeOnValueCommit"]
|
|
123
132
|
},
|
|
124
133
|
"VALUE.INCREMENT": {
|
|
125
|
-
actions: ["increment"]
|
|
134
|
+
actions: ["increment", "invokeOnValueCommit"]
|
|
126
135
|
},
|
|
127
136
|
"VALUE.DECREMENT": {
|
|
128
|
-
actions: ["decrement"]
|
|
137
|
+
actions: ["decrement", "invokeOnValueCommit"]
|
|
129
138
|
}
|
|
130
139
|
},
|
|
131
140
|
states: {
|
|
132
141
|
idle: {
|
|
133
142
|
on: {
|
|
134
143
|
"TRIGGER.PRESS_DOWN": [
|
|
135
|
-
{ guard: "isTouchPointer", target: "
|
|
144
|
+
{ guard: "isTouchPointer", target: "pressed", actions: ["setHint"] },
|
|
136
145
|
{
|
|
137
|
-
target: "
|
|
138
|
-
actions: ["focusInput", "
|
|
146
|
+
target: "pressed",
|
|
147
|
+
actions: ["focusInput", "setHint"]
|
|
139
148
|
}
|
|
140
149
|
],
|
|
141
150
|
"SCRUBBER.PRESS_DOWN": {
|
|
142
151
|
target: "scrubbing",
|
|
143
|
-
actions: ["focusInput", "
|
|
152
|
+
actions: ["focusInput", "setHint", "setCursorPoint"]
|
|
144
153
|
},
|
|
145
154
|
"INPUT.FOCUS": {
|
|
146
155
|
target: "focused",
|
|
@@ -153,24 +162,24 @@ var machine = createMachine({
|
|
|
153
162
|
effects: ["attachWheelListener"],
|
|
154
163
|
on: {
|
|
155
164
|
"TRIGGER.PRESS_DOWN": [
|
|
156
|
-
{ guard: "isTouchPointer", target: "
|
|
157
|
-
{ target: "
|
|
165
|
+
{ guard: "isTouchPointer", target: "pressed", actions: ["setHint"] },
|
|
166
|
+
{ target: "pressed", actions: ["focusInput", "setHint"] }
|
|
158
167
|
],
|
|
159
168
|
"SCRUBBER.PRESS_DOWN": {
|
|
160
169
|
target: "scrubbing",
|
|
161
170
|
actions: ["focusInput", "setHint", "setCursorPoint"]
|
|
162
171
|
},
|
|
163
172
|
"INPUT.ARROW_UP": {
|
|
164
|
-
actions: ["increment"]
|
|
173
|
+
actions: ["increment", "invokeOnValueCommit"]
|
|
165
174
|
},
|
|
166
175
|
"INPUT.ARROW_DOWN": {
|
|
167
|
-
actions: ["decrement"]
|
|
176
|
+
actions: ["decrement", "invokeOnValueCommit"]
|
|
168
177
|
},
|
|
169
178
|
"INPUT.HOME": {
|
|
170
|
-
actions: ["decrementToMin"]
|
|
179
|
+
actions: ["decrementToMin", "invokeOnValueCommit"]
|
|
171
180
|
},
|
|
172
181
|
"INPUT.END": {
|
|
173
|
-
actions: ["incrementToMax"]
|
|
182
|
+
actions: ["incrementToMax", "invokeOnValueCommit"]
|
|
174
183
|
},
|
|
175
184
|
"INPUT.CHANGE": {
|
|
176
185
|
actions: ["setValue", "setHint"]
|
|
@@ -184,41 +193,66 @@ var machine = createMachine({
|
|
|
184
193
|
{
|
|
185
194
|
guard: not("isInRange"),
|
|
186
195
|
target: "idle",
|
|
187
|
-
actions: ["setFormattedValue", "clearHint", "invokeOnBlur", "
|
|
196
|
+
actions: ["setFormattedValue", "clearHint", "invokeOnBlur", "invokeOnValueCommit"]
|
|
188
197
|
},
|
|
189
198
|
{
|
|
190
199
|
target: "idle",
|
|
191
200
|
actions: ["setFormattedValue", "clearHint", "invokeOnBlur", "invokeOnValueCommit"]
|
|
192
201
|
}
|
|
193
202
|
],
|
|
203
|
+
// No target, so the input stays focused. It must not report a blur.
|
|
194
204
|
"INPUT.ENTER": {
|
|
195
|
-
actions: ["setFormattedValue", "clearHint", "
|
|
205
|
+
actions: ["setFormattedValue", "clearHint", "invokeOnValueCommit"]
|
|
196
206
|
}
|
|
197
207
|
}
|
|
198
208
|
},
|
|
199
|
-
|
|
209
|
+
pressed: {
|
|
200
210
|
tags: ["focus"],
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
{ guard: "isIncrementHint", actions: ["increment"] },
|
|
204
|
-
{ guard: "isDecrementHint", actions: ["decrement"] }
|
|
205
|
-
]),
|
|
211
|
+
initial: "waiting",
|
|
212
|
+
effects: ["trackButtonDisabled", "preventContextMenu"],
|
|
206
213
|
on: {
|
|
207
|
-
CHANGE_DELAY: {
|
|
208
|
-
target: "spinning",
|
|
209
|
-
guard: and("isInRange", "spinOnPress")
|
|
210
|
-
},
|
|
211
214
|
"TRIGGER.PRESS_UP": [
|
|
212
|
-
{ guard: "isTouchPointer", target: "focused", actions: ["clearHint"] },
|
|
213
|
-
{ target: "focused", actions: ["focusInput", "clearHint"] }
|
|
215
|
+
{ guard: "isTouchPointer", target: "focused", actions: ["clearHint", "invokeOnValueCommit"] },
|
|
216
|
+
{ target: "focused", actions: ["focusInput", "clearHint", "invokeOnValueCommit"] }
|
|
214
217
|
]
|
|
218
|
+
},
|
|
219
|
+
states: {
|
|
220
|
+
waiting: {
|
|
221
|
+
effects: ["waitForChangeDelay"],
|
|
222
|
+
entry: choose([
|
|
223
|
+
{ guard: "isIncrementHint", actions: ["increment"] },
|
|
224
|
+
{ guard: "isDecrementHint", actions: ["decrement"] }
|
|
225
|
+
]),
|
|
226
|
+
on: {
|
|
227
|
+
CHANGE_DELAY: {
|
|
228
|
+
target: "repeating",
|
|
229
|
+
guard: and("isInRange", "spinOnPress")
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
},
|
|
233
|
+
repeating: {
|
|
234
|
+
effects: ["spinValue"],
|
|
235
|
+
on: {
|
|
236
|
+
SPIN: [
|
|
237
|
+
{
|
|
238
|
+
guard: "isIncrementHint",
|
|
239
|
+
actions: ["increment"]
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
guard: "isDecrementHint",
|
|
243
|
+
actions: ["decrement"]
|
|
244
|
+
}
|
|
245
|
+
]
|
|
246
|
+
}
|
|
247
|
+
}
|
|
215
248
|
}
|
|
216
249
|
},
|
|
217
|
-
|
|
250
|
+
scrubbing: {
|
|
218
251
|
tags: ["focus"],
|
|
219
|
-
effects: ["
|
|
252
|
+
effects: ["activatePointerLock", "trackMousemove", "preventTextSelection", "trackVisualViewport"],
|
|
253
|
+
entry: ["clearCumulativeDelta"],
|
|
220
254
|
on: {
|
|
221
|
-
|
|
255
|
+
"SCRUBBER.STEP": [
|
|
222
256
|
{
|
|
223
257
|
guard: "isIncrementHint",
|
|
224
258
|
actions: ["increment"]
|
|
@@ -228,20 +262,9 @@ var machine = createMachine({
|
|
|
228
262
|
actions: ["decrement"]
|
|
229
263
|
}
|
|
230
264
|
],
|
|
231
|
-
"TRIGGER.PRESS_UP": {
|
|
232
|
-
target: "focused",
|
|
233
|
-
actions: ["focusInput", "clearHint"]
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
},
|
|
237
|
-
scrubbing: {
|
|
238
|
-
tags: ["focus"],
|
|
239
|
-
effects: ["activatePointerLock", "trackMousemove", "preventTextSelection", "trackVisualViewport"],
|
|
240
|
-
entry: ["clearCumulativeDelta"],
|
|
241
|
-
on: {
|
|
242
265
|
"SCRUBBER.POINTER_UP": {
|
|
243
266
|
target: "focused",
|
|
244
|
-
actions: ["focusInput", "clearCursorPoint", "clearCumulativeDelta"]
|
|
267
|
+
actions: ["focusInput", "clearCursorPoint", "clearCumulativeDelta", "invokeOnValueCommit"]
|
|
245
268
|
},
|
|
246
269
|
"SCRUBBER.POINTER_MOVE": {
|
|
247
270
|
actions: ["accumulateDelta", "setCursorPoint"]
|
|
@@ -266,9 +289,13 @@ var machine = createMachine({
|
|
|
266
289
|
}, 300);
|
|
267
290
|
return () => clearTimeout(id);
|
|
268
291
|
},
|
|
269
|
-
|
|
292
|
+
preventContextMenu({ scope }) {
|
|
293
|
+
return addDomEvent(scope.getWin(), "contextmenu", (event) => event.preventDefault());
|
|
294
|
+
},
|
|
295
|
+
spinValue({ send, context }) {
|
|
270
296
|
const id = setInterval(() => {
|
|
271
|
-
|
|
297
|
+
const src = context.get("hint") === "increment" ? "increment-press" : "decrement-press";
|
|
298
|
+
send({ type: "SPIN", src });
|
|
272
299
|
}, 50);
|
|
273
300
|
return () => clearInterval(id);
|
|
274
301
|
},
|
|
@@ -295,7 +322,8 @@ var machine = createMachine({
|
|
|
295
322
|
return observeAttributes(btn, {
|
|
296
323
|
attributes: ["disabled"],
|
|
297
324
|
callback() {
|
|
298
|
-
|
|
325
|
+
const src = hint === "increment" ? "increment-press" : "decrement-press";
|
|
326
|
+
send({ type: "TRIGGER.PRESS_UP", src });
|
|
299
327
|
}
|
|
300
328
|
});
|
|
301
329
|
},
|
|
@@ -306,9 +334,9 @@ var machine = createMachine({
|
|
|
306
334
|
event.preventDefault();
|
|
307
335
|
const dir = Math.sign(event.deltaY) * -1;
|
|
308
336
|
if (dir === 1) {
|
|
309
|
-
send({ type: "VALUE.INCREMENT" });
|
|
337
|
+
send({ type: "VALUE.INCREMENT", src: "wheel" });
|
|
310
338
|
} else if (dir === -1) {
|
|
311
|
-
send({ type: "VALUE.DECREMENT" });
|
|
339
|
+
send({ type: "VALUE.DECREMENT", src: "wheel" });
|
|
312
340
|
}
|
|
313
341
|
}
|
|
314
342
|
return addDomEvent(inputEl, "wheel", onWheel, { passive: false });
|
|
@@ -349,7 +377,7 @@ var machine = createMachine({
|
|
|
349
377
|
});
|
|
350
378
|
}
|
|
351
379
|
function onMouseup() {
|
|
352
|
-
send({ type: "SCRUBBER.POINTER_UP" });
|
|
380
|
+
send({ type: "SCRUBBER.POINTER_UP", src: "scrub" });
|
|
353
381
|
}
|
|
354
382
|
return callAll(addDomEvent(doc, "mousemove", onMousemove, false), addDomEvent(doc, "mouseup", onMouseup, false));
|
|
355
383
|
}
|
|
@@ -380,7 +408,7 @@ var machine = createMachine({
|
|
|
380
408
|
context.set("value", formatValue(nextValue, { computed, prop }));
|
|
381
409
|
},
|
|
382
410
|
setRawValue({ context, event, prop, computed }) {
|
|
383
|
-
let nextValue = parseValue(event.value, { computed, prop });
|
|
411
|
+
let nextValue = typeof event.value === "number" ? event.value : parseValue(event.value, { computed, prop });
|
|
384
412
|
if (!prop("allowOverflow")) nextValue = clampValue(nextValue, prop("min"), prop("max"));
|
|
385
413
|
context.set("value", formatValue(nextValue, { computed, prop }));
|
|
386
414
|
},
|
|
@@ -419,8 +447,7 @@ var machine = createMachine({
|
|
|
419
447
|
valueAsNumber: computed("valueAsNumber")
|
|
420
448
|
});
|
|
421
449
|
},
|
|
422
|
-
invokeOnInvalid({ computed, prop
|
|
423
|
-
if (event.type === "INPUT.CHANGE") return;
|
|
450
|
+
invokeOnInvalid({ computed, prop }) {
|
|
424
451
|
const reason = computed("valueAsNumber") > prop("max") ? "rangeOverflow" : "rangeUnderflow";
|
|
425
452
|
prop("onValueInvalid")?.({
|
|
426
453
|
reason,
|
|
@@ -428,10 +455,11 @@ var machine = createMachine({
|
|
|
428
455
|
valueAsNumber: computed("valueAsNumber")
|
|
429
456
|
});
|
|
430
457
|
},
|
|
431
|
-
invokeOnValueCommit({ computed, prop }) {
|
|
458
|
+
invokeOnValueCommit({ computed, prop, event }) {
|
|
432
459
|
prop("onValueCommit")?.({
|
|
433
460
|
value: computed("formattedValue"),
|
|
434
|
-
valueAsNumber: computed("valueAsNumber")
|
|
461
|
+
valueAsNumber: computed("valueAsNumber"),
|
|
462
|
+
reason: event.src
|
|
435
463
|
});
|
|
436
464
|
},
|
|
437
465
|
syncInputElement({ context, event, computed, scope }) {
|
|
@@ -467,10 +495,8 @@ var machine = createMachine({
|
|
|
467
495
|
if (Math.abs(newDelta) >= sensitivity) {
|
|
468
496
|
const step = prop("step");
|
|
469
497
|
const hint = event.hint;
|
|
470
|
-
if (hint === "increment") {
|
|
471
|
-
send({ type: "
|
|
472
|
-
} else if (hint === "decrement") {
|
|
473
|
-
send({ type: "VALUE.DECREMENT", step });
|
|
498
|
+
if (hint === "increment" || hint === "decrement") {
|
|
499
|
+
send({ type: "SCRUBBER.STEP", step, hint, src: "scrub" });
|
|
474
500
|
}
|
|
475
501
|
context.set("cumulativeDelta", newDelta % sensitivity);
|
|
476
502
|
} else {
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Required } from '@zag-js/types';
|
|
2
|
+
import { IntlTranslations } from './number-input.types.mjs';
|
|
3
|
+
import '@internationalized/number';
|
|
4
|
+
import '@zag-js/core';
|
|
5
|
+
|
|
6
|
+
declare const defaultTranslations: Required<Pick<IntlTranslations, "incrementLabel" | "decrementLabel">>;
|
|
7
|
+
|
|
8
|
+
export { defaultTranslations };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Required } from '@zag-js/types';
|
|
2
|
+
import { IntlTranslations } from './number-input.types.js';
|
|
3
|
+
import '@internationalized/number';
|
|
4
|
+
import '@zag-js/core';
|
|
5
|
+
|
|
6
|
+
declare const defaultTranslations: Required<Pick<IntlTranslations, "incrementLabel" | "decrementLabel">>;
|
|
7
|
+
|
|
8
|
+
export { defaultTranslations };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/number-input.translations.ts
|
|
21
|
+
var number_input_translations_exports = {};
|
|
22
|
+
__export(number_input_translations_exports, {
|
|
23
|
+
defaultTranslations: () => defaultTranslations
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(number_input_translations_exports);
|
|
26
|
+
var defaultTranslations = {
|
|
27
|
+
incrementLabel: "increment value",
|
|
28
|
+
decrementLabel: "decrease value"
|
|
29
|
+
};
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
32
|
+
defaultTranslations
|
|
33
|
+
});
|
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
import { NumberParser } from '@internationalized/number';
|
|
2
2
|
import { Machine, EventObject, Service } from '@zag-js/core';
|
|
3
|
-
import { PropTypes,
|
|
3
|
+
import { PropTypes, LocaleProperties, CommonProperties } from '@zag-js/types';
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* The reason for the number input value change
|
|
7
|
+
*/
|
|
8
|
+
type ValueChangeReason = "input-change" | "input-blur" | "keyboard" | "increment-press" | "decrement-press" | "wheel" | "scrub" | "script";
|
|
5
9
|
interface ValueChangeDetails {
|
|
6
10
|
value: string;
|
|
7
11
|
valueAsNumber: number;
|
|
12
|
+
reason?: ValueChangeReason | undefined;
|
|
8
13
|
}
|
|
9
|
-
interface FocusChangeDetails
|
|
14
|
+
interface FocusChangeDetails {
|
|
15
|
+
value: string;
|
|
16
|
+
valueAsNumber: number;
|
|
10
17
|
focused: boolean;
|
|
11
18
|
}
|
|
12
19
|
type ValidityState = "rangeUnderflow" | "rangeOverflow";
|
|
13
|
-
|
|
20
|
+
/** Detached from `ValueChangeDetails`: here `reason` is why the value is invalid. */
|
|
21
|
+
interface ValueInvalidDetails {
|
|
22
|
+
value: string;
|
|
23
|
+
valueAsNumber: number;
|
|
14
24
|
reason: ValidityState;
|
|
15
25
|
}
|
|
16
26
|
type InputMode = "text" | "tel" | "numeric" | "decimal";
|
|
@@ -143,7 +153,8 @@ interface NumberInputProps extends LocaleProperties, CommonProperties {
|
|
|
143
153
|
*/
|
|
144
154
|
onFocusChange?: ((details: FocusChangeDetails) => void) | undefined;
|
|
145
155
|
/**
|
|
146
|
-
* Function invoked when the value
|
|
156
|
+
* Function invoked when the value settles: the input is blurred or `Enter` is pressed, a stepper
|
|
157
|
+
* or scrub gesture ends, or a key or wheel step completes.
|
|
147
158
|
*/
|
|
148
159
|
onValueCommit?: ((details: ValueChangeDetails) => void) | undefined;
|
|
149
160
|
/**
|
|
@@ -183,7 +194,7 @@ interface NumberInputProps extends LocaleProperties, CommonProperties {
|
|
|
183
194
|
*/
|
|
184
195
|
snapOnStep?: boolean | undefined;
|
|
185
196
|
}
|
|
186
|
-
type PropsWithDefault = "dir" | "locale" | "focusInputOnChange" | "clampValueOnBlur" | "allowOverflow" | "inputMode" | "pattern" | "
|
|
197
|
+
type PropsWithDefault = "dir" | "locale" | "focusInputOnChange" | "clampValueOnBlur" | "allowOverflow" | "inputMode" | "pattern" | "step" | "largeStep" | "smallStep" | "spinOnPress" | "min" | "max" | "scrubberPixelSensitivity" | "scrubberDirection" | "snapOnStep";
|
|
187
198
|
type ComputedContext = Readonly<{
|
|
188
199
|
/**
|
|
189
200
|
* The value of the input as a number
|
|
@@ -273,9 +284,10 @@ interface PrivateContext {
|
|
|
273
284
|
visualScale: number;
|
|
274
285
|
}
|
|
275
286
|
interface NumberInputSchema {
|
|
276
|
-
state: "idle" | "focused" | "
|
|
287
|
+
state: "idle" | "focused" | "pressed" | "pressed.waiting" | "pressed.repeating" | "scrubbing";
|
|
277
288
|
tag: "focus";
|
|
278
|
-
props:
|
|
289
|
+
props: NumberInputProps;
|
|
290
|
+
defaultPropKey: PropsWithDefault;
|
|
279
291
|
context: PrivateContext;
|
|
280
292
|
computed: ComputedContext;
|
|
281
293
|
action: string;
|
|
@@ -285,6 +297,54 @@ interface NumberInputSchema {
|
|
|
285
297
|
}
|
|
286
298
|
type NumberInputService = Service<NumberInputSchema>;
|
|
287
299
|
type NumberInputMachine = Machine<NumberInputSchema>;
|
|
300
|
+
interface RootState {
|
|
301
|
+
/**
|
|
302
|
+
* Whether the number input is disabled.
|
|
303
|
+
*/
|
|
304
|
+
disabled: boolean;
|
|
305
|
+
/**
|
|
306
|
+
* Whether the number input is focused.
|
|
307
|
+
*/
|
|
308
|
+
focused: boolean;
|
|
309
|
+
/**
|
|
310
|
+
* Whether the number input is invalid.
|
|
311
|
+
*/
|
|
312
|
+
invalid: boolean;
|
|
313
|
+
/**
|
|
314
|
+
* Whether the number input is being scrubbed.
|
|
315
|
+
*/
|
|
316
|
+
scrubbing: boolean;
|
|
317
|
+
}
|
|
318
|
+
interface InputState {
|
|
319
|
+
/**
|
|
320
|
+
* Whether the input is disabled.
|
|
321
|
+
*/
|
|
322
|
+
disabled: boolean;
|
|
323
|
+
/**
|
|
324
|
+
* Whether the input is invalid.
|
|
325
|
+
*/
|
|
326
|
+
invalid: boolean;
|
|
327
|
+
/**
|
|
328
|
+
* Whether the input is read-only.
|
|
329
|
+
*/
|
|
330
|
+
readOnly: boolean;
|
|
331
|
+
/**
|
|
332
|
+
* Whether the input is being scrubbed.
|
|
333
|
+
*/
|
|
334
|
+
scrubbing: boolean;
|
|
335
|
+
}
|
|
336
|
+
interface IncrementTriggerState {
|
|
337
|
+
/**
|
|
338
|
+
* Whether the increment trigger is disabled.
|
|
339
|
+
*/
|
|
340
|
+
disabled: boolean;
|
|
341
|
+
}
|
|
342
|
+
interface DecrementTriggerState {
|
|
343
|
+
/**
|
|
344
|
+
* Whether the decrement trigger is disabled.
|
|
345
|
+
*/
|
|
346
|
+
disabled: boolean;
|
|
347
|
+
}
|
|
288
348
|
interface NumberInputApi<T extends PropTypes = PropTypes> {
|
|
289
349
|
/**
|
|
290
350
|
* Whether the input is focused.
|
|
@@ -338,15 +398,31 @@ interface NumberInputApi<T extends PropTypes = PropTypes> {
|
|
|
338
398
|
* Function to focus the input.
|
|
339
399
|
*/
|
|
340
400
|
focus: VoidFunction;
|
|
401
|
+
/**
|
|
402
|
+
* Returns the state of the root.
|
|
403
|
+
*/
|
|
404
|
+
getRootState: () => RootState;
|
|
341
405
|
getRootProps: () => T["element"];
|
|
342
406
|
getLabelProps: () => T["label"];
|
|
343
407
|
getControlProps: () => T["element"];
|
|
344
408
|
getValueTextProps: () => T["element"];
|
|
409
|
+
/**
|
|
410
|
+
* Returns the state of the input.
|
|
411
|
+
*/
|
|
412
|
+
getInputState: () => InputState;
|
|
345
413
|
getInputProps: () => T["input"];
|
|
414
|
+
/**
|
|
415
|
+
* Returns the state of the decrement trigger.
|
|
416
|
+
*/
|
|
417
|
+
getDecrementTriggerState: () => DecrementTriggerState;
|
|
346
418
|
getDecrementTriggerProps: () => T["button"];
|
|
419
|
+
/**
|
|
420
|
+
* Returns the state of the increment trigger.
|
|
421
|
+
*/
|
|
422
|
+
getIncrementTriggerState: () => IncrementTriggerState;
|
|
347
423
|
getIncrementTriggerProps: () => T["button"];
|
|
348
424
|
getScrubberProps: () => T["element"];
|
|
349
425
|
getScrubberCursorProps: () => T["element"];
|
|
350
426
|
}
|
|
351
427
|
|
|
352
|
-
export type { ElementIds, FocusChangeDetails, HintValue, InputMode, IntlTranslations, NumberInputApi, NumberInputMachine, NumberInputProps, NumberInputSchema, NumberInputService, ValidityState, ValueChangeDetails, ValueInvalidDetails };
|
|
428
|
+
export type { DecrementTriggerState, ElementIds, FocusChangeDetails, HintValue, IncrementTriggerState, InputMode, InputState, IntlTranslations, NumberInputApi, NumberInputMachine, NumberInputProps, NumberInputSchema, NumberInputService, RootState, ValidityState, ValueChangeDetails, ValueChangeReason, ValueInvalidDetails };
|