@zag-js/number-input 0.0.0-dev-20220704163406 → 0.0.0-dev-20220706194607
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.js
CHANGED
|
@@ -376,12 +376,14 @@ function connect(state, send, normalize) {
|
|
|
376
376
|
const isFocused = state.hasTag("focus");
|
|
377
377
|
const isInvalid = state.context.isOutOfRange || !!state.context.invalid;
|
|
378
378
|
const isDisabled = !!state.context.disabled;
|
|
379
|
+
const isValueEmpty = state.context.isValueEmpty;
|
|
379
380
|
const isIncrementDisabled = isDisabled || !state.context.canIncrement;
|
|
380
381
|
const isDecrementDisabled = isDisabled || !state.context.canDecrement;
|
|
381
382
|
const messages = state.context.messages;
|
|
382
383
|
return {
|
|
383
384
|
isFocused,
|
|
384
385
|
isInvalid,
|
|
386
|
+
isValueEmpty,
|
|
385
387
|
value: state.context.formattedValue,
|
|
386
388
|
valueAsNumber: state.context.valueAsNumber,
|
|
387
389
|
setValue(value) {
|
|
@@ -602,6 +604,7 @@ function machine(ctx = {}) {
|
|
|
602
604
|
isAtMin: (ctx2) => isAtMin(ctx2.value, ctx2),
|
|
603
605
|
isAtMax: (ctx2) => isAtMax(ctx2.value, ctx2),
|
|
604
606
|
isOutOfRange: (ctx2) => !isWithinRange(ctx2.value, ctx2),
|
|
607
|
+
isValueEmpty: (ctx2) => ctx2.value === "",
|
|
605
608
|
canIncrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMax,
|
|
606
609
|
canDecrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMin,
|
|
607
610
|
valueText: (ctx2) => {
|
|
@@ -688,7 +691,7 @@ function machine(ctx = {}) {
|
|
|
688
691
|
actions: ["clearValue", "clearHint"]
|
|
689
692
|
},
|
|
690
693
|
{
|
|
691
|
-
guard: and("clampOnBlur", not("isInRange")),
|
|
694
|
+
guard: and("clampOnBlur", not("isInRange"), not("isEmptyValue")),
|
|
692
695
|
target: "idle",
|
|
693
696
|
actions: ["clampValue", "clearHint"]
|
|
694
697
|
},
|
|
@@ -778,6 +781,7 @@ function machine(ctx = {}) {
|
|
|
778
781
|
var _a;
|
|
779
782
|
return ((_a = evt.hint) != null ? _a : ctx2.hint) === "decrement";
|
|
780
783
|
},
|
|
784
|
+
isEmptyValue: (ctx2) => ctx2.isValueEmpty,
|
|
781
785
|
isIncrementHint: (ctx2, evt) => {
|
|
782
786
|
var _a;
|
|
783
787
|
return ((_a = evt.hint) != null ? _a : ctx2.hint) === "increment";
|
package/dist/index.mjs
CHANGED
|
@@ -352,12 +352,14 @@ function connect(state, send, normalize) {
|
|
|
352
352
|
const isFocused = state.hasTag("focus");
|
|
353
353
|
const isInvalid = state.context.isOutOfRange || !!state.context.invalid;
|
|
354
354
|
const isDisabled = !!state.context.disabled;
|
|
355
|
+
const isValueEmpty = state.context.isValueEmpty;
|
|
355
356
|
const isIncrementDisabled = isDisabled || !state.context.canIncrement;
|
|
356
357
|
const isDecrementDisabled = isDisabled || !state.context.canDecrement;
|
|
357
358
|
const messages = state.context.messages;
|
|
358
359
|
return {
|
|
359
360
|
isFocused,
|
|
360
361
|
isInvalid,
|
|
362
|
+
isValueEmpty,
|
|
361
363
|
value: state.context.formattedValue,
|
|
362
364
|
valueAsNumber: state.context.valueAsNumber,
|
|
363
365
|
setValue(value) {
|
|
@@ -578,6 +580,7 @@ function machine(ctx = {}) {
|
|
|
578
580
|
isAtMin: (ctx2) => isAtMin(ctx2.value, ctx2),
|
|
579
581
|
isAtMax: (ctx2) => isAtMax(ctx2.value, ctx2),
|
|
580
582
|
isOutOfRange: (ctx2) => !isWithinRange(ctx2.value, ctx2),
|
|
583
|
+
isValueEmpty: (ctx2) => ctx2.value === "",
|
|
581
584
|
canIncrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMax,
|
|
582
585
|
canDecrement: (ctx2) => ctx2.allowOverflow || !ctx2.isAtMin,
|
|
583
586
|
valueText: (ctx2) => {
|
|
@@ -664,7 +667,7 @@ function machine(ctx = {}) {
|
|
|
664
667
|
actions: ["clearValue", "clearHint"]
|
|
665
668
|
},
|
|
666
669
|
{
|
|
667
|
-
guard: and("clampOnBlur", not("isInRange")),
|
|
670
|
+
guard: and("clampOnBlur", not("isInRange"), not("isEmptyValue")),
|
|
668
671
|
target: "idle",
|
|
669
672
|
actions: ["clampValue", "clearHint"]
|
|
670
673
|
},
|
|
@@ -754,6 +757,7 @@ function machine(ctx = {}) {
|
|
|
754
757
|
var _a;
|
|
755
758
|
return ((_a = evt.hint) != null ? _a : ctx2.hint) === "decrement";
|
|
756
759
|
},
|
|
760
|
+
isEmptyValue: (ctx2) => ctx2.isValueEmpty,
|
|
757
761
|
isIncrementHint: (ctx2, evt) => {
|
|
758
762
|
var _a;
|
|
759
763
|
return ((_a = evt.hint) != null ? _a : ctx2.hint) === "increment";
|
|
@@ -3,6 +3,7 @@ import type { Send, State } from "./number-input.types";
|
|
|
3
3
|
export declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
|
|
4
4
|
isFocused: boolean;
|
|
5
5
|
isInvalid: boolean;
|
|
6
|
+
isValueEmpty: boolean;
|
|
6
7
|
value: string;
|
|
7
8
|
valueAsNumber: number;
|
|
8
9
|
setValue(value: string | number): void;
|
|
@@ -149,6 +149,11 @@ declare type ComputedContext = Readonly<{
|
|
|
149
149
|
* Whether the value is out of the min/max range
|
|
150
150
|
*/
|
|
151
151
|
isOutOfRange: boolean;
|
|
152
|
+
/**
|
|
153
|
+
* @computed
|
|
154
|
+
* Whether the value is empty
|
|
155
|
+
*/
|
|
156
|
+
isValueEmpty: boolean;
|
|
152
157
|
/**
|
|
153
158
|
* @computed
|
|
154
159
|
* Whether the increment button is enabled
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zag-js/number-input",
|
|
3
|
-
"version": "0.0.0-dev-
|
|
3
|
+
"version": "0.0.0-dev-20220706194607",
|
|
4
4
|
"description": "Core logic for the number-input widget implemented as a state machine",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"js",
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"url": "https://github.com/chakra-ui/zag/issues"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@zag-js/core": "0.0.0-dev-
|
|
33
|
-
"@zag-js/dom-utils": "0.0.0-dev-
|
|
32
|
+
"@zag-js/core": "0.0.0-dev-20220706194607",
|
|
33
|
+
"@zag-js/dom-utils": "0.0.0-dev-20220706194607",
|
|
34
34
|
"@zag-js/number-utils": "0.1.2",
|
|
35
|
-
"@zag-js/types": "0.0.0-dev-
|
|
35
|
+
"@zag-js/types": "0.0.0-dev-20220706194607",
|
|
36
36
|
"@zag-js/utils": "0.1.2"
|
|
37
37
|
},
|
|
38
38
|
"scripts": {
|