@jamsrui/otp-input 0.0.16 → 0.0.18
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/dist/index.d.mts
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import * as react from 'react';
|
|
2
2
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
3
3
|
import { OtpInput as OtpInput$1 } from './otp-input.mjs';
|
|
4
|
+
import { OtpInputConfig } from './otp-input-config.mjs';
|
|
5
|
+
export { useOtpInputConfig } from './otp-input-config.mjs';
|
|
4
6
|
import { OtpInputGroup } from './otp-input-group.mjs';
|
|
5
7
|
import { OtpInputSeparator } from './otp-input-separator.mjs';
|
|
6
8
|
import { OtpInputSlot } from './otp-input-slot.mjs';
|
|
7
|
-
export {
|
|
9
|
+
export { OtpInputSlots, OtpInputVariants, otpInputVariants } from './styles.mjs';
|
|
10
|
+
export { useOtpInput } from './use-otp-input.mjs';
|
|
8
11
|
export { REGEXP_ONLY_CHARS, REGEXP_ONLY_DIGITS, REGEXP_ONLY_DIGITS_AND_CHARS } from './regexp.mjs';
|
|
9
|
-
import '
|
|
12
|
+
import '@jamsrui/core';
|
|
10
13
|
import '@jamsrui/utils';
|
|
11
14
|
import './otp-input-caret.mjs';
|
|
12
15
|
import './otp-input-input.mjs';
|
|
13
16
|
import './otp-input-root.mjs';
|
|
14
|
-
import './styles.mjs';
|
|
15
|
-
import '@jamsrui/core';
|
|
16
17
|
|
|
17
18
|
declare const OtpInput: ((props: OtpInput$1.Props) => react_jsx_runtime.JSX.Element) & {
|
|
18
|
-
Root: (props: OtpInput$1.Props) => react_jsx_runtime.JSX.Element;
|
|
19
19
|
Slot: (props: OtpInputSlot.Props) => react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
|
|
20
20
|
Separator: (props: OtpInputSeparator.Props) => react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
|
|
21
21
|
Group: (props: OtpInputGroup.Props) => react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
|
|
@@ -23,6 +23,8 @@ declare const OtpInput: ((props: OtpInput$1.Props) => react_jsx_runtime.JSX.Elem
|
|
|
23
23
|
declare namespace OtpInput {
|
|
24
24
|
interface Props extends OtpInput$1.Props {
|
|
25
25
|
}
|
|
26
|
+
interface Config extends OtpInputConfig.Props {
|
|
27
|
+
}
|
|
26
28
|
interface Group extends OtpInputGroup.Props {
|
|
27
29
|
}
|
|
28
30
|
interface Separator extends OtpInputSeparator.Props {
|
|
@@ -31,4 +33,4 @@ declare namespace OtpInput {
|
|
|
31
33
|
}
|
|
32
34
|
}
|
|
33
35
|
|
|
34
|
-
export { OtpInput };
|
|
36
|
+
export { OtpInput, OtpInputConfig, OtpInputGroup, OtpInputSeparator, OtpInputSlot };
|
package/dist/index.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{OtpInput as
|
|
1
|
+
import{OtpInput as r}from"./otp-input.mjs";import{OtpInputConfig as e,useOtpInputConfig as n}from"./otp-input-config.mjs";import{OtpInputGroup as t}from"./otp-input-group.mjs";import{OtpInputSeparator as p}from"./otp-input-separator.mjs";import{OtpInputSlot as o}from"./otp-input-slot.mjs";import{otpInputVariants as u}from"./styles.mjs";import{useOtpInput as I}from"./use-otp-input.mjs";import{REGEXP_ONLY_CHARS as R,REGEXP_ONLY_DIGITS as l,REGEXP_ONLY_DIGITS_AND_CHARS as C}from"./regexp.mjs";const P=Object.assign(r,{Slot:o,Separator:p,Group:t});export{P as OtpInput,e as OtpInputConfig,t as OtpInputGroup,p as OtpInputSeparator,o as OtpInputSlot,R as REGEXP_ONLY_CHARS,l as REGEXP_ONLY_DIGITS,C as REGEXP_ONLY_DIGITS_AND_CHARS,u as otpInputVariants,I as useOtpInput,n as useOtpInputConfig};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import {
|
|
2
|
+
import { WithGlobalConfig } from '@jamsrui/core';
|
|
3
3
|
import { OtpInput } from './otp-input.mjs';
|
|
4
4
|
import './use-otp-input.mjs';
|
|
5
5
|
import '@jamsrui/utils';
|
|
@@ -18,7 +18,7 @@ declare const OtpInputConfig: (props: Omit<Partial<Record<string, any>>, "childr
|
|
|
18
18
|
children: React.ReactNode;
|
|
19
19
|
}) => react_jsx_runtime.JSX.Element;
|
|
20
20
|
declare namespace OtpInputConfig {
|
|
21
|
-
interface Props extends
|
|
21
|
+
interface Props extends WithGlobalConfig<OtpInput.Props> {
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use client";import{createConfigContext as
|
|
1
|
+
"use client";import{createConfigContext as t}from"@jamsrui/utils";const[o,n]=t({displayName:"OtpInputConfig"});export{o as OtpInputConfig,n as useOtpInputConfig};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createContext as e,use as n}from"react";const p=e(null),u=()=>{const t=n(p);if(!t)throw new Error("useOtpInputContext must be used within an OtpInputContext");return t};export{p as OtpInputContext,u as useOtpInputContext};
|
|
1
|
+
"use client";import{createContext as e,use as n}from"react";const p=e(null),u=()=>{const t=n(p);if(!t)throw new Error("useOtpInputContext must be used within an OtpInputContext");return t};export{p as OtpInputContext,u as useOtpInputContext};
|
package/dist/regexp.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const _="^\\d+$",
|
|
1
|
+
"use client";const _="^\\d+$",t="^[a-zA-Z]+$",o="^[a-zA-Z0-9]+$";export{t as REGEXP_ONLY_CHARS,_ as REGEXP_ONLY_DIGITS,o as REGEXP_ONLY_DIGITS_AND_CHARS};
|
package/dist/use-otp-input.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{useCallback as l,useEffect as st,useMemo as C,useRef as z,useState as J}from"react";import{useControlledState as at,useFocus as lt,useHover as ut,useMergeRefs as ct}from"@jamsrui/hooks";import{dataAttr as O,dataAttrDev as m,mapPropsVariants as pt,mergeProps as it}from"@jamsrui/utils";import{otpInputVariants as Q}from"./styles.mjs";const Pt=S=>{const[U,W]=pt(S,Q.variantKeys),r=Q(W),{value:X,onValueChange:Y,defaultValue:Z,disabled:c=!1,maxLength:o,onComplete:y,placeholder:b,pattern:N,ref:tt,...w}=U,[p="",V]=at({defaultProp:Z,prop:X,onChange:Y}),s=z(null),{ref:et,isHovered:G}=ut({isDisabled:c}),{ref:nt,isFocused:D}=lt({isDisabled:c}),L=ct([s,et,nt,tt]),R=z([s.current?.selectionStart??null,s.current?.selectionEnd??null,s.current?.selectionDirection??"none"]),d=C(()=>N?new RegExp(N):null,[N]),[f,v]=J(null),[P,h]=J(null),M=l(t=>{v(null),h(null)},[]),T=l(t=>{if(s.current){const e=Math.min(s.current.value.length,o-1),n=s.current.value.length;s.current.setSelectionRange(e,n),v(e),h(n)}},[o]),k=l(t=>{const e=t.currentTarget.value.slice(0,o);if(e.length>0&&d&&!d.test(e)){t.preventDefault();return}V(e),e.length===o&&y?.(e)},[o,y,d,V]);st(()=>{const t=s.current;if(!t)return;R.current=[t.selectionStart,t.selectionEnd,t.selectionDirection];function e(){if(!t)return;if(document.activeElement!==t){v(null),h(null);return}const n=t.selectionStart,g=t.selectionEnd,E=t.selectionDirection,i=R.current;let a=-1,u=-1,I;if(p.length!==0&&n!==null&&g!==null){if(n===g){if(n===0)a=0,u=1;else if(n===o)a=o-1,u=o;else if(o>1&&p.length>1){let q=0;if(i[0]!==null&&i[1]!==null){I=n<i[1]?"backward":"forward";const ot=i[0]===i[1]&&i[0]<n;I==="backward"&&!ot&&(q=-1)}a=n+q,u=a+1}}a!=-1&&u!==-1&&a!==u&&t.setSelectionRange(a,u,I)}const _=a!==-1?a:n,$=u!==-1?u:g,rt=I??E;v(_),h($),R.current=[_,$,rt]}return document.addEventListener("selectionchange",e,{capture:!0}),()=>{document.removeEventListener("selectionchange",e,{capture:!0})}},[o,p]);const F=C(()=>Array.from({length:6}).map((t,e)=>{const n=p[e]??null,g=b?.[e],E=f!==null&&P!==null&&(f===P&&f===e||f<=e&&P>e);return{char:n,placeholderChar:g,isActive:E}}),[b,P,f,p]),H=l(t=>({"data-slot":m("root"),"data-disabled":O(c),"aria-disabled":O(c),"data-hover":O(G),"data-focus":O(D),...t,className:r.root({className:t.className})}),[D,G,r,c]),x=l(t=>({"data-slot":m("group"),...t,className:r.group({className:t.className})}),[r]),A=l(t=>({"data-slot":m("slot"),...t,className:r.slot({className:t.className})}),[r]),B=l(t=>({"data-slot":m("separator"),...t,className:r.separator({className:t.className})}),[r]),K=l(()=>({...it(w,{onChange:k,onBlur:M,onFocus:T}),ref:L,"data-slot":m("input"),value:p,maxLength:o,className:r.input({className:S.className}),disabled:c,pattern:d?.source}),[w,p,k,M,T,L,o,r,S.className,c,d?.source]),j=l(t=>({"data-slot":m("caret"),...t,className:r.caret({className:t.className})}),[r]);return C(()=>({getRootProps:H,getGroupProps:x,getSlotProps:A,getSeparatorProps:B,getInputProps:K,getCaretProps:j,slots:F}),[H,x,A,B,K,j,F])};export{Pt as useOtpInput};
|
|
1
|
+
"use client";import{useCallback as l,useEffect as st,useMemo as C,useRef as z,useState as J}from"react";import{useControlledState as at,useFocus as lt,useHover as ut,useMergeRefs as ct}from"@jamsrui/hooks";import{dataAttr as O,dataAttrDev as m,mapPropsVariants as pt,mergeProps as it}from"@jamsrui/utils";import{otpInputVariants as Q}from"./styles.mjs";const Pt=S=>{const[U,W]=pt(S,Q.variantKeys),r=Q(W),{value:X,onValueChange:Y,defaultValue:Z,disabled:c=!1,maxLength:o,onComplete:y,placeholder:b,pattern:N,ref:tt,...w}=U,[p="",V]=at({defaultProp:Z,prop:X,onChange:Y}),s=z(null),{ref:et,isHovered:G}=ut({isDisabled:c}),{ref:nt,isFocused:D}=lt({isDisabled:c}),L=ct([s,et,nt,tt]),R=z([s.current?.selectionStart??null,s.current?.selectionEnd??null,s.current?.selectionDirection??"none"]),d=C(()=>N?new RegExp(N):null,[N]),[f,v]=J(null),[P,h]=J(null),M=l(t=>{v(null),h(null)},[]),T=l(t=>{if(s.current){const e=Math.min(s.current.value.length,o-1),n=s.current.value.length;s.current.setSelectionRange(e,n),v(e),h(n)}},[o]),k=l(t=>{const e=t.currentTarget.value.slice(0,o);if(e.length>0&&d&&!d.test(e)){t.preventDefault();return}V(e),e.length===o&&y?.(e)},[o,y,d,V]);st(()=>{const t=s.current;if(!t)return;R.current=[t.selectionStart,t.selectionEnd,t.selectionDirection];function e(){if(!t)return;if(document.activeElement!==t){v(null),h(null);return}const n=t.selectionStart,g=t.selectionEnd,E=t.selectionDirection,i=R.current;let a=-1,u=-1,I;if(p.length!==0&&n!==null&&g!==null){if(n===g){if(n===0)a=0,u=1;else if(n===o)a=o-1,u=o;else if(o>1&&p.length>1){let q=0;if(i[0]!==null&&i[1]!==null){I=n<i[1]?"backward":"forward";const ot=i[0]===i[1]&&i[0]<n;I==="backward"&&!ot&&(q=-1)}a=n+q,u=a+1}}a!=-1&&u!==-1&&a!==u&&t.setSelectionRange(a,u,I)}const _=a!==-1?a:n,$=u!==-1?u:g,rt=I??E;v(_),h($),R.current=[_,$,rt]}return document.addEventListener("selectionchange",e,{capture:!0}),()=>{document.removeEventListener("selectionchange",e,{capture:!0})}},[o,p]);const F=C(()=>Array.from({length:6}).map((t,e)=>{const n=p[e]??null,g=b?.[e],E=f!==null&&P!==null&&(f===P&&f===e||f<=e&&P>e);return{char:n,placeholderChar:g,isActive:E}}),[b,P,f,p]),H=l(t=>({"data-slot":m("root"),"data-disabled":O(c),"aria-disabled":O(c),"data-hover":O(G),"data-focus":O(D),...t,className:r.root({className:t.className})}),[D,G,r,c]),x=l(t=>({"data-slot":m("group"),...t,className:r.group({className:t.className})}),[r]),A=l(t=>({"data-slot":m("slot"),...t,className:r.slot({className:t.className})}),[r]),B=l(t=>({"data-slot":m("separator"),...t,className:r.separator({className:t.className})}),[r]),K=l(()=>({...it(w,{onChange:k,onBlur:M,onFocus:T}),ref:L,"data-slot":m("input"),value:p,maxLength:o,className:r.input({className:S.className}),disabled:c,pattern:d?.source}),[w,p,k,M,T,L,o,r,S.className,c,d?.source]),j=l(t=>({"data-slot":m("caret"),...t,className:r.caret({className:t.className})}),[r]);return C(()=>({getRootProps:H,getGroupProps:x,getSlotProps:A,getSeparatorProps:B,getInputProps:K,getCaretProps:j,slots:F}),[H,x,A,B,K,j,F])};export{Pt as useOtpInput};
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jamsrui/otp-input",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"peerDependencies": {
|
|
5
5
|
"react": ">=19"
|
|
6
6
|
},
|
|
7
7
|
"dependencies": {
|
|
8
|
-
"@jamsrui/
|
|
9
|
-
"@jamsrui/
|
|
10
|
-
"@jamsrui/
|
|
8
|
+
"@jamsrui/hooks": "^0.0.17",
|
|
9
|
+
"@jamsrui/utils": "^0.0.17",
|
|
10
|
+
"@jamsrui/core": "^0.0.14"
|
|
11
11
|
},
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|