@kubit-ui-web/react-components
Version:
Kubit React Components is a customizable, accessible library of React web components, designed to enhance your application's user experience
64 lines • 4.11 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.InputPassword = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = __importDefault(require("react"));
const stylesName_1 = require("../../constants/stylesName/stylesName");
const useInput_1 = require("../../hooks/useInput/useInput");
const useStyles_1 = require("../../hooks/useStyles/useStyles");
const errorBoundary_1 = require("../../provider/errorBoundary/errorBoundary");
const fallbackComponent_1 = require("../../provider/errorBoundary/fallbackComponent");
const input_1 = require("../input/types/input");
const inputType_1 = require("../input/types/inputType");
const inputPasswordStandAlone_1 = require("./inputPasswordStandAlone");
const inputPassword_1 = require("./types/inputPassword");
const InputPasswordComponent = react_1.default.forwardRef(({ type = inputType_1.InputTypeType.PASSWORD, internalErrorExecution = input_1.INTERNAL_ERROR_EXECUTION.ON_CHANGE_ON_BLUR, errorExecution, keyValidation, maxLength, mask, maskType, disabled, error, value: currentValue, ignoreKeys, disabledCopyAndPaste, onBlur, onChange, onFocus, onKeyDown, onError, onInternalErrors, activeIcon, disabledIcon, onInputTypeChange, onIconClick, onPaste, ctv, ...props }, ref) => {
const [inputPasswordType, setInputPasswordType] = react_1.default.useState(type);
const styles = (0, useStyles_1.useStyles)(stylesName_1.STYLES_NAME.INPUT_PASSWORD, props.variant, ctv);
const handleRightIconClick = event => {
const icon = inputPasswordType === inputType_1.InputTypeType.PASSWORD ? disabledIcon : activeIcon;
setInputPasswordType(inputPasswordType === inputType_1.InputTypeType.PASSWORD ? inputType_1.InputTypeType.TEXT : inputType_1.InputTypeType.PASSWORD);
onInputTypeChange && onInputTypeChange();
// deprecated - Remove this icon.onClick when the 'icon' is removed from the component
const iconClickValue = inputPasswordType === inputType_1.InputTypeType.PASSWORD
? inputPassword_1.OnIconClickValueType.VISIBLE
: inputPassword_1.OnIconClickValueType.HIDE;
icon.onClick?.(iconClickValue, event);
onIconClick?.(iconClickValue);
};
const { value, state, inputRef, handleChangeInternal, handleBlurInternal, handleFocusInternal, handleKeyDownInternal, handlePasteInternal, } = (0, useInput_1.useInput)({
ref,
errorExecution,
internalErrorExecution,
keyValidation,
maxLength,
mask,
maskType,
disabled,
error,
currentValue,
type: inputPasswordType,
ignoreKeys,
disabledCopyAndPaste,
onBlur,
onChange,
onFocus,
onKeyDown,
onError,
onInternalErrors,
onPaste,
});
const icon = inputPasswordType === inputType_1.InputTypeType.PASSWORD ? disabledIcon : activeIcon;
return ((0, jsx_runtime_1.jsx)(inputPasswordStandAlone_1.InputPasswordStandAlone, { ...props, ref: inputRef, maxLength: maxLength, rightIcon: {
...icon,
onClick: handleRightIconClick,
}, state: state, styles: styles, type: inputPasswordType, value: value, onBlur: handleBlurInternal, onChange: handleChangeInternal, onFocus: handleFocusInternal, onKeyDown: handleKeyDownInternal, onPaste: handlePasteInternal }));
});
InputPasswordComponent.displayName = 'InputPasswordComponent';
const InputPasswordBoundary = (props, ref) => ((0, jsx_runtime_1.jsx)(errorBoundary_1.ErrorBoundary, { fallBackComponent: (0, jsx_runtime_1.jsx)(fallbackComponent_1.FallbackComponent, { children: (0, jsx_runtime_1.jsx)(inputPasswordStandAlone_1.InputPasswordStandAlone, { ...props, ref: ref }) }), children: (0, jsx_runtime_1.jsx)(InputPasswordComponent, { ...props, ref: ref }) }));
const InputPassword = react_1.default.forwardRef(InputPasswordBoundary);
exports.InputPassword = InputPassword;
//# sourceMappingURL=inputPassword.js.map