Skip to content

Commit

Permalink
wizard: create new component with add eyeIcon button inside textInput
Browse files Browse the repository at this point in the history
this commit create new component with add eyeIcon button inside textInput,
for password field
  • Loading branch information
mgold1234 authored and lucasgarfield committed Jan 27, 2025
1 parent f2c5dcc commit d94279e
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 2 deletions.
55 changes: 55 additions & 0 deletions src/Components/CreateImageWizard/ValidatedInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import {
TextAreaProps,
TextInput,
TextInputProps,
Button,
InputGroup,
InputGroupItem,
} from '@patternfly/react-core';
import { EyeIcon, EyeSlashIcon } from '@patternfly/react-icons';

import type { StepValidation } from './utilities/useValidation';

Expand All @@ -34,6 +38,57 @@ type HookValidatedInputPropTypes = TextInputProps &
inputType?: 'textInput' | 'textArea';
};

export const HookPasswordValidatedInput = ({
ariaLabel,
placeholder,
dataTestId,
value,
ouiaId,
stepValidation,
fieldName,
onChange,
warning = undefined,
inputType,
isDisabled,
}: HookValidatedInputPropTypes) => {
const [isPasswordVisible, setIsPasswordVisible] = useState(false);
const togglePasswordVisibility = () => {
setIsPasswordVisible(!isPasswordVisible);
};

return (
<>
<InputGroup>
<InputGroupItem isFill>
<HookValidatedInput
type={isPasswordVisible ? 'text' : 'password'}
ouiaId={ouiaId || ''}
data-testid={dataTestId}
value={value}
onChange={onChange!}
stepValidation={stepValidation}
ariaLabel={ariaLabel || ''}
fieldName={fieldName}
placeholder={placeholder || ''}
inputType={inputType || 'textInput'}
warning={warning || ''}
isDisabled={isDisabled || false}
/>
</InputGroupItem>
<InputGroupItem>
<Button
variant="control"
onClick={togglePasswordVisibility}
aria-label={isPasswordVisible ? 'Show password' : 'Hide password'}
>
{isPasswordVisible ? <EyeSlashIcon /> : <EyeIcon />}
</Button>
</InputGroupItem>
</InputGroup>
</>
);
};

export const HookValidatedInput = ({
dataTestId,
ouiaId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import {
setUserAdministratorByIndex,
} from '../../../../../store/wizardSlice';
import { useUsersValidation } from '../../../utilities/useValidation';
import { HookValidatedInput } from '../../../ValidatedInput';
import {
HookPasswordValidatedInput,
HookValidatedInput,
} from '../../../ValidatedInput';
const UserInfo = () => {
const dispatch = useAppDispatch();
const index = 0;
Expand Down Expand Up @@ -74,7 +77,7 @@ const UserInfo = () => {
/>
</FormGroup>
<FormGroup isRequired label="Password">
<HookValidatedInput
<HookPasswordValidatedInput
ariaLabel="blueprint user password"
value={userPassword || ''}
onChange={(_e, value) => handlePasswordChange(_e, value)}
Expand Down

0 comments on commit d94279e

Please sign in to comment.