| 1 |
import { __rest } from "tslib"; |
| 2 |
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime"; |
| 3 |
import { useState } from 'react'; |
| 4 |
import { Form, FormGroup, ActionGroup, FormHelperText } from '../Form'; |
| 5 |
import { TextInput } from '../TextInput'; |
| 6 |
import { Button } from '../Button'; |
| 7 |
import { Checkbox } from '../Checkbox'; |
| 8 |
import { ValidatedOptions } from '../../helpers/constants'; |
| 9 |
import { InputGroup, InputGroupItem } from '../InputGroup'; |
| 10 |
import RhUiViewFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-view-fill-icon'; |
| 11 |
import RhUiViewOffFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-view-off-fill-icon'; |
| 12 |
import { HelperText, HelperTextItem } from '../HelperText'; |
| 13 |
export const LoginForm = (_a) => { |
| 14 |
var { noAutoFocus = false, className = '', showHelperText = false, helperText = null, helperTextIcon = null, usernameLabel = 'Username', usernameValue = '', onChangeUsername = () => undefined, isValidUsername = true, isPasswordRequired = true, passwordLabel = 'Password', passwordValue = '', onChangePassword = () => undefined, isShowPasswordEnabled = false, hidePasswordAriaLabel = 'Hide password', showPasswordAriaLabel = 'Show password', isValidPassword = true, loginButtonLabel = 'Log In', isLoginButtonDisabled = false, onLoginButtonClick = () => undefined, rememberMeLabel = '', isRememberMeChecked = false, onChangeRememberMe = () => undefined } = _a, props = __rest(_a, ["noAutoFocus", "className", "showHelperText", "helperText", "helperTextIcon", "usernameLabel", "usernameValue", "onChangeUsername", "isValidUsername", "isPasswordRequired", "passwordLabel", "passwordValue", "onChangePassword", "isShowPasswordEnabled", "hidePasswordAriaLabel", "showPasswordAriaLabel", "isValidPassword", "loginButtonLabel", "isLoginButtonDisabled", "onLoginButtonClick", "rememberMeLabel", "isRememberMeChecked", "onChangeRememberMe"]); |
| 15 |
const [passwordHidden, setPasswordHidden] = useState(true); |
| 16 |
const passwordInput = (_jsx(TextInput, { isRequired: isPasswordRequired, type: passwordHidden ? 'password' : 'text', id: "pf-login-password-id", name: "pf-login-password-id", validated: isValidPassword ? ValidatedOptions.default : ValidatedOptions.error, value: passwordValue, onChange: onChangePassword })); |
| 17 |
return (_jsxs(Form, Object.assign({ className: className }, props, { children: [showHelperText && (_jsx(FormHelperText, { children: _jsx(HelperText, { children: _jsx(HelperTextItem, { variant: !isValidUsername || !isValidPassword ? 'error' : 'default', icon: helperTextIcon, children: helperText }) }) })), _jsx(FormGroup, { label: usernameLabel, isRequired: true, fieldId: "pf-login-username-id", children: _jsx(TextInput, { autoFocus: !noAutoFocus, id: "pf-login-username-id", isRequired: true, validated: isValidUsername ? ValidatedOptions.default : ValidatedOptions.error, type: "text", name: "pf-login-username-id", value: usernameValue, onChange: onChangeUsername }) }), _jsxs(FormGroup, { label: passwordLabel, isRequired: isPasswordRequired, fieldId: "pf-login-password-id", children: [isShowPasswordEnabled && (_jsxs(InputGroup, { children: [_jsx(InputGroupItem, { isFill: true, children: passwordInput }), _jsx(InputGroupItem, { children: _jsx(Button, { variant: "control", onClick: () => setPasswordHidden(!passwordHidden), "aria-label": passwordHidden ? showPasswordAriaLabel : hidePasswordAriaLabel, icon: passwordHidden ? _jsx(RhUiViewFillIcon, {}) : _jsx(RhUiViewOffFillIcon, {}) }) })] })), !isShowPasswordEnabled && passwordInput] }), rememberMeLabel.length > 0 && (_jsx(FormGroup, { fieldId: "pf-login-remember-me-id", children: _jsx(Checkbox, { id: "pf-login-remember-me-id", label: rememberMeLabel, isChecked: isRememberMeChecked, onChange: onChangeRememberMe }) })), _jsx(ActionGroup, { children: _jsx(Button, { variant: "primary", type: "submit", onClick: onLoginButtonClick, isBlock: true, isDisabled: isLoginButtonDisabled, children: loginButtonLabel }) })] }))); |
| 18 |
}; |
| 19 |
LoginForm.displayName = 'LoginForm'; |
| 20 |
//# sourceMappingURL=LoginForm.js.map |