Skip to content

Commit aa46097

Browse files
authored
feat: add toggle password visibility (#113)
* feature: add toggle password visibility * separate password into standalone component
1 parent c868485 commit aa46097

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { faEye, faEyeSlash } from '@fortawesome/free-solid-svg-icons';
2+
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome';
3+
import { useState } from 'react';
4+
import TextField, { TextFieldCommonProps } from 'renderer/components/TextField';
5+
6+
export default function PasswordField({
7+
label,
8+
value,
9+
autoFocus,
10+
onChange,
11+
placeholder,
12+
readOnly,
13+
}: TextFieldCommonProps) {
14+
const props = {
15+
label,
16+
value,
17+
autoFocus,
18+
onChange,
19+
placeholder,
20+
readOnly,
21+
};
22+
const [showPassword, setShowPassword] = useState(false);
23+
24+
return (
25+
<TextField
26+
type={showPassword ? 'text' : 'password'}
27+
actionClick={() => setShowPassword(!showPassword)}
28+
actionIcon={
29+
showPassword ? (
30+
<FontAwesomeIcon icon={faEye} />
31+
) : (
32+
<FontAwesomeIcon icon={faEyeSlash} />
33+
)
34+
}
35+
{...props}
36+
/>
37+
);
38+
}

src/renderer/components/TextField/index.tsx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
import { ReactElement } from 'react';
22
import styles from './styles.module.scss';
33

4-
interface TextFieldProps {
4+
export interface TextFieldCommonProps {
5+
readOnly?: boolean;
6+
onChange?: (value: string) => void;
57
label?: string;
68
value?: string;
79
autoFocus?: boolean;
810
placeholder?: string;
11+
}
12+
13+
interface TextFieldProps extends TextFieldCommonProps {
914
multipleLine?: boolean;
1015
type?: 'text' | 'password';
11-
onChange?: (value: string) => void;
1216
actionIcon?: ReactElement;
1317
actionClick?: () => void;
14-
readOnly?: boolean;
1518
}
1619

1720
export default function TextField({

src/renderer/screens/HomeScreen/ConnectionConfigEditor/MySQLConnectionEditor.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
} from 'drivers/SQLLikeConnection';
55
import Stack from 'renderer/components/Stack';
66
import TextField from 'renderer/components/TextField';
7+
import PasswordField from 'renderer/components/PasswordField';
78

89
export default function MySQLConnectionEditor({
910
config,
@@ -31,8 +32,7 @@ export default function MySQLConnectionEditor({
3132
value={config?.user}
3233
onChange={(value) => onChange({ ...config, user: value })}
3334
/>
34-
<TextField
35-
type="password"
35+
<PasswordField
3636
label="Password"
3737
value={config?.password}
3838
onChange={(value) => onChange({ ...config, password: value })}

0 commit comments

Comments
 (0)