Skip to content

Commit 85f8c68

Browse files
albsbzalbsbz
andauthored
th-126: The Password field content on the Sign up both Business and Customer and Sign in pages is hidden by asterisks after the Show Hide password button was clicked (#148)
* th-126: + show hide password button * th-126: * input with icon component * th-126: + color changing * th-126: * vars naming * th-126: * enum import input component --------- Co-authored-by: albsbz <[email protected]>
1 parent d0f3edd commit 85f8c68

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed

frontend/src/libs/components/icon/maps/icon-name-to-svg.map.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
faCaretDown,
55
faChevronDown,
66
faChevronLeft,
7+
faEye,
78
faGear,
89
faListUl,
910
faLocationDot,
@@ -30,6 +31,7 @@ const iconNameToSvg: Record<ValueOf<typeof IconName>, IconDefinition> = {
3031
[IconName.MAP]: faMap,
3132
[IconName.TRUCK]: faTruckPickup,
3233
[IconName.USERS]: faUsers,
34+
[IconName.EYE]: faEye,
3335
};
3436

3537
export { iconNameToSvg };

frontend/src/libs/components/input/input.tsx

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,15 @@ import {
55
type FieldValues,
66
} from 'react-hook-form';
77

8+
import { IconName } from '~/libs/enums/icon-name.enum.js';
89
import { getValidClassNames } from '~/libs/helpers/helpers.js';
9-
import { useFormController } from '~/libs/hooks/hooks.js';
10+
import {
11+
useCallback,
12+
useFormController,
13+
useState,
14+
} from '~/libs/hooks/hooks.js';
1015

16+
import { Icon } from '../components.js';
1117
import styles from './styles.module.scss';
1218

1319
type Properties<T extends FieldValues> = {
@@ -36,7 +42,7 @@ const Input = <T extends FieldValues>({
3642
step,
3743
}: Properties<T>): JSX.Element => {
3844
const { field } = useFormController({ name, control });
39-
45+
const [isPasswordShown, setIsPasswordShown] = useState(false);
4046
const error = errors[name]?.message;
4147
const hasError = Boolean(error);
4248
const hasValue = Boolean(field.value);
@@ -48,13 +54,21 @@ const Input = <T extends FieldValues>({
4854
hasError && styles.error,
4955
];
5056

57+
const toggleShowPassword = useCallback(
58+
(event: React.MouseEvent<HTMLElement>): void => {
59+
event.preventDefault();
60+
setIsPasswordShown(!isPasswordShown);
61+
},
62+
[isPasswordShown],
63+
);
64+
5165
return (
5266
<label className={styles.inputComponentWrapper}>
5367
{hasLabel && <span className={styles.label}>{label}</span>}
5468
<span className={styles.inputWrapper}>
5569
<input
5670
{...field}
57-
type={type}
71+
type={isPasswordShown ? 'text' : type}
5872
placeholder={placeholder}
5973
className={getValidClassNames(...inputStyles)}
6074
disabled={isDisabled}
@@ -63,7 +77,16 @@ const Input = <T extends FieldValues>({
6377
step={step}
6478
/>
6579
{type === 'password' && (
66-
<span className={styles.passwordEye}>&#128065;</span>
80+
<button
81+
className={getValidClassNames(
82+
styles.passwordEye,
83+
isPasswordShown && styles.passwordEyeLight,
84+
)}
85+
onClick={toggleShowPassword}
86+
tabIndex={-1}
87+
>
88+
<Icon iconName={IconName.EYE} size="sm" />
89+
</button>
6790
)}
6891
</span>
6992

frontend/src/libs/components/input/styles.module.scss

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,18 @@ $error-message-height: calc($error-font-size * $line-height-coefficient);
8686
.passwordEye {
8787
position: absolute;
8888
top: 8px;
89-
right: 15px;
89+
right: 10px;
90+
color: $grey-dark;
91+
background-color: $white;
92+
border: 0;
9093
cursor: pointer;
9194
user-select: none;
9295
}
9396

97+
.passwordEyeLight {
98+
color: $grey-light;
99+
}
100+
94101
.inputWrapper {
95102
position: relative;
96103
display: block;

frontend/src/libs/enums/icon-name.enum.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ const IconName = {
1111
STAR: 'star',
1212
TRUCK: 'truck',
1313
USERS: 'users',
14+
EYE: 'eye',
1415
} as const;
1516

1617
export { IconName };

0 commit comments

Comments
 (0)