@plexui/ui 0.7.41 → 0.7.43

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.
@@ -69,7 +69,7 @@ export const FloatingLabelInput = forwardRef(function FloatingLabelInput(props,
69
69
  }
70
70
  }, [onAnimationStart, onAutofill]);
71
71
  return (_jsxs("div", { className: clsx(s.Root, className), children: [_jsxs("div", { className: clsx(s.FieldFootprint, {
72
- [s.HasValue]: hasValue,
72
+ [s.HasValue]: hasValue || !!startAdornment,
73
73
  }), "data-focused": focused ? "" : undefined, "data-has-value": hasValue ? "" : undefined, "data-invalid": invalid ? "" : undefined, "data-disabled": disabled ? "" : undefined, "data-readonly": readOnly ? "" : undefined, onMouseDown: handleContainerMouseDown, children: [_jsx("label", { className: s.TypeableLabel, htmlFor: inputId, children: _jsx("div", { className: s.LabelPositioner, children: _jsx("div", { className: s.LabelText, children: label }) }) }), startAdornment && (_jsx("div", { className: s.StartAdornment, children: startAdornment })), _jsx("input", { ...restProps, ref: mergeRefs([ref, inputRef]), id: inputId, name: name, type: type, className: s.Input, value: value, defaultValue: defaultValue, disabled: disabled, readOnly: readOnly, "aria-invalid": invalid ? true : undefined, "aria-describedby": ariaDescribedBy, onChange: handleChange, onFocus: handleFocus, onBlur: handleBlur, onAnimationStart: handleAnimationStart, "data-lpignore": allowAutofillExtensions ? undefined : true, "data-1p-ignore": allowAutofillExtensions ? undefined : true }), endAdornment && (_jsx("div", { className: s.EndAdornment, children: endAdornment })), showClearButton && (_jsx("button", { type: "button", "aria-label": "Clear input", className: s.ClearButton, onClick: onClear, children: _jsx(X, {}) }))] }), errorMessage && (_jsx(FieldError, { id: errorId, className: s.ErrorMessage, children: errorMessage }))] }));
74
74
  });
75
75
  FloatingLabelInput.displayName = "FloatingLabelInput";
@@ -1 +1 @@
1
- {"version":3,"file":"FloatingLabelInput.js","sourceRoot":"","sources":["../../../../src/components/FloatingLabelInput/FloatingLabelInput.tsx"],"names":[],"mappings":"A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,CAAC,IAAI,oBACzC,uBAAuB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,GAC1D,EACD,YAAY,IAAI,CACf,cAAK,SAAS,EAAE,CAAC,CAAC,YAAY,YAC3B,YAAY,GACT,CACP,EACA,eAAe,IAAI,CAClB,iBACE,IAAI,EAAC,QAAQ,gBACF,aAAa,EACxB,SAAS,EAAE,CAAC,CAAC,WAAW,EACxB,OAAO,EAAE,OAAO,YAEhB,KAAC,CAAC,KAAG,GACE,CACV,IACG,EACL,YAAY,IAAI,CACf,KAAC,UAAU,IAAC,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC,YAAY,YAC/C,YAAY,GACF,CACd,IACG,CACP,CAAA;AACH,CAAC,CACF,CAAA;AAED,kBAAkB,CAAC,WAAW,GAAG,oBAAoB,CAAA","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport { forwardRef, useCallback, useEffect, useId, useRef, useState } from \"react\"\nimport { mergeRefs } from \"react-merge-refs\"\n\nimport { FieldError } from \"../FieldError\"\nimport { X } from \"../Icon\"\n\nimport s from \"./FloatingLabelInput.module.css\"\n\nexport type FloatingLabelInputProps = {\n /**\n * Label text for the floating label\n */\n label: string\n /**\n * Error message to display below the input\n */\n errorMessage?: string\n /**\n * Mark the input as invalid\n * @default false (or true if errorMessage is provided)\n */\n invalid?: boolean\n /**\n * Disables the input visually and from interactions\n * @default false\n */\n disabled?: boolean\n /**\n * Makes the input read-only\n * @default false\n */\n readOnly?: boolean\n /**\n * Callback invoked when the clear button is clicked\n */\n onClear?: () => void\n /**\n * Callback invoked when the input is autofilled by the browser\n */\n onAutofill?: () => void\n /**\n * Allow autofill extensions to appear in the input\n * @default false\n */\n allowAutofillExtensions?: boolean\n /**\n * Content rendered after the input, before the clear button.\n * Useful for toggle buttons (e.g. password visibility), icons, or other interactive elements.\n */\n startAdornment?: React.ReactNode\n endAdornment?: React.ReactNode\n} & React.InputHTMLAttributes<HTMLInputElement>\n\nexport const FloatingLabelInput = forwardRef<HTMLInputElement, FloatingLabelInputProps>(\n function FloatingLabelInput(props, ref) {\n const {\n label,\n errorMessage,\n \"invalid\": invalidProp,\n disabled = false,\n readOnly = false,\n onClear,\n onAutofill,\n allowAutofillExtensions = false,\n startAdornment,\n endAdornment,\n className,\n \"id\": idProp,\n name,\n type = \"text\",\n value,\n defaultValue,\n onChange,\n onFocus,\n onBlur,\n onAnimationStart,\n \"aria-describedby\": ariaDescribedByProp,\n ...restProps\n } = props\n\n const inputRef = useRef<HTMLInputElement | null>(null)\n const generatedId = useId()\n const inputId = idProp || `floating-label-input-${generatedId}`\n const errorId = `${inputId}-error`\n\n const [focused, setFocused] = useState(false)\n const [hasValue, setHasValue] = useState(() => {\n return !!(value !== undefined ? value : defaultValue)\n })\n\n // Sync hasValue with controlled value prop\n useEffect(() => {\n if (value !== undefined) {\n setHasValue(!!value)\n }\n }, [value])\n\n // Determine invalid state from prop or presence of errorMessage\n const invalid = invalidProp ?? !!errorMessage\n\n // Determine if clear button should be shown\n const showClearButton = !!onClear && hasValue && !disabled && !readOnly\n\n // Merge aria-describedby with error id\n const ariaDescribedBy =\n [ariaDescribedByProp, errorMessage ? errorId : undefined].filter(Boolean).join(\" \") ||\n undefined\n\n // Handle clicks on the container to focus the input\n const handleContainerMouseDown = useCallback((evt: React.MouseEvent<HTMLDivElement>) => {\n const input = inputRef.current\n if (!evt.target || !(evt.target instanceof Element) || !input) {\n return\n }\n if (input.contains(evt.target)) {\n return\n }\n if (evt.target.closest(\"button, [type='button'], [role='button']\")) {\n return\n }\n evt.preventDefault()\n if (document.activeElement !== input) {\n input.focus()\n }\n const length = input.value.length\n input.setSelectionRange(length, length)\n }, [])\n\n const handleFocus = useCallback(\n (evt: React.FocusEvent<HTMLInputElement>) => {\n setFocused(true)\n onFocus?.(evt)\n },\n [onFocus],\n )\n\n const handleBlur = useCallback(\n (evt: React.FocusEvent<HTMLInputElement>) => {\n setFocused(false)\n onBlur?.(evt)\n },\n [onBlur],\n )\n\n const handleChange = useCallback(\n (evt: React.ChangeEvent<HTMLInputElement>) => {\n setHasValue(!!evt.currentTarget.value)\n onChange?.(evt)\n },\n [onChange],\n )\n\n const handleAnimationStart = useCallback(\n (evt: React.AnimationEvent<HTMLInputElement>) => {\n onAnimationStart?.(evt)\n // Detect browser autofill\n if (evt.animationName === \"native-autofill-in\") {\n setHasValue(true)\n onAutofill?.()\n }\n },\n [onAnimationStart, onAutofill],\n )\n\n return (\n <div className={clsx(s.Root, className)}>\n <div\n className={clsx(s.FieldFootprint, {\n [s.HasValue]: hasValue,\n })}\n data-focused={focused ? \"\" : undefined}\n data-has-value={hasValue ? \"\" : undefined}\n data-invalid={invalid ? \"\" : undefined}\n data-disabled={disabled ? \"\" : undefined}\n data-readonly={readOnly ? \"\" : undefined}\n onMouseDown={handleContainerMouseDown}\n >\n <label className={s.TypeableLabel} htmlFor={inputId}>\n <div className={s.LabelPositioner}>\n <div className={s.LabelText}>{label}</div>\n </div>\n </label>\n {startAdornment && (\n <div className={s.StartAdornment}>{startAdornment}</div>\n )}\n <input\n {...restProps}\n ref={mergeRefs([ref, inputRef])}\n id={inputId}\n name={name}\n type={type}\n className={s.Input}\n value={value}\n defaultValue={defaultValue}\n disabled={disabled}\n readOnly={readOnly}\n aria-invalid={invalid ? true : undefined}\n aria-describedby={ariaDescribedBy}\n onChange={handleChange}\n onFocus={handleFocus}\n onBlur={handleBlur}\n onAnimationStart={handleAnimationStart}\n data-lpignore={allowAutofillExtensions ? undefined : true}\n data-1p-ignore={allowAutofillExtensions ? undefined : true}\n />\n {endAdornment && (\n <div className={s.EndAdornment}>\n {endAdornment}\n </div>\n )}\n {showClearButton && (\n <button\n type=\"button\"\n aria-label=\"Clear input\"\n className={s.ClearButton}\n onClick={onClear}\n >\n <X />\n </button>\n )}\n </div>\n {errorMessage && (\n <FieldError id={errorId} className={s.ErrorMessage}>\n {errorMessage}\n </FieldError>\n )}\n </div>\n )\n },\n)\n\nFloatingLabelInput.displayName = \"FloatingLabelInput\"\n"]}
1
+ {"version":3,"file":"FloatingLabelInput.js","sourceRoot":"","sources":["../../../../src/components/FloatingLabelInput/FloatingLabelInput.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACnF,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAE5C,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAC1C,OAAO,EAAE,CAAC,EAAE,MAAM,SAAS,CAAA;AAE3B,OAAO,CAAC,MAAM,iCAAiC,CAAA;AA+C/C,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CAC1C,SAAS,kBAAkB,CAAC,KAAK,EAAE,GAAG;IACpC,MAAM,EACJ,KAAK,EACL,YAAY,EACZ,SAAS,EAAE,WAAW,EACtB,QAAQ,GAAG,KAAK,EAChB,QAAQ,GAAG,KAAK,EAChB,OAAO,EACP,UAAU,EACV,uBAAuB,GAAG,KAAK,EAC/B,cAAc,EACd,YAAY,EACZ,SAAS,EACT,IAAI,EAAE,MAAM,EACZ,IAAI,EACJ,IAAI,GAAG,MAAM,EACb,KAAK,EACL,YAAY,EACZ,QAAQ,EACR,OAAO,EACP,MAAM,EACN,gBAAgB,EAChB,kBAAkB,EAAE,mBAAmB,EACvC,GAAG,SAAS,EACb,GAAG,KAAK,CAAA;IAET,MAAM,QAAQ,GAAG,MAAM,CAA0B,IAAI,CAAC,CAAA;IACtD,MAAM,WAAW,GAAG,KAAK,EAAE,CAAA;IAC3B,MAAM,OAAO,GAAG,MAAM,IAAI,wBAAwB,WAAW,EAAE,CAAA;IAC/D,MAAM,OAAO,GAAG,GAAG,OAAO,QAAQ,CAAA;IAElC,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAA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e,EACjC,QAAQ,EAAE,YAAY,EACtB,OAAO,EAAE,WAAW,EACpB,MAAM,EAAE,UAAU,EAClB,gBAAgB,EAAE,oBAAoB,mBACvB,uBAAuB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,oBACzC,uBAAuB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,GAC1D,EACD,YAAY,IAAI,CACf,cAAK,SAAS,EAAE,CAAC,CAAC,YAAY,YAC3B,YAAY,GACT,CACP,EACA,eAAe,IAAI,CAClB,iBACE,IAAI,EAAC,QAAQ,gBACF,aAAa,EACxB,SAAS,EAAE,CAAC,CAAC,WAAW,EACxB,OAAO,EAAE,OAAO,YAEhB,KAAC,CAAC,KAAG,GACE,CACV,IACG,EACL,YAAY,IAAI,CACf,KAAC,UAAU,IAAC,EAAE,EAAE,OAAO,EAAE,SAAS,EAAE,CAAC,CAAC,YAAY,YAC/C,YAAY,GACF,CACd,IACG,CACP,CAAA;AACH,CAAC,CACF,CAAA;AAED,kBAAkB,CAAC,WAAW,GAAG,oBAAoB,CAAA","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport { forwardRef, useCallback, useEffect, useId, useRef, useState } from \"react\"\nimport { mergeRefs } from \"react-merge-refs\"\n\nimport { FieldError } from \"../FieldError\"\nimport { X } from \"../Icon\"\n\nimport s from \"./FloatingLabelInput.module.css\"\n\nexport type FloatingLabelInputProps = {\n /**\n * Label text for the floating label\n */\n label: string\n /**\n * Error message to display below the input\n */\n errorMessage?: string\n /**\n * Mark the input as invalid\n * @default false (or true if errorMessage is provided)\n */\n invalid?: boolean\n /**\n * Disables the input visually and from interactions\n * @default false\n */\n disabled?: boolean\n /**\n * Makes the input read-only\n * @default false\n */\n readOnly?: boolean\n /**\n * Callback invoked when the clear button is clicked\n */\n onClear?: () => void\n /**\n * Callback invoked when the input is autofilled by the browser\n */\n onAutofill?: () => void\n /**\n * Allow autofill extensions to appear in the input\n * @default false\n */\n allowAutofillExtensions?: boolean\n /**\n * Content rendered after the input, before the clear button.\n * Useful for toggle buttons (e.g. password visibility), icons, or other interactive elements.\n */\n startAdornment?: React.ReactNode\n endAdornment?: React.ReactNode\n} & React.InputHTMLAttributes<HTMLInputElement>\n\nexport const FloatingLabelInput = forwardRef<HTMLInputElement, FloatingLabelInputProps>(\n function FloatingLabelInput(props, ref) {\n const {\n label,\n errorMessage,\n \"invalid\": invalidProp,\n disabled = false,\n readOnly = false,\n onClear,\n onAutofill,\n allowAutofillExtensions = false,\n startAdornment,\n endAdornment,\n className,\n \"id\": idProp,\n name,\n type = \"text\",\n value,\n defaultValue,\n onChange,\n onFocus,\n onBlur,\n onAnimationStart,\n \"aria-describedby\": ariaDescribedByProp,\n ...restProps\n } = props\n\n const inputRef = useRef<HTMLInputElement | null>(null)\n const generatedId = useId()\n const inputId = idProp || `floating-label-input-${generatedId}`\n const errorId = `${inputId}-error`\n\n const [focused, setFocused] = useState(false)\n const [hasValue, setHasValue] = useState(() => {\n return !!(value !== undefined ? value : defaultValue)\n })\n\n // Sync hasValue with controlled value prop\n useEffect(() => {\n if (value !== undefined) {\n setHasValue(!!value)\n }\n }, [value])\n\n // Determine invalid state from prop or presence of errorMessage\n const invalid = invalidProp ?? !!errorMessage\n\n // Determine if clear button should be shown\n const showClearButton = !!onClear && hasValue && !disabled && !readOnly\n\n // Merge aria-describedby with error id\n const ariaDescribedBy =\n [ariaDescribedByProp, errorMessage ? errorId : undefined].filter(Boolean).join(\" \") ||\n undefined\n\n // Handle clicks on the container to focus the input\n const handleContainerMouseDown = useCallback((evt: React.MouseEvent<HTMLDivElement>) => {\n const input = inputRef.current\n if (!evt.target || !(evt.target instanceof Element) || !input) {\n return\n }\n if (input.contains(evt.target)) {\n return\n }\n if (evt.target.closest(\"button, [type='button'], [role='button']\")) {\n return\n }\n evt.preventDefault()\n if (document.activeElement !== input) {\n input.focus()\n }\n const length = input.value.length\n input.setSelectionRange(length, length)\n }, [])\n\n const handleFocus = useCallback(\n (evt: React.FocusEvent<HTMLInputElement>) => {\n setFocused(true)\n onFocus?.(evt)\n },\n [onFocus],\n )\n\n const handleBlur = useCallback(\n (evt: React.FocusEvent<HTMLInputElement>) => {\n setFocused(false)\n onBlur?.(evt)\n },\n [onBlur],\n )\n\n const handleChange = useCallback(\n (evt: React.ChangeEvent<HTMLInputElement>) => {\n setHasValue(!!evt.currentTarget.value)\n onChange?.(evt)\n },\n [onChange],\n )\n\n const handleAnimationStart = useCallback(\n (evt: React.AnimationEvent<HTMLInputElement>) => {\n onAnimationStart?.(evt)\n // Detect browser autofill\n if (evt.animationName === \"native-autofill-in\") {\n setHasValue(true)\n onAutofill?.()\n }\n },\n [onAnimationStart, onAutofill],\n )\n\n return (\n <div className={clsx(s.Root, className)}>\n <div\n className={clsx(s.FieldFootprint, {\n [s.HasValue]: hasValue || !!startAdornment,\n })}\n data-focused={focused ? \"\" : undefined}\n data-has-value={hasValue ? \"\" : undefined}\n data-invalid={invalid ? \"\" : undefined}\n data-disabled={disabled ? \"\" : undefined}\n data-readonly={readOnly ? \"\" : undefined}\n onMouseDown={handleContainerMouseDown}\n >\n <label className={s.TypeableLabel} htmlFor={inputId}>\n <div className={s.LabelPositioner}>\n <div className={s.LabelText}>{label}</div>\n </div>\n </label>\n {startAdornment && (\n <div className={s.StartAdornment}>{startAdornment}</div>\n )}\n <input\n {...restProps}\n ref={mergeRefs([ref, inputRef])}\n id={inputId}\n name={name}\n type={type}\n className={s.Input}\n value={value}\n defaultValue={defaultValue}\n disabled={disabled}\n readOnly={readOnly}\n aria-invalid={invalid ? true : undefined}\n aria-describedby={ariaDescribedBy}\n onChange={handleChange}\n onFocus={handleFocus}\n onBlur={handleBlur}\n onAnimationStart={handleAnimationStart}\n data-lpignore={allowAutofillExtensions ? undefined : true}\n data-1p-ignore={allowAutofillExtensions ? undefined : true}\n />\n {endAdornment && (\n <div className={s.EndAdornment}>\n {endAdornment}\n </div>\n )}\n {showClearButton && (\n <button\n type=\"button\"\n aria-label=\"Clear input\"\n className={s.ClearButton}\n onClick={onClear}\n >\n <X />\n </button>\n )}\n </div>\n {errorMessage && (\n <FieldError id={errorId} className={s.ErrorMessage}>\n {errorMessage}\n </FieldError>\n )}\n </div>\n )\n },\n)\n\nFloatingLabelInput.displayName = \"FloatingLabelInput\"\n"]}
@@ -88,11 +88,6 @@
88
88
  flex-shrink: 0;
89
89
  position: relative;
90
90
  z-index: 1;
91
- opacity: 0;
92
- transition: opacity var(--floating-input-transition-duration) ease-in-out;
93
- }.FieldFootprint[data-focused] .StartAdornment,
94
- .HasValue .StartAdornment {
95
- opacity: 1;
96
91
  }/* Input element */.Input {
97
92
  background-color: transparent;
98
93
  outline: none;
@@ -0,0 +1,174 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import clsx from "clsx";
4
+ import { Fragment, forwardRef, useCallback, useEffect, useId, useImperativeHandle, useMemo, useRef, useState, } from "react";
5
+ import { FieldError } from "../FieldError";
6
+ import s from "./OTPInput.module.css";
7
+ function sanitizeDigits(value, length) {
8
+ return value.replace(/\D/g, "").slice(0, length);
9
+ }
10
+ function shouldShowGap(index, grouping) {
11
+ let pos = 0;
12
+ for (const groupSize of grouping) {
13
+ pos += groupSize;
14
+ if (index === pos)
15
+ return true;
16
+ }
17
+ return false;
18
+ }
19
+ export const OTPInput = forwardRef(function OTPInput(props, ref) {
20
+ const { length: lengthProp = 6, value, onChange, onComplete, grouping, invalid = false, errorMessage, disabled = false, autoFocus = false, className, } = props;
21
+ const length = Math.max(1, Math.floor(lengthProp));
22
+ const controlledValue = useMemo(() => sanitizeDigits(value ?? "", length), [value, length]);
23
+ const isControlled = value !== undefined;
24
+ const [internalValue, setInternalValue] = useState(() => sanitizeDigits(value ?? "", length));
25
+ const [focusedIndex, setFocusedIndex] = useState(-1);
26
+ const rootRef = useRef(null);
27
+ const inputRefs = useRef([]);
28
+ useImperativeHandle(ref, () => rootRef.current, []);
29
+ useEffect(() => {
30
+ if (isControlled) {
31
+ setInternalValue(controlledValue);
32
+ return;
33
+ }
34
+ setInternalValue((current) => sanitizeDigits(current, length));
35
+ }, [controlledValue, isControlled, length]);
36
+ const currentValue = isControlled ? controlledValue : internalValue;
37
+ const digits = useMemo(() => Array.from({ length }, (_, index) => currentValue[index] ?? ""), [currentValue, length]);
38
+ const errorId = `otp-input-${useId()}-error`;
39
+ useEffect(() => {
40
+ if (!autoFocus || disabled)
41
+ return;
42
+ inputRefs.current[0]?.focus();
43
+ }, [autoFocus, disabled]);
44
+ const commitValue = useCallback((nextValueRaw) => {
45
+ const nextValue = sanitizeDigits(nextValueRaw, length);
46
+ if (!isControlled) {
47
+ setInternalValue(nextValue);
48
+ }
49
+ if (nextValue !== currentValue) {
50
+ onChange?.(nextValue);
51
+ }
52
+ if (nextValue.length === length) {
53
+ onComplete?.(nextValue);
54
+ }
55
+ return nextValue;
56
+ }, [currentValue, isControlled, length, onChange, onComplete]);
57
+ const focusCell = useCallback((index) => {
58
+ const clampedIndex = Math.max(0, Math.min(index, length - 1));
59
+ const input = inputRefs.current[clampedIndex];
60
+ if (!input)
61
+ return;
62
+ input.focus();
63
+ input.setSelectionRange(1, 1);
64
+ }, [length]);
65
+ const handleCellClick = useCallback((index) => {
66
+ if (disabled)
67
+ return;
68
+ focusCell(index);
69
+ }, [disabled, focusCell]);
70
+ const handlePaste = useCallback((index, evt) => {
71
+ if (disabled)
72
+ return;
73
+ evt.preventDefault();
74
+ const pastedDigits = sanitizeDigits(evt.clipboardData.getData("text"), length);
75
+ if (!pastedDigits)
76
+ return;
77
+ const nextDigits = [...digits];
78
+ let writeIndex = index;
79
+ for (const digit of pastedDigits) {
80
+ if (writeIndex >= length)
81
+ break;
82
+ nextDigits[writeIndex] = digit;
83
+ writeIndex += 1;
84
+ }
85
+ const nextValue = commitValue(nextDigits.join(""));
86
+ const nextFocusIndex = Math.min(nextValue.length, length - 1);
87
+ focusCell(nextFocusIndex);
88
+ }, [commitValue, digits, disabled, focusCell, length]);
89
+ const handleChange = useCallback((index, evt) => {
90
+ if (disabled)
91
+ return;
92
+ const typedDigits = evt.currentTarget.value.replace(/\D/g, "");
93
+ if (!typedDigits) {
94
+ const nextDigits = [...digits];
95
+ nextDigits[index] = "";
96
+ commitValue(nextDigits.join(""));
97
+ return;
98
+ }
99
+ const nextDigits = [...digits];
100
+ if (typedDigits.length === 1) {
101
+ nextDigits[index] = typedDigits[0];
102
+ const nextValue = commitValue(nextDigits.join(""));
103
+ if (index < length - 1 && nextValue.length > index) {
104
+ focusCell(index + 1);
105
+ }
106
+ return;
107
+ }
108
+ let writeIndex = index;
109
+ for (const digit of typedDigits) {
110
+ if (writeIndex >= length)
111
+ break;
112
+ nextDigits[writeIndex] = digit;
113
+ writeIndex += 1;
114
+ }
115
+ const nextValue = commitValue(nextDigits.join(""));
116
+ const nextFocusIndex = Math.min(nextValue.length, length - 1);
117
+ focusCell(nextFocusIndex);
118
+ }, [commitValue, digits, disabled, focusCell, length]);
119
+ const handleKeyDown = useCallback((index, evt) => {
120
+ if (disabled)
121
+ return;
122
+ if (evt.key === "Backspace") {
123
+ evt.preventDefault();
124
+ const nextDigits = [...digits];
125
+ if (nextDigits[index]) {
126
+ nextDigits[index] = "";
127
+ commitValue(nextDigits.join(""));
128
+ return;
129
+ }
130
+ if (index > 0) {
131
+ nextDigits[index - 1] = "";
132
+ commitValue(nextDigits.join(""));
133
+ focusCell(index - 1);
134
+ }
135
+ return;
136
+ }
137
+ if (evt.key === "Delete") {
138
+ evt.preventDefault();
139
+ const nextDigits = [...digits];
140
+ nextDigits[index] = "";
141
+ commitValue(nextDigits.join(""));
142
+ return;
143
+ }
144
+ if (evt.key === "ArrowLeft") {
145
+ evt.preventDefault();
146
+ focusCell(index - 1);
147
+ return;
148
+ }
149
+ if (evt.key === "ArrowRight") {
150
+ evt.preventDefault();
151
+ focusCell(index + 1);
152
+ }
153
+ }, [commitValue, digits, disabled, focusCell]);
154
+ const handleBlur = useCallback(() => {
155
+ requestAnimationFrame(() => {
156
+ const activeElement = document.activeElement;
157
+ const isAnyCellFocused = inputRefs.current.some((input) => input === activeElement);
158
+ if (!isAnyCellFocused) {
159
+ setFocusedIndex(-1);
160
+ }
161
+ });
162
+ }, []);
163
+ return (_jsxs("div", { ref: rootRef, className: clsx(s.Root, className), children: [_jsx("div", { className: s.Cells, children: Array.from({ length }, (_, index) => {
164
+ const isGroupGap = grouping ? shouldShowGap(index, grouping) : false;
165
+ return (_jsxs(Fragment, { children: [isGroupGap && _jsx("div", { className: s.GroupGap, "aria-hidden": true }), _jsxs("div", { className: clsx(s.Cell, {
166
+ [s.CellFocused]: focusedIndex === index,
167
+ [s.CellFilled]: !!digits[index],
168
+ }), "data-invalid": invalid ? "" : undefined, "data-disabled": disabled ? "" : undefined, onClick: () => handleCellClick(index), children: [_jsx("input", { ref: (element) => {
169
+ inputRefs.current[index] = element;
170
+ }, type: "text", inputMode: "numeric", pattern: "[0-9]", maxLength: 1, value: digits[index], disabled: disabled, className: s.CellInput, onChange: (evt) => handleChange(index, evt), onKeyDown: (evt) => handleKeyDown(index, evt), onFocus: () => setFocusedIndex(index), onBlur: handleBlur, onPaste: (evt) => handlePaste(index, evt), "aria-label": `Digit ${index + 1}`, "aria-invalid": invalid ? true : undefined, "aria-describedby": errorMessage ? errorId : undefined, autoComplete: index === 0 ? "one-time-code" : "off" }), !digits[index] && focusedIndex !== index && _jsx("div", { className: s.DotPlaceholder })] })] }, index));
171
+ }) }), errorMessage && (_jsx(FieldError, { id: errorId, className: s.ErrorMessage, children: errorMessage }))] }));
172
+ });
173
+ OTPInput.displayName = "OTPInput";
174
+ //# sourceMappingURL=OTPInput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"OTPInput.js","sourceRoot":"","sources":["../../../../src/components/OTPInput/OTPInput.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,IAAI,MAAM,MAAM,CAAA;AACvB,OAAO,EACL,QAAQ,EACR,UAAU,EACV,WAAW,EACX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AAQ,CAAC,WAAW,GAAG,UAAU,CAAA","sourcesContent":["\"use client\"\n\nimport clsx from \"clsx\"\nimport {\n Fragment,\n forwardRef,\n useCallback,\n useEffect,\n useId,\n useImperativeHandle,\n useMemo,\n useRef,\n useState,\n} from \"react\"\n\nimport { FieldError } from \"../FieldError\"\n\nimport s from \"./OTPInput.module.css\"\n\nexport type OTPInputProps = {\n length?: number\n value?: string\n onChange?: (value: string) => void\n onComplete?: (value: string) => void\n grouping?: number[]\n invalid?: boolean\n errorMessage?: string\n disabled?: boolean\n autoFocus?: boolean\n className?: string\n}\n\nfunction sanitizeDigits(value: string, length: number): string {\n return value.replace(/\\D/g, \"\").slice(0, length)\n}\n\nfunction shouldShowGap(index: number, grouping: number[]): boolean {\n let pos = 0\n for (const groupSize of grouping) {\n pos += groupSize\n if (index === pos) return true\n }\n return false\n}\n\nexport const OTPInput = forwardRef<HTMLDivElement, OTPInputProps>(function OTPInput(props, ref) {\n const {\n length: lengthProp = 6,\n value,\n onChange,\n onComplete,\n grouping,\n invalid = false,\n errorMessage,\n disabled = false,\n autoFocus = false,\n className,\n } = props\n\n const length = Math.max(1, Math.floor(lengthProp))\n const controlledValue = useMemo(() => sanitizeDigits(value ?? \"\", length), [value, length])\n const isControlled = value !== undefined\n\n const [internalValue, setInternalValue] = useState(() => sanitizeDigits(value ?? \"\", length))\n const [focusedIndex, setFocusedIndex] = useState(-1)\n\n const rootRef = useRef<HTMLDivElement | null>(null)\n const inputRefs = useRef<Array<HTMLInputElement | null>>([])\n\n useImperativeHandle(ref, () => rootRef.current as HTMLDivElement, [])\n\n useEffect(() => {\n if (isControlled) {\n setInternalValue(controlledValue)\n return\n }\n setInternalValue((current) => sanitizeDigits(current, length))\n }, [controlledValue, isControlled, length])\n\n const currentValue = isControlled ? controlledValue : internalValue\n const digits = useMemo(\n () => Array.from({ length }, (_, index) => currentValue[index] ?? \"\"),\n [currentValue, length],\n )\n\n const errorId = `otp-input-${useId()}-error`\n\n useEffect(() => {\n if (!autoFocus || disabled) return\n inputRefs.current[0]?.focus()\n }, [autoFocus, disabled])\n\n const commitValue = useCallback(\n (nextValueRaw: string) => {\n const nextValue = sanitizeDigits(nextValueRaw, length)\n if (!isControlled) {\n setInternalValue(nextValue)\n }\n if (nextValue !== currentValue) {\n onChange?.(nextValue)\n }\n if (nextValue.length === length) {\n onComplete?.(nextValue)\n }\n return nextValue\n },\n [currentValue, isControlled, length, onChange, onComplete],\n )\n\n const focusCell = useCallback((index: number) => {\n const clampedIndex = Math.max(0, Math.min(index, length - 1))\n const input = inputRefs.current[clampedIndex]\n if (!input) return\n input.focus()\n input.setSelectionRange(1, 1)\n }, [length])\n\n const handleCellClick = useCallback((index: number) => {\n if (disabled) return\n focusCell(index)\n }, [disabled, focusCell])\n\n const handlePaste = useCallback(\n (index: number, evt: React.ClipboardEvent<HTMLInputElement>) => {\n if (disabled) return\n evt.preventDefault()\n const pastedDigits = sanitizeDigits(evt.clipboardData.getData(\"text\"), length)\n if (!pastedDigits) return\n\n const nextDigits = [...digits]\n let writeIndex = index\n\n for (const digit of pastedDigits) {\n if (writeIndex >= length) break\n nextDigits[writeIndex] = digit\n writeIndex += 1\n }\n\n const nextValue = commitValue(nextDigits.join(\"\"))\n const nextFocusIndex = Math.min(nextValue.length, length - 1)\n focusCell(nextFocusIndex)\n },\n [commitValue, digits, disabled, focusCell, length],\n )\n\n const handleChange = useCallback(\n (index: number, evt: React.ChangeEvent<HTMLInputElement>) => {\n if (disabled) return\n const typedDigits = evt.currentTarget.value.replace(/\\D/g, \"\")\n\n if (!typedDigits) {\n const nextDigits = [...digits]\n nextDigits[index] = \"\"\n commitValue(nextDigits.join(\"\"))\n return\n }\n\n const nextDigits = [...digits]\n\n if (typedDigits.length === 1) {\n nextDigits[index] = typedDigits[0]\n const nextValue = commitValue(nextDigits.join(\"\"))\n if (index < length - 1 && nextValue.length > index) {\n focusCell(index + 1)\n }\n return\n }\n\n let writeIndex = index\n for (const digit of typedDigits) {\n if (writeIndex >= length) break\n nextDigits[writeIndex] = digit\n writeIndex += 1\n }\n\n const nextValue = commitValue(nextDigits.join(\"\"))\n const nextFocusIndex = Math.min(nextValue.length, length - 1)\n focusCell(nextFocusIndex)\n },\n [commitValue, digits, disabled, focusCell, length],\n )\n\n const handleKeyDown = useCallback(\n (index: number, evt: React.KeyboardEvent<HTMLInputElement>) => {\n if (disabled) return\n\n if (evt.key === \"Backspace\") {\n evt.preventDefault()\n const nextDigits = [...digits]\n\n if (nextDigits[index]) {\n nextDigits[index] = \"\"\n commitValue(nextDigits.join(\"\"))\n return\n }\n\n if (index > 0) {\n nextDigits[index - 1] = \"\"\n commitValue(nextDigits.join(\"\"))\n focusCell(index - 1)\n }\n return\n }\n\n if (evt.key === \"Delete\") {\n evt.preventDefault()\n const nextDigits = [...digits]\n nextDigits[index] = \"\"\n commitValue(nextDigits.join(\"\"))\n return\n }\n\n if (evt.key === \"ArrowLeft\") {\n evt.preventDefault()\n focusCell(index - 1)\n return\n }\n\n if (evt.key === \"ArrowRight\") {\n evt.preventDefault()\n focusCell(index + 1)\n }\n },\n [commitValue, digits, disabled, focusCell],\n )\n\n const handleBlur = useCallback(() => {\n requestAnimationFrame(() => {\n const activeElement = document.activeElement\n const isAnyCellFocused = inputRefs.current.some((input) => input === activeElement)\n if (!isAnyCellFocused) {\n setFocusedIndex(-1)\n }\n })\n }, [])\n\n return (\n <div ref={rootRef} className={clsx(s.Root, className)}>\n <div className={s.Cells}>\n {Array.from({ length }, (_, index) => {\n const isGroupGap = grouping ? shouldShowGap(index, grouping) : false\n\n return (\n <Fragment key={index}>\n {isGroupGap && <div className={s.GroupGap} aria-hidden />}\n <div\n className={clsx(s.Cell, {\n [s.CellFocused]: focusedIndex === index,\n [s.CellFilled]: !!digits[index],\n })}\n data-invalid={invalid ? \"\" : undefined}\n data-disabled={disabled ? \"\" : undefined}\n onClick={() => handleCellClick(index)}\n >\n <input\n ref={(element) => {\n inputRefs.current[index] = element\n }}\n type=\"text\"\n inputMode=\"numeric\"\n pattern=\"[0-9]\"\n maxLength={1}\n value={digits[index]}\n disabled={disabled}\n className={s.CellInput}\n onChange={(evt) => handleChange(index, evt)}\n onKeyDown={(evt) => handleKeyDown(index, evt)}\n onFocus={() => setFocusedIndex(index)}\n onBlur={handleBlur}\n onPaste={(evt) => handlePaste(index, evt)}\n aria-label={`Digit ${index + 1}`}\n aria-invalid={invalid ? true : undefined}\n aria-describedby={errorMessage ? errorId : undefined}\n autoComplete={index === 0 ? \"one-time-code\" : \"off\"}\n />\n {!digits[index] && focusedIndex !== index && <div className={s.DotPlaceholder} />}\n </div>\n </Fragment>\n )\n })}\n </div>\n {errorMessage && (\n <FieldError id={errorId} className={s.ErrorMessage}>\n {errorMessage}\n </FieldError>\n )}\n </div>\n )\n})\n\nOTPInput.displayName = \"OTPInput\"\n"]}
@@ -0,0 +1,66 @@
1
+ @layer components {.Root {
2
+ position: relative;
3
+ --field-error-padding-inline: 0;
4
+ --field-error-margin-top: 0.5rem;
5
+ }.Cells {
6
+ display: flex;
7
+ align-items: center;
8
+ gap: 8px;
9
+ }.GroupGap {
10
+ width: 8px;
11
+ }.Cell {
12
+ position: relative;
13
+ width: 44px;
14
+ height: 52px;
15
+ border-radius: var(--floating-input-border-radius);
16
+ border: 1px solid var(--floating-input-border-color);
17
+ background-color: var(--floating-input-background);
18
+ display: flex;
19
+ align-items: center;
20
+ justify-content: center;
21
+ cursor: text;
22
+ transition: border-color var(--floating-input-transition-duration) ease-in-out;
23
+ }.Cell:hover:not([data-disabled]) {
24
+ border-color: var(--floating-input-border-color-hover);
25
+ }.CellFocused {
26
+ border-color: var(--floating-input-border-color-focus);
27
+ }.Cell[data-invalid] {
28
+ border-color: var(--floating-input-border-color-invalid);
29
+ }.Cell[data-disabled] {
30
+ opacity: 0.5;
31
+ cursor: not-allowed;
32
+ }.CellInput {
33
+ position: absolute;
34
+ inset: 0;
35
+ width: 100%;
36
+ height: 100%;
37
+ text-align: center;
38
+ font-size: 1.5rem;
39
+ font-weight: 600;
40
+ line-height: 1;
41
+ color: var(--color-text);
42
+ background: transparent;
43
+ border: none;
44
+ outline: none;
45
+ padding: 0;
46
+ caret-color: var(--color-text);
47
+ border-radius: inherit;
48
+ }.CellInput:disabled {
49
+ cursor: not-allowed;
50
+ }.DotPlaceholder {
51
+ width: 6px;
52
+ height: 6px;
53
+ border-radius: 50%;
54
+ background-color: var(--color-text-tertiary);
55
+ opacity: 0.5;
56
+ pointer-events: none;
57
+ }.CellFilled .DotPlaceholder {
58
+ display: none;
59
+ }.ErrorMessage {
60
+ margin-top: var(--field-error-margin-top);
61
+ }@media (prefers-reduced-motion: reduce) {
62
+ .Cell {
63
+ transition: none;
64
+ }
65
+ }
66
+ }
@@ -0,0 +1,2 @@
1
+ export { OTPInput } from "./OTPInput";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/components/OTPInput/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAsB,MAAM,YAAY,CAAA","sourcesContent":["export { OTPInput, type OTPInputProps } from \"./OTPInput\"\n"]}
@@ -0,0 +1,13 @@
1
+ export type OTPInputProps = {
2
+ length?: number;
3
+ value?: string;
4
+ onChange?: (value: string) => void;
5
+ onComplete?: (value: string) => void;
6
+ grouping?: number[];
7
+ invalid?: boolean;
8
+ errorMessage?: string;
9
+ disabled?: boolean;
10
+ autoFocus?: boolean;
11
+ className?: string;
12
+ };
13
+ export declare const OTPInput: import("react").ForwardRefExoticComponent<OTPInputProps & import("react").RefAttributes<HTMLDivElement>>;
@@ -0,0 +1 @@
1
+ export { OTPInput, type OTPInputProps } from "./OTPInput";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plexui/ui",
3
- "version": "0.7.41",
3
+ "version": "0.7.43",
4
4
  "description": "Modern design system for building high-quality applications",
5
5
  "type": "module",
6
6
  "license": "MIT",