11import { MinusIcon } from '@primereact/icons' ;
2- import { InputOtpInstance } from '@primereact/types/shared/inputotp' ;
32import { Button } from 'primereact/button' ;
43import { InputOtp } from 'primereact/inputotp' ;
54import * as React from 'react' ;
@@ -11,39 +10,29 @@ export default function SampleDemo() {
1110 < div className = "font-bold text-xl mb-2" > Authenticate Your Account</ div >
1211 < p className = "text-surface-500 dark:text-surface-400 block mb-8" > Please enter the code sent to your phone.</ p >
1312 < InputOtp defaultValue = { '' } className = "gap-0" >
14- { ( instance : InputOtpInstance ) => {
15- const { onInput, onClick, onKeyDown, onPaste, state, registerText } = instance ;
13+ { Array . from ( { length : 6 } , ( _ , index ) => {
14+ const inputClasses = [
15+ 'w-12 h-12 text-2xl appearance-none text-center transition-all duration-200' ,
16+ 'border border-[var(--p-inputtext-border-color)] rounded-none bg-transparent' ,
17+ 'outline-offset-[-2px] outline-transparent transition-[outline-color] duration-300' ,
18+ 'text-[var(--p-inputtext-color)]' ,
19+ index === 0 || index === 3 ? 'rounded-l-xl' : '' ,
20+ index === 2 || index === 5 ? 'rounded-r-xl' : '' ,
21+ ! ( index === 2 || index === 5 ) ? 'border-r-0' : '' ,
22+ 'focus:outline-2 focus:outline-[var(--p-focus-ring-color)]'
23+ ] . join ( ' ' ) ;
1624
1725 return (
18- < >
19- { Array . from ( { length : 6 } , ( _ , index ) => {
20- registerText ( ) ;
21-
22- const inputClasses = [
23- 'w-12 h-12 text-2xl appearance-none text-center transition-all duration-200' ,
24- 'border border-[var(--p-inputtext-border-color)] bg-transparent' ,
25- 'outline-offset-[-2px] outline-transparent transition-[outline-color] duration-300' ,
26- 'text-[var(--p-inputtext-color)]' ,
27- index === 0 || index === 3 ? 'rounded-l-xl' : 'rounded-none' ,
28- index === 2 || index === 5 ? 'rounded-r-xl' : '' ,
29- ! ( index === 2 || index === 5 ) ? 'border-r-0' : '' ,
30- 'focus:outline-2 focus:outline-[var(--p-focus-ring-color)]'
31- ] . join ( ' ' ) ;
32-
33- return (
34- < React . Fragment key = { index } >
35- < input value = { state . tokens [ index ] ?? '' } type = "text" inputMode = "text" className = { inputClasses } maxLength = { 1 } onInput = { ( e ) => onInput ( e , index ) } onClick = { onClick } onKeyDown = { onKeyDown } onPaste = { onPaste } />
36- { index === 2 && (
37- < div className = "px-4" >
38- < MinusIcon />
39- </ div >
40- ) }
41- </ React . Fragment >
42- ) ;
43- } ) }
44- </ >
26+ < React . Fragment key = { index } >
27+ < InputOtp . Text className = { inputClasses } />
28+ { index === 2 && (
29+ < div className = "px-4" >
30+ < MinusIcon />
31+ </ div >
32+ ) }
33+ </ React . Fragment >
4534 ) ;
46- } }
35+ } ) }
4736 </ InputOtp >
4837 < div className = "flex justify-between mt-8 self-stretch" >
4938 < Button variant = "link" className = "p-0" >
0 commit comments