@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
75 lines • 4.14 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import React from 'react';
import { useStyles } from '../../hooks/useStyles/useStyles';
import { ErrorBoundary } from '../../provider/errorBoundary/errorBoundary';
import { FallbackComponent } from '../../provider/errorBoundary/fallbackComponent';
import { INTERNAL_ERROR_EXECUTION, MASK_TYPE } from '../input/types/input';
import { InputTypeType } from '../input/types/inputType';
import { useInputDate } from './hooks/useInputDate';
import { InputDateStandAlone } from './inputDateStandAlone';
import { getMask } from './utils/getMask';
import { getPlaceholder } from './utils/getPlaceholder';
const INPUT_DATE_STYLES = 'INPUT_DATE_STYLES';
const InputDateComponent = React.forwardRef(({ type = InputTypeType.TEXT, initialDate, initialSecondDate, dateSeparator = 'to', maskType = MASK_TYPE.NUMBERS, truncate = false, internalErrorExecution = 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 = useStyles(INPUT_DATE_STYLES, props.variant, ctv);
// for date ranges
const DOUBLE_MASK = `${getMask(format)} ${getMask(format)}`;
const mask = hasRange ? DOUBLE_MASK : getMask(format);
const { dateFormatted, calendarOpen, handleClickInput, handlePickCalendarDate, handleOpenCalendar, value, state, inputRef, handleBlurInternal, handleWrapperBlur, handleFocusInternal, handleKeyDownInternal, handleChangeInternal, } = 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: InputTypeType.DATE,
truncate,
informationAssociated: informationAssociatedValue?.content,
ignoreKeys,
name,
onBlur,
onFocus,
onKeyDown,
onChange,
onError,
onInternalErrors,
});
return (_jsx(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: 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) => (_jsx(ErrorBoundary, { fallBackComponent: _jsx(FallbackComponent, { children: _jsx(InputDateStandAlone, { ...props, ref: ref }) }), children: _jsx(InputDateComponent, { ...props, ref: ref }) }));
const InputDate = React.forwardRef(InputDateBoundary);
export { InputDate };
//# sourceMappingURL=inputDate.js.map