@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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Chakra UI
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,225 @@
1
- export { connect } from "./number-input.connect";
2
- export { machine } from "./number-input.machine";
3
- export type { UserDefinedContext as Context } from "./number-input.types";
1
+ import { RequiredBy, DirectionProperty, CommonProperties, Context, PropTypes, NormalizeProps } from '@zag-js/types';
2
+ import * as _zag_js_core from '@zag-js/core';
3
+ import { StateMachine } from '@zag-js/core';
4
+
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 & CommonProperties & {
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
+ * The minimum number of fraction digits to use. Possible values are from 0 to 20
132
+ */
133
+ minFractionDigits?: number;
134
+ /**
135
+ * The maximum number of fraction digits to use. Possible values are from 0 to 20;
136
+ */
137
+ maxFractionDigits?: number;
138
+ };
139
+ declare type UserDefinedContext = RequiredBy<PublicContext, "id">;
140
+ declare type ComputedContext = Readonly<{
141
+ /**
142
+ * @computed
143
+ * The value of the input as a number
144
+ */
145
+ valueAsNumber: number;
146
+ /**
147
+ * @computed
148
+ * Whether the value is at the min
149
+ */
150
+ isAtMin: boolean;
151
+ /**
152
+ * @computed
153
+ * Whether the value is at the max
154
+ */
155
+ isAtMax: boolean;
156
+ /**
157
+ * @computed
158
+ * Whether the value is out of the min/max range
159
+ */
160
+ isOutOfRange: boolean;
161
+ /**
162
+ * @computed
163
+ * Whether the value is empty
164
+ */
165
+ isValueEmpty: boolean;
166
+ /**
167
+ * @computed
168
+ * Whether the increment button is enabled
169
+ */
170
+ canIncrement: boolean;
171
+ /**
172
+ * @computed
173
+ * Whether the decrement button is enabled
174
+ */
175
+ canDecrement: boolean;
176
+ /**
177
+ * @computed
178
+ * The `aria-valuetext` attribute of the input
179
+ */
180
+ valueText: string | undefined;
181
+ /**
182
+ * @computed
183
+ * The formatted value of the input
184
+ */
185
+ formattedValue: string;
186
+ /**
187
+ * @computed
188
+ * Whether the writing direction is RTL
189
+ */
190
+ isRtl: boolean;
191
+ }>;
192
+ declare type PrivateContext = Context<{}>;
193
+ declare type MachineContext = PublicContext & PrivateContext & ComputedContext;
194
+ declare type MachineState = {
195
+ value: "unknown" | "idle" | "focused" | "spinning" | "before:spin" | "scrubbing";
196
+ tags: "focus";
197
+ };
198
+ declare type State = StateMachine.State<MachineContext, MachineState>;
199
+ declare type Send = StateMachine.Send<StateMachine.AnyEventObject>;
200
+
201
+ declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
202
+ isFocused: boolean;
203
+ isInvalid: boolean;
204
+ isValueEmpty: boolean;
205
+ value: string;
206
+ valueAsNumber: number;
207
+ setValue(value: string | number): void;
208
+ clearValue(): void;
209
+ increment(): void;
210
+ decrement(): void;
211
+ setToMax(): void;
212
+ setToMin(): void;
213
+ focus(): void;
214
+ rootProps: T["element"];
215
+ labelProps: T["label"];
216
+ groupProps: T["element"];
217
+ inputProps: T["input"];
218
+ decrementButtonProps: T["button"];
219
+ incrementButtonProps: T["button"];
220
+ scrubberProps: T["element"];
221
+ };
222
+
223
+ declare function machine(ctx: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
224
+
225
+ export { UserDefinedContext as Context, connect, machine };