@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
66 lines • 3.9 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.InputCounter = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = __importDefault(require("react"));
const stylesName_1 = require("../../constants/stylesName/stylesName");
const useId_1 = require("../../hooks/useId/useId");
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 inputCounterStandAlone_1 = require("./inputCounterStandAlone");
const counter_utils_1 = require("./utils/counter.utils");
const InputCounterComponent = react_1.default.forwardRef(({ type = inputType_1.InputTypeType.TEXT, truncate = false, disabledCopyAndPaste, internalErrorExecution = input_1.INTERNAL_ERROR_EXECUTION.ON_CHANGE_ON_BLUR, errorExecution, keyValidation, min, max, maxLength, minLength, mask, maskType, disabled, error, value: currentValue, informationAssociatedValue, ignoreKeys, regex, onBlur, onChange, onFocus, onKeyDown, onError, onInternalErrors, onPaste, ctv, ...props }, ref) => {
const uniqueId = (0, useId_1.useId)('inputCounter');
const inputId = props.id ?? uniqueId;
const styles = (0, useStyles_1.useStyles)(stylesName_1.STYLES_NAME.INPUT_COUNTER, props.variant, ctv);
const { value, state, inputRef, handleChangeInternal, handleBlurInternal, handleFocusInternal, handleKeyDownInternal, handlePasteInternal, } = (0, useInput_1.useInput)({
ref,
errorExecution,
internalErrorExecution,
keyValidation,
max,
min,
maxLength,
minLength,
mask,
maskType,
disabled,
error,
currentValue,
type,
truncate,
informationAssociated: informationAssociatedValue?.content,
ignoreKeys,
regex,
disabledCopyAndPaste,
onBlur,
onChange,
onFocus,
onKeyDown,
onError,
onInternalErrors,
onPaste,
});
const [showMessage, setShowMessage] = react_1.default.useState(false);
const handleChange = e => {
handleChangeInternal?.(e);
setShowMessage(false);
};
const handleBlur = e => {
handleBlurInternal?.(e);
setShowMessage(true);
};
return ((0, jsx_runtime_1.jsx)(inputCounterStandAlone_1.InputCounterStandAlone, { ...props, ref: inputRef, id: inputId, informationAssociatedValue: informationAssociatedValue, max: max, maxLength: maxLength, min: min, minLength: minLength, screenReaderCurrentCharacters: (0, counter_utils_1.buildScreenReaderText)(value, ref, maxLength, props.screenReaderCurrentCharacters), showMessage: showMessage, state: state, styles: styles, truncate: truncate, type: type, value: value, onBlur: handleBlur, onChange: handleChange, onFocus: handleFocusInternal, onKeyDown: handleKeyDownInternal, onPaste: handlePasteInternal }));
});
InputCounterComponent.displayName = 'InputCounterComponent';
const InputCounterBoundary = (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)(inputCounterStandAlone_1.InputCounterStandAlone, { ...props, ref: ref }) }), children: (0, jsx_runtime_1.jsx)(InputCounterComponent, { ...props, ref: ref }) }));
const InputCounter = react_1.default.forwardRef(InputCounterBoundary);
exports.InputCounter = InputCounter;
//# sourceMappingURL=inputCounter.js.map