@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,8 @@
1
+ "use client";
2
+ import {
3
+ InputOtpSegment
4
+ } from "./chunk-IJHHP6DJ.mjs";
5
+ import "./chunk-R2XKH6IK.mjs";
6
+ export {
7
+ InputOtpSegment
8
+ };
@@ -0,0 +1,14 @@
1
+ import * as _sytechui_system from '@sytechui/system';
2
+ import { UseInputOtpProps } from './use-input-otp.mjs';
3
+ import 'input-otp';
4
+ import 'tailwind-variants';
5
+ import 'react';
6
+ import '@sytechui/theme';
7
+ import '@sytechui/react-utils';
8
+ import '@react-types/textfield';
9
+
10
+ interface InputOtpProps extends UseInputOtpProps {
11
+ }
12
+ declare const InputOtp: _sytechui_system.InternalForwardRefRenderFunction<"input", InputOtpProps, never>;
13
+
14
+ export { type InputOtpProps, InputOtp as default };
@@ -0,0 +1,14 @@
1
+ import * as _sytechui_system from '@sytechui/system';
2
+ import { UseInputOtpProps } from './use-input-otp.js';
3
+ import 'input-otp';
4
+ import 'tailwind-variants';
5
+ import 'react';
6
+ import '@sytechui/theme';
7
+ import '@sytechui/react-utils';
8
+ import '@react-types/textfield';
9
+
10
+ interface InputOtpProps extends UseInputOtpProps {
11
+ }
12
+ declare const InputOtp: _sytechui_system.InternalForwardRefRenderFunction<"input", InputOtpProps, never>;
13
+
14
+ export { type InputOtpProps, InputOtp as default };
@@ -0,0 +1,374 @@
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/input-otp.tsx
22
+ var input_otp_exports = {};
23
+ __export(input_otp_exports, {
24
+ default: () => input_otp_default
25
+ });
26
+ module.exports = __toCommonJS(input_otp_exports);
27
+ var import_system2 = require("@sytechui/system");
28
+ var import_react3 = require("react");
29
+ var import_input_otp = require("input-otp");
30
+
31
+ // src/use-input-otp.ts
32
+ var import_system = require("@sytechui/system");
33
+ var import_theme = require("@sytechui/theme");
34
+ var import_react_utils = require("@sytechui/react-utils");
35
+ var import_shared_utils = require("@sytechui/shared-utils");
36
+ var import_use_form_reset = require("@sytechui/use-form-reset");
37
+ var import_react = require("react");
38
+ var import_utils = require("@react-stately/utils");
39
+ var import_form = require("@react-stately/form");
40
+ var import_form2 = require("@react-aria/form");
41
+ var import_focus = require("@react-aria/focus");
42
+ var import_form3 = require("@sytechui/form");
43
+ function useInputOtp(originalProps) {
44
+ var _a, _b, _c, _d;
45
+ const globalContext = (0, import_system.useProviderContext)();
46
+ const { validationBehavior: formValidationBehavior } = (0, import_form3.useSlottedContext)(import_form3.FormContext) || {};
47
+ const [props, variantProps] = (0, import_system.mapPropsVariants)(originalProps, import_theme.inputOtp.variantKeys);
48
+ const {
49
+ ref,
50
+ baseRef,
51
+ as,
52
+ className,
53
+ classNames,
54
+ length = 4,
55
+ autoFocus,
56
+ "aria-label": ariaLabel = "One-time password input",
57
+ onValueChange = () => {
58
+ },
59
+ allowedKeys = "^[0-9]*$",
60
+ validationBehavior = (_a = formValidationBehavior != null ? formValidationBehavior : globalContext == null ? void 0 : globalContext.validationBehavior) != null ? _a : "native",
61
+ type,
62
+ name,
63
+ maxLength,
64
+ minLength,
65
+ textAlign = "center",
66
+ onComplete = () => {
67
+ },
68
+ pushPasswordManagerStrategy,
69
+ pasteTransformer,
70
+ containerClassName,
71
+ noScriptCSSFallback,
72
+ onChange,
73
+ inputMode,
74
+ ...otherProps
75
+ } = props;
76
+ const Component = as || "div";
77
+ const inputRef = (0, import_react_utils.useDOMRef)(ref);
78
+ const baseDomRef = (0, import_react_utils.useDOMRef)(baseRef);
79
+ const { isFocusVisible, isFocused, focusProps } = (0, import_focus.useFocusRing)({
80
+ autoFocus,
81
+ isTextInput: true
82
+ });
83
+ const handleValueChange = (0, import_react.useCallback)(
84
+ (value2) => {
85
+ onValueChange(value2 != null ? value2 : "");
86
+ },
87
+ [onValueChange]
88
+ );
89
+ const [value, setValue] = (0, import_utils.useControlledState)(
90
+ props.value,
91
+ (_b = props.defaultValue) != null ? _b : "",
92
+ handleValueChange
93
+ );
94
+ const disableAnimation = (_d = (_c = originalProps.disableAnimation) != null ? _c : globalContext == null ? void 0 : globalContext.disableAnimation) != null ? _d : false;
95
+ const isDisabled = originalProps.isDisabled;
96
+ const baseStyles = (0, import_theme.cn)(classNames == null ? void 0 : classNames.base, className);
97
+ const validationState = (0, import_form.useFormValidationState)({
98
+ ...props,
99
+ validationBehavior,
100
+ value
101
+ });
102
+ (0, import_use_form_reset.useFormReset)(inputRef, value, setValue);
103
+ (0, import_form2.useFormValidation)({ ...props, validationBehavior }, validationState, inputRef);
104
+ const {
105
+ isInvalid: isAriaInvalid,
106
+ validationErrors,
107
+ validationDetails
108
+ } = validationState.displayValidation;
109
+ const isReadOnly = originalProps.isReadOnly;
110
+ const isRequired = originalProps.isRequired;
111
+ const isInvalid = originalProps.isInvalid || isAriaInvalid;
112
+ const errorMessage = typeof props.errorMessage === "function" ? props.errorMessage({ isInvalid, validationErrors, validationDetails }) : props.errorMessage || (validationErrors == null ? void 0 : validationErrors.join(" "));
113
+ const description = props.description;
114
+ const hasHelper = !!description || !!errorMessage;
115
+ const slots = (0, import_react.useMemo)(
116
+ () => (0, import_theme.inputOtp)({
117
+ ...variantProps,
118
+ disableAnimation,
119
+ isInvalid,
120
+ isReadOnly
121
+ }),
122
+ [(0, import_shared_utils.objectToDeps)(variantProps), disableAnimation, isInvalid, isReadOnly]
123
+ );
124
+ const getBaseProps = (0, import_react.useCallback)(
125
+ (props2 = {}) => {
126
+ return {
127
+ ref: baseDomRef,
128
+ className: slots.base({
129
+ class: baseStyles
130
+ }),
131
+ "data-slot": "base",
132
+ "data-disabled": (0, import_shared_utils.dataAttr)(isDisabled),
133
+ "data-invalid": (0, import_shared_utils.dataAttr)(isInvalid),
134
+ "data-required": (0, import_shared_utils.dataAttr)(originalProps == null ? void 0 : originalProps.isRequired),
135
+ "data-readonly": (0, import_shared_utils.dataAttr)(originalProps == null ? void 0 : originalProps.isReadOnly),
136
+ "data-filled": (0, import_shared_utils.dataAttr)(value.length === length),
137
+ "aria-label": ariaLabel,
138
+ "aria-required": (0, import_shared_utils.dataAttr)(originalProps.isRequired),
139
+ "aria-readonly": (0, import_shared_utils.dataAttr)(originalProps == null ? void 0 : originalProps.isReadOnly),
140
+ role: "base",
141
+ ...(0, import_shared_utils.mergeProps)(
142
+ (0, import_react_utils.filterDOMProps)(otherProps, {
143
+ enabled: true
144
+ }),
145
+ (0, import_react_utils.filterDOMProps)(props2)
146
+ ),
147
+ onChange: (e) => {
148
+ var _a2;
149
+ const val = (_a2 = e.target) == null ? void 0 : _a2.value;
150
+ const regex = new RegExp(allowedKeys);
151
+ if (regex.test(val)) {
152
+ onChange == null ? void 0 : onChange(e);
153
+ }
154
+ }
155
+ };
156
+ },
157
+ [baseDomRef, slots, baseStyles, isDisabled, isInvalid, isRequired, isReadOnly, value, length]
158
+ );
159
+ const getInputOtpProps = (0, import_react.useCallback)(
160
+ (props2 = {}) => {
161
+ var _a2;
162
+ const otpProps = {
163
+ ...focusProps,
164
+ required: isRequired,
165
+ disabled: isDisabled,
166
+ readOnly: isReadOnly,
167
+ pattern: allowedKeys,
168
+ maxLength: maxLength != null ? maxLength : length,
169
+ minLength: minLength != null ? minLength : length,
170
+ textAlign,
171
+ ref: inputRef,
172
+ name,
173
+ value,
174
+ autoFocus,
175
+ onChange: setValue,
176
+ onBlur: (0, import_shared_utils.chain)(focusProps.onBlur, props2 == null ? void 0 : props2.onBlur),
177
+ onComplete,
178
+ pushPasswordManagerStrategy,
179
+ pasteTransformer,
180
+ noScriptCSSFallback,
181
+ inputMode: inputMode != null ? inputMode : (0, import_shared_utils.isPatternNumeric)(allowedKeys) ? "numeric" : "text",
182
+ containerClassName: (_a2 = slots.wrapper) == null ? void 0 : _a2.call(slots, { class: (0, import_theme.cn)(classNames == null ? void 0 : classNames.wrapper, containerClassName) }),
183
+ ...props2
184
+ };
185
+ return otpProps;
186
+ },
187
+ [
188
+ inputMode,
189
+ isRequired,
190
+ isDisabled,
191
+ isReadOnly,
192
+ allowedKeys,
193
+ inputRef,
194
+ name,
195
+ value,
196
+ length,
197
+ setValue,
198
+ props.onBlur,
199
+ onComplete,
200
+ autoFocus
201
+ ]
202
+ );
203
+ const getSegmentWrapperProps = (0, import_react.useCallback)(
204
+ (props2 = {}) => {
205
+ return {
206
+ className: slots.segmentWrapper({
207
+ class: (0, import_theme.cn)(classNames == null ? void 0 : classNames.segmentWrapper, props2 == null ? void 0 : props2.className)
208
+ }),
209
+ "data-slot": "segment-wrapper",
210
+ "data-disabled": (0, import_shared_utils.dataAttr)(isDisabled),
211
+ "aria-label": ariaLabel,
212
+ ...props2
213
+ };
214
+ },
215
+ [classNames == null ? void 0 : classNames.segmentWrapper, isDisabled]
216
+ );
217
+ const getHelperWrapperProps = (0, import_react.useCallback)(
218
+ (props2 = {}) => {
219
+ return {
220
+ className: slots.helperWrapper({
221
+ class: (0, import_theme.cn)(classNames == null ? void 0 : classNames.helperWrapper, props2 == null ? void 0 : props2.className)
222
+ }),
223
+ "data-slot": "helper-wrapper",
224
+ ...props2
225
+ };
226
+ },
227
+ [classNames == null ? void 0 : classNames.helperWrapper]
228
+ );
229
+ const getErrorMessageProps = (0, import_react.useCallback)(
230
+ (props2 = {}) => {
231
+ return {
232
+ className: slots.errorMessage({
233
+ class: (0, import_theme.cn)(classNames == null ? void 0 : classNames.errorMessage, props2 == null ? void 0 : props2.className)
234
+ }),
235
+ "data-slot": "error-message",
236
+ ...props2
237
+ };
238
+ },
239
+ [classNames == null ? void 0 : classNames.errorMessage]
240
+ );
241
+ const getDescriptionProps = (0, import_react.useCallback)(
242
+ (props2 = {}) => {
243
+ return {
244
+ className: slots.description({
245
+ class: (0, import_theme.cn)(classNames == null ? void 0 : classNames.description, props2 == null ? void 0 : props2.className)
246
+ }),
247
+ "data-slot": "description",
248
+ ...props2
249
+ };
250
+ },
251
+ [classNames == null ? void 0 : classNames.description]
252
+ );
253
+ return {
254
+ Component,
255
+ inputRef,
256
+ length,
257
+ value,
258
+ type,
259
+ slots,
260
+ hasHelper,
261
+ classNames,
262
+ isInvalid,
263
+ description,
264
+ errorMessage,
265
+ isFocusVisible,
266
+ isFocused,
267
+ getBaseProps,
268
+ getInputOtpProps,
269
+ getSegmentWrapperProps,
270
+ getHelperWrapperProps,
271
+ getErrorMessageProps,
272
+ getDescriptionProps
273
+ };
274
+ }
275
+
276
+ // src/input-otp-context.ts
277
+ var import_react_utils2 = require("@sytechui/react-utils");
278
+ var [InputOtpProvider, useInputOtpContext] = (0, import_react_utils2.createContext)({
279
+ name: "InputOtpContext",
280
+ errorMessage: "useInputOtpContext: `context` is undefined. Seems like you forgot to wrap all input-otp components within `<InputOtp />`"
281
+ });
282
+
283
+ // src/input-otp-segment.tsx
284
+ var import_react2 = require("react");
285
+ var import_shared_utils2 = require("@sytechui/shared-utils");
286
+ var import_theme2 = require("@sytechui/theme");
287
+ var import_jsx_runtime = require("react/jsx-runtime");
288
+ var InputOtpSegment = ({
289
+ ...props
290
+ }) => {
291
+ var _a;
292
+ const { classNames, slots, type } = useInputOtpContext();
293
+ const passwordCharStyles = (0, import_theme2.cn)(classNames == null ? void 0 : classNames.passwordChar);
294
+ const caretStyles = (0, import_theme2.cn)(classNames == null ? void 0 : classNames.caret);
295
+ const segmentStyles = (0, import_theme2.cn)(classNames == null ? void 0 : classNames.segment);
296
+ const displayValue = (0, import_react2.useMemo)(() => {
297
+ var _a2, _b;
298
+ if (props.isActive && !props.char) {
299
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: (0, import_theme2.cn)((_a2 = slots.caret) == null ? void 0 : _a2.call(slots, { class: caretStyles })) });
300
+ }
301
+ if (props.char) {
302
+ return type === "password" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: (0, import_theme2.cn)((_b = slots.passwordChar) == null ? void 0 : _b.call(slots, { class: passwordCharStyles })) }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: props.char });
303
+ }
304
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { children: props.placeholderChar });
305
+ }, [props.char, props.isActive, props.placeholderChar, type]);
306
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
307
+ "div",
308
+ {
309
+ className: (0, import_theme2.cn)((_a = slots.segment) == null ? void 0 : _a.call(slots, { class: segmentStyles })),
310
+ "data-active": (0, import_shared_utils2.dataAttr)(props.isActive),
311
+ "data-focus": (0, import_shared_utils2.dataAttr)(props.isFocused && props.isActive),
312
+ "data-focus-visible": (0, import_shared_utils2.dataAttr)(props.isFocusVisible && props.isActive),
313
+ "data-has-value": (0, import_shared_utils2.dataAttr)(!!props.char),
314
+ "data-slot": "segment2",
315
+ role: "presentation",
316
+ children: displayValue
317
+ }
318
+ );
319
+ };
320
+
321
+ // src/input-otp.tsx
322
+ var import_jsx_runtime2 = require("react/jsx-runtime");
323
+ var InputOtp = (0, import_system2.forwardRef)((props, ref) => {
324
+ const context = useInputOtp({ ...props, ref });
325
+ const {
326
+ Component,
327
+ hasHelper,
328
+ isInvalid,
329
+ errorMessage,
330
+ description,
331
+ isFocusVisible,
332
+ isFocused,
333
+ getBaseProps,
334
+ getInputOtpProps,
335
+ getSegmentWrapperProps,
336
+ getHelperWrapperProps,
337
+ getErrorMessageProps,
338
+ getDescriptionProps
339
+ } = context;
340
+ const helperSection = (0, import_react3.useMemo)(() => {
341
+ if (!hasHelper) {
342
+ return null;
343
+ }
344
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ...getHelperWrapperProps(), children: isInvalid && errorMessage ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ...getErrorMessageProps(), children: errorMessage }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ...getDescriptionProps(), children: description }) });
345
+ }, [
346
+ hasHelper,
347
+ isInvalid,
348
+ errorMessage,
349
+ description,
350
+ getHelperWrapperProps,
351
+ getErrorMessageProps,
352
+ getDescriptionProps
353
+ ]);
354
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(InputOtpProvider, { value: context, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(Component, { ...getBaseProps(), children: [
355
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
356
+ import_input_otp.OTPInput,
357
+ {
358
+ ...getInputOtpProps(),
359
+ render: ({ slots }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { ...getSegmentWrapperProps(), children: slots.map((slot, idx) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
360
+ InputOtpSegment,
361
+ {
362
+ ...slot,
363
+ isFocusVisible,
364
+ isFocused
365
+ },
366
+ idx
367
+ )) })
368
+ }
369
+ ),
370
+ helperSection
371
+ ] }) });
372
+ });
373
+ InputOtp.displayName = "HeroUI.InputOtp";
374
+ var input_otp_default = InputOtp;
@@ -0,0 +1,10 @@
1
+ "use client";
2
+ import {
3
+ input_otp_default
4
+ } from "./chunk-ZVXVMEIW.mjs";
5
+ import "./chunk-IJHHP6DJ.mjs";
6
+ import "./chunk-R2XKH6IK.mjs";
7
+ import "./chunk-VZ7MKXTH.mjs";
8
+ export {
9
+ input_otp_default as default
10
+ };