Skip to content

Commit 63e655f

Browse files
refactor: cr fixes
1 parent 37e3e8c commit 63e655f

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ export default function App() {
4848
| onCompleted | `function` | `() => {}` | false | Function called when the code is completed |
4949
| placeholder | `string` | `·` | false | String rendered in each item when no value has been typed |
5050
| value | `string` | `() => {}` | false | Control internal input value |
51-
| type | `text or password` | `text` | false | Control input type |
51+
| type | `text` or `password` | `text` | false | Display the item value or a password mask |
52+
| passwordMask | `string` | `` | false | Password mask |
5253

5354
### CSS Properties
5455

src/index.tsx

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

12-
enum InputType {
13-
TEXT = 'text',
14-
PASSWORD = 'password'
15-
}
16-
1712
type Props = {
1813
autoFocus?: boolean;
1914
length?: number;
@@ -22,7 +17,8 @@ type Props = {
2217
placeholder?: string;
2318
value?: string;
2419
dataCy?: string;
25-
type?: InputType;
20+
type?: 'text' | 'password';
21+
passwordMask?: string;
2622
};
2723

2824
const ReactInputVerificationCode = ({
@@ -33,7 +29,8 @@ const ReactInputVerificationCode = ({
3329
placeholder = '·',
3430
value: pValue,
3531
dataCy = 'verification-code',
36-
type = InputType.TEXT,
32+
type = 'text',
33+
passwordMask = '•'
3734
}: Props) => {
3835
const emptyValue = new Array(length).fill(placeholder);
3936

@@ -174,12 +171,10 @@ const ReactInputVerificationCode = ({
174171
if (pValue !== value.join('')) setValue(pValue.split(''));
175172
}, [pValue]);
176173

177-
178-
const renderItemValue = (value: string) => {
179-
if (!value) return placeholder;
180-
181-
return type === InputType.PASSWORD ? '●' : value;
182-
}
174+
const renderItemText = (itemValue: string) => {
175+
if (itemValue === placeholder) return placeholder;
176+
return type === 'password' ? passwordMask : itemValue;
177+
};
183178

184179
return (
185180
<React.Fragment>
@@ -228,7 +223,7 @@ const ReactInputVerificationCode = ({
228223
onFocus={onItemFocus(i)}
229224
data-cy={`${dataCy}-${i}-item`}
230225
>
231-
{renderItemValue(value[i])}
226+
{renderItemText(value[i])}
232227
</Item>
233228
))}
234229
</Container>

0 commit comments

Comments
 (0)