@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
63 lines • 4 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.InputCurrency = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const react_1 = __importDefault(require("react"));
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");
// helpers
const input_1 = require("../input/types/input");
const inputType_1 = require("../input/types/inputType");
const inputCurrencyStandAlone_1 = require("./inputCurrencyStandAlone");
const INPUT_CURRENCY_STYLES = 'INPUT_CURRENCY_STYLES';
const InputCurrencyComponent = react_1.default.forwardRef(({ maxDecimals = 2, truncate = true, min = 0, internalErrorExecution = input_1.INTERNAL_ERROR_EXECUTION.ON_CHANGE_ON_BLUR, disabledArrowUpDownInputNumber = false, ignoreKeys = ['+', '-', 'e'], disabledWheelMouse = true, disabledCopyAndPaste, type = inputType_1.InputTypeType.NUMBER, max, errorExecution, keyValidation, maxLength, minLength, mask, maskType, disabled, error, value: currentValue, informationAssociatedValue, regex, formatNumber, locale, variant, onBlur, onChange, onFocus, onKeyDown, onError, onInternalErrors, onPaste, ctv, ...props }, ref) => {
const styles = (0, useStyles_1.useStyles)(INPUT_CURRENCY_STYLES, variant, ctv);
const inputCurrencyType = formatNumber ? inputType_1.InputTypeType.TEXT : type;
// if formatNumber is true (input element of type text), min and maxDecimals should be undefined because it will be handled by the formatNumber function
const inputCurrencyMin = formatNumber ? undefined : min;
const inputCurrencyMaxDecimals = formatNumber ? undefined : maxDecimals;
const { value, state, inputRef, handleChangeInternal, handleBlurInternal, handleFocusInternal, handleKeyDownInternal, handlePasteInternal, } = (0, useInput_1.useInput)({
ref,
errorExecution,
internalErrorExecution,
keyValidation,
max,
min: inputCurrencyMin,
maxLength,
minLength,
mask,
maskType,
disabled,
disabledArrowUpDownInputNumber,
error,
currentValue,
type: inputCurrencyType,
maxDecimals: inputCurrencyMaxDecimals,
truncate,
informationAssociated: informationAssociatedValue?.content,
ignoreKeys,
regex,
formatNumber,
locale,
disabledWheelMouse,
disabledCopyAndPaste,
onBlur,
onChange,
onFocus,
onKeyDown,
onError,
onInternalErrors,
onPaste,
});
return ((0, jsx_runtime_1.jsx)(inputCurrencyStandAlone_1.InputCurrencyStandAlone, { ...props, ref: inputRef, informationAssociatedValue: informationAssociatedValue, max: max, maxDecimals: maxDecimals, maxLength: maxLength, min: inputCurrencyMin, minLength: minLength, state: state, styles: styles, truncate: truncate, type: inputCurrencyType, value: value, onBlur: handleBlurInternal, onChange: handleChangeInternal, onFocus: handleFocusInternal, onKeyDown: handleKeyDownInternal, onPaste: handlePasteInternal }));
});
InputCurrencyComponent.displayName = 'InputCurrencyComponent';
const InputCurrencyBoundary = (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)(inputCurrencyStandAlone_1.InputCurrencyStandAlone, { ...props, ref: ref }) }), children: (0, jsx_runtime_1.jsx)(InputCurrencyComponent, { ...props, ref: ref }) }));
const InputCurrency = react_1.default.forwardRef(InputCurrencyBoundary);
exports.InputCurrency = InputCurrency;
//# sourceMappingURL=inputCurrency.js.map