@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
60 lines • 3.31 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import React from 'react';
import { STYLES_NAME } from '../../constants/stylesName/stylesName';
import { useId } from '../../hooks/useId/useId';
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 { InputCounterStandAlone } from './inputCounterStandAlone';
import { buildScreenReaderText } from './utils/counter.utils';
const InputCounterComponent = React.forwardRef(({ type = InputTypeType.TEXT, truncate = false, disabledCopyAndPaste, internalErrorExecution = 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 = useId('inputCounter');
const inputId = props.id ?? uniqueId;
const styles = useStyles(STYLES_NAME.INPUT_COUNTER, props.variant, ctv);
const { value, state, inputRef, handleChangeInternal, handleBlurInternal, handleFocusInternal, handleKeyDownInternal, handlePasteInternal, } = 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.useState(false);
const handleChange = e => {
handleChangeInternal?.(e);
setShowMessage(false);
};
const handleBlur = e => {
handleBlurInternal?.(e);
setShowMessage(true);
};
return (_jsx(InputCounterStandAlone, { ...props, ref: inputRef, id: inputId, informationAssociatedValue: informationAssociatedValue, max: max, maxLength: maxLength, min: min, minLength: minLength, screenReaderCurrentCharacters: 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) => (_jsx(ErrorBoundary, { fallBackComponent: _jsx(FallbackComponent, { children: _jsx(InputCounterStandAlone, { ...props, ref: ref }) }), children: _jsx(InputCounterComponent, { ...props, ref: ref }) }));
const InputCounter = React.forwardRef(InputCounterBoundary);
export { InputCounter };
//# sourceMappingURL=inputCounter.js.map