Skip to content

Commit caab41c

Browse files
chore: Otp custom demo updates
1 parent 82c99c1 commit caab41c

2 files changed

Lines changed: 26 additions & 56 deletions

File tree

apps/showcase/demo/inputotp/custom-demo.tsx

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,17 @@
1-
import { InputOtpInstance } from '@primereact/types/shared/inputotp';
21
import { InputOtp } from 'primereact/inputotp';
32

43
export default function CustomDemo() {
54
return (
65
<div className="card flex justify-center">
76
<InputOtp defaultValue={''}>
8-
{(instance: InputOtpInstance) => {
9-
const { onInput, onClick, onKeyDown, onPaste, state, registerText } = instance;
10-
7+
{Array.from({ length: 4 }, (_, index) => {
118
return (
12-
<>
13-
{Array.from({ length: 4 }, (_, index) => {
14-
registerText();
15-
16-
return (
17-
<input
18-
value={state.tokens[index] ?? ''}
19-
key={index}
20-
type="text"
21-
inputMode="text"
22-
className="w-10 text-4xl border-0 appearance-none text-center transition-all duration-200 bg-transparent border-b-2 border-b-[var(--p-inputtext-border-color)] focus:outline-none focus:border-b-[var(--p-primary-color)]"
23-
maxLength={1}
24-
onInput={(e) => onInput(e, index)}
25-
onClick={onClick}
26-
onKeyDown={onKeyDown}
27-
onPaste={onPaste}
28-
/>
29-
);
30-
})}
31-
</>
9+
<InputOtp.Text
10+
key={index}
11+
className="w-[40px] text-4xl appearance-none text-center transition-all duration-200 bg-transparent border-0 border-b-2 border-b-[var(--p-inputtext-border-color)] rounded-none focus:outline-none focus:border-b-[var(--p-primary-color)]"
12+
/>
3213
);
33-
}}
14+
})}
3415
</InputOtp>
3516
</div>
3617
);

apps/showcase/demo/inputotp/sample-demo.tsx

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { MinusIcon } from '@primereact/icons';
2-
import { InputOtpInstance } from '@primereact/types/shared/inputotp';
32
import { Button } from 'primereact/button';
43
import { InputOtp } from 'primereact/inputotp';
54
import * 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

Comments
 (0)