@zag-js/pin-input 1.34.1 → 1.35.1

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.
@@ -0,0 +1,35 @@
1
+ // src/pin-input.props.ts
2
+ import { createProps } from "@zag-js/types";
3
+ import { createSplitProps } from "@zag-js/utils";
4
+ var props = createProps()([
5
+ "autoFocus",
6
+ "blurOnComplete",
7
+ "count",
8
+ "defaultValue",
9
+ "dir",
10
+ "disabled",
11
+ "form",
12
+ "getRootNode",
13
+ "id",
14
+ "ids",
15
+ "invalid",
16
+ "mask",
17
+ "name",
18
+ "onValueChange",
19
+ "onValueComplete",
20
+ "onValueInvalid",
21
+ "otp",
22
+ "pattern",
23
+ "placeholder",
24
+ "readOnly",
25
+ "required",
26
+ "selectOnFocus",
27
+ "translations",
28
+ "type",
29
+ "value"
30
+ ]);
31
+ var splitProps = createSplitProps(props);
32
+ export {
33
+ props,
34
+ splitProps
35
+ };
@@ -0,0 +1,188 @@
1
+ import { Machine, EventObject, Service } from '@zag-js/core';
2
+ import { PropTypes, RequiredBy, DirectionProperty, CommonProperties } from '@zag-js/types';
3
+
4
+ interface ValueChangeDetails {
5
+ value: string[];
6
+ valueAsString: string;
7
+ }
8
+ interface ValueInvalidDetails {
9
+ value: string;
10
+ index: number;
11
+ }
12
+ type IntlTranslations = {
13
+ inputLabel: (index: number, length: number) => string;
14
+ };
15
+ type ElementIds = Partial<{
16
+ root: string;
17
+ hiddenInput: string;
18
+ label: string;
19
+ control: string;
20
+ input: (id: string) => string;
21
+ }>;
22
+ interface PinInputProps extends DirectionProperty, CommonProperties {
23
+ /**
24
+ * The name of the input element. Useful for form submission.
25
+ */
26
+ name?: string | undefined;
27
+ /**
28
+ * The associate form of the underlying input element.
29
+ */
30
+ form?: string | undefined;
31
+ /**
32
+ * The regular expression that the user-entered input value is checked against.
33
+ */
34
+ pattern?: string | undefined;
35
+ /**
36
+ * The ids of the elements in the pin input. Useful for composition.
37
+ */
38
+ ids?: ElementIds | undefined;
39
+ /**
40
+ * Whether the inputs are disabled
41
+ */
42
+ disabled?: boolean | undefined;
43
+ /**
44
+ * The placeholder text for the input
45
+ * @default "○"
46
+ */
47
+ placeholder?: string | undefined;
48
+ /**
49
+ * Whether to auto-focus the first input.
50
+ */
51
+ autoFocus?: boolean | undefined;
52
+ /**
53
+ * Whether the pin input is in the invalid state
54
+ */
55
+ invalid?: boolean | undefined;
56
+ /**
57
+ * Whether the pin input is required
58
+ */
59
+ required?: boolean | undefined;
60
+ /**
61
+ * Whether the pin input is in the valid state
62
+ */
63
+ readOnly?: boolean | undefined;
64
+ /**
65
+ * If `true`, the pin input component signals to its fields that they should
66
+ * use `autocomplete="one-time-code"`.
67
+ */
68
+ otp?: boolean | undefined;
69
+ /**
70
+ * The controlled value of the the pin input.
71
+ */
72
+ value?: string[] | undefined;
73
+ /**
74
+ * The initial value of the the pin input when rendered.
75
+ * Use when you don't need to control the value of the pin input.
76
+ */
77
+ defaultValue?: string[] | undefined;
78
+ /**
79
+ * The type of value the pin-input should allow
80
+ * @default "numeric"
81
+ */
82
+ type?: "alphanumeric" | "numeric" | "alphabetic" | undefined;
83
+ /**
84
+ * Function called when all inputs have valid values
85
+ */
86
+ onValueComplete?: ((details: ValueChangeDetails) => void) | undefined;
87
+ /**
88
+ * Function called on input change
89
+ */
90
+ onValueChange?: ((details: ValueChangeDetails) => void) | undefined;
91
+ /**
92
+ * Function called when an invalid value is entered
93
+ */
94
+ onValueInvalid?: ((details: ValueInvalidDetails) => void) | undefined;
95
+ /**
96
+ * If `true`, the input's value will be masked just like `type=password`
97
+ */
98
+ mask?: boolean | undefined;
99
+ /**
100
+ * Whether to blur the input when the value is complete
101
+ */
102
+ blurOnComplete?: boolean | undefined;
103
+ /**
104
+ * Whether to select input value when input is focused
105
+ */
106
+ selectOnFocus?: boolean | undefined;
107
+ /**
108
+ * Specifies the localized strings that identifies the accessibility elements and their states
109
+ */
110
+ translations?: IntlTranslations | undefined;
111
+ /**
112
+ * The number of inputs to render to improve SSR aria attributes.
113
+ * This will be required in next major version.
114
+ */
115
+ count?: number | undefined;
116
+ }
117
+ type PropsWithDefault = "placeholder" | "otp" | "type" | "defaultValue";
118
+ interface PinInputSchema {
119
+ state: "idle" | "focused";
120
+ props: RequiredBy<PinInputProps, PropsWithDefault>;
121
+ context: {
122
+ value: string[];
123
+ focusedIndex: number;
124
+ count: number;
125
+ };
126
+ computed: {
127
+ _value: string[];
128
+ valueLength: number;
129
+ filledValueLength: number;
130
+ isValueComplete: boolean;
131
+ valueAsString: string;
132
+ focusedValue: string;
133
+ };
134
+ event: EventObject;
135
+ action: string;
136
+ effect: string;
137
+ guard: string;
138
+ }
139
+ type PinInputService = Service<PinInputSchema>;
140
+ type PinInputMachine = Machine<PinInputSchema>;
141
+ interface InputProps {
142
+ index: number;
143
+ }
144
+ interface PinInputApi<T extends PropTypes = PropTypes> {
145
+ /**
146
+ * The value of the input as an array of strings.
147
+ */
148
+ value: string[];
149
+ /**
150
+ * The value of the input as a string.
151
+ */
152
+ valueAsString: string;
153
+ /**
154
+ * Whether all inputs are filled.
155
+ */
156
+ complete: boolean;
157
+ /**
158
+ * The number of inputs to render
159
+ */
160
+ count: number;
161
+ /**
162
+ * The array of input values.
163
+ */
164
+ items: number[];
165
+ /**
166
+ * Function to set the value of the inputs.
167
+ */
168
+ setValue: (value: string[]) => void;
169
+ /**
170
+ * Function to clear the value of the inputs.
171
+ */
172
+ clearValue: VoidFunction;
173
+ /**
174
+ * Function to set the value of the input at a specific index.
175
+ */
176
+ setValueAtIndex: (index: number, value: string) => void;
177
+ /**
178
+ * Function to focus the pin-input. This will focus the first input.
179
+ */
180
+ focus: VoidFunction;
181
+ getRootProps: () => T["element"];
182
+ getLabelProps: () => T["label"];
183
+ getHiddenInputProps: () => T["input"];
184
+ getControlProps: () => T["element"];
185
+ getInputProps: (props: InputProps) => T["input"];
186
+ }
187
+
188
+ export type { ElementIds, InputProps, IntlTranslations, PinInputApi, PinInputMachine, PinInputProps, PinInputSchema, PinInputService, ValueChangeDetails, ValueInvalidDetails };
@@ -0,0 +1,188 @@
1
+ import { Machine, EventObject, Service } from '@zag-js/core';
2
+ import { PropTypes, RequiredBy, DirectionProperty, CommonProperties } from '@zag-js/types';
3
+
4
+ interface ValueChangeDetails {
5
+ value: string[];
6
+ valueAsString: string;
7
+ }
8
+ interface ValueInvalidDetails {
9
+ value: string;
10
+ index: number;
11
+ }
12
+ type IntlTranslations = {
13
+ inputLabel: (index: number, length: number) => string;
14
+ };
15
+ type ElementIds = Partial<{
16
+ root: string;
17
+ hiddenInput: string;
18
+ label: string;
19
+ control: string;
20
+ input: (id: string) => string;
21
+ }>;
22
+ interface PinInputProps extends DirectionProperty, CommonProperties {
23
+ /**
24
+ * The name of the input element. Useful for form submission.
25
+ */
26
+ name?: string | undefined;
27
+ /**
28
+ * The associate form of the underlying input element.
29
+ */
30
+ form?: string | undefined;
31
+ /**
32
+ * The regular expression that the user-entered input value is checked against.
33
+ */
34
+ pattern?: string | undefined;
35
+ /**
36
+ * The ids of the elements in the pin input. Useful for composition.
37
+ */
38
+ ids?: ElementIds | undefined;
39
+ /**
40
+ * Whether the inputs are disabled
41
+ */
42
+ disabled?: boolean | undefined;
43
+ /**
44
+ * The placeholder text for the input
45
+ * @default "○"
46
+ */
47
+ placeholder?: string | undefined;
48
+ /**
49
+ * Whether to auto-focus the first input.
50
+ */
51
+ autoFocus?: boolean | undefined;
52
+ /**
53
+ * Whether the pin input is in the invalid state
54
+ */
55
+ invalid?: boolean | undefined;
56
+ /**
57
+ * Whether the pin input is required
58
+ */
59
+ required?: boolean | undefined;
60
+ /**
61
+ * Whether the pin input is in the valid state
62
+ */
63
+ readOnly?: boolean | undefined;
64
+ /**
65
+ * If `true`, the pin input component signals to its fields that they should
66
+ * use `autocomplete="one-time-code"`.
67
+ */
68
+ otp?: boolean | undefined;
69
+ /**
70
+ * The controlled value of the the pin input.
71
+ */
72
+ value?: string[] | undefined;
73
+ /**
74
+ * The initial value of the the pin input when rendered.
75
+ * Use when you don't need to control the value of the pin input.
76
+ */
77
+ defaultValue?: string[] | undefined;
78
+ /**
79
+ * The type of value the pin-input should allow
80
+ * @default "numeric"
81
+ */
82
+ type?: "alphanumeric" | "numeric" | "alphabetic" | undefined;
83
+ /**
84
+ * Function called when all inputs have valid values
85
+ */
86
+ onValueComplete?: ((details: ValueChangeDetails) => void) | undefined;
87
+ /**
88
+ * Function called on input change
89
+ */
90
+ onValueChange?: ((details: ValueChangeDetails) => void) | undefined;
91
+ /**
92
+ * Function called when an invalid value is entered
93
+ */
94
+ onValueInvalid?: ((details: ValueInvalidDetails) => void) | undefined;
95
+ /**
96
+ * If `true`, the input's value will be masked just like `type=password`
97
+ */
98
+ mask?: boolean | undefined;
99
+ /**
100
+ * Whether to blur the input when the value is complete
101
+ */
102
+ blurOnComplete?: boolean | undefined;
103
+ /**
104
+ * Whether to select input value when input is focused
105
+ */
106
+ selectOnFocus?: boolean | undefined;
107
+ /**
108
+ * Specifies the localized strings that identifies the accessibility elements and their states
109
+ */
110
+ translations?: IntlTranslations | undefined;
111
+ /**
112
+ * The number of inputs to render to improve SSR aria attributes.
113
+ * This will be required in next major version.
114
+ */
115
+ count?: number | undefined;
116
+ }
117
+ type PropsWithDefault = "placeholder" | "otp" | "type" | "defaultValue";
118
+ interface PinInputSchema {
119
+ state: "idle" | "focused";
120
+ props: RequiredBy<PinInputProps, PropsWithDefault>;
121
+ context: {
122
+ value: string[];
123
+ focusedIndex: number;
124
+ count: number;
125
+ };
126
+ computed: {
127
+ _value: string[];
128
+ valueLength: number;
129
+ filledValueLength: number;
130
+ isValueComplete: boolean;
131
+ valueAsString: string;
132
+ focusedValue: string;
133
+ };
134
+ event: EventObject;
135
+ action: string;
136
+ effect: string;
137
+ guard: string;
138
+ }
139
+ type PinInputService = Service<PinInputSchema>;
140
+ type PinInputMachine = Machine<PinInputSchema>;
141
+ interface InputProps {
142
+ index: number;
143
+ }
144
+ interface PinInputApi<T extends PropTypes = PropTypes> {
145
+ /**
146
+ * The value of the input as an array of strings.
147
+ */
148
+ value: string[];
149
+ /**
150
+ * The value of the input as a string.
151
+ */
152
+ valueAsString: string;
153
+ /**
154
+ * Whether all inputs are filled.
155
+ */
156
+ complete: boolean;
157
+ /**
158
+ * The number of inputs to render
159
+ */
160
+ count: number;
161
+ /**
162
+ * The array of input values.
163
+ */
164
+ items: number[];
165
+ /**
166
+ * Function to set the value of the inputs.
167
+ */
168
+ setValue: (value: string[]) => void;
169
+ /**
170
+ * Function to clear the value of the inputs.
171
+ */
172
+ clearValue: VoidFunction;
173
+ /**
174
+ * Function to set the value of the input at a specific index.
175
+ */
176
+ setValueAtIndex: (index: number, value: string) => void;
177
+ /**
178
+ * Function to focus the pin-input. This will focus the first input.
179
+ */
180
+ focus: VoidFunction;
181
+ getRootProps: () => T["element"];
182
+ getLabelProps: () => T["label"];
183
+ getHiddenInputProps: () => T["input"];
184
+ getControlProps: () => T["element"];
185
+ getInputProps: (props: InputProps) => T["input"];
186
+ }
187
+
188
+ export type { ElementIds, InputProps, IntlTranslations, PinInputApi, PinInputMachine, PinInputProps, PinInputSchema, PinInputService, ValueChangeDetails, ValueInvalidDetails };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/pin-input.types.ts
17
+ var pin_input_types_exports = {};
18
+ module.exports = __toCommonJS(pin_input_types_exports);
File without changes
@@ -0,0 +1,10 @@
1
+ declare const REGEX: {
2
+ numeric: RegExp;
3
+ alphabetic: RegExp;
4
+ alphanumeric: RegExp;
5
+ };
6
+ type PinInputType = keyof typeof REGEX;
7
+ declare function isValidType(type: string, value: string): boolean;
8
+ declare function isValidValue(value: string, type: PinInputType, pattern?: string): boolean;
9
+
10
+ export { isValidType, isValidValue };
@@ -0,0 +1,10 @@
1
+ declare const REGEX: {
2
+ numeric: RegExp;
3
+ alphabetic: RegExp;
4
+ alphanumeric: RegExp;
5
+ };
6
+ type PinInputType = keyof typeof REGEX;
7
+ declare function isValidType(type: string, value: string): boolean;
8
+ declare function isValidValue(value: string, type: PinInputType, pattern?: string): boolean;
9
+
10
+ export { isValidType, isValidValue };
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/pin-input.utils.ts
21
+ var pin_input_utils_exports = {};
22
+ __export(pin_input_utils_exports, {
23
+ isValidType: () => isValidType,
24
+ isValidValue: () => isValidValue
25
+ });
26
+ module.exports = __toCommonJS(pin_input_utils_exports);
27
+ var REGEX = {
28
+ numeric: /^[0-9]+$/,
29
+ alphabetic: /^[A-Za-z]+$/,
30
+ alphanumeric: /^[a-zA-Z0-9]+$/i
31
+ };
32
+ function isValidType(type, value) {
33
+ if (!type) return true;
34
+ return !!REGEX[type]?.test(value);
35
+ }
36
+ function isValidValue(value, type, pattern) {
37
+ if (!pattern) return isValidType(type, value);
38
+ const regex = new RegExp(pattern, "g");
39
+ return regex.test(value);
40
+ }
41
+ // Annotate the CommonJS export names for ESM import in node:
42
+ 0 && (module.exports = {
43
+ isValidType,
44
+ isValidValue
45
+ });
@@ -0,0 +1,19 @@
1
+ // src/pin-input.utils.ts
2
+ var REGEX = {
3
+ numeric: /^[0-9]+$/,
4
+ alphabetic: /^[A-Za-z]+$/,
5
+ alphanumeric: /^[a-zA-Z0-9]+$/i
6
+ };
7
+ function isValidType(type, value) {
8
+ if (!type) return true;
9
+ return !!REGEX[type]?.test(value);
10
+ }
11
+ function isValidValue(value, type, pattern) {
12
+ if (!pattern) return isValidType(type, value);
13
+ const regex = new RegExp(pattern, "g");
14
+ return regex.test(value);
15
+ }
16
+ export {
17
+ isValidType,
18
+ isValidValue
19
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/pin-input",
3
- "version": "1.34.1",
3
+ "version": "1.35.1",
4
4
  "description": "Core logic for the pin-input widget implemented as a state machine",
5
5
  "keywords": [
6
6
  "js",
@@ -26,16 +26,16 @@
26
26
  "url": "https://github.com/chakra-ui/zag/issues"
27
27
  },
28
28
  "dependencies": {
29
- "@zag-js/anatomy": "1.34.1",
30
- "@zag-js/dom-query": "1.34.1",
31
- "@zag-js/utils": "1.34.1",
32
- "@zag-js/core": "1.34.1",
33
- "@zag-js/types": "1.34.1"
29
+ "@zag-js/anatomy": "1.35.1",
30
+ "@zag-js/dom-query": "1.35.1",
31
+ "@zag-js/utils": "1.35.1",
32
+ "@zag-js/core": "1.35.1",
33
+ "@zag-js/types": "1.35.1"
34
34
  },
35
35
  "devDependencies": {
36
36
  "clean-package": "2.2.0"
37
37
  },
38
- "clean-package": "../../../clean-package.config.json",
38
+ "clean-package": "./clean-package.config.json",
39
39
  "main": "dist/index.js",
40
40
  "module": "dist/index.mjs",
41
41
  "types": "dist/index.d.ts",
@@ -50,6 +50,16 @@
50
50
  "default": "./dist/index.js"
51
51
  }
52
52
  },
53
+ "./anatomy": {
54
+ "import": {
55
+ "types": "./dist/pin-input.anatomy.d.mts",
56
+ "default": "./dist/pin-input.anatomy.mjs"
57
+ },
58
+ "require": {
59
+ "types": "./dist/pin-input.anatomy.d.ts",
60
+ "default": "./dist/pin-input.anatomy.js"
61
+ }
62
+ },
53
63
  "./package.json": "./package.json"
54
64
  },
55
65
  "scripts": {