@lifesg/react-design-system 1.0.0-alpha.21 → 1.0.0-alpha.22
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.
- package/cjs/index.js +57 -32
- package/cjs/index.js.map +1 -1
- package/form/index.js +1 -1
- package/form/index.js.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +57 -32
- package/index.js.map +1 -1
- package/modal/index.js +1 -1
- package/modal/index.js.map +1 -1
- package/navbar/index.js +1 -1
- package/navbar/index.js.map +1 -1
- package/otp-input/index.js +1 -1
- package/otp-input/index.js.map +1 -1
- package/otp-input/otp-input.d.ts +1 -1
- package/otp-input/types.d.ts +5 -5
- package/overlay/index.js +1 -1
- package/overlay/index.js.map +1 -1
- package/package.json +1 -1
- package/popover/index.js +1 -1
- package/popover/index.js.map +1 -1
package/otp-input/index.js
CHANGED
|
@@ -596,5 +596,5 @@ import e,{jsxs as t,jsx as n}from"react/jsx-runtime";import r,{useRef as i,useIm
|
|
|
596
596
|
outline: none;
|
|
597
597
|
`;c(dn.BodySmall)`
|
|
598
598
|
color: ${e=>e.disabled?Bt.Neutral[4](e):Bt.Neutral[3](e)};
|
|
599
|
-
`;const _n=e=>n(zn,{weight:"semibold",...e}),Nn=({id:e,"data-testid":
|
|
599
|
+
`;const _n=e=>n(zn,{weight:"semibold",...e}),Nn=({id:e,value:r=[],"data-testid":o,className:c,cooldownDuration:d,actionButtonProps:s,errorMessage:h,numOfInput:u,onChange:p,onCooldownStart:g,onCooldownEnd:f,...m})=>{const{disabled:y,onClick:b,styleType:$="secondary",...v}=s??{},S=i([]),w=i(p),[F,x]=a(new Array(u).fill("")),[B,H]=a(d),[C,D]=a(new Date);l((()=>(S?.current[0]?.focus(),document.addEventListener("paste",_),()=>document.removeEventListener("paste",_))),[]),l((()=>{if(0!==d){g&&g();const e=O();return()=>e()}}),[C]),l((()=>{w.current=p}),[p]),l((()=>{r.length===u&&x(r)}),[r]);const k=e=>t=>{const n=t.target.value.replace(/[^0-9]/g,"");if(N(n)){const t=[...F];t[e]=n.substring(n.length-1),S.current[e+1]?.focus(),x(t),p&&p(t)}},z=e=>t=>{const{key:n,code:r}=t;if("Backspace"===n||"Backspace"===r){const t=[...F];""!==t[e]?t[e]="":0!==e&&(t[e-1]="",S.current[e-1]?.focus()),x(t),p&&p(t)}},_=e=>{const t=e.clipboardData.getData("text"),n=t.split("");t&&N(t,u)?(x(n),w.current&&w.current(n)):e.preventDefault()},N=(e,t=1)=>!!e&&RegExp(`^[0-9]{${t}}$`).test(e),E=()=>{const e=Date.now(),t=1e3*d;return e<C.valueOf()+t},O=()=>{const e=setInterval((()=>{const t=Date.now(),n=1e3*d,r=Math.ceil((C.valueOf()+n-t)/1e3);H(r),r<=0&&(f&&f(),clearInterval(e))}),1e3);return()=>{clearInterval(e)}},W=(e,t,n)=>n?`${n}-${t}-${e+1}`:`${t}-${e+1}`;return t(yn,{id:e,"data-testid":o,className:c,children:[n(bn,{children:F.map(((t,r)=>n($n,{id:W(r,"otp-input",e),"data-testid":W(r,"otp-input",o),ref:e=>S.current[r]=e,type:"text",inputMode:"numeric",value:t,error:!!h,onChange:k(r),onKeyDown:z(r),...m},r)))}),h&&n(_n,{children:h}),n(vn,{styleType:$,...v,onClick:e=>{x(new Array(u).fill("")),E()||(D(new Date),H(d)),b&&b(e)},disabled:y||E(),children:v.children?v.children:"Resend OTP"+(B?` in ${B} second${B>1?"s":""}`:"")})]})};export{Nn as OtpInput};
|
|
600
600
|
//# sourceMappingURL=index.js.map
|