UNPKG

@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

81 lines 4.74 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.InputDate = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const react_1 = __importDefault(require("react")); 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 useInputDate_1 = require("./hooks/useInputDate"); const inputDateStandAlone_1 = require("./inputDateStandAlone"); const getMask_1 = require("./utils/getMask"); const getPlaceholder_1 = require("./utils/getPlaceholder"); const INPUT_DATE_STYLES = 'INPUT_DATE_STYLES'; const InputDateComponent = react_1.default.forwardRef(({ type = inputType_1.InputTypeType.TEXT, initialDate, initialSecondDate, dateSeparator = 'to', maskType = input_1.MASK_TYPE.NUMBERS, truncate = false, internalErrorExecution = input_1.INTERNAL_ERROR_EXECUTION.ON_CHANGE_ON_BLUR, format, placeholder = format, today, minDate, maxDate, hasRange, onClick, onDateError, onSelectedDateChange, onCalendarOpen, min, max, errorExecution, keyValidation, maxLength, minLength, disabled, error, value: currentValue, informationAssociatedValue, ignoreKeys, onBlur, onWrapperBlur, onFocus, onKeyDown, onChange, onError, onInternalErrors, name, ctv, ...props }, ref) => { const styles = (0, useStyles_1.useStyles)(INPUT_DATE_STYLES, props.variant, ctv); // for date ranges const DOUBLE_MASK = `${(0, getMask_1.getMask)(format)} ${(0, getMask_1.getMask)(format)}`; const mask = hasRange ? DOUBLE_MASK : (0, getMask_1.getMask)(format); const { dateFormatted, calendarOpen, handleClickInput, handlePickCalendarDate, handleOpenCalendar, value, state, inputRef, handleBlurInternal, handleWrapperBlur, handleFocusInternal, handleKeyDownInternal, handleChangeInternal, } = (0, useInputDate_1.useInputDate)({ ref, format, minDate, maxDate, initialDate, initialSecondDate, today, hasRange, dateSeparator, onWrapperBlur, onClick, onDateError, onSelectedDateChange, onCalendarOpen, errorExecution, internalErrorExecution, keyValidation, max, min, maxLength, minLength, mask, maskType, disabled, error, currentValue, type: inputType_1.InputTypeType.DATE, truncate, informationAssociated: informationAssociatedValue?.content, ignoreKeys, name, onBlur, onFocus, onKeyDown, onChange, onError, onInternalErrors, }); return ((0, jsx_runtime_1.jsx)(inputDateStandAlone_1.InputDateStandAlone, { ...props, ref: inputRef, calendarOpen: calendarOpen, dateFormatted: dateFormatted, hasRange: hasRange, icon: { ...props.icon, onClick: event => { handleOpenCalendar(!calendarOpen); props.icon?.onClick?.(event); }, }, informationAssociatedValue: informationAssociatedValue, mask: mask, maskType: maskType, max: max, maxDate: maxDate ?? new Date(), maxLength: maxLength, min: min, minDate: minDate, minLength: minLength, placeholder: (0, getPlaceholder_1.getPlaceholder)(placeholder, state, styles[state]?.label?.type), rightIcon: { ...props.rightIcon, onClick: event => { handleOpenCalendar(!calendarOpen); props.rightIcon?.onClick?.(event); }, }, state: state, styles: styles, truncate: truncate, type: type, value: value, onBlur: handleBlurInternal, onCalendarOpen: handleOpenCalendar, onChange: handleChangeInternal, onClick: handleClickInput, onDateChange: handlePickCalendarDate, onFocus: handleFocusInternal, onKeyDown: handleKeyDownInternal, onWrapperBlur: handleWrapperBlur })); }); InputDateComponent.displayName = 'InputDateComponent'; const InputDateBoundary = (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)(inputDateStandAlone_1.InputDateStandAlone, { ...props, ref: ref }) }), children: (0, jsx_runtime_1.jsx)(InputDateComponent, { ...props, ref: ref }) })); const InputDate = react_1.default.forwardRef(InputDateBoundary); exports.InputDate = InputDate; //# sourceMappingURL=inputDate.js.map