@jamsrui/otp-input 0.0.12 → 0.0.14

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,6 +1,24 @@
1
- export { OtpInput } from './otp-input.mjs';
1
+ import * as react from 'react';
2
+ import * as react_jsx_runtime from 'react/jsx-runtime';
3
+ import { OtpInput as OtpInput$1 } from './otp-input.mjs';
4
+ import { OtpInputGroup } from './otp-input-group.mjs';
5
+ import { OtpInputSeparator } from './otp-input-separator.mjs';
6
+ import { OtpInputSlot } from './otp-input-slot.mjs';
2
7
  export { OtpInputConfig, useOtpInputConfig } from './otp-input-config.mjs';
3
- import 'react';
8
+ export { REGEXP_ONLY_CHARS, REGEXP_ONLY_DIGITS, REGEXP_ONLY_DIGITS_AND_CHARS } from './regexp.mjs';
9
+ import './use-otp-input.mjs';
4
10
  import '@jamsrui/utils';
5
- import 'react/jsx-runtime';
11
+ import './otp-input-caret.mjs';
12
+ import './otp-input-input.mjs';
13
+ import './otp-input-root.mjs';
14
+ import './styles.mjs';
6
15
  import '@jamsrui/core';
16
+
17
+ declare const OtpInput: ((props: OtpInput$1.Props) => react_jsx_runtime.JSX.Element) & {
18
+ Root: (props: OtpInput$1.Props) => react_jsx_runtime.JSX.Element;
19
+ Slot: (props: OtpInputSlot.Props) => react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
20
+ Separator: (props: OtpInputSeparator.Props) => react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
21
+ Group: (props: OtpInputGroup.Props) => react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
22
+ };
23
+
24
+ export { OtpInput };
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- "use client";import{a as p,b as n}from"./chunk-WEHL2U4J.mjs";import{a as t}from"./chunk-WPMKZ7NQ.mjs";export{t as OtpInput,p as OtpInputConfig,n as useOtpInputConfig};
1
+ import{OtpInput as t}from"./otp-input.mjs";import{OtpInputGroup as p}from"./otp-input-group.mjs";import{OtpInputSeparator as o}from"./otp-input-separator.mjs";import{OtpInputSlot as r}from"./otp-input-slot.mjs";import{OtpInputConfig as _,useOtpInputConfig as e}from"./otp-input-config.mjs";import{REGEXP_ONLY_CHARS as G,REGEXP_ONLY_DIGITS as R,REGEXP_ONLY_DIGITS_AND_CHARS as a}from"./regexp.mjs";const m=Object.assign(t,{Root:t,Slot:r,Separator:o,Group:p});export{m as OtpInput,_ as OtpInputConfig,G as REGEXP_ONLY_CHARS,R as REGEXP_ONLY_DIGITS,a as REGEXP_ONLY_DIGITS_AND_CHARS,e as useOtpInputConfig};
@@ -0,0 +1,10 @@
1
+ import * as react from 'react';
2
+ import { UIProps } from '@jamsrui/utils';
3
+
4
+ declare const OtpInputCaret: (props: OtpInputCaret.Props) => react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
5
+ declare namespace OtpInputCaret {
6
+ interface Props extends UIProps<"span"> {
7
+ }
8
+ }
9
+
10
+ export { OtpInputCaret };
@@ -0,0 +1 @@
1
+ "use client";import{useRenderElement as r}from"@jamsrui/hooks";import{useOtpInputContext as p}from"./otp-input-context.mjs";const m=e=>{const{getCaretProps:t}=p();return r("span",{props:t(e)})};export{m as OtpInputCaret};
@@ -1,8 +1,16 @@
1
- import { OtpInput } from './otp-input.mjs';
2
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
3
2
  import { GlobalConfigProps } from '@jamsrui/core';
4
- import 'react';
3
+ import { OtpInput } from './otp-input.mjs';
4
+ import './use-otp-input.mjs';
5
5
  import '@jamsrui/utils';
6
+ import './otp-input-caret.mjs';
7
+ import 'react';
8
+ import './otp-input-group.mjs';
9
+ import './otp-input-input.mjs';
10
+ import './otp-input-root.mjs';
11
+ import './otp-input-separator.mjs';
12
+ import './otp-input-slot.mjs';
13
+ import './styles.mjs';
6
14
 
7
15
  declare const useOtpInputConfig: () => Record<string, any>;
8
16
  declare const OtpInputConfig: (props: Omit<Partial<Record<string, any>>, "children"> & {
@@ -1 +1 @@
1
- import{a,b}from"./chunk-WEHL2U4J.mjs";export{a as OtpInputConfig,b as useOtpInputConfig};
1
+ "use client";import{createConfigContext as p}from"@jamsrui/utils";const[o,n]=p({displayName:"OtpInputConfig"});export{o as OtpInputConfig,n as useOtpInputConfig};
@@ -0,0 +1,19 @@
1
+ import * as react from 'react';
2
+ import { useOtpInput } from './use-otp-input.mjs';
3
+ import '@jamsrui/utils';
4
+ import './otp-input-caret.mjs';
5
+ import './otp-input-group.mjs';
6
+ import './otp-input-input.mjs';
7
+ import './otp-input-root.mjs';
8
+ import './otp-input-separator.mjs';
9
+ import './otp-input-slot.mjs';
10
+ import './styles.mjs';
11
+
12
+ declare const useOtpInputContext: () => OtpInputContext.Props;
13
+ declare const OtpInputContext: react.Context<OtpInputContext.Props | null>;
14
+ declare namespace OtpInputContext {
15
+ interface Props extends ReturnType<typeof useOtpInput> {
16
+ }
17
+ }
18
+
19
+ export { OtpInputContext, useOtpInputContext };
@@ -0,0 +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};
@@ -0,0 +1,10 @@
1
+ import * as react from 'react';
2
+ import { UIProps } from '@jamsrui/utils';
3
+
4
+ declare const OtpInputGroup: (props: OtpInputGroup.Props) => react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
5
+ declare namespace OtpInputGroup {
6
+ interface Props extends UIProps<"div"> {
7
+ }
8
+ }
9
+
10
+ export { OtpInputGroup };
@@ -0,0 +1 @@
1
+ "use client";import{useRenderElement as r}from"@jamsrui/hooks";import{useOtpInputContext as p}from"./otp-input-context.mjs";const u=e=>{const{getGroupProps:t}=p();return r("div",{props:t(e)})};export{u as OtpInputGroup};
@@ -0,0 +1,10 @@
1
+ import * as react from 'react';
2
+ import { UIProps } from '@jamsrui/utils';
3
+
4
+ declare const OtpInputInput: (props: OtpInputInput.Props) => react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
5
+ declare namespace OtpInputInput {
6
+ interface Props extends UIProps<"input"> {
7
+ }
8
+ }
9
+
10
+ export { OtpInputInput };
@@ -0,0 +1 @@
1
+ "use client";import{useRenderElement as p}from"@jamsrui/hooks";import{useOtpInputContext as e}from"./otp-input-context.mjs";const u=n=>{const{getInputProps:t}=e();return p("input",{props:t()})};export{u as OtpInputInput};
@@ -0,0 +1,10 @@
1
+ import * as react from 'react';
2
+ import { UIProps } from '@jamsrui/utils';
3
+
4
+ declare const OtpInputRoot: (props: OtpInputRoot.Props) => react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
5
+ declare namespace OtpInputRoot {
6
+ interface Props extends UIProps<"div"> {
7
+ }
8
+ }
9
+
10
+ export { OtpInputRoot };
@@ -0,0 +1 @@
1
+ "use client";import{useRenderElement as o}from"@jamsrui/hooks";import{useOtpInputContext as r}from"./otp-input-context.mjs";const m=t=>{const{getRootProps:e}=r();return o("div",{props:e(t)})};export{m as OtpInputRoot};
@@ -0,0 +1,10 @@
1
+ import * as react from 'react';
2
+ import { UIProps } from '@jamsrui/utils';
3
+
4
+ declare const OtpInputSeparator: (props: OtpInputSeparator.Props) => react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
5
+ declare namespace OtpInputSeparator {
6
+ interface Props extends UIProps<"div"> {
7
+ }
8
+ }
9
+
10
+ export { OtpInputSeparator };
@@ -0,0 +1 @@
1
+ "use client";import{useRenderElement as r}from"@jamsrui/hooks";import{useOtpInputContext as p}from"./otp-input-context.mjs";const a=e=>{const{getSeparatorProps:t}=p();return r("div",{props:t(e)})};export{a as OtpInputSeparator};
@@ -0,0 +1,11 @@
1
+ import * as react from 'react';
2
+ import { UIProps } from '@jamsrui/utils';
3
+
4
+ declare const OtpInputSlot: (props: OtpInputSlot.Props) => react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
5
+ declare namespace OtpInputSlot {
6
+ interface Props extends UIProps<"div"> {
7
+ index: number;
8
+ }
9
+ }
10
+
11
+ export { OtpInputSlot };
@@ -0,0 +1 @@
1
+ "use client";import{jsx as d}from"react/jsx-runtime";import{useMemo as l}from"react";import{useRenderElement as c}from"@jamsrui/hooks";import{dataAttr as m}from"@jamsrui/utils";import{OtpInputCaret as u}from"./otp-input-caret.mjs";import{useOtpInputContext as a}from"./otp-input-context.mjs";const P=n=>{const{getSlotProps:p,slots:s}=a(),t=s[n.index],e=t?.isActive??!1,r=t?.char??"",o=t?.placeholderChar??"",i=l(()=>r||o||(e?d(u,{}):null),[r,o,e]);return c("div",{props:[p(n),{"data-active":m(e),children:i}]})};export{P as OtpInputSlot};
@@ -1,9 +1,18 @@
1
- import * as react from 'react';
2
- import { UIProps } from '@jamsrui/utils';
1
+ import * as react_jsx_runtime from 'react/jsx-runtime';
2
+ import { useOtpInput } from './use-otp-input.mjs';
3
+ import '@jamsrui/utils';
4
+ import './otp-input-caret.mjs';
5
+ import 'react';
6
+ import './otp-input-group.mjs';
7
+ import './otp-input-input.mjs';
8
+ import './otp-input-root.mjs';
9
+ import './otp-input-separator.mjs';
10
+ import './otp-input-slot.mjs';
11
+ import './styles.mjs';
3
12
 
4
- declare const OtpInput: (props: OtpInput.Props) => react.ReactElement<unknown, string | react.JSXElementConstructor<any>>;
13
+ declare const OtpInput: (props: OtpInput.Props) => react_jsx_runtime.JSX.Element;
5
14
  declare namespace OtpInput {
6
- interface Props extends UIProps<"div"> {
15
+ interface Props extends useOtpInput.Props {
7
16
  }
8
17
  }
9
18
 
@@ -1 +1 @@
1
- import{a}from"./chunk-WPMKZ7NQ.mjs";export{a as OtpInput};
1
+ "use client";import{jsx as t,jsxs as O}from"react/jsx-runtime";import{OtpInputContext as e}from"./otp-input-context.mjs";import{OtpInputInput as u}from"./otp-input-input.mjs";import{OtpInputRoot as s}from"./otp-input-root.mjs";import{useOtpInput as I}from"./use-otp-input.mjs";const f=p=>{const{children:o,...n}=p,r=I(n);return t(e,{value:r,children:O(s,{children:[t(u,{}),o]})})};export{f as OtpInput};
@@ -0,0 +1,5 @@
1
+ declare const REGEXP_ONLY_DIGITS = "^\\d+$";
2
+ declare const REGEXP_ONLY_CHARS = "^[a-zA-Z]+$";
3
+ declare const REGEXP_ONLY_DIGITS_AND_CHARS = "^[a-zA-Z0-9]+$";
4
+
5
+ export { REGEXP_ONLY_CHARS, REGEXP_ONLY_DIGITS, REGEXP_ONLY_DIGITS_AND_CHARS };
@@ -0,0 +1 @@
1
+ const _="^\\d+$",o="^[a-zA-Z]+$",t="^[a-zA-Z0-9]+$";export{o as REGEXP_ONLY_CHARS,_ as REGEXP_ONLY_DIGITS,t as REGEXP_ONLY_DIGITS_AND_CHARS};
package/dist/styles.d.mts CHANGED
@@ -1,2 +1,104 @@
1
+ import * as _jamsrui_utils from '@jamsrui/utils';
2
+ import { VariantProps } from '@jamsrui/utils';
1
3
 
2
- export { }
4
+ declare const otpInputVariants: _jamsrui_utils.TVReturnType<{
5
+ radius: {
6
+ sm: {};
7
+ md: {};
8
+ lg: {};
9
+ xl: {};
10
+ "2xl": {};
11
+ "3xl": {};
12
+ full: {};
13
+ none: {};
14
+ };
15
+ size: {
16
+ sm: {
17
+ slot: string;
18
+ caret: string;
19
+ };
20
+ md: {
21
+ slot: string;
22
+ caret: string;
23
+ };
24
+ lg: {
25
+ slot: string;
26
+ caret: string;
27
+ };
28
+ };
29
+ }, {
30
+ root: string;
31
+ group: string;
32
+ slot: string;
33
+ separator: string;
34
+ input: string[];
35
+ caret: string;
36
+ }, undefined, {
37
+ radius: {
38
+ sm: {};
39
+ md: {};
40
+ lg: {};
41
+ xl: {};
42
+ "2xl": {};
43
+ "3xl": {};
44
+ full: {};
45
+ none: {};
46
+ };
47
+ size: {
48
+ sm: {
49
+ slot: string;
50
+ caret: string;
51
+ };
52
+ md: {
53
+ slot: string;
54
+ caret: string;
55
+ };
56
+ lg: {
57
+ slot: string;
58
+ caret: string;
59
+ };
60
+ };
61
+ }, {
62
+ root: string;
63
+ group: string;
64
+ slot: string;
65
+ separator: string;
66
+ input: string[];
67
+ caret: string;
68
+ }, _jamsrui_utils.TVReturnType<{
69
+ radius: {
70
+ sm: {};
71
+ md: {};
72
+ lg: {};
73
+ xl: {};
74
+ "2xl": {};
75
+ "3xl": {};
76
+ full: {};
77
+ none: {};
78
+ };
79
+ size: {
80
+ sm: {
81
+ slot: string;
82
+ caret: string;
83
+ };
84
+ md: {
85
+ slot: string;
86
+ caret: string;
87
+ };
88
+ lg: {
89
+ slot: string;
90
+ caret: string;
91
+ };
92
+ };
93
+ }, {
94
+ root: string;
95
+ group: string;
96
+ slot: string;
97
+ separator: string;
98
+ input: string[];
99
+ caret: string;
100
+ }, undefined, unknown, unknown, undefined>>;
101
+ type OtpInputVariants = VariantProps<typeof otpInputVariants>;
102
+ type OtpInputSlots = keyof ReturnType<typeof otpInputVariants>;
103
+
104
+ export { type OtpInputSlots, type OtpInputVariants, otpInputVariants };
package/dist/styles.mjs CHANGED
@@ -0,0 +1 @@
1
+ import{radiusVariant as t,tv as r}from"@jamsrui/utils";const o=r({slots:{root:"otp-input otp-input__root relative flex gap-2 items-center group data-disabled:opacity-50 data-disabled:cursor-not-allowed",group:"otp-input__group flex",slot:"otp-input__slot border-divider relative flex items-center justify-center border-y border-r first:border-l first:rounded-l-md last:rounded-r-md transition-all duration-300 ease-in-out outline-solid outline-0 outline-accent-foreground/20 group-data-hover:border-primary-foreground/20 group-focus-within:border-primary-foreground/30 data-active:outline-primary-foreground",separator:"otp-input__separator w-4 h-1 bg-divider",input:["otp-input__input absolute bg-transparent inset-0 size-full outline-none outline-0 border-none border-0","z-10 text-transparent selection:text-transparent selection:bg-transparent"],caret:"otp-input__caret absolute pointer-events-none flex w-[1.5px] bg-primary-foreground animate-caret-blink z-1"},variants:{radius:t(["group","separator"],"otp-input"),size:{sm:{slot:"w-8 h-8 data-active:outline-2",caret:"h-4"},md:{slot:"w-10 h-10 data-active:outline-3",caret:"h-5"},lg:{slot:"w-12 h-12 data-active:outline-4",caret:"h-6"}}},defaultVariants:{radius:"md",size:"md"}});export{o as otpInputVariants};
@@ -1,7 +1,36 @@
1
- declare const useOTPInput: (props: useOTPInput.Props) => void;
2
- declare namespace useOTPInput {
3
- interface Props {
1
+ import { PropGetter } from '@jamsrui/utils';
2
+ import { OtpInputCaret } from './otp-input-caret.mjs';
3
+ import { OtpInputGroup } from './otp-input-group.mjs';
4
+ import { OtpInputInput } from './otp-input-input.mjs';
5
+ import { OtpInputRoot } from './otp-input-root.mjs';
6
+ import { OtpInputSeparator } from './otp-input-separator.mjs';
7
+ import { OtpInputSlot } from './otp-input-slot.mjs';
8
+ import { OtpInputVariants } from './styles.mjs';
9
+ import 'react';
10
+
11
+ type OverrideProps<T, R> = Omit<T, keyof R> & R;
12
+ declare const useOtpInput: (props: useOtpInput.Props) => {
13
+ getRootProps: PropGetter<OtpInputRoot.Props>;
14
+ getGroupProps: PropGetter<OtpInputGroup.Props>;
15
+ getSlotProps: PropGetter<OtpInputSlot.Props>;
16
+ getSeparatorProps: PropGetter<OtpInputSeparator.Props>;
17
+ getInputProps: () => OtpInputInput.Props;
18
+ getCaretProps: PropGetter<OtpInputCaret.Props>;
19
+ slots: {
20
+ char: string | null;
21
+ placeholderChar: string | undefined;
22
+ isActive: boolean;
23
+ }[];
24
+ };
25
+ declare namespace useOtpInput {
26
+ interface Props extends OtpInputVariants, OverrideProps<OtpInputInput.Props, {
27
+ value?: string;
28
+ onValueChange?: (value: string) => void;
29
+ defaultValue?: string;
30
+ maxLength: number;
31
+ onComplete?: (value: string) => void;
32
+ }> {
4
33
  }
5
34
  }
6
35
 
7
- export { useOTPInput };
36
+ export { useOtpInput };
@@ -1 +1 @@
1
- var e=p=>{};export{e as useOTPInput};
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};
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@jamsrui/otp-input",
3
- "version": "0.0.12",
3
+ "version": "0.0.14",
4
4
  "peerDependencies": {
5
5
  "react": ">=19"
6
6
  },
7
7
  "dependencies": {
8
- "@jamsrui/hooks": "^0.0.12",
9
- "@jamsrui/core": "^0.0.10",
10
- "@jamsrui/utils": "^0.0.12"
8
+ "@jamsrui/core": "^0.0.12",
9
+ "@jamsrui/hooks": "^0.0.14",
10
+ "@jamsrui/utils": "^0.0.14"
11
11
  },
12
12
  "exports": {
13
13
  ".": {
@@ -1 +0,0 @@
1
- import{createConfigContext as p}from"@jamsrui/utils";var[o,n]=p({displayName:"OtpInputConfig"});export{o as a,n as b};
@@ -1 +0,0 @@
1
- import{useRenderElement as t}from"@jamsrui/hooks";var s=e=>{let{render:p,...r}=e;return t("div",{props:r})};export{s as a};