forked from opendatahub-io/odh-dashboard
-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathPasswordInput.tsx
More file actions
35 lines (31 loc) · 1.01 KB
/
PasswordInput.tsx
File metadata and controls
35 lines (31 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import * as React from 'react';
import { Button, InputGroup, TextInput, InputGroupItem } from '@patternfly/react-core';
import { EyeIcon, EyeSlashIcon } from '@patternfly/react-icons';
type Props = React.ComponentProps<typeof TextInput> & {
ariaLabelShow?: string;
ariaLabelHide?: string;
};
const PasswordInput: React.FC<Props> = ({
ariaLabelShow = 'Show password',
ariaLabelHide = 'Hide password',
...props
}) => {
const [isPasswordHidden, setPasswordHidden] = React.useState(true);
return (
<InputGroup>
<InputGroupItem isFill>
<TextInput {...props} type={isPasswordHidden ? 'password' : 'text'} />
</InputGroupItem>
<InputGroupItem>
<Button
aria-label={isPasswordHidden ? ariaLabelShow : ariaLabelHide}
variant="control"
onClick={() => setPasswordHidden(!isPasswordHidden)}
>
{isPasswordHidden ? <EyeSlashIcon /> : <EyeIcon />}
</Button>
</InputGroupItem>
</InputGroup>
);
};
export default PasswordInput;