@clicktap/ui 0.40.3 → 0.40.5
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,4 +1,4 @@
|
|
|
1
1
|
import { PinInputProps } from './PinInput.types';
|
|
2
2
|
/** based on https://github.com/chakra-ui/chakra-ui/blob/main/packages/components/src/pin-input/use-pin-input.ts */
|
|
3
|
-
export declare function PinInput({ autoFocus, description, errorMessage, isDisabled, isInvalid, isMasked, isRequired, label, length, name: _name, onChange: controlledOnChange, value: _value, type, validationBehavior: _validationBehavior, className, classNames, ...props }: PinInputProps): import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
export declare function PinInput({ autoFocus, description, errorMessage, isDisabled, isInvalid, isMasked, isRequired, label, length, name: _name, onChange: controlledOnChange, value: _value, type, validationBehavior: _validationBehavior, className, classNames, inputProps, ...props }: PinInputProps): import("react/jsx-runtime").JSX.Element;
|
|
4
4
|
export default PinInput;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{jsxs as
|
|
1
|
+
"use client";import{jsxs as $,jsx as m}from"react/jsx-runtime";import{useState as L,useRef as R,useEffect as j,useCallback as V}from"react";import{Group as T,Label as _}from"react-aria-components";import{cn as f}from"../../utils/cn.js";function C({autoFocus:y=!1,description:D,errorMessage:b,isDisabled:I=!1,isInvalid:w=!1,isMasked:N=!1,isRequired:z=!0,label:k,length:n=6,name:P,onChange:c,value:S="",type:h="numeric",validationBehavior:W,className:B,classNames:p,inputProps:A,...J}){const[a,g]=L(()=>Array(n).fill("")),l=R([]);j(()=>{l.current=l.current.slice(0,n)},[n]),j(()=>{y&&l.current[0]?.focus()},[y]);const K=V(t=>{const e=t.target.value,u=Number(t.target.getAttribute("data-pin-input-index"));e!==""&&u<n-1&&l.current?.[u+1]?.focus();const o=a.map((s,d)=>d===u?e:s);g(o);const r=o.join("");c?.(r)},[a,n,c]),v=V(t=>{const e=Number(t.currentTarget.getAttribute("data-pin-input-index"));if(t.ctrlKey||t.metaKey)return;const u=["Backspace","Delete","ArrowLeft","ArrowRight","ArrowUp","ArrowDown","Control","Alt","Meta","Shift","Tab","Enter","Escape"],o={alpha:/^[a-z]$/i,alphanumeric:/^[a-z0-9]$/i,numeric:/^[0-9]$/i};if(!t.key.match(o[h])&&!u.includes(t.key)&&t.preventDefault(),a[e]===""&&e>0&&t.key==="Backspace"){const r=a.map((d,x)=>x===e-1?"":d);g(r),l.current?.[e-1]?.focus(),t.preventDefault();const s=r.join("");c?.(s)}if(a[e]===""&&e<a.length-1&&t.key==="Delete"){const r=a.map((d,x)=>x===e+1?"":d);g(r),l.current?.[e+1]?.focus(),t.preventDefault();const s=r.join("");c?.(s)}},[a,h,c]),E=V(t=>{const e=Number(t.currentTarget.getAttribute("data-pin-input-index"));t.preventDefault();const u=t.clipboardData?.getData("text");if(!u)return;const o=u.split("").filter(i=>{switch(h){case"alpha":return/^[a-zA-Z]$/.test(i);case"alphanumeric":return/^[a-z0-9]$/i.test(i);default:return/^[0-9]$/.test(i)}});if(o.length===0)return;const r=[...a];let s=e;for(let i=0;i<o.length&&e+i<n;i++)r[e+i]=o[i],s=e+i;g(r);const d=r.join("");c?.(d);const x=s+1<n?s+1:n-1;l.current[x]?.focus()},[a,h,n,c]);return $(T,{className:f("flex flex-wrap gap-2",B),"aria-label":k,...J,children:[k&&m(_,{className:f("flex text-slate-500 text-sm grow shrink-0 basis-full",p?.label),children:k}),a.map((t,e)=>m("div",{className:f("flex flex-col w-full flex-1 text-slate-900",p?.inputWrap),children:m("input",{type:N?"password":"text",autoComplete:"one-time-code","data-1p-ignore":"true","data-lpignore":"true","data-bwignore":"true","data-form-type":"other",...A,className:f("border-solid border border-slate-300 rounded-md","text-sm text-slate-900 placeholder-slate-400 text-center","h-10 px-2 py-0 m-0 w-full","bg-white","[&::-ms-reveal]:hidden [&::-ms-clear]:hidden","transition-all duration-200 ease-in-out","hover:border-slate-400","focus:outline-2 focus:outline focus:outline-slate-200 focus:border-slate-400","disabled:border-slate-200 disabled:bg-slate-100",w&&"border-red-500 bg-red-100 text-red-600",w&&"hover:border-red-600 focus:border-red-600 focus:outline-red-200",p?.input,A?.className),onChange:K,onKeyDown:v,onPaste:E,ref:u=>{l.current[e]=u},value:t,maxLength:1,"data-pin-input-index":e,disabled:I,required:z,"aria-label":`Pin Input Digit ${e+1}`})},`pin-input-${e}`)),(D||w&&b)&&$("div",{className:f("flex flex-row flex-wrap grow shrink-0 basis-full",p?.textWrap),children:[D&&m("p",{className:f("flex text-slate-500 text-sm grow shrink-0 basis-full",p?.description),children:D}),w&&b&&typeof b=="string"&&m("p",{className:f("flex text-red-500 text-sm grow shrink-0 basis-full",p?.error),children:b})]})]})}export{C as PinInput,C as default};
|
|
@@ -1,7 +1,22 @@
|
|
|
1
|
+
import { InputHTMLAttributes } from 'react';
|
|
1
2
|
import { GroupProps, ValidationResult } from 'react-aria-components';
|
|
2
3
|
import { SlotsToClasses } from '../../types/SlotsToClasses';
|
|
4
|
+
/**
|
|
5
|
+
* Props the component owns on each digit `<input>`. A consumer cannot override these through
|
|
6
|
+
* `inputProps` — they are the component's wiring, and overriding them breaks it.
|
|
7
|
+
*/
|
|
8
|
+
type OwnedInputProps = 'value' | 'onChange' | 'onKeyDown' | 'onPaste' | 'ref' | 'maxLength' | 'disabled' | 'required';
|
|
3
9
|
/** @todo extend certain textfield props like name, validationBehavior and isRequired */
|
|
4
10
|
export interface PinInputProps extends GroupProps {
|
|
11
|
+
/**
|
|
12
|
+
* Extra props for each digit `<input>` — the escape hatch for anything the component does not
|
|
13
|
+
* model, so the next unanticipated attribute does not need a release (CTAP-942).
|
|
14
|
+
*
|
|
15
|
+
* Applied AFTER the component's defaults (so `autoComplete` and the password-manager opt-outs can
|
|
16
|
+
* be overridden) and BEFORE its wiring (which cannot). `className` is merged with the component's
|
|
17
|
+
* own classes rather than replacing them; prefer `classNames.input` for styling.
|
|
18
|
+
*/
|
|
19
|
+
inputProps?: Omit<InputHTMLAttributes<HTMLInputElement>, OwnedInputProps>;
|
|
5
20
|
autoFocus?: boolean;
|
|
6
21
|
description?: string;
|
|
7
22
|
errorMessage?: string | ((validation: ValidationResult) => string);
|
|
@@ -16,3 +31,4 @@ export interface PinInputProps extends GroupProps {
|
|
|
16
31
|
validationBehavior?: 'native' | 'aria';
|
|
17
32
|
classNames?: SlotsToClasses<'label' | 'input' | 'description' | 'error' | 'inputWrap' | 'textWrap'>;
|
|
18
33
|
}
|
|
34
|
+
export {};
|