feat: verificationTokenComponent (#9476)

Co-authored-by: Peer Richelsen <peeroke@gmail.com>
pull/9868/head^2
firefox341 2023-07-02 00:10:19 +05:30 committed by GitHub
parent 9b25f81b61
commit 4bea5a09c6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 73 additions and 0 deletions

View File

@ -0,0 +1,36 @@
import { useLocale } from "@calcom/lib/hooks/useLocale";
import { Label, Input } from "@calcom/ui";
type Digit = {
value: number;
onChange: () => void;
};
type PropType = {
digits: Digit[];
digitClassName: string;
};
const TokenHandler = ({ digits, digitClassName }: PropType) => {
const { t } = useLocale();
return (
<div>
<Label htmlFor="code">{t("code")}</Label>
<div className="flex flex-row justify-between">
{digits.map((element, index) => (
<Input
key={index}
className={digitClassName}
name={`2fa${index + 1}`}
inputMode="decimal"
{...element}
autoFocus={index === 0}
autoComplete="one-time-code"
/>
))}
</div>
</div>
);
};
export default TokenHandler;

View File

@ -0,0 +1,37 @@
import { Canvas, Meta, Story, ArgsTable } from '@storybook/addon-docs';
import { Examples, Example, Note, Title,CustomArgsTable } from '@calcom/storybook/components'
import TokenHandler from './TokenHandler'
<Meta title="UI/TokenHandler" component={TokenHandler} />
<Title title="TokenHandler" subtitle="Version 0.1"/>
## Structure
<TokenHandler digits={[
{
value: "1",
onChange: (e) => {},
},
{
value: "2",
onChange: (e) => {},
},
{
value: "3",
onChange: (e) => {},
},
{
value: "4",
onChange: (e) => {},
},
{
value: "5",
onChange: (e) => {},
},
{
value: "6",
onChange: (e) => {},
},
]} digitClassName="digit-input" />
#all the numbers should be visible while the first one is focused