Skip to content

Commit fcb3cf7

Browse files
feat: add type prop
1 parent c381a0a commit fcb3cf7

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/index.tsx

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ const KEY_CODE = {
99
DELETE: 46,
1010
};
1111

12+
enum InputType {
13+
TEXT = 'text',
14+
PASSWORD = 'password'
15+
}
16+
1217
type Props = {
1318
autoFocus?: boolean;
1419
length?: number;
@@ -17,6 +22,7 @@ type Props = {
1722
placeholder?: string;
1823
value?: string;
1924
dataCy?: string;
25+
type?: InputType;
2026
};
2127

2228
const ReactInputVerificationCode = ({
@@ -26,7 +32,8 @@ const ReactInputVerificationCode = ({
2632
onCompleted = () => {},
2733
placeholder = '·',
2834
value: pValue,
29-
dataCy = 'verification-code'
35+
dataCy = 'verification-code',
36+
type = InputType.TEXT,
3037
}: Props) => {
3138
const emptyValue = new Array(length).fill(placeholder);
3239

@@ -167,6 +174,13 @@ const ReactInputVerificationCode = ({
167174
if (pValue !== value.join('')) setValue(pValue.split(''));
168175
}, [pValue]);
169176

177+
178+
const renderItemValue = (value: string) => {
179+
if (!value) return placeholder;
180+
181+
return type === InputType.PASSWORD ? '●' : value;
182+
}
183+
170184
return (
171185
<React.Fragment>
172186
<Global
@@ -214,7 +228,7 @@ const ReactInputVerificationCode = ({
214228
onFocus={onItemFocus(i)}
215229
data-cy={`${dataCy}-${i}-item`}
216230
>
217-
{value[i] || placeholder}
231+
{renderItemValue(value[i])}
218232
</Item>
219233
))}
220234
</Container>

0 commit comments

Comments
 (0)