@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
68 lines • 2.92 kB
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import React from 'react';
import { STYLES_NAME } from '../../constants/stylesName/stylesName';
import { useStyles } from '../../hooks/useStyles/useStyles';
import { ErrorBoundary } from '../../provider/errorBoundary/errorBoundary';
import { FallbackComponent } from '../../provider/errorBoundary/fallbackComponent';
import { CalendarStandAlone } from './calendarStandAlone';
import { CalendarVariantType } from './types/variant';
const CalendarComponent = React.forwardRef(({ hasRange = false, variant = CalendarVariantType.DEFAULT, maxDate = new Date(), defaultCurrentDate, onSelectedDateChange, ctv, ...props }, ref) => {
const styles = useStyles(STYLES_NAME.CALENDAR, variant, ctv);
const getCurrentDate = () => {
const _defaultCurrentDate = defaultCurrentDate ?? new Date();
if (!hasRange && props.selectedDate) {
return props.selectedDate;
}
if (date[1]) {
return date[1];
}
else if (date[0]) {
return date[0];
}
return _defaultCurrentDate;
};
const getInitialDate = () => {
let initialDate;
if (hasRange) {
initialDate = [
props.selectedDate ? props.selectedDate : null,
props.secondSelectedDate ? props.secondSelectedDate : null,
];
}
else if (props.selectedDate) {
try {
initialDate = [props.selectedDate];
}
catch {
initialDate = [null];
}
}
else {
initialDate = [null];
}
return initialDate;
};
React.useEffect(() => {
setDate(getInitialDate());
}, [props.selectedDate]);
const [date, setDate] = React.useState(getInitialDate());
const [currentDate, setCurrentDate] = React.useState(getCurrentDate());
React.useEffect(() => {
setCurrentDate(getCurrentDate());
}, [defaultCurrentDate]);
return (_jsx(CalendarStandAlone, { ...props, ref: ref, currentDate: currentDate, hasRange: hasRange, maxDate: maxDate, selectedDate: date, setCurrentDate: setCurrentDate, setSelectedDate: date => {
setDate(date);
onSelectedDateChange?.(date);
}, styles: styles }));
});
CalendarComponent.displayName = 'CalendarComponent';
const CalendarBoundary = (props, ref) => (_jsx(ErrorBoundary, { fallBackComponent: _jsx(FallbackComponent, { children: _jsx(CalendarStandAlone, { ...props, ref: ref }) }), children: _jsx(CalendarComponent, { ...props, ref: ref }) }));
/**
* @description
* Calendar component is a selector of dates, that includes a month and year selector.
* @param {React.PropsWithChildren<ICalendar<V>>} props
* @returns {JSX.Element}
*/
const Calendar = React.forwardRef(CalendarBoundary);
export { Calendar };
//# sourceMappingURL=calendar.js.map