@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
58 lines • 3.45 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import React from 'react';
import { STYLES_NAME } from '../../constants/stylesName/stylesName';
import { useInput } from '../../hooks/useInput/useInput';
import { useStyles } from '../../hooks/useStyles/useStyles';
import { ErrorBoundary } from '../../provider/errorBoundary/errorBoundary';
import { FallbackComponent } from '../../provider/errorBoundary/fallbackComponent';
import { INTERNAL_ERROR_EXECUTION } from '../input/types/input';
import { InputTypeType } from '../input/types/inputType';
import { InputPasswordStandAlone } from './inputPasswordStandAlone';
import { OnIconClickValueType, } from './types/inputPassword';
const InputPasswordComponent = React.forwardRef(({ type = InputTypeType.PASSWORD, internalErrorExecution = 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.useState(type);
const styles = useStyles(STYLES_NAME.INPUT_PASSWORD, props.variant, ctv);
const handleRightIconClick = event => {
const icon = inputPasswordType === InputTypeType.PASSWORD ? disabledIcon : activeIcon;
setInputPasswordType(inputPasswordType === InputTypeType.PASSWORD ? InputTypeType.TEXT : InputTypeType.PASSWORD);
onInputTypeChange && onInputTypeChange();
// deprecated - Remove this icon.onClick when the 'icon' is removed from the component
const iconClickValue = inputPasswordType === InputTypeType.PASSWORD
? OnIconClickValueType.VISIBLE
: OnIconClickValueType.HIDE;
icon.onClick?.(iconClickValue, event);
onIconClick?.(iconClickValue);
};
const { value, state, inputRef, handleChangeInternal, handleBlurInternal, handleFocusInternal, handleKeyDownInternal, handlePasteInternal, } = 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 === InputTypeType.PASSWORD ? disabledIcon : activeIcon;
return (_jsx(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) => (_jsx(ErrorBoundary, { fallBackComponent: _jsx(FallbackComponent, { children: _jsx(InputPasswordStandAlone, { ...props, ref: ref }) }), children: _jsx(InputPasswordComponent, { ...props, ref: ref }) }));
const InputPassword = React.forwardRef(InputPasswordBoundary);
export { InputPassword };
//# sourceMappingURL=inputPassword.js.map