@sytechui/input-otp 2.1.32

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,273 @@
1
+ "use client";
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/use-input-otp.ts
22
+ var use_input_otp_exports = {};
23
+ __export(use_input_otp_exports, {
24
+ useInputOtp: () => useInputOtp
25
+ });
26
+ module.exports = __toCommonJS(use_input_otp_exports);
27
+ var import_system = require("@sytechui/system");
28
+ var import_theme = require("@sytechui/theme");
29
+ var import_react_utils = require("@sytechui/react-utils");
30
+ var import_shared_utils = require("@sytechui/shared-utils");
31
+ var import_use_form_reset = require("@sytechui/use-form-reset");
32
+ var import_react = require("react");
33
+ var import_utils = require("@react-stately/utils");
34
+ var import_form = require("@react-stately/form");
35
+ var import_form2 = require("@react-aria/form");
36
+ var import_focus = require("@react-aria/focus");
37
+ var import_form3 = require("@sytechui/form");
38
+ function useInputOtp(originalProps) {
39
+ var _a, _b, _c, _d;
40
+ const globalContext = (0, import_system.useProviderContext)();
41
+ const { validationBehavior: formValidationBehavior } = (0, import_form3.useSlottedContext)(import_form3.FormContext) || {};
42
+ const [props, variantProps] = (0, import_system.mapPropsVariants)(originalProps, import_theme.inputOtp.variantKeys);
43
+ const {
44
+ ref,
45
+ baseRef,
46
+ as,
47
+ className,
48
+ classNames,
49
+ length = 4,
50
+ autoFocus,
51
+ "aria-label": ariaLabel = "One-time password input",
52
+ onValueChange = () => {
53
+ },
54
+ allowedKeys = "^[0-9]*$",
55
+ validationBehavior = (_a = formValidationBehavior != null ? formValidationBehavior : globalContext == null ? void 0 : globalContext.validationBehavior) != null ? _a : "native",
56
+ type,
57
+ name,
58
+ maxLength,
59
+ minLength,
60
+ textAlign = "center",
61
+ onComplete = () => {
62
+ },
63
+ pushPasswordManagerStrategy,
64
+ pasteTransformer,
65
+ containerClassName,
66
+ noScriptCSSFallback,
67
+ onChange,
68
+ inputMode,
69
+ ...otherProps
70
+ } = props;
71
+ const Component = as || "div";
72
+ const inputRef = (0, import_react_utils.useDOMRef)(ref);
73
+ const baseDomRef = (0, import_react_utils.useDOMRef)(baseRef);
74
+ const { isFocusVisible, isFocused, focusProps } = (0, import_focus.useFocusRing)({
75
+ autoFocus,
76
+ isTextInput: true
77
+ });
78
+ const handleValueChange = (0, import_react.useCallback)(
79
+ (value2) => {
80
+ onValueChange(value2 != null ? value2 : "");
81
+ },
82
+ [onValueChange]
83
+ );
84
+ const [value, setValue] = (0, import_utils.useControlledState)(
85
+ props.value,
86
+ (_b = props.defaultValue) != null ? _b : "",
87
+ handleValueChange
88
+ );
89
+ const disableAnimation = (_d = (_c = originalProps.disableAnimation) != null ? _c : globalContext == null ? void 0 : globalContext.disableAnimation) != null ? _d : false;
90
+ const isDisabled = originalProps.isDisabled;
91
+ const baseStyles = (0, import_theme.cn)(classNames == null ? void 0 : classNames.base, className);
92
+ const validationState = (0, import_form.useFormValidationState)({
93
+ ...props,
94
+ validationBehavior,
95
+ value
96
+ });
97
+ (0, import_use_form_reset.useFormReset)(inputRef, value, setValue);
98
+ (0, import_form2.useFormValidation)({ ...props, validationBehavior }, validationState, inputRef);
99
+ const {
100
+ isInvalid: isAriaInvalid,
101
+ validationErrors,
102
+ validationDetails
103
+ } = validationState.displayValidation;
104
+ const isReadOnly = originalProps.isReadOnly;
105
+ const isRequired = originalProps.isRequired;
106
+ const isInvalid = originalProps.isInvalid || isAriaInvalid;
107
+ const errorMessage = typeof props.errorMessage === "function" ? props.errorMessage({ isInvalid, validationErrors, validationDetails }) : props.errorMessage || (validationErrors == null ? void 0 : validationErrors.join(" "));
108
+ const description = props.description;
109
+ const hasHelper = !!description || !!errorMessage;
110
+ const slots = (0, import_react.useMemo)(
111
+ () => (0, import_theme.inputOtp)({
112
+ ...variantProps,
113
+ disableAnimation,
114
+ isInvalid,
115
+ isReadOnly
116
+ }),
117
+ [(0, import_shared_utils.objectToDeps)(variantProps), disableAnimation, isInvalid, isReadOnly]
118
+ );
119
+ const getBaseProps = (0, import_react.useCallback)(
120
+ (props2 = {}) => {
121
+ return {
122
+ ref: baseDomRef,
123
+ className: slots.base({
124
+ class: baseStyles
125
+ }),
126
+ "data-slot": "base",
127
+ "data-disabled": (0, import_shared_utils.dataAttr)(isDisabled),
128
+ "data-invalid": (0, import_shared_utils.dataAttr)(isInvalid),
129
+ "data-required": (0, import_shared_utils.dataAttr)(originalProps == null ? void 0 : originalProps.isRequired),
130
+ "data-readonly": (0, import_shared_utils.dataAttr)(originalProps == null ? void 0 : originalProps.isReadOnly),
131
+ "data-filled": (0, import_shared_utils.dataAttr)(value.length === length),
132
+ "aria-label": ariaLabel,
133
+ "aria-required": (0, import_shared_utils.dataAttr)(originalProps.isRequired),
134
+ "aria-readonly": (0, import_shared_utils.dataAttr)(originalProps == null ? void 0 : originalProps.isReadOnly),
135
+ role: "base",
136
+ ...(0, import_shared_utils.mergeProps)(
137
+ (0, import_react_utils.filterDOMProps)(otherProps, {
138
+ enabled: true
139
+ }),
140
+ (0, import_react_utils.filterDOMProps)(props2)
141
+ ),
142
+ onChange: (e) => {
143
+ var _a2;
144
+ const val = (_a2 = e.target) == null ? void 0 : _a2.value;
145
+ const regex = new RegExp(allowedKeys);
146
+ if (regex.test(val)) {
147
+ onChange == null ? void 0 : onChange(e);
148
+ }
149
+ }
150
+ };
151
+ },
152
+ [baseDomRef, slots, baseStyles, isDisabled, isInvalid, isRequired, isReadOnly, value, length]
153
+ );
154
+ const getInputOtpProps = (0, import_react.useCallback)(
155
+ (props2 = {}) => {
156
+ var _a2;
157
+ const otpProps = {
158
+ ...focusProps,
159
+ required: isRequired,
160
+ disabled: isDisabled,
161
+ readOnly: isReadOnly,
162
+ pattern: allowedKeys,
163
+ maxLength: maxLength != null ? maxLength : length,
164
+ minLength: minLength != null ? minLength : length,
165
+ textAlign,
166
+ ref: inputRef,
167
+ name,
168
+ value,
169
+ autoFocus,
170
+ onChange: setValue,
171
+ onBlur: (0, import_shared_utils.chain)(focusProps.onBlur, props2 == null ? void 0 : props2.onBlur),
172
+ onComplete,
173
+ pushPasswordManagerStrategy,
174
+ pasteTransformer,
175
+ noScriptCSSFallback,
176
+ inputMode: inputMode != null ? inputMode : (0, import_shared_utils.isPatternNumeric)(allowedKeys) ? "numeric" : "text",
177
+ containerClassName: (_a2 = slots.wrapper) == null ? void 0 : _a2.call(slots, { class: (0, import_theme.cn)(classNames == null ? void 0 : classNames.wrapper, containerClassName) }),
178
+ ...props2
179
+ };
180
+ return otpProps;
181
+ },
182
+ [
183
+ inputMode,
184
+ isRequired,
185
+ isDisabled,
186
+ isReadOnly,
187
+ allowedKeys,
188
+ inputRef,
189
+ name,
190
+ value,
191
+ length,
192
+ setValue,
193
+ props.onBlur,
194
+ onComplete,
195
+ autoFocus
196
+ ]
197
+ );
198
+ const getSegmentWrapperProps = (0, import_react.useCallback)(
199
+ (props2 = {}) => {
200
+ return {
201
+ className: slots.segmentWrapper({
202
+ class: (0, import_theme.cn)(classNames == null ? void 0 : classNames.segmentWrapper, props2 == null ? void 0 : props2.className)
203
+ }),
204
+ "data-slot": "segment-wrapper",
205
+ "data-disabled": (0, import_shared_utils.dataAttr)(isDisabled),
206
+ "aria-label": ariaLabel,
207
+ ...props2
208
+ };
209
+ },
210
+ [classNames == null ? void 0 : classNames.segmentWrapper, isDisabled]
211
+ );
212
+ const getHelperWrapperProps = (0, import_react.useCallback)(
213
+ (props2 = {}) => {
214
+ return {
215
+ className: slots.helperWrapper({
216
+ class: (0, import_theme.cn)(classNames == null ? void 0 : classNames.helperWrapper, props2 == null ? void 0 : props2.className)
217
+ }),
218
+ "data-slot": "helper-wrapper",
219
+ ...props2
220
+ };
221
+ },
222
+ [classNames == null ? void 0 : classNames.helperWrapper]
223
+ );
224
+ const getErrorMessageProps = (0, import_react.useCallback)(
225
+ (props2 = {}) => {
226
+ return {
227
+ className: slots.errorMessage({
228
+ class: (0, import_theme.cn)(classNames == null ? void 0 : classNames.errorMessage, props2 == null ? void 0 : props2.className)
229
+ }),
230
+ "data-slot": "error-message",
231
+ ...props2
232
+ };
233
+ },
234
+ [classNames == null ? void 0 : classNames.errorMessage]
235
+ );
236
+ const getDescriptionProps = (0, import_react.useCallback)(
237
+ (props2 = {}) => {
238
+ return {
239
+ className: slots.description({
240
+ class: (0, import_theme.cn)(classNames == null ? void 0 : classNames.description, props2 == null ? void 0 : props2.className)
241
+ }),
242
+ "data-slot": "description",
243
+ ...props2
244
+ };
245
+ },
246
+ [classNames == null ? void 0 : classNames.description]
247
+ );
248
+ return {
249
+ Component,
250
+ inputRef,
251
+ length,
252
+ value,
253
+ type,
254
+ slots,
255
+ hasHelper,
256
+ classNames,
257
+ isInvalid,
258
+ description,
259
+ errorMessage,
260
+ isFocusVisible,
261
+ isFocused,
262
+ getBaseProps,
263
+ getInputOtpProps,
264
+ getSegmentWrapperProps,
265
+ getHelperWrapperProps,
266
+ getErrorMessageProps,
267
+ getDescriptionProps
268
+ };
269
+ }
270
+ // Annotate the CommonJS export names for ESM import in node:
271
+ 0 && (module.exports = {
272
+ useInputOtp
273
+ });
@@ -0,0 +1,7 @@
1
+ "use client";
2
+ import {
3
+ useInputOtp
4
+ } from "./chunk-VZ7MKXTH.mjs";
5
+ export {
6
+ useInputOtp
7
+ };
package/package.json ADDED
@@ -0,0 +1,63 @@
1
+ {
2
+ "name": "@sytechui/input-otp",
3
+ "version": "2.1.32",
4
+ "description": "",
5
+ "keywords": [
6
+ "input-otp"
7
+ ],
8
+ "author": "HeroUI <support@heroui.com>",
9
+ "homepage": "https://heroui.com",
10
+ "license": "MIT",
11
+ "main": "dist/index.js",
12
+ "sideEffects": false,
13
+ "files": [
14
+ "dist"
15
+ ],
16
+ "publishConfig": {
17
+ "access": "public"
18
+ },
19
+ "repository": {
20
+ "type": "git",
21
+ "url": "git+https://github.com/heroui-inc/heroui.git",
22
+ "directory": "packages/components/input-otp"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/heroui-inc/heroui/issues"
26
+ },
27
+ "peerDependencies": {
28
+ "react": ">=18",
29
+ "react-dom": ">=18",
30
+ "@sytechui/theme": ">=2.4.24",
31
+ "@sytechui/system": ">=2.4.18"
32
+ },
33
+ "dependencies": {
34
+ "@react-aria/form": "3.1.5",
35
+ "@react-stately/utils": "3.11.0",
36
+ "@react-stately/form": "3.2.4",
37
+ "@react-types/textfield": "3.12.8",
38
+ "input-otp": "1.4.1",
39
+ "@react-aria/focus": "3.21.5",
40
+ "@sytechui/react-utils": "2.1.14",
41
+ "@sytechui/form": "2.1.32",
42
+ "@sytechui/shared-utils": "2.1.12",
43
+ "@sytechui/use-form-reset": "2.0.1"
44
+ },
45
+ "clean-package": "../../../clean-package.config.json",
46
+ "module": "dist/index.mjs",
47
+ "types": "dist/index.d.ts",
48
+ "exports": {
49
+ ".": {
50
+ "types": "./dist/index.d.ts",
51
+ "import": "./dist/index.mjs",
52
+ "require": "./dist/index.js"
53
+ },
54
+ "./package.json": "./package.json"
55
+ },
56
+ "scripts": {
57
+ "build": "tsup src --dts",
58
+ "build:fast": "tsup src",
59
+ "dev": "pnpm build:fast --watch",
60
+ "clean": "rimraf dist .turbo",
61
+ "typecheck": "tsc --noEmit"
62
+ }
63
+ }