@zag-js/number-input 2.0.0-next.0 → 2.0.0-next.1
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 +42 -18
- package/dist/number-input.connect.mjs +43 -19
- package/dist/number-input.machine.js +3 -3
- package/dist/number-input.machine.mjs +3 -3
- package/dist/number-input.types.d.mts +66 -2
- package/dist/number-input.types.d.ts +66 -2
- package/package.json +11 -8
package/dist/index.d.mts
CHANGED
|
@@ -2,7 +2,7 @@ export { anatomy } from './number-input.anatomy.mjs';
|
|
|
2
2
|
export { connect } from './number-input.connect.mjs';
|
|
3
3
|
export { machine } from './number-input.machine.mjs';
|
|
4
4
|
export { props, splitProps } from './number-input.props.mjs';
|
|
5
|
-
export { NumberInputApi as Api, ElementIds, FocusChangeDetails, HintValue, InputMode, IntlTranslations, NumberInputMachine as Machine, NumberInputProps as Props, NumberInputService as Service, ValidityState, ValueChangeDetails, ValueInvalidDetails } from './number-input.types.mjs';
|
|
5
|
+
export { NumberInputApi as Api, DecrementTriggerState, ElementIds, FocusChangeDetails, HintValue, IncrementTriggerState, InputMode, InputState, IntlTranslations, NumberInputMachine as Machine, NumberInputProps as Props, RootState, NumberInputService as Service, ValidityState, ValueChangeDetails, ValueInvalidDetails } from './number-input.types.mjs';
|
|
6
6
|
import '@zag-js/anatomy';
|
|
7
7
|
import '@zag-js/types';
|
|
8
8
|
import '@zag-js/core';
|
package/dist/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { anatomy } from './number-input.anatomy.js';
|
|
|
2
2
|
export { connect } from './number-input.connect.js';
|
|
3
3
|
export { machine } from './number-input.machine.js';
|
|
4
4
|
export { props, splitProps } from './number-input.props.js';
|
|
5
|
-
export { NumberInputApi as Api, ElementIds, FocusChangeDetails, HintValue, InputMode, IntlTranslations, NumberInputMachine as Machine, NumberInputProps as Props, NumberInputService as Service, ValidityState, ValueChangeDetails, ValueInvalidDetails } from './number-input.types.js';
|
|
5
|
+
export { NumberInputApi as Api, DecrementTriggerState, ElementIds, FocusChangeDetails, HintValue, IncrementTriggerState, InputMode, InputState, IntlTranslations, NumberInputMachine as Machine, NumberInputProps as Props, RootState, NumberInputService as Service, ValidityState, ValueChangeDetails, ValueInvalidDetails } from './number-input.types.js';
|
|
6
6
|
import '@zag-js/anatomy';
|
|
7
7
|
import '@zag-js/types';
|
|
8
8
|
import '@zag-js/core';
|
|
@@ -50,6 +50,18 @@ function connect(service, normalize) {
|
|
|
50
50
|
const isIncrementDisabled = disabled || !computed("canIncrement") || readOnly;
|
|
51
51
|
const isDecrementDisabled = disabled || !computed("canDecrement") || readOnly;
|
|
52
52
|
const translations = prop("translations");
|
|
53
|
+
function getRootState() {
|
|
54
|
+
return { disabled, focused, invalid, scrubbing };
|
|
55
|
+
}
|
|
56
|
+
function getInputState() {
|
|
57
|
+
return { disabled, invalid, readOnly, scrubbing };
|
|
58
|
+
}
|
|
59
|
+
function getIncrementTriggerState() {
|
|
60
|
+
return { disabled: isIncrementDisabled };
|
|
61
|
+
}
|
|
62
|
+
function getDecrementTriggerState() {
|
|
63
|
+
return { disabled: isDecrementDisabled };
|
|
64
|
+
}
|
|
53
65
|
return {
|
|
54
66
|
focused,
|
|
55
67
|
scrubbing,
|
|
@@ -78,14 +90,16 @@ function connect(service, normalize) {
|
|
|
78
90
|
focus() {
|
|
79
91
|
dom.getInputEl(scope)?.focus();
|
|
80
92
|
},
|
|
93
|
+
getRootState,
|
|
81
94
|
getRootProps() {
|
|
95
|
+
const rootState = getRootState();
|
|
82
96
|
return normalize.element({
|
|
83
97
|
...import_number_input.parts.root.attrs(scope.id),
|
|
84
98
|
dir: prop("dir"),
|
|
85
|
-
"data-disabled": (0, import_dom_query.dataAttr)(disabled),
|
|
86
|
-
"data-focus": (0, import_dom_query.dataAttr)(focused),
|
|
87
|
-
"data-invalid": (0, import_dom_query.dataAttr)(invalid),
|
|
88
|
-
"data-scrubbing": (0, import_dom_query.dataAttr)(scrubbing)
|
|
99
|
+
"data-disabled": (0, import_dom_query.dataAttr)(rootState.disabled),
|
|
100
|
+
"data-focus": (0, import_dom_query.dataAttr)(rootState.focused),
|
|
101
|
+
"data-invalid": (0, import_dom_query.dataAttr)(rootState.invalid),
|
|
102
|
+
"data-scrubbing": (0, import_dom_query.dataAttr)(rootState.scrubbing)
|
|
89
103
|
});
|
|
90
104
|
},
|
|
91
105
|
getLabelProps() {
|
|
@@ -129,7 +143,9 @@ function connect(service, normalize) {
|
|
|
129
143
|
"data-scrubbing": (0, import_dom_query.dataAttr)(scrubbing)
|
|
130
144
|
});
|
|
131
145
|
},
|
|
146
|
+
getInputState,
|
|
132
147
|
getInputProps() {
|
|
148
|
+
const inputState = getInputState();
|
|
133
149
|
return normalize.input({
|
|
134
150
|
...import_number_input.parts.input.attrs(scope.id),
|
|
135
151
|
dir: prop("dir"),
|
|
@@ -140,11 +156,11 @@ function connect(service, normalize) {
|
|
|
140
156
|
defaultValue: computed("formattedValue"),
|
|
141
157
|
pattern: prop("formatOptions") ? void 0 : prop("pattern"),
|
|
142
158
|
inputMode: prop("inputMode"),
|
|
143
|
-
"aria-invalid": (0, import_dom_query.ariaAttr)(invalid),
|
|
144
|
-
"data-invalid": (0, import_dom_query.dataAttr)(invalid),
|
|
145
|
-
disabled,
|
|
146
|
-
"data-disabled": (0, import_dom_query.dataAttr)(disabled),
|
|
147
|
-
readOnly,
|
|
159
|
+
"aria-invalid": (0, import_dom_query.ariaAttr)(inputState.invalid),
|
|
160
|
+
"data-invalid": (0, import_dom_query.dataAttr)(inputState.invalid),
|
|
161
|
+
disabled: inputState.disabled,
|
|
162
|
+
"data-disabled": (0, import_dom_query.dataAttr)(inputState.disabled),
|
|
163
|
+
readOnly: inputState.readOnly,
|
|
148
164
|
required: prop("required"),
|
|
149
165
|
autoComplete: "off",
|
|
150
166
|
autoCorrect: "off",
|
|
@@ -155,7 +171,7 @@ function connect(service, normalize) {
|
|
|
155
171
|
"aria-valuemax": prop("max"),
|
|
156
172
|
"aria-valuenow": Number.isNaN(computed("valueAsNumber")) ? void 0 : computed("valueAsNumber"),
|
|
157
173
|
"aria-valuetext": computed("valueText"),
|
|
158
|
-
"data-scrubbing": (0, import_dom_query.dataAttr)(scrubbing),
|
|
174
|
+
"data-scrubbing": (0, import_dom_query.dataAttr)(inputState.scrubbing),
|
|
159
175
|
onFocus() {
|
|
160
176
|
send({ type: "INPUT.FOCUS" });
|
|
161
177
|
},
|
|
@@ -181,7 +197,7 @@ function connect(service, normalize) {
|
|
|
181
197
|
if (event.defaultPrevented) return;
|
|
182
198
|
if (readOnly) return;
|
|
183
199
|
if ((0, import_dom_query.isComposingEvent)(event)) return;
|
|
184
|
-
const step = (0, import_dom_query.
|
|
200
|
+
const step = (0, import_dom_query.getEventStepValue)(event, {
|
|
185
201
|
step: prop("step"),
|
|
186
202
|
largeStep: prop("largeStep"),
|
|
187
203
|
smallStep: prop("smallStep")
|
|
@@ -190,20 +206,24 @@ function connect(service, normalize) {
|
|
|
190
206
|
ArrowUp() {
|
|
191
207
|
send({ type: "INPUT.ARROW_UP", step });
|
|
192
208
|
event.preventDefault();
|
|
209
|
+
event.stopPropagation();
|
|
193
210
|
},
|
|
194
211
|
ArrowDown() {
|
|
195
212
|
send({ type: "INPUT.ARROW_DOWN", step });
|
|
196
213
|
event.preventDefault();
|
|
214
|
+
event.stopPropagation();
|
|
197
215
|
},
|
|
198
216
|
Home() {
|
|
199
217
|
if ((0, import_dom_query.isModifierKey)(event)) return;
|
|
200
218
|
send({ type: "INPUT.HOME" });
|
|
201
219
|
event.preventDefault();
|
|
220
|
+
event.stopPropagation();
|
|
202
221
|
},
|
|
203
222
|
End() {
|
|
204
223
|
if ((0, import_dom_query.isModifierKey)(event)) return;
|
|
205
224
|
send({ type: "INPUT.END" });
|
|
206
225
|
event.preventDefault();
|
|
226
|
+
event.stopPropagation();
|
|
207
227
|
},
|
|
208
228
|
Enter(event2) {
|
|
209
229
|
const selection = (0, import_cursor.recordCursor)(event2.currentTarget, scope);
|
|
@@ -215,19 +235,21 @@ function connect(service, normalize) {
|
|
|
215
235
|
}
|
|
216
236
|
});
|
|
217
237
|
},
|
|
238
|
+
getDecrementTriggerState,
|
|
218
239
|
getDecrementTriggerProps() {
|
|
240
|
+
const decrementTriggerState = getDecrementTriggerState();
|
|
219
241
|
return normalize.button({
|
|
220
242
|
...import_number_input.parts.decrementTrigger.attrs(scope.id),
|
|
221
243
|
dir: prop("dir"),
|
|
222
|
-
disabled:
|
|
223
|
-
"data-disabled": (0, import_dom_query.dataAttr)(
|
|
244
|
+
disabled: decrementTriggerState.disabled,
|
|
245
|
+
"data-disabled": (0, import_dom_query.dataAttr)(decrementTriggerState.disabled),
|
|
224
246
|
"aria-label": translations.decrementLabel,
|
|
225
247
|
type: "button",
|
|
226
248
|
tabIndex: -1,
|
|
227
249
|
"aria-controls": dom.getInputId(scope),
|
|
228
250
|
"data-scrubbing": (0, import_dom_query.dataAttr)(scrubbing),
|
|
229
251
|
onPointerDown(event) {
|
|
230
|
-
if (
|
|
252
|
+
if (decrementTriggerState.disabled) return;
|
|
231
253
|
if (!(0, import_dom_query.isLeftClick)(event)) return;
|
|
232
254
|
send({ type: "TRIGGER.PRESS_DOWN", hint: "decrement", pointerType: event.pointerType });
|
|
233
255
|
if (event.pointerType === "mouse") {
|
|
@@ -241,24 +263,26 @@ function connect(service, normalize) {
|
|
|
241
263
|
send({ type: "TRIGGER.PRESS_UP", hint: "decrement", pointerType: event.pointerType });
|
|
242
264
|
},
|
|
243
265
|
onPointerLeave() {
|
|
244
|
-
if (
|
|
266
|
+
if (decrementTriggerState.disabled) return;
|
|
245
267
|
send({ type: "TRIGGER.PRESS_UP", hint: "decrement" });
|
|
246
268
|
}
|
|
247
269
|
});
|
|
248
270
|
},
|
|
271
|
+
getIncrementTriggerState,
|
|
249
272
|
getIncrementTriggerProps() {
|
|
273
|
+
const incrementTriggerState = getIncrementTriggerState();
|
|
250
274
|
return normalize.button({
|
|
251
275
|
...import_number_input.parts.incrementTrigger.attrs(scope.id),
|
|
252
276
|
dir: prop("dir"),
|
|
253
|
-
disabled:
|
|
254
|
-
"data-disabled": (0, import_dom_query.dataAttr)(
|
|
277
|
+
disabled: incrementTriggerState.disabled,
|
|
278
|
+
"data-disabled": (0, import_dom_query.dataAttr)(incrementTriggerState.disabled),
|
|
255
279
|
"aria-label": translations.incrementLabel,
|
|
256
280
|
type: "button",
|
|
257
281
|
tabIndex: -1,
|
|
258
282
|
"aria-controls": dom.getInputId(scope),
|
|
259
283
|
"data-scrubbing": (0, import_dom_query.dataAttr)(scrubbing),
|
|
260
284
|
onPointerDown(event) {
|
|
261
|
-
if (
|
|
285
|
+
if (incrementTriggerState.disabled || !(0, import_dom_query.isLeftClick)(event)) return;
|
|
262
286
|
send({ type: "TRIGGER.PRESS_DOWN", hint: "increment", pointerType: event.pointerType });
|
|
263
287
|
if (event.pointerType === "mouse") {
|
|
264
288
|
event.preventDefault();
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
ariaAttr,
|
|
4
4
|
dataAttr,
|
|
5
5
|
getEventPoint,
|
|
6
|
-
|
|
6
|
+
getEventStepValue,
|
|
7
7
|
getWindow,
|
|
8
8
|
MAX_Z_INDEX,
|
|
9
9
|
isComposingEvent,
|
|
@@ -28,6 +28,18 @@ function connect(service, normalize) {
|
|
|
28
28
|
const isIncrementDisabled = disabled || !computed("canIncrement") || readOnly;
|
|
29
29
|
const isDecrementDisabled = disabled || !computed("canDecrement") || readOnly;
|
|
30
30
|
const translations = prop("translations");
|
|
31
|
+
function getRootState() {
|
|
32
|
+
return { disabled, focused, invalid, scrubbing };
|
|
33
|
+
}
|
|
34
|
+
function getInputState() {
|
|
35
|
+
return { disabled, invalid, readOnly, scrubbing };
|
|
36
|
+
}
|
|
37
|
+
function getIncrementTriggerState() {
|
|
38
|
+
return { disabled: isIncrementDisabled };
|
|
39
|
+
}
|
|
40
|
+
function getDecrementTriggerState() {
|
|
41
|
+
return { disabled: isDecrementDisabled };
|
|
42
|
+
}
|
|
31
43
|
return {
|
|
32
44
|
focused,
|
|
33
45
|
scrubbing,
|
|
@@ -56,14 +68,16 @@ function connect(service, normalize) {
|
|
|
56
68
|
focus() {
|
|
57
69
|
dom.getInputEl(scope)?.focus();
|
|
58
70
|
},
|
|
71
|
+
getRootState,
|
|
59
72
|
getRootProps() {
|
|
73
|
+
const rootState = getRootState();
|
|
60
74
|
return normalize.element({
|
|
61
75
|
...parts.root.attrs(scope.id),
|
|
62
76
|
dir: prop("dir"),
|
|
63
|
-
"data-disabled": dataAttr(disabled),
|
|
64
|
-
"data-focus": dataAttr(focused),
|
|
65
|
-
"data-invalid": dataAttr(invalid),
|
|
66
|
-
"data-scrubbing": dataAttr(scrubbing)
|
|
77
|
+
"data-disabled": dataAttr(rootState.disabled),
|
|
78
|
+
"data-focus": dataAttr(rootState.focused),
|
|
79
|
+
"data-invalid": dataAttr(rootState.invalid),
|
|
80
|
+
"data-scrubbing": dataAttr(rootState.scrubbing)
|
|
67
81
|
});
|
|
68
82
|
},
|
|
69
83
|
getLabelProps() {
|
|
@@ -107,7 +121,9 @@ function connect(service, normalize) {
|
|
|
107
121
|
"data-scrubbing": dataAttr(scrubbing)
|
|
108
122
|
});
|
|
109
123
|
},
|
|
124
|
+
getInputState,
|
|
110
125
|
getInputProps() {
|
|
126
|
+
const inputState = getInputState();
|
|
111
127
|
return normalize.input({
|
|
112
128
|
...parts.input.attrs(scope.id),
|
|
113
129
|
dir: prop("dir"),
|
|
@@ -118,11 +134,11 @@ function connect(service, normalize) {
|
|
|
118
134
|
defaultValue: computed("formattedValue"),
|
|
119
135
|
pattern: prop("formatOptions") ? void 0 : prop("pattern"),
|
|
120
136
|
inputMode: prop("inputMode"),
|
|
121
|
-
"aria-invalid": ariaAttr(invalid),
|
|
122
|
-
"data-invalid": dataAttr(invalid),
|
|
123
|
-
disabled,
|
|
124
|
-
"data-disabled": dataAttr(disabled),
|
|
125
|
-
readOnly,
|
|
137
|
+
"aria-invalid": ariaAttr(inputState.invalid),
|
|
138
|
+
"data-invalid": dataAttr(inputState.invalid),
|
|
139
|
+
disabled: inputState.disabled,
|
|
140
|
+
"data-disabled": dataAttr(inputState.disabled),
|
|
141
|
+
readOnly: inputState.readOnly,
|
|
126
142
|
required: prop("required"),
|
|
127
143
|
autoComplete: "off",
|
|
128
144
|
autoCorrect: "off",
|
|
@@ -133,7 +149,7 @@ function connect(service, normalize) {
|
|
|
133
149
|
"aria-valuemax": prop("max"),
|
|
134
150
|
"aria-valuenow": Number.isNaN(computed("valueAsNumber")) ? void 0 : computed("valueAsNumber"),
|
|
135
151
|
"aria-valuetext": computed("valueText"),
|
|
136
|
-
"data-scrubbing": dataAttr(scrubbing),
|
|
152
|
+
"data-scrubbing": dataAttr(inputState.scrubbing),
|
|
137
153
|
onFocus() {
|
|
138
154
|
send({ type: "INPUT.FOCUS" });
|
|
139
155
|
},
|
|
@@ -159,7 +175,7 @@ function connect(service, normalize) {
|
|
|
159
175
|
if (event.defaultPrevented) return;
|
|
160
176
|
if (readOnly) return;
|
|
161
177
|
if (isComposingEvent(event)) return;
|
|
162
|
-
const step =
|
|
178
|
+
const step = getEventStepValue(event, {
|
|
163
179
|
step: prop("step"),
|
|
164
180
|
largeStep: prop("largeStep"),
|
|
165
181
|
smallStep: prop("smallStep")
|
|
@@ -168,20 +184,24 @@ function connect(service, normalize) {
|
|
|
168
184
|
ArrowUp() {
|
|
169
185
|
send({ type: "INPUT.ARROW_UP", step });
|
|
170
186
|
event.preventDefault();
|
|
187
|
+
event.stopPropagation();
|
|
171
188
|
},
|
|
172
189
|
ArrowDown() {
|
|
173
190
|
send({ type: "INPUT.ARROW_DOWN", step });
|
|
174
191
|
event.preventDefault();
|
|
192
|
+
event.stopPropagation();
|
|
175
193
|
},
|
|
176
194
|
Home() {
|
|
177
195
|
if (isModifierKey(event)) return;
|
|
178
196
|
send({ type: "INPUT.HOME" });
|
|
179
197
|
event.preventDefault();
|
|
198
|
+
event.stopPropagation();
|
|
180
199
|
},
|
|
181
200
|
End() {
|
|
182
201
|
if (isModifierKey(event)) return;
|
|
183
202
|
send({ type: "INPUT.END" });
|
|
184
203
|
event.preventDefault();
|
|
204
|
+
event.stopPropagation();
|
|
185
205
|
},
|
|
186
206
|
Enter(event2) {
|
|
187
207
|
const selection = recordCursor(event2.currentTarget, scope);
|
|
@@ -193,19 +213,21 @@ function connect(service, normalize) {
|
|
|
193
213
|
}
|
|
194
214
|
});
|
|
195
215
|
},
|
|
216
|
+
getDecrementTriggerState,
|
|
196
217
|
getDecrementTriggerProps() {
|
|
218
|
+
const decrementTriggerState = getDecrementTriggerState();
|
|
197
219
|
return normalize.button({
|
|
198
220
|
...parts.decrementTrigger.attrs(scope.id),
|
|
199
221
|
dir: prop("dir"),
|
|
200
|
-
disabled:
|
|
201
|
-
"data-disabled": dataAttr(
|
|
222
|
+
disabled: decrementTriggerState.disabled,
|
|
223
|
+
"data-disabled": dataAttr(decrementTriggerState.disabled),
|
|
202
224
|
"aria-label": translations.decrementLabel,
|
|
203
225
|
type: "button",
|
|
204
226
|
tabIndex: -1,
|
|
205
227
|
"aria-controls": dom.getInputId(scope),
|
|
206
228
|
"data-scrubbing": dataAttr(scrubbing),
|
|
207
229
|
onPointerDown(event) {
|
|
208
|
-
if (
|
|
230
|
+
if (decrementTriggerState.disabled) return;
|
|
209
231
|
if (!isLeftClick(event)) return;
|
|
210
232
|
send({ type: "TRIGGER.PRESS_DOWN", hint: "decrement", pointerType: event.pointerType });
|
|
211
233
|
if (event.pointerType === "mouse") {
|
|
@@ -219,24 +241,26 @@ function connect(service, normalize) {
|
|
|
219
241
|
send({ type: "TRIGGER.PRESS_UP", hint: "decrement", pointerType: event.pointerType });
|
|
220
242
|
},
|
|
221
243
|
onPointerLeave() {
|
|
222
|
-
if (
|
|
244
|
+
if (decrementTriggerState.disabled) return;
|
|
223
245
|
send({ type: "TRIGGER.PRESS_UP", hint: "decrement" });
|
|
224
246
|
}
|
|
225
247
|
});
|
|
226
248
|
},
|
|
249
|
+
getIncrementTriggerState,
|
|
227
250
|
getIncrementTriggerProps() {
|
|
251
|
+
const incrementTriggerState = getIncrementTriggerState();
|
|
228
252
|
return normalize.button({
|
|
229
253
|
...parts.incrementTrigger.attrs(scope.id),
|
|
230
254
|
dir: prop("dir"),
|
|
231
|
-
disabled:
|
|
232
|
-
"data-disabled": dataAttr(
|
|
255
|
+
disabled: incrementTriggerState.disabled,
|
|
256
|
+
"data-disabled": dataAttr(incrementTriggerState.disabled),
|
|
233
257
|
"aria-label": translations.incrementLabel,
|
|
234
258
|
type: "button",
|
|
235
259
|
tabIndex: -1,
|
|
236
260
|
"aria-controls": dom.getInputId(scope),
|
|
237
261
|
"data-scrubbing": dataAttr(scrubbing),
|
|
238
262
|
onPointerDown(event) {
|
|
239
|
-
if (
|
|
263
|
+
if (incrementTriggerState.disabled || !isLeftClick(event)) return;
|
|
240
264
|
send({ type: "TRIGGER.PRESS_DOWN", hint: "increment", pointerType: event.pointerType });
|
|
241
265
|
if (event.pointerType === "mouse") {
|
|
242
266
|
event.preventDefault();
|
|
@@ -54,8 +54,6 @@ var machine = createMachine({
|
|
|
54
54
|
pattern: "-?[0-9]*(.[0-9]+)?",
|
|
55
55
|
defaultValue: "",
|
|
56
56
|
step,
|
|
57
|
-
largeStep: props.largeStep ?? step * 10,
|
|
58
|
-
smallStep: props.smallStep ?? step * 0.1,
|
|
59
57
|
min: Number.MIN_SAFE_INTEGER,
|
|
60
58
|
max: Number.MAX_SAFE_INTEGER,
|
|
61
59
|
spinOnPress: true,
|
|
@@ -63,6 +61,8 @@ var machine = createMachine({
|
|
|
63
61
|
scrubberDirection: "horizontal",
|
|
64
62
|
snapOnStep: false,
|
|
65
63
|
...props,
|
|
64
|
+
largeStep: props.largeStep ?? 10 * step,
|
|
65
|
+
smallStep: props.smallStep ?? step / 10,
|
|
66
66
|
translations: {
|
|
67
67
|
incrementLabel: "increment value",
|
|
68
68
|
decrementLabel: "decrease value",
|
|
@@ -396,7 +396,7 @@ var machine = createMachine({
|
|
|
396
396
|
context.set("value", (0, import_number_input.formatValue)(nextValue, { computed, prop }));
|
|
397
397
|
},
|
|
398
398
|
setRawValue({ context, event, prop, computed }) {
|
|
399
|
-
let nextValue = (0, import_number_input.parseValue)(event.value, { computed, prop });
|
|
399
|
+
let nextValue = typeof event.value === "number" ? event.value : (0, import_number_input.parseValue)(event.value, { computed, prop });
|
|
400
400
|
if (!prop("allowOverflow")) nextValue = (0, import_utils.clampValue)(nextValue, prop("min"), prop("max"));
|
|
401
401
|
context.set("value", (0, import_number_input.formatValue)(nextValue, { computed, prop }));
|
|
402
402
|
},
|
|
@@ -38,8 +38,6 @@ var machine = createMachine({
|
|
|
38
38
|
pattern: "-?[0-9]*(.[0-9]+)?",
|
|
39
39
|
defaultValue: "",
|
|
40
40
|
step,
|
|
41
|
-
largeStep: props.largeStep ?? step * 10,
|
|
42
|
-
smallStep: props.smallStep ?? step * 0.1,
|
|
43
41
|
min: Number.MIN_SAFE_INTEGER,
|
|
44
42
|
max: Number.MAX_SAFE_INTEGER,
|
|
45
43
|
spinOnPress: true,
|
|
@@ -47,6 +45,8 @@ var machine = createMachine({
|
|
|
47
45
|
scrubberDirection: "horizontal",
|
|
48
46
|
snapOnStep: false,
|
|
49
47
|
...props,
|
|
48
|
+
largeStep: props.largeStep ?? 10 * step,
|
|
49
|
+
smallStep: props.smallStep ?? step / 10,
|
|
50
50
|
translations: {
|
|
51
51
|
incrementLabel: "increment value",
|
|
52
52
|
decrementLabel: "decrease value",
|
|
@@ -380,7 +380,7 @@ var machine = createMachine({
|
|
|
380
380
|
context.set("value", formatValue(nextValue, { computed, prop }));
|
|
381
381
|
},
|
|
382
382
|
setRawValue({ context, event, prop, computed }) {
|
|
383
|
-
let nextValue = parseValue(event.value, { computed, prop });
|
|
383
|
+
let nextValue = typeof event.value === "number" ? event.value : parseValue(event.value, { computed, prop });
|
|
384
384
|
if (!prop("allowOverflow")) nextValue = clampValue(nextValue, prop("min"), prop("max"));
|
|
385
385
|
context.set("value", formatValue(nextValue, { computed, prop }));
|
|
386
386
|
},
|
|
@@ -183,7 +183,7 @@ interface NumberInputProps extends LocaleProperties, CommonProperties {
|
|
|
183
183
|
*/
|
|
184
184
|
snapOnStep?: boolean | undefined;
|
|
185
185
|
}
|
|
186
|
-
type PropsWithDefault = "dir" | "locale" | "focusInputOnChange" | "clampValueOnBlur" | "allowOverflow" | "inputMode" | "pattern" | "translations" | "step" | "
|
|
186
|
+
type PropsWithDefault = "dir" | "locale" | "focusInputOnChange" | "clampValueOnBlur" | "allowOverflow" | "inputMode" | "pattern" | "translations" | "step" | "largeStep" | "smallStep" | "spinOnPress" | "min" | "max" | "scrubberPixelSensitivity" | "scrubberDirection" | "snapOnStep";
|
|
187
187
|
type ComputedContext = Readonly<{
|
|
188
188
|
/**
|
|
189
189
|
* The value of the input as a number
|
|
@@ -285,6 +285,54 @@ interface NumberInputSchema {
|
|
|
285
285
|
}
|
|
286
286
|
type NumberInputService = Service<NumberInputSchema>;
|
|
287
287
|
type NumberInputMachine = Machine<NumberInputSchema>;
|
|
288
|
+
interface RootState {
|
|
289
|
+
/**
|
|
290
|
+
* Whether the number input is disabled.
|
|
291
|
+
*/
|
|
292
|
+
disabled: boolean;
|
|
293
|
+
/**
|
|
294
|
+
* Whether the number input is focused.
|
|
295
|
+
*/
|
|
296
|
+
focused: boolean;
|
|
297
|
+
/**
|
|
298
|
+
* Whether the number input is invalid.
|
|
299
|
+
*/
|
|
300
|
+
invalid: boolean;
|
|
301
|
+
/**
|
|
302
|
+
* Whether the number input is being scrubbed.
|
|
303
|
+
*/
|
|
304
|
+
scrubbing: boolean;
|
|
305
|
+
}
|
|
306
|
+
interface InputState {
|
|
307
|
+
/**
|
|
308
|
+
* Whether the input is disabled.
|
|
309
|
+
*/
|
|
310
|
+
disabled: boolean;
|
|
311
|
+
/**
|
|
312
|
+
* Whether the input is invalid.
|
|
313
|
+
*/
|
|
314
|
+
invalid: boolean;
|
|
315
|
+
/**
|
|
316
|
+
* Whether the input is read-only.
|
|
317
|
+
*/
|
|
318
|
+
readOnly: boolean;
|
|
319
|
+
/**
|
|
320
|
+
* Whether the input is being scrubbed.
|
|
321
|
+
*/
|
|
322
|
+
scrubbing: boolean;
|
|
323
|
+
}
|
|
324
|
+
interface IncrementTriggerState {
|
|
325
|
+
/**
|
|
326
|
+
* Whether the increment trigger is disabled.
|
|
327
|
+
*/
|
|
328
|
+
disabled: boolean;
|
|
329
|
+
}
|
|
330
|
+
interface DecrementTriggerState {
|
|
331
|
+
/**
|
|
332
|
+
* Whether the decrement trigger is disabled.
|
|
333
|
+
*/
|
|
334
|
+
disabled: boolean;
|
|
335
|
+
}
|
|
288
336
|
interface NumberInputApi<T extends PropTypes = PropTypes> {
|
|
289
337
|
/**
|
|
290
338
|
* Whether the input is focused.
|
|
@@ -338,15 +386,31 @@ interface NumberInputApi<T extends PropTypes = PropTypes> {
|
|
|
338
386
|
* Function to focus the input.
|
|
339
387
|
*/
|
|
340
388
|
focus: VoidFunction;
|
|
389
|
+
/**
|
|
390
|
+
* Returns the state of the root.
|
|
391
|
+
*/
|
|
392
|
+
getRootState: () => RootState;
|
|
341
393
|
getRootProps: () => T["element"];
|
|
342
394
|
getLabelProps: () => T["label"];
|
|
343
395
|
getControlProps: () => T["element"];
|
|
344
396
|
getValueTextProps: () => T["element"];
|
|
397
|
+
/**
|
|
398
|
+
* Returns the state of the input.
|
|
399
|
+
*/
|
|
400
|
+
getInputState: () => InputState;
|
|
345
401
|
getInputProps: () => T["input"];
|
|
402
|
+
/**
|
|
403
|
+
* Returns the state of the decrement trigger.
|
|
404
|
+
*/
|
|
405
|
+
getDecrementTriggerState: () => DecrementTriggerState;
|
|
346
406
|
getDecrementTriggerProps: () => T["button"];
|
|
407
|
+
/**
|
|
408
|
+
* Returns the state of the increment trigger.
|
|
409
|
+
*/
|
|
410
|
+
getIncrementTriggerState: () => IncrementTriggerState;
|
|
347
411
|
getIncrementTriggerProps: () => T["button"];
|
|
348
412
|
getScrubberProps: () => T["element"];
|
|
349
413
|
getScrubberCursorProps: () => T["element"];
|
|
350
414
|
}
|
|
351
415
|
|
|
352
|
-
export type { ElementIds, FocusChangeDetails, HintValue, InputMode, IntlTranslations, NumberInputApi, NumberInputMachine, NumberInputProps, NumberInputSchema, NumberInputService, ValidityState, ValueChangeDetails, ValueInvalidDetails };
|
|
416
|
+
export type { DecrementTriggerState, ElementIds, FocusChangeDetails, HintValue, IncrementTriggerState, InputMode, InputState, IntlTranslations, NumberInputApi, NumberInputMachine, NumberInputProps, NumberInputSchema, NumberInputService, RootState, ValidityState, ValueChangeDetails, ValueInvalidDetails };
|
|
@@ -183,7 +183,7 @@ interface NumberInputProps extends LocaleProperties, CommonProperties {
|
|
|
183
183
|
*/
|
|
184
184
|
snapOnStep?: boolean | undefined;
|
|
185
185
|
}
|
|
186
|
-
type PropsWithDefault = "dir" | "locale" | "focusInputOnChange" | "clampValueOnBlur" | "allowOverflow" | "inputMode" | "pattern" | "translations" | "step" | "
|
|
186
|
+
type PropsWithDefault = "dir" | "locale" | "focusInputOnChange" | "clampValueOnBlur" | "allowOverflow" | "inputMode" | "pattern" | "translations" | "step" | "largeStep" | "smallStep" | "spinOnPress" | "min" | "max" | "scrubberPixelSensitivity" | "scrubberDirection" | "snapOnStep";
|
|
187
187
|
type ComputedContext = Readonly<{
|
|
188
188
|
/**
|
|
189
189
|
* The value of the input as a number
|
|
@@ -285,6 +285,54 @@ interface NumberInputSchema {
|
|
|
285
285
|
}
|
|
286
286
|
type NumberInputService = Service<NumberInputSchema>;
|
|
287
287
|
type NumberInputMachine = Machine<NumberInputSchema>;
|
|
288
|
+
interface RootState {
|
|
289
|
+
/**
|
|
290
|
+
* Whether the number input is disabled.
|
|
291
|
+
*/
|
|
292
|
+
disabled: boolean;
|
|
293
|
+
/**
|
|
294
|
+
* Whether the number input is focused.
|
|
295
|
+
*/
|
|
296
|
+
focused: boolean;
|
|
297
|
+
/**
|
|
298
|
+
* Whether the number input is invalid.
|
|
299
|
+
*/
|
|
300
|
+
invalid: boolean;
|
|
301
|
+
/**
|
|
302
|
+
* Whether the number input is being scrubbed.
|
|
303
|
+
*/
|
|
304
|
+
scrubbing: boolean;
|
|
305
|
+
}
|
|
306
|
+
interface InputState {
|
|
307
|
+
/**
|
|
308
|
+
* Whether the input is disabled.
|
|
309
|
+
*/
|
|
310
|
+
disabled: boolean;
|
|
311
|
+
/**
|
|
312
|
+
* Whether the input is invalid.
|
|
313
|
+
*/
|
|
314
|
+
invalid: boolean;
|
|
315
|
+
/**
|
|
316
|
+
* Whether the input is read-only.
|
|
317
|
+
*/
|
|
318
|
+
readOnly: boolean;
|
|
319
|
+
/**
|
|
320
|
+
* Whether the input is being scrubbed.
|
|
321
|
+
*/
|
|
322
|
+
scrubbing: boolean;
|
|
323
|
+
}
|
|
324
|
+
interface IncrementTriggerState {
|
|
325
|
+
/**
|
|
326
|
+
* Whether the increment trigger is disabled.
|
|
327
|
+
*/
|
|
328
|
+
disabled: boolean;
|
|
329
|
+
}
|
|
330
|
+
interface DecrementTriggerState {
|
|
331
|
+
/**
|
|
332
|
+
* Whether the decrement trigger is disabled.
|
|
333
|
+
*/
|
|
334
|
+
disabled: boolean;
|
|
335
|
+
}
|
|
288
336
|
interface NumberInputApi<T extends PropTypes = PropTypes> {
|
|
289
337
|
/**
|
|
290
338
|
* Whether the input is focused.
|
|
@@ -338,15 +386,31 @@ interface NumberInputApi<T extends PropTypes = PropTypes> {
|
|
|
338
386
|
* Function to focus the input.
|
|
339
387
|
*/
|
|
340
388
|
focus: VoidFunction;
|
|
389
|
+
/**
|
|
390
|
+
* Returns the state of the root.
|
|
391
|
+
*/
|
|
392
|
+
getRootState: () => RootState;
|
|
341
393
|
getRootProps: () => T["element"];
|
|
342
394
|
getLabelProps: () => T["label"];
|
|
343
395
|
getControlProps: () => T["element"];
|
|
344
396
|
getValueTextProps: () => T["element"];
|
|
397
|
+
/**
|
|
398
|
+
* Returns the state of the input.
|
|
399
|
+
*/
|
|
400
|
+
getInputState: () => InputState;
|
|
345
401
|
getInputProps: () => T["input"];
|
|
402
|
+
/**
|
|
403
|
+
* Returns the state of the decrement trigger.
|
|
404
|
+
*/
|
|
405
|
+
getDecrementTriggerState: () => DecrementTriggerState;
|
|
346
406
|
getDecrementTriggerProps: () => T["button"];
|
|
407
|
+
/**
|
|
408
|
+
* Returns the state of the increment trigger.
|
|
409
|
+
*/
|
|
410
|
+
getIncrementTriggerState: () => IncrementTriggerState;
|
|
347
411
|
getIncrementTriggerProps: () => T["button"];
|
|
348
412
|
getScrubberProps: () => T["element"];
|
|
349
413
|
getScrubberCursorProps: () => T["element"];
|
|
350
414
|
}
|
|
351
415
|
|
|
352
|
-
export type { ElementIds, FocusChangeDetails, HintValue, InputMode, IntlTranslations, NumberInputApi, NumberInputMachine, NumberInputProps, NumberInputSchema, NumberInputService, ValidityState, ValueChangeDetails, ValueInvalidDetails };
|
|
416
|
+
export type { DecrementTriggerState, ElementIds, FocusChangeDetails, HintValue, IncrementTriggerState, InputMode, InputState, IntlTranslations, NumberInputApi, NumberInputMachine, NumberInputProps, NumberInputSchema, NumberInputService, RootState, ValidityState, ValueChangeDetails, ValueInvalidDetails };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/number-input",
|
|
3
|
-
"version": "2.0.0-next.
|
|
3
|
+
"version": "2.0.0-next.1",
|
|
4
4
|
"description": "Core logic for the number-input widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -14,7 +14,10 @@
|
|
|
14
14
|
"author": "Segun Adebayo <sage@adebayosegun.com>",
|
|
15
15
|
"homepage": "https://github.com/chakra-ui/zag#readme",
|
|
16
16
|
"license": "MIT",
|
|
17
|
-
"repository":
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "https://github.com/chakra-ui/zag/tree/main/packages/number-input"
|
|
20
|
+
},
|
|
18
21
|
"sideEffects": false,
|
|
19
22
|
"files": [
|
|
20
23
|
"dist"
|
|
@@ -26,12 +29,12 @@
|
|
|
26
29
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
27
30
|
},
|
|
28
31
|
"dependencies": {
|
|
29
|
-
"@internationalized/number": "3.6.
|
|
30
|
-
"@zag-js/anatomy": "2.0.0-next.
|
|
31
|
-
"@zag-js/core": "2.0.0-next.
|
|
32
|
-
"@zag-js/dom-query": "2.0.0-next.
|
|
33
|
-
"@zag-js/types": "2.0.0-next.
|
|
34
|
-
"@zag-js/utils": "2.0.0-next.
|
|
32
|
+
"@internationalized/number": "3.6.7",
|
|
33
|
+
"@zag-js/anatomy": "2.0.0-next.1",
|
|
34
|
+
"@zag-js/core": "2.0.0-next.1",
|
|
35
|
+
"@zag-js/dom-query": "2.0.0-next.1",
|
|
36
|
+
"@zag-js/types": "2.0.0-next.1",
|
|
37
|
+
"@zag-js/utils": "2.0.0-next.1"
|
|
35
38
|
},
|
|
36
39
|
"devDependencies": {
|
|
37
40
|
"clean-package": "2.2.0"
|