2024-03-28 14:05:58 +08:00
|
|
|
import React from 'react';
|
2024-04-09 14:47:58 +08:00
|
|
|
import { Flex, Input, Typography } from 'antd';
|
2024-07-10 18:28:11 +08:00
|
|
|
import type { GetProps } from 'antd';
|
|
|
|
|
|
|
|
type OTPProps = GetProps<typeof Input.OTP>;
|
2024-03-28 14:05:58 +08:00
|
|
|
|
|
|
|
const { Title } = Typography;
|
|
|
|
|
|
|
|
const App: React.FC = () => {
|
2024-07-10 18:28:11 +08:00
|
|
|
const onChange: OTPProps['onChange'] = (text) => {
|
2024-03-28 14:05:58 +08:00
|
|
|
console.log('onChange:', text);
|
|
|
|
};
|
|
|
|
|
2024-04-09 14:47:58 +08:00
|
|
|
const sharedProps: OTPProps = {
|
2024-03-28 14:05:58 +08:00
|
|
|
onChange,
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2024-04-09 14:47:58 +08:00
|
|
|
<Flex gap="middle" align="flex-start" vertical>
|
2024-03-28 14:05:58 +08:00
|
|
|
<Title level={5}>With formatter (Upcase)</Title>
|
|
|
|
<Input.OTP formatter={(str) => str.toUpperCase()} {...sharedProps} />
|
|
|
|
<Title level={5}>With Disabled</Title>
|
|
|
|
<Input.OTP disabled {...sharedProps} />
|
|
|
|
<Title level={5}>With Length (8)</Title>
|
|
|
|
<Input.OTP length={8} {...sharedProps} />
|
|
|
|
<Title level={5}>With variant</Title>
|
|
|
|
<Input.OTP variant="filled" {...sharedProps} />
|
2024-04-09 14:47:58 +08:00
|
|
|
<Title level={5}>With custom display character</Title>
|
|
|
|
<Input.OTP mask="🔒" {...sharedProps} />
|
|
|
|
</Flex>
|
2024-03-28 14:05:58 +08:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default App;
|