@zag-js/number-input 0.1.10 → 0.1.13

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,198 +0,0 @@
1
- import type { StateMachine as S } from "@zag-js/core";
2
- import { FormatDecimalOptions } from "@zag-js/number-utils";
3
- import type { Point } from "@zag-js/rect-utils";
4
- import type { Context, DirectionProperty } from "@zag-js/types";
5
- declare type ValidityState = "rangeUnderflow" | "rangeOverflow";
6
- declare type ElementIds = Partial<{
7
- root: string;
8
- label: string;
9
- input: string;
10
- incBtn: string;
11
- decBtn: string;
12
- scrubber: string;
13
- }>;
14
- declare type IntlMessages = {
15
- /**
16
- * Function that returns the human-readable value.
17
- * It is used to set the `aria-valuetext` property of the input
18
- */
19
- valueText?: (value: string) => string;
20
- /**
21
- * The label foe the increment button
22
- */
23
- incrementLabel: string;
24
- /**
25
- * The label for the decrement button
26
- */
27
- decrementLabel: string;
28
- };
29
- declare type PublicContext = DirectionProperty & FormatDecimalOptions & {
30
- /**
31
- * The ids of the elements in the number input. Useful for composition.
32
- */
33
- ids?: ElementIds;
34
- /**
35
- * The name attribute of the number input. Useful for form submission.
36
- */
37
- name?: string;
38
- /**
39
- * Whether the number input is disabled.
40
- */
41
- disabled?: boolean;
42
- /**
43
- * Whether the number input is readonly
44
- */
45
- readonly?: boolean;
46
- /**
47
- * Whether the number input value is invalid.
48
- */
49
- invalid?: boolean;
50
- /**
51
- * The pattern used to check the <input> element's value against
52
- *
53
- * @default
54
- * "[0-9]*(.[0-9]+)?"
55
- */
56
- pattern: string;
57
- /**
58
- * The value of the input
59
- */
60
- value: string;
61
- /**
62
- * The minimum value of the number input
63
- */
64
- min: number;
65
- /**
66
- * The maximum value of the number input
67
- */
68
- max: number;
69
- /**
70
- * The amount to increment or decrement the value by
71
- */
72
- step: number;
73
- /**
74
- * Whether to allow mouse wheel to change the value
75
- */
76
- allowMouseWheel?: boolean;
77
- /**
78
- * Whether to allow the value overflow the min/max range
79
- * @default true
80
- */
81
- allowOverflow: boolean;
82
- /**
83
- * Whether the pressed key should be allowed in the input.
84
- * The default behavior is to allow DOM floating point characters defined by /^[Ee0-9+\-.]$/
85
- */
86
- validateCharacter?: (char: string) => boolean;
87
- /**
88
- * Whether to clamp the value when the input loses focus (blur)
89
- * @default true
90
- */
91
- clampValueOnBlur: boolean;
92
- /**
93
- * Whether to focus input when the value changes
94
- * @default true
95
- */
96
- focusInputOnChange: boolean;
97
- /**
98
- * Specifies the localized strings that identifies the accessibility elements and their states
99
- */
100
- messages: IntlMessages;
101
- /**
102
- * If using a custom display format, this converts the custom format to a format `parseFloat` understands.
103
- */
104
- parse?: (value: string) => string;
105
- /**
106
- * If using a custom display format, this converts the default format to the custom format.
107
- */
108
- format?: (value: string) => string | number;
109
- /**
110
- * Hints at the type of data that might be entered by the user. It also determines
111
- * the type of keyboard shown to the user on mobile devices
112
- * @default "decimal"
113
- */
114
- inputMode: "text" | "tel" | "numeric" | "decimal";
115
- /**
116
- * Function invoked when the value changes
117
- */
118
- onChange?: (details: {
119
- value: string;
120
- valueAsNumber: number;
121
- }) => void;
122
- /**
123
- * Function invoked when the value overflows or underflows the min/max range
124
- */
125
- onInvalid?: (details: {
126
- reason: ValidityState;
127
- value: string;
128
- valueAsNumber: number;
129
- }) => void;
130
- };
131
- export declare type UserDefinedContext = Partial<PublicContext>;
132
- declare type ComputedContext = Readonly<{
133
- /**
134
- * @computed
135
- * The value of the input as a number
136
- */
137
- valueAsNumber: number;
138
- /**
139
- * @computed
140
- * Whether the value is at the min
141
- */
142
- isAtMin: boolean;
143
- /**
144
- * @computed
145
- * Whether the value is at the max
146
- */
147
- isAtMax: boolean;
148
- /**
149
- * @computed
150
- * Whether the value is out of the min/max range
151
- */
152
- isOutOfRange: boolean;
153
- /**
154
- * @computed
155
- * Whether the increment button is enabled
156
- */
157
- canIncrement: boolean;
158
- /**
159
- * @computed
160
- * Whether the decrement button is enabled
161
- */
162
- canDecrement: boolean;
163
- /**
164
- * @computed
165
- * The `aria-valuetext` attribute of the input
166
- */
167
- valueText: string | undefined;
168
- /**
169
- * @computed
170
- * The formatted value of the input
171
- */
172
- formattedValue: string;
173
- /**
174
- * @computed
175
- * Whether the writing direction is RTL
176
- */
177
- isRtl: boolean;
178
- }>;
179
- declare type PrivateContext = Context<{
180
- /**
181
- * @internal
182
- * The hint that determines if we're incrementing or decrementing
183
- */
184
- hint: "increment" | "decrement" | "set" | null;
185
- /**
186
- * @internal
187
- * The scrubber cursor position
188
- */
189
- scrubberCursorPoint: Point | null;
190
- }>;
191
- export declare type MachineContext = PublicContext & PrivateContext & ComputedContext;
192
- export declare type MachineState = {
193
- value: "unknown" | "idle" | "focused" | "spinning" | "before:spin" | "scrubbing";
194
- tags: "focus";
195
- };
196
- export declare type State = S.State<MachineContext, MachineState>;
197
- export declare type Send = S.Send<S.AnyEventObject>;
198
- export {};
@@ -1,13 +0,0 @@
1
- import type { KeyboardEvent } from "react";
2
- import type { MachineContext as Ctx } from "./number-input.types";
3
- export declare const utils: {
4
- isValidNumericEvent: (ctx: Ctx, event: KeyboardEvent) => boolean;
5
- isFloatingPoint: (v: string) => boolean;
6
- sanitize: (ctx: Ctx, value: string) => string;
7
- increment: (ctx: Ctx, step?: number) => string;
8
- decrement: (ctx: Ctx, step?: number) => string;
9
- clamp: (ctx: Ctx) => string;
10
- parse: (ctx: Ctx, value: string) => string;
11
- format: (ctx: Ctx, value: string | number) => string | number;
12
- round: (ctx: Ctx) => string;
13
- };