@zag-js/number-input 1.43.1 → 1.43.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/number-input.connect.js +2 -1
- package/dist/number-input.connect.mjs +3 -2
- package/dist/number-input.machine.js +20 -21
- package/dist/number-input.machine.mjs +8 -8
- 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 +7 -7
- package/dist/number-input.types.d.ts +7 -7
- package/package.json +6 -6
|
@@ -38,6 +38,7 @@ var import_utils = require("@zag-js/utils");
|
|
|
38
38
|
var import_cursor = require("./cursor.js");
|
|
39
39
|
var import_number_input = require("./number-input.anatomy.js");
|
|
40
40
|
var dom = __toESM(require("./number-input.dom.js"));
|
|
41
|
+
var import_number_input2 = require("./number-input.translations.js");
|
|
41
42
|
function connect(service, normalize) {
|
|
42
43
|
const { state, send, prop, scope, computed } = service;
|
|
43
44
|
const focused = state.hasTag("focus");
|
|
@@ -49,7 +50,7 @@ function connect(service, normalize) {
|
|
|
49
50
|
const invalid = prop("invalid") !== void 0 ? !!prop("invalid") : computed("isOutOfRange");
|
|
50
51
|
const isIncrementDisabled = disabled || !computed("canIncrement") || readOnly;
|
|
51
52
|
const isDecrementDisabled = disabled || !computed("canDecrement") || readOnly;
|
|
52
|
-
const translations = prop("translations");
|
|
53
|
+
const translations = (0, import_utils.mergeWithDefault)(import_number_input2.defaultTranslations, prop("translations"));
|
|
53
54
|
return {
|
|
54
55
|
focused,
|
|
55
56
|
invalid,
|
|
@@ -11,10 +11,11 @@ import {
|
|
|
11
11
|
raf,
|
|
12
12
|
setCaretToEnd
|
|
13
13
|
} from "@zag-js/dom-query";
|
|
14
|
-
import { roundToDpr } from "@zag-js/utils";
|
|
14
|
+
import { mergeWithDefault, roundToDpr } from "@zag-js/utils";
|
|
15
15
|
import { recordCursor } from "./cursor.mjs";
|
|
16
16
|
import { parts } from "./number-input.anatomy.mjs";
|
|
17
17
|
import * as dom from "./number-input.dom.mjs";
|
|
18
|
+
import { defaultTranslations } from "./number-input.translations.mjs";
|
|
18
19
|
function connect(service, normalize) {
|
|
19
20
|
const { state, send, prop, scope, computed } = service;
|
|
20
21
|
const focused = state.hasTag("focus");
|
|
@@ -26,7 +27,7 @@ function connect(service, normalize) {
|
|
|
26
27
|
const invalid = prop("invalid") !== void 0 ? !!prop("invalid") : computed("isOutOfRange");
|
|
27
28
|
const isIncrementDisabled = disabled || !computed("canIncrement") || readOnly;
|
|
28
29
|
const isDecrementDisabled = disabled || !computed("canDecrement") || readOnly;
|
|
29
|
-
const translations = prop("translations");
|
|
30
|
+
const translations = mergeWithDefault(defaultTranslations, prop("translations"));
|
|
30
31
|
return {
|
|
31
32
|
focused,
|
|
32
33
|
invalid,
|
|
@@ -38,12 +38,13 @@ var import_dom_query = require("@zag-js/dom-query");
|
|
|
38
38
|
var import_utils = require("@zag-js/utils");
|
|
39
39
|
var import_cursor = require("./cursor.js");
|
|
40
40
|
var dom = __toESM(require("./number-input.dom.js"));
|
|
41
|
-
var import_number_input = require("./number-input.
|
|
41
|
+
var import_number_input = require("./number-input.translations.js");
|
|
42
|
+
var import_number_input2 = require("./number-input.utils.js");
|
|
42
43
|
var { choose, guards, createMachine } = (0, import_core.setup)();
|
|
43
44
|
var { not, and } = guards;
|
|
44
45
|
var machine = createMachine({
|
|
45
46
|
props({ props }) {
|
|
46
|
-
const step = (0,
|
|
47
|
+
const step = (0, import_number_input2.getDefaultStep)(props.step, props.formatOptions);
|
|
47
48
|
return {
|
|
48
49
|
dir: "ltr",
|
|
49
50
|
locale: "en-US",
|
|
@@ -59,12 +60,7 @@ var machine = createMachine({
|
|
|
59
60
|
spinOnPress: true,
|
|
60
61
|
...props,
|
|
61
62
|
largeStep: props.largeStep ?? 10 * step,
|
|
62
|
-
smallStep: props.smallStep ?? step / 10
|
|
63
|
-
translations: {
|
|
64
|
-
incrementLabel: "increment value",
|
|
65
|
-
decrementLabel: "decrease value",
|
|
66
|
-
...props.translations
|
|
67
|
-
}
|
|
63
|
+
smallStep: props.smallStep ?? step / 10
|
|
68
64
|
};
|
|
69
65
|
},
|
|
70
66
|
initialState() {
|
|
@@ -77,7 +73,7 @@ var machine = createMachine({
|
|
|
77
73
|
value: prop("value"),
|
|
78
74
|
onChange(value) {
|
|
79
75
|
const computed = getComputed();
|
|
80
|
-
const valueAsNumber = (0,
|
|
76
|
+
const valueAsNumber = (0, import_number_input2.parseValue)(value, { computed, prop });
|
|
81
77
|
prop("onValueChange")?.({ value, valueAsNumber });
|
|
82
78
|
}
|
|
83
79
|
})),
|
|
@@ -93,8 +89,8 @@ var machine = createMachine({
|
|
|
93
89
|
},
|
|
94
90
|
computed: {
|
|
95
91
|
isRtl: ({ prop }) => prop("dir") === "rtl",
|
|
96
|
-
valueAsNumber: ({ context, computed, prop }) => (0,
|
|
97
|
-
formattedValue: ({ computed, prop }) => (0,
|
|
92
|
+
valueAsNumber: ({ context, computed, prop }) => (0, import_number_input2.parseValue)(context.get("value"), { computed, prop }),
|
|
93
|
+
formattedValue: ({ computed, prop }) => (0, import_number_input2.formatValue)(computed("valueAsNumber"), { computed, prop }),
|
|
98
94
|
isAtMin: ({ computed, prop }) => (0, import_utils.isValueAtMin)(computed("valueAsNumber"), prop("min")),
|
|
99
95
|
isAtMax: ({ computed, prop }) => (0, import_utils.isValueAtMax)(computed("valueAsNumber"), prop("max")),
|
|
100
96
|
isOutOfRange: ({ computed, prop }) => !(0, import_utils.isValueWithinRange)(computed("valueAsNumber"), prop("min"), prop("max")),
|
|
@@ -102,14 +98,17 @@ var machine = createMachine({
|
|
|
102
98
|
isDisabled: ({ prop, context }) => !!prop("disabled") || context.get("fieldsetDisabled"),
|
|
103
99
|
canIncrement: ({ prop, computed }) => prop("allowOverflow") || !computed("isAtMax"),
|
|
104
100
|
canDecrement: ({ prop, computed }) => prop("allowOverflow") || !computed("isAtMin"),
|
|
105
|
-
valueText: ({ prop, context }) =>
|
|
101
|
+
valueText: ({ prop, context }) => {
|
|
102
|
+
const translations = (0, import_utils.mergeWithDefault)(import_number_input.defaultTranslations, prop("translations"));
|
|
103
|
+
return translations.valueText?.(context.get("value"));
|
|
104
|
+
},
|
|
106
105
|
formatter: (0, import_core.memo)(
|
|
107
106
|
({ prop }) => [prop("locale"), prop("formatOptions")],
|
|
108
|
-
([locale, formatOptions]) => (0,
|
|
107
|
+
([locale, formatOptions]) => (0, import_number_input2.createFormatter)(locale, formatOptions)
|
|
109
108
|
),
|
|
110
109
|
parser: (0, import_core.memo)(
|
|
111
110
|
({ prop }) => [prop("locale"), prop("formatOptions")],
|
|
112
|
-
([locale, formatOptions]) => (0,
|
|
111
|
+
([locale, formatOptions]) => (0, import_number_input2.createParser)(locale, formatOptions)
|
|
113
112
|
)
|
|
114
113
|
},
|
|
115
114
|
watch({ track, action, context, computed, prop }) {
|
|
@@ -363,21 +362,21 @@ var machine = createMachine({
|
|
|
363
362
|
increment({ context, event, prop, computed }) {
|
|
364
363
|
let nextValue = (0, import_utils.incrementValue)(computed("valueAsNumber"), event.step ?? prop("step"));
|
|
365
364
|
if (!prop("allowOverflow")) nextValue = (0, import_utils.clampValue)(nextValue, prop("min"), prop("max"));
|
|
366
|
-
context.set("value", (0,
|
|
365
|
+
context.set("value", (0, import_number_input2.formatValue)(nextValue, { computed, prop }));
|
|
367
366
|
},
|
|
368
367
|
decrement({ context, event, prop, computed }) {
|
|
369
368
|
let nextValue = (0, import_utils.decrementValue)(computed("valueAsNumber"), event.step ?? prop("step"));
|
|
370
369
|
if (!prop("allowOverflow")) nextValue = (0, import_utils.clampValue)(nextValue, prop("min"), prop("max"));
|
|
371
|
-
context.set("value", (0,
|
|
370
|
+
context.set("value", (0, import_number_input2.formatValue)(nextValue, { computed, prop }));
|
|
372
371
|
},
|
|
373
372
|
setClampedValue({ context, prop, computed }) {
|
|
374
373
|
const nextValue = (0, import_utils.clampValue)(computed("valueAsNumber"), prop("min"), prop("max"));
|
|
375
|
-
context.set("value", (0,
|
|
374
|
+
context.set("value", (0, import_number_input2.formatValue)(nextValue, { computed, prop }));
|
|
376
375
|
},
|
|
377
376
|
setRawValue({ context, event, prop, computed }) {
|
|
378
|
-
let nextValue = typeof event.value === "number" ? event.value : (0,
|
|
377
|
+
let nextValue = typeof event.value === "number" ? event.value : (0, import_number_input2.parseValue)(event.value, { computed, prop });
|
|
379
378
|
if (!prop("allowOverflow")) nextValue = (0, import_utils.clampValue)(nextValue, prop("min"), prop("max"));
|
|
380
|
-
context.set("value", (0,
|
|
379
|
+
context.set("value", (0, import_number_input2.formatValue)(nextValue, { computed, prop }));
|
|
381
380
|
},
|
|
382
381
|
setValue({ context, event }) {
|
|
383
382
|
const value = event.target?.value ?? event.value;
|
|
@@ -387,11 +386,11 @@ var machine = createMachine({
|
|
|
387
386
|
context.set("value", "");
|
|
388
387
|
},
|
|
389
388
|
incrementToMax({ context, prop, computed }) {
|
|
390
|
-
const value = (0,
|
|
389
|
+
const value = (0, import_number_input2.formatValue)(prop("max"), { computed, prop });
|
|
391
390
|
context.set("value", value);
|
|
392
391
|
},
|
|
393
392
|
decrementToMin({ context, prop, computed }) {
|
|
394
|
-
const value = (0,
|
|
393
|
+
const value = (0, import_number_input2.formatValue)(prop("min"), { computed, prop });
|
|
395
394
|
context.set("value", value);
|
|
396
395
|
},
|
|
397
396
|
setHint({ context, event }) {
|
|
@@ -16,10 +16,12 @@ import {
|
|
|
16
16
|
incrementValue,
|
|
17
17
|
isValueAtMax,
|
|
18
18
|
isValueAtMin,
|
|
19
|
-
isValueWithinRange
|
|
19
|
+
isValueWithinRange,
|
|
20
|
+
mergeWithDefault
|
|
20
21
|
} from "@zag-js/utils";
|
|
21
22
|
import { recordCursor, restoreCursor } from "./cursor.mjs";
|
|
22
23
|
import * as dom from "./number-input.dom.mjs";
|
|
24
|
+
import { defaultTranslations } from "./number-input.translations.mjs";
|
|
23
25
|
import { createFormatter, createParser, formatValue, getDefaultStep, parseValue } from "./number-input.utils.mjs";
|
|
24
26
|
var { choose, guards, createMachine } = setup();
|
|
25
27
|
var { not, and } = guards;
|
|
@@ -41,12 +43,7 @@ var machine = createMachine({
|
|
|
41
43
|
spinOnPress: true,
|
|
42
44
|
...props,
|
|
43
45
|
largeStep: props.largeStep ?? 10 * step,
|
|
44
|
-
smallStep: props.smallStep ?? step / 10
|
|
45
|
-
translations: {
|
|
46
|
-
incrementLabel: "increment value",
|
|
47
|
-
decrementLabel: "decrease value",
|
|
48
|
-
...props.translations
|
|
49
|
-
}
|
|
46
|
+
smallStep: props.smallStep ?? step / 10
|
|
50
47
|
};
|
|
51
48
|
},
|
|
52
49
|
initialState() {
|
|
@@ -84,7 +81,10 @@ var machine = createMachine({
|
|
|
84
81
|
isDisabled: ({ prop, context }) => !!prop("disabled") || context.get("fieldsetDisabled"),
|
|
85
82
|
canIncrement: ({ prop, computed }) => prop("allowOverflow") || !computed("isAtMax"),
|
|
86
83
|
canDecrement: ({ prop, computed }) => prop("allowOverflow") || !computed("isAtMin"),
|
|
87
|
-
valueText: ({ prop, context }) =>
|
|
84
|
+
valueText: ({ prop, context }) => {
|
|
85
|
+
const translations = mergeWithDefault(defaultTranslations, prop("translations"));
|
|
86
|
+
return translations.valueText?.(context.get("value"));
|
|
87
|
+
},
|
|
88
88
|
formatter: memo(
|
|
89
89
|
({ prop }) => [prop("locale"), prop("formatOptions")],
|
|
90
90
|
([locale, formatOptions]) => createFormatter(locale, formatOptions)
|
|
@@ -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,6 +1,6 @@
|
|
|
1
1
|
import { NumberParser } from '@internationalized/number';
|
|
2
2
|
import { Machine, EventObject, Service } from '@zag-js/core';
|
|
3
|
-
import { PropTypes, RequiredBy, LocaleProperties, CommonProperties } from '@zag-js/types';
|
|
3
|
+
import { PropTypes, Partial, RequiredBy, LocaleProperties, CommonProperties } from '@zag-js/types';
|
|
4
4
|
|
|
5
5
|
interface ValueChangeDetails {
|
|
6
6
|
value: string;
|
|
@@ -22,21 +22,21 @@ type ElementIds = Partial<{
|
|
|
22
22
|
decrementTrigger: string;
|
|
23
23
|
scrubber: string;
|
|
24
24
|
}>;
|
|
25
|
-
|
|
25
|
+
type IntlTranslations = Partial<{
|
|
26
26
|
/**
|
|
27
27
|
* Function that returns the human-readable value.
|
|
28
28
|
* It is used to set the `aria-valuetext` property of the input
|
|
29
29
|
*/
|
|
30
|
-
valueText
|
|
30
|
+
valueText: (value: string) => string;
|
|
31
31
|
/**
|
|
32
32
|
* The label foe the increment button
|
|
33
33
|
*/
|
|
34
|
-
incrementLabel
|
|
34
|
+
incrementLabel: string;
|
|
35
35
|
/**
|
|
36
36
|
* The label for the decrement button
|
|
37
37
|
*/
|
|
38
|
-
decrementLabel
|
|
39
|
-
}
|
|
38
|
+
decrementLabel: string;
|
|
39
|
+
}>;
|
|
40
40
|
interface NumberInputProps extends LocaleProperties, CommonProperties {
|
|
41
41
|
/**
|
|
42
42
|
* The ids of the elements in the number input. Useful for composition.
|
|
@@ -161,7 +161,7 @@ interface NumberInputProps extends LocaleProperties, CommonProperties {
|
|
|
161
161
|
*/
|
|
162
162
|
spinOnPress?: boolean | undefined;
|
|
163
163
|
}
|
|
164
|
-
type PropsWithDefault = "dir" | "locale" | "focusInputOnChange" | "clampValueOnBlur" | "allowOverflow" | "inputMode" | "pattern" | "
|
|
164
|
+
type PropsWithDefault = "dir" | "locale" | "focusInputOnChange" | "clampValueOnBlur" | "allowOverflow" | "inputMode" | "pattern" | "step" | "largeStep" | "smallStep" | "spinOnPress" | "min" | "max";
|
|
165
165
|
type ComputedContext = Readonly<{
|
|
166
166
|
/**
|
|
167
167
|
* The value of the input as a number
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NumberParser } from '@internationalized/number';
|
|
2
2
|
import { Machine, EventObject, Service } from '@zag-js/core';
|
|
3
|
-
import { PropTypes, RequiredBy, LocaleProperties, CommonProperties } from '@zag-js/types';
|
|
3
|
+
import { PropTypes, Partial, RequiredBy, LocaleProperties, CommonProperties } from '@zag-js/types';
|
|
4
4
|
|
|
5
5
|
interface ValueChangeDetails {
|
|
6
6
|
value: string;
|
|
@@ -22,21 +22,21 @@ type ElementIds = Partial<{
|
|
|
22
22
|
decrementTrigger: string;
|
|
23
23
|
scrubber: string;
|
|
24
24
|
}>;
|
|
25
|
-
|
|
25
|
+
type IntlTranslations = Partial<{
|
|
26
26
|
/**
|
|
27
27
|
* Function that returns the human-readable value.
|
|
28
28
|
* It is used to set the `aria-valuetext` property of the input
|
|
29
29
|
*/
|
|
30
|
-
valueText
|
|
30
|
+
valueText: (value: string) => string;
|
|
31
31
|
/**
|
|
32
32
|
* The label foe the increment button
|
|
33
33
|
*/
|
|
34
|
-
incrementLabel
|
|
34
|
+
incrementLabel: string;
|
|
35
35
|
/**
|
|
36
36
|
* The label for the decrement button
|
|
37
37
|
*/
|
|
38
|
-
decrementLabel
|
|
39
|
-
}
|
|
38
|
+
decrementLabel: string;
|
|
39
|
+
}>;
|
|
40
40
|
interface NumberInputProps extends LocaleProperties, CommonProperties {
|
|
41
41
|
/**
|
|
42
42
|
* The ids of the elements in the number input. Useful for composition.
|
|
@@ -161,7 +161,7 @@ interface NumberInputProps extends LocaleProperties, CommonProperties {
|
|
|
161
161
|
*/
|
|
162
162
|
spinOnPress?: boolean | undefined;
|
|
163
163
|
}
|
|
164
|
-
type PropsWithDefault = "dir" | "locale" | "focusInputOnChange" | "clampValueOnBlur" | "allowOverflow" | "inputMode" | "pattern" | "
|
|
164
|
+
type PropsWithDefault = "dir" | "locale" | "focusInputOnChange" | "clampValueOnBlur" | "allowOverflow" | "inputMode" | "pattern" | "step" | "largeStep" | "smallStep" | "spinOnPress" | "min" | "max";
|
|
165
165
|
type ComputedContext = Readonly<{
|
|
166
166
|
/**
|
|
167
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.43.
|
|
3
|
+
"version": "1.43.2",
|
|
4
4
|
"description": "Core logic for the number-input widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
32
|
"@internationalized/number": "3.6.7",
|
|
33
|
-
"@zag-js/anatomy": "1.43.
|
|
34
|
-
"@zag-js/core": "1.43.
|
|
35
|
-
"@zag-js/dom-query": "1.43.
|
|
36
|
-
"@zag-js/types": "1.43.
|
|
37
|
-
"@zag-js/utils": "1.43.
|
|
33
|
+
"@zag-js/anatomy": "1.43.2",
|
|
34
|
+
"@zag-js/core": "1.43.2",
|
|
35
|
+
"@zag-js/dom-query": "1.43.2",
|
|
36
|
+
"@zag-js/types": "1.43.2",
|
|
37
|
+
"@zag-js/utils": "1.43.2"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"clean-package": "2.2.0"
|