@zag-js/pin-input 0.10.4 → 0.11.0

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,5 +1,10 @@
1
- import type { StateMachine as S } from "@zag-js/core";
2
- import type { CommonProperties, Context, DirectionProperty, RequiredBy } from "@zag-js/types";
1
+ import * as _zag_js_anatomy from '@zag-js/anatomy';
2
+ import { RequiredBy, DirectionProperty, CommonProperties, Context, PropTypes, NormalizeProps } from '@zag-js/types';
3
+ import * as _zag_js_core from '@zag-js/core';
4
+ import { StateMachine } from '@zag-js/core';
5
+
6
+ declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "label" | "hiddenInput" | "input" | "control">;
7
+
3
8
  type IntlTranslations = {
4
9
  inputLabel: (index: number, length: number) => string;
5
10
  };
@@ -93,7 +98,7 @@ type PublicContext = DirectionProperty & CommonProperties & {
93
98
  */
94
99
  translations: IntlTranslations;
95
100
  };
96
- export type UserDefinedContext = RequiredBy<PublicContext, "id">;
101
+ type UserDefinedContext = RequiredBy<PublicContext, "id">;
97
102
  type ComputedContext = Readonly<{
98
103
  /**
99
104
  * @computed
@@ -122,10 +127,51 @@ type ComputedContext = Readonly<{
122
127
  focusedValue: string;
123
128
  }>;
124
129
  type PrivateContext = Context<{}>;
125
- export type MachineContext = PublicContext & PrivateContext & ComputedContext;
126
- export type MachineState = {
130
+ type MachineContext = PublicContext & PrivateContext & ComputedContext;
131
+ type MachineState = {
127
132
  value: "idle" | "focused";
128
133
  };
129
- export type State = S.State<MachineContext, MachineState>;
130
- export type Send = S.Send<S.AnyEventObject>;
131
- export {};
134
+ type State = StateMachine.State<MachineContext, MachineState>;
135
+ type Send = StateMachine.Send<StateMachine.AnyEventObject>;
136
+
137
+ declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
138
+ /**
139
+ * The value of the input as an array of strings.
140
+ */
141
+ value: string[];
142
+ /**
143
+ * The value of the input as a string.
144
+ */
145
+ valueAsString: string;
146
+ /**
147
+ * Whether all inputs are filled.
148
+ */
149
+ isValueComplete: boolean;
150
+ /**
151
+ * Function to set the value of the inputs.
152
+ */
153
+ setValue(value: string[]): void;
154
+ /**
155
+ * Function to clear the value of the inputs.
156
+ */
157
+ clearValue(): void;
158
+ /**
159
+ * Function to set the value of the input at a specific index.
160
+ */
161
+ setValueAtIndex(index: number, value: string): void;
162
+ /**
163
+ * Function to focus the pin-input. This will focus the first input.
164
+ */
165
+ focus: () => void;
166
+ rootProps: T["element"];
167
+ labelProps: T["label"];
168
+ hiddenInputProps: T["input"];
169
+ controlProps: T["element"];
170
+ getInputProps({ index }: {
171
+ index: number;
172
+ }): T["input"];
173
+ };
174
+
175
+ declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
176
+
177
+ export { UserDefinedContext as Context, anatomy, connect, machine };
package/dist/index.d.ts CHANGED
@@ -1,4 +1,177 @@
1
- export { anatomy } from "./pin-input.anatomy";
2
- export { connect } from "./pin-input.connect";
3
- export { machine } from "./pin-input.machine";
4
- export type { UserDefinedContext as Context } from "./pin-input.types";
1
+ import * as _zag_js_anatomy from '@zag-js/anatomy';
2
+ import { RequiredBy, DirectionProperty, CommonProperties, Context, PropTypes, NormalizeProps } from '@zag-js/types';
3
+ import * as _zag_js_core from '@zag-js/core';
4
+ import { StateMachine } from '@zag-js/core';
5
+
6
+ declare const anatomy: _zag_js_anatomy.AnatomyInstance<"root" | "label" | "hiddenInput" | "input" | "control">;
7
+
8
+ type IntlTranslations = {
9
+ inputLabel: (index: number, length: number) => string;
10
+ };
11
+ type ElementIds = Partial<{
12
+ root: string;
13
+ hiddenInput: string;
14
+ label: string;
15
+ control: string;
16
+ input(id: string): string;
17
+ }>;
18
+ type PublicContext = DirectionProperty & CommonProperties & {
19
+ /**
20
+ * The name of the input element. Useful for form submission.
21
+ */
22
+ name?: string;
23
+ /**
24
+ * The associate form of the underlying input element.
25
+ */
26
+ form?: string;
27
+ /**
28
+ * The regular expression that the user-entered input value is checked against.
29
+ */
30
+ pattern?: string;
31
+ /**
32
+ * The ids of the elements in the pin input. Useful for composition.
33
+ */
34
+ ids?: ElementIds;
35
+ /**
36
+ * Whether the inputs are disabled
37
+ */
38
+ disabled?: boolean;
39
+ /**
40
+ * The placeholder text for the input
41
+ */
42
+ placeholder?: string;
43
+ /**
44
+ * Whether to auto-focus the first input.
45
+ */
46
+ autoFocus?: boolean;
47
+ /**
48
+ * Whether the pin input is in the invalid state
49
+ */
50
+ invalid?: boolean;
51
+ /**
52
+ * If `true`, the pin input component signals to its fields that they should
53
+ * use `autocomplete="one-time-code"`.
54
+ */
55
+ otp?: boolean;
56
+ /**
57
+ * The value of the the pin input.
58
+ */
59
+ value: string[];
60
+ /**
61
+ * The type of value the pin-input should allow
62
+ */
63
+ type?: "alphanumeric" | "numeric" | "alphabetic";
64
+ /**
65
+ * Function called when all inputs have valid values
66
+ */
67
+ onComplete?: (details: {
68
+ value: string[];
69
+ valueAsString: string;
70
+ }) => void;
71
+ /**
72
+ * Function called on input change
73
+ */
74
+ onChange?: (details: {
75
+ value: string[];
76
+ }) => void;
77
+ /**
78
+ * Function called when an invalid value is entered
79
+ */
80
+ onInvalid?: (details: {
81
+ value: string;
82
+ index: number;
83
+ }) => void;
84
+ /**
85
+ * If `true`, the input's value will be masked just like `type=password`
86
+ */
87
+ mask?: boolean;
88
+ /**
89
+ * Whether to blur the input when the value is complete
90
+ */
91
+ blurOnComplete?: boolean;
92
+ /**
93
+ * Whether to select input value when input is focused
94
+ */
95
+ selectOnFocus?: boolean;
96
+ /**
97
+ * Specifies the localized strings that identifies the accessibility elements and their states
98
+ */
99
+ translations: IntlTranslations;
100
+ };
101
+ type UserDefinedContext = RequiredBy<PublicContext, "id">;
102
+ type ComputedContext = Readonly<{
103
+ /**
104
+ * @computed
105
+ * The number of inputs
106
+ */
107
+ valueLength: number;
108
+ /**
109
+ * @computed
110
+ * The number of inputs that are not empty
111
+ */
112
+ filledValueLength: number;
113
+ /**
114
+ * @computed
115
+ * Whether all input values are valid
116
+ */
117
+ isValueComplete: boolean;
118
+ /**
119
+ * @computed
120
+ * The string representation of the input values
121
+ */
122
+ valueAsString: string;
123
+ /**
124
+ * @computed
125
+ * The value at focused index
126
+ */
127
+ focusedValue: string;
128
+ }>;
129
+ type PrivateContext = Context<{}>;
130
+ type MachineContext = PublicContext & PrivateContext & ComputedContext;
131
+ type MachineState = {
132
+ value: "idle" | "focused";
133
+ };
134
+ type State = StateMachine.State<MachineContext, MachineState>;
135
+ type Send = StateMachine.Send<StateMachine.AnyEventObject>;
136
+
137
+ declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): {
138
+ /**
139
+ * The value of the input as an array of strings.
140
+ */
141
+ value: string[];
142
+ /**
143
+ * The value of the input as a string.
144
+ */
145
+ valueAsString: string;
146
+ /**
147
+ * Whether all inputs are filled.
148
+ */
149
+ isValueComplete: boolean;
150
+ /**
151
+ * Function to set the value of the inputs.
152
+ */
153
+ setValue(value: string[]): void;
154
+ /**
155
+ * Function to clear the value of the inputs.
156
+ */
157
+ clearValue(): void;
158
+ /**
159
+ * Function to set the value of the input at a specific index.
160
+ */
161
+ setValueAtIndex(index: number, value: string): void;
162
+ /**
163
+ * Function to focus the pin-input. This will focus the first input.
164
+ */
165
+ focus: () => void;
166
+ rootProps: T["element"];
167
+ labelProps: T["label"];
168
+ hiddenInputProps: T["input"];
169
+ controlProps: T["element"];
170
+ getInputProps({ index }: {
171
+ index: number;
172
+ }): T["input"];
173
+ };
174
+
175
+ declare function machine(userContext: UserDefinedContext): _zag_js_core.Machine<MachineContext, MachineState, _zag_js_core.StateMachine.AnyEventObject>;
176
+
177
+ export { UserDefinedContext as Context, anatomy, connect, machine };