@zag-js/pin-input 0.1.9 → 0.1.12
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 +136 -3
- package/dist/index.js +309 -252
- package/dist/index.mjs +305 -256
- package/package.json +15 -11
- package/dist/pin-input.connect.d.ts +0 -15
- package/dist/pin-input.dom.d.ts +0 -11
- package/dist/pin-input.machine.d.ts +0 -2
- package/dist/pin-input.types.d.ts +0 -113
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,136 @@
|
|
|
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 IntlMessages = {
|
|
6
|
+
inputLabel: (index: number, length: number) => string;
|
|
7
|
+
};
|
|
8
|
+
declare type ElementIds = Partial<{
|
|
9
|
+
root: string;
|
|
10
|
+
hiddenInput: string;
|
|
11
|
+
input(id: string): string;
|
|
12
|
+
}>;
|
|
13
|
+
declare type PublicContext = DirectionProperty & CommonProperties & {
|
|
14
|
+
/**
|
|
15
|
+
* The name of the input element. Useful for form submission.
|
|
16
|
+
*/
|
|
17
|
+
name?: string;
|
|
18
|
+
/**
|
|
19
|
+
* The regular expression that the user-entered input value is checked against.
|
|
20
|
+
*/
|
|
21
|
+
pattern?: string;
|
|
22
|
+
/**
|
|
23
|
+
* The ids of the elements in the pin input. Useful for composition.
|
|
24
|
+
*/
|
|
25
|
+
ids?: ElementIds;
|
|
26
|
+
/**
|
|
27
|
+
* Whether the inputs are disabled
|
|
28
|
+
*/
|
|
29
|
+
disabled?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* The placeholder text for the input
|
|
32
|
+
*/
|
|
33
|
+
placeholder?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Whether to auto-focus the first input.
|
|
36
|
+
*/
|
|
37
|
+
autoFocus?: boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Whether the pin input is in the invalid state
|
|
40
|
+
*/
|
|
41
|
+
invalid?: boolean;
|
|
42
|
+
/**
|
|
43
|
+
* If `true`, the pin input component signals to its fields that they should
|
|
44
|
+
* use `autocomplete="one-time-code"`.
|
|
45
|
+
*/
|
|
46
|
+
otp?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* The value of the the pin input.
|
|
49
|
+
*/
|
|
50
|
+
value: string[];
|
|
51
|
+
/**
|
|
52
|
+
* The type of value the pin-input should allow
|
|
53
|
+
*/
|
|
54
|
+
type?: "alphanumeric" | "numeric" | "alphabetic";
|
|
55
|
+
/**
|
|
56
|
+
* Function called when all inputs have valid values
|
|
57
|
+
*/
|
|
58
|
+
onComplete?: (details: {
|
|
59
|
+
value: string[];
|
|
60
|
+
valueAsString: string;
|
|
61
|
+
}) => void;
|
|
62
|
+
/**
|
|
63
|
+
* Function called on input change
|
|
64
|
+
*/
|
|
65
|
+
onChange?: (details: {
|
|
66
|
+
value: string[];
|
|
67
|
+
}) => void;
|
|
68
|
+
/**
|
|
69
|
+
* Function called when an invalid value is entered
|
|
70
|
+
*/
|
|
71
|
+
onInvalid?: (details: {
|
|
72
|
+
value: string;
|
|
73
|
+
index: number;
|
|
74
|
+
}) => void;
|
|
75
|
+
/**
|
|
76
|
+
* If `true`, the input's value will be masked just like `type=password`
|
|
77
|
+
*/
|
|
78
|
+
mask?: boolean;
|
|
79
|
+
/**
|
|
80
|
+
* Whether to blur the input when the value is complete
|
|
81
|
+
*/
|
|
82
|
+
blurOnComplete?: boolean;
|
|
83
|
+
/**
|
|
84
|
+
* Specifies the localized strings that identifies the accessibility elements and their states
|
|
85
|
+
*/
|
|
86
|
+
messages: IntlMessages;
|
|
87
|
+
};
|
|
88
|
+
declare type UserDefinedContext = RequiredBy<PublicContext, "id">;
|
|
89
|
+
declare type ComputedContext = Readonly<{
|
|
90
|
+
/**
|
|
91
|
+
* @computed
|
|
92
|
+
* The number of inputs
|
|
93
|
+
*/
|
|
94
|
+
valueLength: number;
|
|
95
|
+
/**
|
|
96
|
+
* @computed
|
|
97
|
+
* The number of inputs that are not empty
|
|
98
|
+
*/
|
|
99
|
+
filledValueLength: number;
|
|
100
|
+
/**
|
|
101
|
+
* @computed
|
|
102
|
+
* Whether all input values are valid
|
|
103
|
+
*/
|
|
104
|
+
isValueComplete: boolean;
|
|
105
|
+
/**
|
|
106
|
+
* @computed
|
|
107
|
+
* The string representation of the input values
|
|
108
|
+
*/
|
|
109
|
+
valueAsString: string;
|
|
110
|
+
}>;
|
|
111
|
+
declare type PrivateContext = Context<{}>;
|
|
112
|
+
declare type MachineContext = PublicContext & PrivateContext & ComputedContext;
|
|
113
|
+
declare type MachineState = {
|
|
114
|
+
value: "unknown" | "idle" | "focused";
|
|
115
|
+
};
|
|
116
|
+
declare type State = StateMachine.State<MachineContext, MachineState>;
|
|
117
|
+
declare type Send = StateMachine.Send<StateMachine.AnyEventObject>;
|
|
118
|
+
|
|
119
|
+
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
|
|
120
|
+
value: string[];
|
|
121
|
+
valueAsString: string;
|
|
122
|
+
isValueComplete: boolean;
|
|
123
|
+
setValue(value: string[]): void;
|
|
124
|
+
clearValue(): void;
|
|
125
|
+
setValueAtIndex(index: number, value: string): void;
|
|
126
|
+
focus(): void;
|
|
127
|
+
rootProps: T["element"];
|
|
128
|
+
hiddenInputProps: T["input"];
|
|
129
|
+
getInputProps({ index }: {
|
|
130
|
+
index: number;
|
|
131
|
+
}): T["input"];
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
declare function machine(ctx: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
|
|
135
|
+
|
|
136
|
+
export { UserDefinedContext as Context, connect, machine };
|