import { OTP } from 'sud-ui';OTP를 입력할 때.
import React, { useState } from 'react';
import { OTP } from 'sud-ui';
const BasicOTP = () => {
const [value, setValue] = useState("");
return (
<OTP
value={value}
onChange={(e) => setValue(e.target.value)}
/>
);
};
export default BasicOTP;import React, { useState } from 'react';
import { OTP } from 'sud-ui';
const DisabledOTP = () => {
const [value, setValue] = useState("");
return (
<OTP
value={value}
onChange={(e) => setValue(e.target.value)}
disabled
/>
);
};
export default DisabledOTP;import React, { useState } from 'react';
import { OTP, Radio, Card } from 'sud-ui';
const TypeOTP = () => {
const [type, setType] = useState('text');
const [textValue, setTextValue] = useState('');
const [numberValue, setNumberValue] = useState('');
const typeOptions = [
{ label: 'text', value: 'text' },
{ label: 'int', value: 'int' },
];
return (
<div className="flex flex-col gap-[20px]">
<Card style={{ width: "100%" }} shadow="none" colorType="sub">
<div className="flex justify-center w-full">
<Radio.Group
options={typeOptions}
direction="horizontal"
value={type}
onChange={setType}
/>
</div>
</Card>
<OTP
type={type}
value={type === "text" ? textValue : numberValue}
onChange={(e) =>
type === "text"
? setTextValue(e.target.value)
: setNumberValue(e.target.value)
}
/>
</div>
);
};
export default TypeOTP;import React, { useState } from 'react';
import { OTP } from 'sud-ui';
const PasswordOTP = () => {
const [value, setValue] = useState("");
return (
<OTP
value={value}
onChange={(e) => setValue(e.target.value)}
password
/>
);
};
export default PasswordOTP;import React, { useState } from 'react';
import { OTP } from 'sud-ui';
const ErrorOTP = () => {
const [value, setValue] = useState("");
return (
<OTP
value={value}
onChange={(e) => setValue(e.target.value)}
error={value.length > 0}
errorText="The error message is displayed."
/>
);
};
export default ErrorOTP;import React, { useState } from 'react';
import { OTP } from 'sud-ui';
const CustomColorOTP = () => {
const [value, setValue] = useState("");
return (
<OTP
value={value}
onChange={(e) => setValue(e.target.value)}
color="orange-8"
background="orange-1"
borderColor="orange-8"
/>
);
};
export default CustomColorOTP;import React, { useState } from 'react';
import { OTP, Radio, Card } from 'sud-ui';
const SizeOTP = () => {
const [size, setSize] = useState('md');
const [value, setValue] = useState('');
const sizeOptions = [
{ label: 'sm', value: 'sm' },
{ label: 'md', value: 'md' },
{ label: 'lg', value: 'lg' }
];
return (
<div className="flex flex-col gap-[20px]">
<Card style={{ width: "100%" }} shadow="none" colorType="sub">
<div className="flex justify-center w-full">
<Radio.Group
options={sizeOptions}
direction="horizontal"
value={size}
onChange={setSize}
/>
</div>
</Card>
<OTP
size={size}
value={value}
onChange={(e) => setValue(e.target.value)}
/>
</div>
);
};
export default SizeOTP;import React, { useState } from 'react';
import { OTP } from 'sud-ui';
const ReadOnlyOTP = () => {
const [value, setValue] = useState("");
return (
<OTP
value={value}
onChange={(e) => setValue(e.target.value)}
readOnly
/>
);
};
export default ReadOnlyOTP;import React, { useState } from 'react';
import { OTP } from 'sud-ui';
const LengthOTP = () => {
const [value, setValue] = useState("");
return (
<OTP
value={value}
onChange={(e) => setValue(e.target.value)}
length={4}
/>
);
};
export default LengthOTP;import React, { useState } from 'react';
import { OTP } from 'sud-ui';
const LabelOTP = () => {
const [value, setValue] = useState("");
return (
<OTP
value={value}
onChange={(e) => setValue(e.target.value)}
label="OTP input"
/>
);
};
export default LabelOTP;import React, { useState } from 'react';
import { OTP, Radio, Card } from 'sud-ui';
const ShapeOTP = () => {
const [shape, setShape] = useState('rounded');
const shapeOptions = [
{ label: 'rounded', value: 'rounded' },
{ label: 'square', value: 'square' },
{ label: 'capsule', value: 'capsule' }
];
return (
<div className="flex flex-col gap-[20px]">
<Card style={{ width: "100%" }} shadow="none" colorType="sub">
<div className="flex justify-center w-full">
<Radio.Group
options={shapeOptions}
direction="horizontal"
value={shape}
onChange={setShape}
/>
</div>
</Card>
<OTP
shape={shape}
value={shapeValue}
onChange={(e) => setShapeValue(e.target.value)}
/>
</div>
);
};
export default ShapeOTP;import React, { useState } from 'react';
import { OTP, Radio, Card } from 'sud-ui';
const AlphanumericOTP = () => {
const [type, setType] = useState('alphanumeric');
const [textValue, setTextValue] = useState('');
const [numberValue, setNumberValue] = useState('');
const typeOptions = [
{ label: 'text', value: 'text' },
{ label: 'int', value: 'int' },
];
return (
<div className="flex flex-col gap-[20px]">
<Card style={{ width: "100%" }} shadow="none" colorType="sub">
<div className="flex justify-center w-full">
<Radio.Group
options={typeOptions}
direction="horizontal"
value={type}
onChange={setType}
/>
</div>
</Card>
<OTP
type={type}
value={type === "alphanumeric" ? textValue : numberValue}
onChange={(e) =>
type === "alphanumeric"
? setTextValue(e.target.value)
: setNumberValue(e.target.value)
}
/>
</div>
);
};
export default AlphanumericOTP;속성 이름 | 설명 | 타입 | 기본값 |
|---|
| value | OTP 입력 필드의 값 | string | "" |
| onChange | 값이 변경될 때 호출되는 함수 ((e: { target: { value: string } }) => void) | (e: { target: { value: string } }) => void | - |
| length | OTP 입력 필드의 개수 | number | 6 |
| type | OTP 입력 필드의 타입 ("int" | "text") | text | int | int |
| size | OTP 입력 필드의 크기 ("sm" | "md" | "lg") | sm | md | lg | md |
| shape | OTP 입력 필드의 모서리 모양 (shapeType) | square | circle | rounded | capsule | rounded |
| disabled | OTP 입력 필드 비활성화 여부 | boolean | false |
| readOnly | 읽기 전용 여부 | boolean | false |
| autoFocus | 자동 포커스 여부 | boolean | false |
| password | 비밀번호 입력 필드 여부 | boolean | false |
| underline | 밑줄 스타일 여부 | boolean | false |
| label | OTP 입력 필드의 라벨 (string | ReactNode) | string | ReactNode | - |
| error | 에러 상태 여부 | boolean | false |
| errorText | 에러 메시지 | string | - |
| background | 배경색(palette값 또는 HEX code) | string | - |
| color | 텍스트 색상(palette값 또는 HEX code) | string | - |
| border | 테두리 표시 여부 | boolean | true |
| borderColor | 테두리 색상(palette값 또는 HEX code) | string | - |
| borderType | 테두리 스타일 | solid | dashed | dotted | double | groove | ridge | inset | outset | none | solid |
| borderWeight | 테두리 두께 | number | 1 |
| shadow | 그림자 크기 | none | sm | md | lg | sm |
| className | 추가 클래스명 | string | "" |
| style | 추가 스타일 | CSSProperties | {} |