@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.
@@ -1,16 +1,26 @@
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, 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 extends ValueChangeDetails {
14
+ interface FocusChangeDetails {
15
+ value: string;
16
+ valueAsNumber: number;
10
17
  focused: boolean;
11
18
  }
12
19
  type ValidityState = "rangeUnderflow" | "rangeOverflow";
13
- interface ValueInvalidDetails extends ValueChangeDetails {
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 is committed (when the input is blurred or the Enter key is pressed)
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" | "translations" | "step" | "spinOnPress" | "min" | "max" | "largeStep" | "smallStep" | "scrubberPixelSensitivity" | "scrubberDirection" | "snapOnStep";
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" | "spinning" | "before:spin" | "scrubbing";
287
+ state: "idle" | "focused" | "pressed" | "pressed.waiting" | "pressed.repeating" | "scrubbing";
277
288
  tag: "focus";
278
- props: RequiredBy<NumberInputProps, PropsWithDefault>;
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 };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/number-input",
3
- "version": "2.0.0-next.0",
3
+ "version": "2.0.0-next.2",
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": "https://github.com/chakra-ui/zag/tree/main/packages/number-input",
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.6",
30
- "@zag-js/anatomy": "2.0.0-next.0",
31
- "@zag-js/core": "2.0.0-next.0",
32
- "@zag-js/dom-query": "2.0.0-next.0",
33
- "@zag-js/types": "2.0.0-next.0",
34
- "@zag-js/utils": "2.0.0-next.0"
32
+ "@internationalized/number": "3.6.7",
33
+ "@zag-js/anatomy": "2.0.0-next.2",
34
+ "@zag-js/core": "2.0.0-next.2",
35
+ "@zag-js/dom-query": "2.0.0-next.2",
36
+ "@zag-js/types": "2.0.0-next.2",
37
+ "@zag-js/utils": "2.0.0-next.2"
35
38
  },
36
39
  "devDependencies": {
37
40
  "clean-package": "2.2.0"
@@ -65,7 +68,7 @@
65
68
  },
66
69
  "scripts": {
67
70
  "build": "tsup",
68
- "lint": "eslint src",
71
+ "lint": "oxlint src",
69
72
  "typecheck": "tsc --noEmit"
70
73
  }
71
74
  }