wizard: create new component with add eyeIcon button inside textInput
this commit create new component with add eyeIcon button inside textInput, for password field
This commit is contained in:
parent
f2c5dcc1b3
commit
aa8086176b
2 changed files with 60 additions and 2 deletions
|
|
@ -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';
|
||||
|
||||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
@ -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)}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue