ant-design/components/input/demo/otp.tsx
thinkasany 3f9e711d3b
type(demo): improve type by GetProps util (#49805)
* type(demo): improve type by GetProps util

* fix lint
2024-07-10 18:28:11 +08:00

35 lines
998 B
TypeScript

import React from 'react';
import { Flex, Input, Typography } from 'antd';
import type { GetProps } from 'antd';
type OTPProps = GetProps<typeof Input.OTP>;
const { Title } = Typography;
const App: React.FC = () => {
const onChange: OTPProps['onChange'] = (text) => {
console.log('onChange:', text);
};
const sharedProps: OTPProps = {
onChange,
};
return (
<Flex gap="middle" align="flex-start" vertical>
<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} />
<Title level={5}>With custom display character</Title>
<Input.OTP mask="🔒" {...sharedProps} />
</Flex>
);
};
export default App;