@@ -38,38 +38,50 @@ export const validatePassword = (password: string) => {
38
38
return { errorMessage, score } ;
39
39
} ;
40
40
41
- const PasswordVariant : Record < TScore , PasswordInputProps [ "variant" ] > = {
41
+ type InputProps = ComponentProps < typeof Input > ;
42
+
43
+ interface PasswordInputProps
44
+ extends Pick <
45
+ InputProps ,
46
+ "value" | "onChange" | "label" | "id" | "autoComplete"
47
+ > {
48
+ hidePasswordMeter ?: boolean ;
49
+ hint ?: string ;
50
+ }
51
+
52
+ const PasswordVariant : Record < TScore , InputProps [ "variant" ] > = {
42
53
0 : "error" ,
43
54
1 : "error" ,
44
55
2 : "warning" ,
45
56
3 : "success" ,
46
57
4 : "success" ,
47
58
} ;
48
59
49
- interface PasswordInputProps extends ComponentProps < typeof Input > {
50
- hidePasswordMeter ?: boolean ;
51
- }
52
-
53
60
export const PasswordInput = ( {
61
+ autoComplete,
62
+ id,
63
+ label,
64
+ value,
65
+ onChange,
66
+ hint,
54
67
hidePasswordMeter,
55
- ...rest
56
68
} : PasswordInputProps ) => {
57
69
const [ isTouched , setIsTouched ] = useState ( false ) ;
58
70
const [ showPassword , setShowPassword ] = useState ( false ) ;
59
71
60
72
const { errorMessage, score } = useMemo (
61
- ( ) => validatePassword ( rest . value as string ) ,
62
- [ rest . value ]
73
+ ( ) => validatePassword ( value as string ) ,
74
+ [ value ]
63
75
) ;
64
76
65
77
const handleChange = useCallback (
66
78
( e : ChangeEvent < HTMLInputElement > ) => {
67
- rest . onChange ?.( e ) ;
79
+ onChange ?.( e ) ;
68
80
if ( ! isTouched ) {
69
81
setIsTouched ( true ) ;
70
82
}
71
83
} ,
72
- [ isTouched , rest . onChange ]
84
+ [ isTouched , onChange ]
73
85
) ;
74
86
75
87
const handleBlur = useCallback ( ( ) => {
@@ -81,9 +93,12 @@ export const PasswordInput = ({
81
93
return (
82
94
< div className = "deriv-password" >
83
95
< Input
96
+ autoComplete = { autoComplete }
97
+ id = { id }
98
+ label = { label }
84
99
type = { showPassword ? "text" : "password" }
85
- value = { rest . value }
86
- message = { isTouched ? errorMessage : "" }
100
+ value = { value }
101
+ message = { isTouched ? errorMessage : "" || hint }
87
102
onChange = { handleChange }
88
103
onBlur = { handleBlur }
89
104
variant = { isTouched ? PasswordVariant [ score as TScore ] : "general" }
@@ -95,7 +110,6 @@ export const PasswordInput = ({
95
110
{ showPassword ? < EyeIcon /> : < EyeIconSlash /> }
96
111
</ button >
97
112
}
98
- { ...rest }
99
113
/>
100
114
{ ! hidePasswordMeter && < PasswordMeter score = { score as TScore } /> }
101
115
</ div >
0 commit comments