@zag-js/number-input 1.41.1 → 1.42.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/number-input.connect.js +5 -1
- package/dist/number-input.connect.mjs +6 -2
- package/dist/number-input.machine.js +3 -1
- package/dist/number-input.machine.mjs +3 -1
- package/dist/number-input.props.js +2 -0
- package/dist/number-input.props.mjs +2 -0
- package/dist/number-input.types.d.mts +11 -1
- package/dist/number-input.types.d.ts +11 -1
- package/package.json +11 -8
|
@@ -181,7 +181,11 @@ function connect(service, normalize) {
|
|
|
181
181
|
if (event.defaultPrevented) return;
|
|
182
182
|
if (readOnly) return;
|
|
183
183
|
if ((0, import_dom_query.isComposingEvent)(event)) return;
|
|
184
|
-
const step = (0, import_dom_query.
|
|
184
|
+
const step = (0, import_dom_query.getEventStepValue)(event, {
|
|
185
|
+
step: prop("step"),
|
|
186
|
+
largeStep: prop("largeStep"),
|
|
187
|
+
smallStep: prop("smallStep")
|
|
188
|
+
});
|
|
185
189
|
const keyMap = {
|
|
186
190
|
ArrowUp() {
|
|
187
191
|
send({ type: "INPUT.ARROW_UP", step });
|
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
ariaAttr,
|
|
4
4
|
dataAttr,
|
|
5
5
|
getEventPoint,
|
|
6
|
-
|
|
6
|
+
getEventStepValue,
|
|
7
7
|
getWindow,
|
|
8
8
|
isComposingEvent,
|
|
9
9
|
isLeftClick,
|
|
@@ -158,7 +158,11 @@ function connect(service, normalize) {
|
|
|
158
158
|
if (event.defaultPrevented) return;
|
|
159
159
|
if (readOnly) return;
|
|
160
160
|
if (isComposingEvent(event)) return;
|
|
161
|
-
const step =
|
|
161
|
+
const step = getEventStepValue(event, {
|
|
162
|
+
step: prop("step"),
|
|
163
|
+
largeStep: prop("largeStep"),
|
|
164
|
+
smallStep: prop("smallStep")
|
|
165
|
+
});
|
|
162
166
|
const keyMap = {
|
|
163
167
|
ArrowUp() {
|
|
164
168
|
send({ type: "INPUT.ARROW_UP", step });
|
|
@@ -58,6 +58,8 @@ var machine = createMachine({
|
|
|
58
58
|
max: Number.MAX_SAFE_INTEGER,
|
|
59
59
|
spinOnPress: true,
|
|
60
60
|
...props,
|
|
61
|
+
largeStep: props.largeStep ?? 10 * step,
|
|
62
|
+
smallStep: props.smallStep ?? step / 10,
|
|
61
63
|
translations: {
|
|
62
64
|
incrementLabel: "increment value",
|
|
63
65
|
decrementLabel: "decrease value",
|
|
@@ -373,7 +375,7 @@ var machine = createMachine({
|
|
|
373
375
|
context.set("value", (0, import_number_input.formatValue)(nextValue, { computed, prop }));
|
|
374
376
|
},
|
|
375
377
|
setRawValue({ context, event, prop, computed }) {
|
|
376
|
-
let nextValue = (0, import_number_input.parseValue)(event.value, { computed, prop });
|
|
378
|
+
let nextValue = typeof event.value === "number" ? event.value : (0, import_number_input.parseValue)(event.value, { computed, prop });
|
|
377
379
|
if (!prop("allowOverflow")) nextValue = (0, import_utils.clampValue)(nextValue, prop("min"), prop("max"));
|
|
378
380
|
context.set("value", (0, import_number_input.formatValue)(nextValue, { computed, prop }));
|
|
379
381
|
},
|
|
@@ -40,6 +40,8 @@ var machine = createMachine({
|
|
|
40
40
|
max: Number.MAX_SAFE_INTEGER,
|
|
41
41
|
spinOnPress: true,
|
|
42
42
|
...props,
|
|
43
|
+
largeStep: props.largeStep ?? 10 * step,
|
|
44
|
+
smallStep: props.smallStep ?? step / 10,
|
|
43
45
|
translations: {
|
|
44
46
|
incrementLabel: "increment value",
|
|
45
47
|
decrementLabel: "decrease value",
|
|
@@ -355,7 +357,7 @@ var machine = createMachine({
|
|
|
355
357
|
context.set("value", formatValue(nextValue, { computed, prop }));
|
|
356
358
|
},
|
|
357
359
|
setRawValue({ context, event, prop, computed }) {
|
|
358
|
-
let nextValue = parseValue(event.value, { computed, prop });
|
|
360
|
+
let nextValue = typeof event.value === "number" ? event.value : parseValue(event.value, { computed, prop });
|
|
359
361
|
if (!prop("allowOverflow")) nextValue = clampValue(nextValue, prop("min"), prop("max"));
|
|
360
362
|
context.set("value", formatValue(nextValue, { computed, prop }));
|
|
361
363
|
},
|
|
@@ -40,6 +40,7 @@ var props = (0, import_types.createProps)()([
|
|
|
40
40
|
"ids",
|
|
41
41
|
"inputMode",
|
|
42
42
|
"invalid",
|
|
43
|
+
"largeStep",
|
|
43
44
|
"locale",
|
|
44
45
|
"max",
|
|
45
46
|
"min",
|
|
@@ -51,6 +52,7 @@ var props = (0, import_types.createProps)()([
|
|
|
51
52
|
"pattern",
|
|
52
53
|
"required",
|
|
53
54
|
"readOnly",
|
|
55
|
+
"smallStep",
|
|
54
56
|
"spinOnPress",
|
|
55
57
|
"step",
|
|
56
58
|
"translations",
|
|
@@ -15,6 +15,7 @@ var props = createProps()([
|
|
|
15
15
|
"ids",
|
|
16
16
|
"inputMode",
|
|
17
17
|
"invalid",
|
|
18
|
+
"largeStep",
|
|
18
19
|
"locale",
|
|
19
20
|
"max",
|
|
20
21
|
"min",
|
|
@@ -26,6 +27,7 @@ var props = createProps()([
|
|
|
26
27
|
"pattern",
|
|
27
28
|
"required",
|
|
28
29
|
"readOnly",
|
|
30
|
+
"smallStep",
|
|
29
31
|
"spinOnPress",
|
|
30
32
|
"step",
|
|
31
33
|
"translations",
|
|
@@ -96,6 +96,16 @@ interface NumberInputProps extends LocaleProperties, CommonProperties {
|
|
|
96
96
|
* @default 1
|
|
97
97
|
*/
|
|
98
98
|
step?: number | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* The amount to increment or decrement the value by when the `Shift` key is held.
|
|
101
|
+
* @default 10 * step
|
|
102
|
+
*/
|
|
103
|
+
largeStep?: number | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* The amount to increment or decrement the value by when the `Alt` key is held.
|
|
106
|
+
* @default step / 10
|
|
107
|
+
*/
|
|
108
|
+
smallStep?: number | undefined;
|
|
99
109
|
/**
|
|
100
110
|
* Whether to allow mouse wheel to change the value
|
|
101
111
|
*/
|
|
@@ -151,7 +161,7 @@ interface NumberInputProps extends LocaleProperties, CommonProperties {
|
|
|
151
161
|
*/
|
|
152
162
|
spinOnPress?: boolean | undefined;
|
|
153
163
|
}
|
|
154
|
-
type PropsWithDefault = "dir" | "locale" | "focusInputOnChange" | "clampValueOnBlur" | "allowOverflow" | "inputMode" | "pattern" | "translations" | "step" | "
|
|
164
|
+
type PropsWithDefault = "dir" | "locale" | "focusInputOnChange" | "clampValueOnBlur" | "allowOverflow" | "inputMode" | "pattern" | "translations" | "step" | "largeStep" | "smallStep" | "spinOnPress" | "min" | "max";
|
|
155
165
|
type ComputedContext = Readonly<{
|
|
156
166
|
/**
|
|
157
167
|
* The value of the input as a number
|
|
@@ -96,6 +96,16 @@ interface NumberInputProps extends LocaleProperties, CommonProperties {
|
|
|
96
96
|
* @default 1
|
|
97
97
|
*/
|
|
98
98
|
step?: number | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* The amount to increment or decrement the value by when the `Shift` key is held.
|
|
101
|
+
* @default 10 * step
|
|
102
|
+
*/
|
|
103
|
+
largeStep?: number | undefined;
|
|
104
|
+
/**
|
|
105
|
+
* The amount to increment or decrement the value by when the `Alt` key is held.
|
|
106
|
+
* @default step / 10
|
|
107
|
+
*/
|
|
108
|
+
smallStep?: number | undefined;
|
|
99
109
|
/**
|
|
100
110
|
* Whether to allow mouse wheel to change the value
|
|
101
111
|
*/
|
|
@@ -151,7 +161,7 @@ interface NumberInputProps extends LocaleProperties, CommonProperties {
|
|
|
151
161
|
*/
|
|
152
162
|
spinOnPress?: boolean | undefined;
|
|
153
163
|
}
|
|
154
|
-
type PropsWithDefault = "dir" | "locale" | "focusInputOnChange" | "clampValueOnBlur" | "allowOverflow" | "inputMode" | "pattern" | "translations" | "step" | "
|
|
164
|
+
type PropsWithDefault = "dir" | "locale" | "focusInputOnChange" | "clampValueOnBlur" | "allowOverflow" | "inputMode" | "pattern" | "translations" | "step" | "largeStep" | "smallStep" | "spinOnPress" | "min" | "max";
|
|
155
165
|
type ComputedContext = Readonly<{
|
|
156
166
|
/**
|
|
157
167
|
* The value of the input as a number
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/number-input",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.42.0",
|
|
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": "1.
|
|
31
|
-
"@zag-js/core": "1.
|
|
32
|
-
"@zag-js/dom-query": "1.
|
|
33
|
-
"@zag-js/types": "1.
|
|
34
|
-
"@zag-js/utils": "1.
|
|
32
|
+
"@internationalized/number": "3.6.7",
|
|
33
|
+
"@zag-js/anatomy": "1.42.0",
|
|
34
|
+
"@zag-js/core": "1.42.0",
|
|
35
|
+
"@zag-js/dom-query": "1.42.0",
|
|
36
|
+
"@zag-js/types": "1.42.0",
|
|
37
|
+
"@zag-js/utils": "1.42.0"
|
|
35
38
|
},
|
|
36
39
|
"devDependencies": {
|
|
37
40
|
"clean-package": "2.2.0"
|