@zag-js/number-input 0.1.12 → 0.1.15
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 +21 -0
- package/dist/index.d.ts +239 -3
- package/dist/index.js +477 -439
- package/dist/index.mjs +474 -444
- package/package.json +14 -12
- package/dist/number-input.connect.d.ts +0 -23
- package/dist/number-input.dom.d.ts +0 -39
- package/dist/number-input.machine.d.ts +0 -2
- package/dist/number-input.types.d.ts +0 -212
- package/dist/number-input.utils.d.ts +0 -13
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,239 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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 Value = {
|
|
30
|
+
value: string;
|
|
31
|
+
valueAsNumber: number;
|
|
32
|
+
};
|
|
33
|
+
declare type PublicContext = DirectionProperty & CommonProperties & {
|
|
34
|
+
/**
|
|
35
|
+
* The ids of the elements in the number input. Useful for composition.
|
|
36
|
+
*/
|
|
37
|
+
ids?: ElementIds;
|
|
38
|
+
/**
|
|
39
|
+
* The name attribute of the number input. Useful for form submission.
|
|
40
|
+
*/
|
|
41
|
+
name?: string;
|
|
42
|
+
/**
|
|
43
|
+
* Whether the number input is disabled.
|
|
44
|
+
*/
|
|
45
|
+
disabled?: boolean;
|
|
46
|
+
/**
|
|
47
|
+
* Whether the number input is readonly
|
|
48
|
+
*/
|
|
49
|
+
readonly?: boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Whether the number input value is invalid.
|
|
52
|
+
*/
|
|
53
|
+
invalid?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* The pattern used to check the <input> element's value against
|
|
56
|
+
*
|
|
57
|
+
* @default
|
|
58
|
+
* "[0-9]*(.[0-9]+)?"
|
|
59
|
+
*/
|
|
60
|
+
pattern: string;
|
|
61
|
+
/**
|
|
62
|
+
* The value of the input
|
|
63
|
+
*/
|
|
64
|
+
value: string;
|
|
65
|
+
/**
|
|
66
|
+
* The minimum value of the number input
|
|
67
|
+
*/
|
|
68
|
+
min: number;
|
|
69
|
+
/**
|
|
70
|
+
* The maximum value of the number input
|
|
71
|
+
*/
|
|
72
|
+
max: number;
|
|
73
|
+
/**
|
|
74
|
+
* The amount to increment or decrement the value by
|
|
75
|
+
*/
|
|
76
|
+
step: number;
|
|
77
|
+
/**
|
|
78
|
+
* Whether to allow mouse wheel to change the value
|
|
79
|
+
*/
|
|
80
|
+
allowMouseWheel?: boolean;
|
|
81
|
+
/**
|
|
82
|
+
* Whether to allow the value overflow the min/max range
|
|
83
|
+
* @default true
|
|
84
|
+
*/
|
|
85
|
+
allowOverflow: boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Whether the pressed key should be allowed in the input.
|
|
88
|
+
* The default behavior is to allow DOM floating point characters defined by /^[Ee0-9+\-.]$/
|
|
89
|
+
*/
|
|
90
|
+
validateCharacter?: (char: string) => boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Whether to clamp the value when the input loses focus (blur)
|
|
93
|
+
* @default true
|
|
94
|
+
*/
|
|
95
|
+
clampValueOnBlur: boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Whether to focus input when the value changes
|
|
98
|
+
* @default true
|
|
99
|
+
*/
|
|
100
|
+
focusInputOnChange: boolean;
|
|
101
|
+
/**
|
|
102
|
+
* Specifies the localized strings that identifies the accessibility elements and their states
|
|
103
|
+
*/
|
|
104
|
+
messages: IntlMessages;
|
|
105
|
+
/**
|
|
106
|
+
* If using a custom display format, this converts the custom format to a format `parseFloat` understands.
|
|
107
|
+
*/
|
|
108
|
+
parse?: (value: string) => string;
|
|
109
|
+
/**
|
|
110
|
+
* If using a custom display format, this converts the default format to the custom format.
|
|
111
|
+
*/
|
|
112
|
+
format?: (value: string) => string | number;
|
|
113
|
+
/**
|
|
114
|
+
* Hints at the type of data that might be entered by the user. It also determines
|
|
115
|
+
* the type of keyboard shown to the user on mobile devices
|
|
116
|
+
* @default "decimal"
|
|
117
|
+
*/
|
|
118
|
+
inputMode: "text" | "tel" | "numeric" | "decimal";
|
|
119
|
+
/**
|
|
120
|
+
* Function invoked when the value changes
|
|
121
|
+
*/
|
|
122
|
+
onChange?: (details: Value) => void;
|
|
123
|
+
/**
|
|
124
|
+
* Function invoked when the value overflows or underflows the min/max range
|
|
125
|
+
*/
|
|
126
|
+
onInvalid?: (details: Value & {
|
|
127
|
+
reason: ValidityState;
|
|
128
|
+
}) => void;
|
|
129
|
+
/**
|
|
130
|
+
* Function invoked when the number input is focused
|
|
131
|
+
*/
|
|
132
|
+
onFocus?: (details: Value & {
|
|
133
|
+
srcElement: HTMLElement | null;
|
|
134
|
+
}) => void;
|
|
135
|
+
/**
|
|
136
|
+
* The value of the input when it is blurred
|
|
137
|
+
*/
|
|
138
|
+
onBlur?: (details: Value) => void;
|
|
139
|
+
/**
|
|
140
|
+
* The minimum number of fraction digits to use. Possible values are from 0 to 20
|
|
141
|
+
*/
|
|
142
|
+
minFractionDigits?: number;
|
|
143
|
+
/**
|
|
144
|
+
* The maximum number of fraction digits to use. Possible values are from 0 to 20;
|
|
145
|
+
*/
|
|
146
|
+
maxFractionDigits?: number;
|
|
147
|
+
/**
|
|
148
|
+
* Whether to spin the value when the increment/decrement button is pressed
|
|
149
|
+
*/
|
|
150
|
+
spinOnPress?: boolean;
|
|
151
|
+
};
|
|
152
|
+
declare type UserDefinedContext = RequiredBy<PublicContext, "id">;
|
|
153
|
+
declare type ComputedContext = Readonly<{
|
|
154
|
+
/**
|
|
155
|
+
* @computed
|
|
156
|
+
* The value of the input as a number
|
|
157
|
+
*/
|
|
158
|
+
valueAsNumber: number;
|
|
159
|
+
/**
|
|
160
|
+
* @computed
|
|
161
|
+
* Whether the value is at the min
|
|
162
|
+
*/
|
|
163
|
+
isAtMin: boolean;
|
|
164
|
+
/**
|
|
165
|
+
* @computed
|
|
166
|
+
* Whether the value is at the max
|
|
167
|
+
*/
|
|
168
|
+
isAtMax: boolean;
|
|
169
|
+
/**
|
|
170
|
+
* @computed
|
|
171
|
+
* Whether the value is out of the min/max range
|
|
172
|
+
*/
|
|
173
|
+
isOutOfRange: boolean;
|
|
174
|
+
/**
|
|
175
|
+
* @computed
|
|
176
|
+
* Whether the value is empty
|
|
177
|
+
*/
|
|
178
|
+
isValueEmpty: boolean;
|
|
179
|
+
/**
|
|
180
|
+
* @computed
|
|
181
|
+
* Whether the increment button is enabled
|
|
182
|
+
*/
|
|
183
|
+
canIncrement: boolean;
|
|
184
|
+
/**
|
|
185
|
+
* @computed
|
|
186
|
+
* Whether the decrement button is enabled
|
|
187
|
+
*/
|
|
188
|
+
canDecrement: boolean;
|
|
189
|
+
/**
|
|
190
|
+
* @computed
|
|
191
|
+
* The `aria-valuetext` attribute of the input
|
|
192
|
+
*/
|
|
193
|
+
valueText: string | undefined;
|
|
194
|
+
/**
|
|
195
|
+
* @computed
|
|
196
|
+
* The formatted value of the input
|
|
197
|
+
*/
|
|
198
|
+
formattedValue: string;
|
|
199
|
+
/**
|
|
200
|
+
* @computed
|
|
201
|
+
* Whether the writing direction is RTL
|
|
202
|
+
*/
|
|
203
|
+
isRtl: boolean;
|
|
204
|
+
}>;
|
|
205
|
+
declare type PrivateContext = Context<{}>;
|
|
206
|
+
declare type MachineContext = PublicContext & PrivateContext & ComputedContext;
|
|
207
|
+
declare type MachineState = {
|
|
208
|
+
value: "unknown" | "idle" | "focused" | "spinning" | "before:spin" | "scrubbing";
|
|
209
|
+
tags: "focus";
|
|
210
|
+
};
|
|
211
|
+
declare type State = StateMachine.State<MachineContext, MachineState>;
|
|
212
|
+
declare type Send = StateMachine.Send<StateMachine.AnyEventObject>;
|
|
213
|
+
|
|
214
|
+
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
|
|
215
|
+
isFocused: boolean;
|
|
216
|
+
isInvalid: boolean;
|
|
217
|
+
isValueEmpty: boolean;
|
|
218
|
+
value: string;
|
|
219
|
+
valueAsNumber: number;
|
|
220
|
+
setValue(value: string | number): void;
|
|
221
|
+
clearValue(): void;
|
|
222
|
+
increment(): void;
|
|
223
|
+
decrement(): void;
|
|
224
|
+
setToMax(): void;
|
|
225
|
+
setToMin(): void;
|
|
226
|
+
focus(): void;
|
|
227
|
+
blur(): void;
|
|
228
|
+
rootProps: T["element"];
|
|
229
|
+
labelProps: T["label"];
|
|
230
|
+
groupProps: T["element"];
|
|
231
|
+
inputProps: T["input"];
|
|
232
|
+
decrementButtonProps: T["button"];
|
|
233
|
+
incrementButtonProps: T["button"];
|
|
234
|
+
scrubberProps: T["element"];
|
|
235
|
+
};
|
|
236
|
+
|
|
237
|
+
declare function machine(ctx: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
|
|
238
|
+
|
|
239
|
+
export { UserDefinedContext as Context, connect, machine };
|