UNPKG

@yamada-ui/react

Version:

React UI components of the Yamada, by the Yamada, for the Yamada built with React and Emotion

688 lines (684 loc) • 28.2 kB
"use client"; const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs'); const require_context = require('../../utils/context.cjs'); const require_dom = require('../../utils/dom.cjs'); const require_effect = require('../../utils/effect.cjs'); const require_ref = require('../../utils/ref.cjs'); const require_utils_index = require('../../utils/index.cjs'); const require_props = require('../../core/components/props.cjs'); const require_hooks_use_controllable_state_index = require('../../hooks/use-controllable-state/index.cjs'); const require_hooks_use_descendants_index = require('../../hooks/use-descendants/index.cjs'); const require_i18n_provider = require('../../providers/i18n-provider/i18n-provider.cjs'); const require_use_format_date_time = require('../format/use-format-date-time.cjs'); let react = require("react"); react = require_rolldown_runtime.__toESM(react); let dayjs = require("dayjs"); dayjs = require_rolldown_runtime.__toESM(dayjs); //#region src/components/calendar/use-calendar.ts const DEFAULT_HOLIDAYS = []; const DEFAULT_WEEKEND_DAYS = [0, 6]; const DEFAULT_FIRST_DAY_OF_WEEK = "sunday"; const DEFAULT_MAX_DATE = /* @__PURE__ */ new Date("2099-12-31"); const DEFAULT_MIN_DATE = /* @__PURE__ */ new Date("1900-01-01"); const getStartOfWeek = (date, startDayOfWeek) => (0, dayjs.default)(date).subtract(startDayOfWeek === "monday" ? 1 : 0, "day").startOf("week").add(startDayOfWeek === "monday" ? 1 : 0, "day").toDate(); const getEndOfWeek = (date, startDayOfWeek) => (0, dayjs.default)(date).subtract(startDayOfWeek === "monday" ? 1 : 0, "day").endOf("week").add(startDayOfWeek === "monday" ? 1 : 0, "day").toDate(); const getWeekdays = (startDayOfWeek, format) => { let weekdays = []; const date = getStartOfWeek(/* @__PURE__ */ new Date(), startDayOfWeek); for (let i = 0; i < 7; i += 1) { const label = format(date); const value = date.getDay(); weekdays = [...weekdays, { label, value }]; date.setDate(date.getDate() + 1); } return weekdays; }; const getMonthDays = (date, startDayOfWeek, format) => { const currentMonth = date.getMonth(); const startOfMonth = new Date(date.getFullYear(), currentMonth, 1); const endOfMonth = new Date(date.getFullYear(), date.getMonth() + 1, 0); const startDate = getStartOfWeek(startOfMonth, startDayOfWeek); const endDate = getEndOfWeek(endOfMonth, startDayOfWeek); const weeks = []; while (startDate <= endDate) { const days = []; for (let i = 0; i < 7; i += 1) { const value = new Date(startDate); const label = format(value); days.push({ label, value }); startDate.setDate(startDate.getDate() + 1); } weeks.push(days); } return weeks; }; const isSameYear = (date, comparison) => date instanceof Date && comparison instanceof Date && (0, dayjs.default)(date).isSame(comparison, "year"); const isSameMonth = (date, comparison) => date instanceof Date && comparison instanceof Date && (0, dayjs.default)(date).isSame(comparison, "month"); const isSameDate = (date, comparison) => date instanceof Date && comparison instanceof Date && (0, dayjs.default)(date).isSame(comparison, "date"); const isAfterDate = (value, date) => date instanceof Date && (0, dayjs.default)(value).isAfter(date, "date"); const isBeforeDate = (value, date) => date instanceof Date && (0, dayjs.default)(value).isBefore(date, "date"); const isSameAfterDate = (value, date) => date instanceof Date && ((0, dayjs.default)(date).isSame(value, "date") || (0, dayjs.default)(value).isAfter(date, "date")); const isSameBeforeDate = (value, date) => date instanceof Date && ((0, dayjs.default)(date).isSame(value, "date") || (0, dayjs.default)(value).isBefore(date, "date")); const isAfterMonth = (value, date) => date instanceof Date && (0, dayjs.default)(value).isAfter(date, "month"); const isBeforeMonth = (value, date) => date instanceof Date && (0, dayjs.default)(value).isBefore(date, "month"); const isSameAfterMonth = (value, date) => date instanceof Date && ((0, dayjs.default)(date).isSame(value, "month") || (0, dayjs.default)(value).isAfter(date, "month")); const isSameBeforeMonth = (value, date) => date instanceof Date && ((0, dayjs.default)(date).isSame(value, "month") || (0, dayjs.default)(value).isBefore(date, "month")); const isAfterYear = (value, date) => date instanceof Date && (0, dayjs.default)(value).isAfter(date, "year"); const isBeforeYear = (value, date) => date instanceof Date && (0, dayjs.default)(value).isBefore(date, "year"); const isSameAfterYear = (value, date) => date instanceof Date && ((0, dayjs.default)(date).isSame(value, "year") || (0, dayjs.default)(value).isAfter(date, "year")); const isSameBeforeYear = (value, date) => date instanceof Date && ((0, dayjs.default)(date).isSame(value, "year") || (0, dayjs.default)(value).isBefore(date, "year")); const isIncludeDates = (comparison, dates) => dates.some((date) => (0, dayjs.default)(date).isSame(comparison, "date")); const isInRange = (date, minDate, maxDate) => { const hasMinDate = minDate instanceof Date; const hasMaxDate = maxDate instanceof Date; if (!hasMaxDate && !hasMinDate) return false; const minInRange = hasMinDate ? isAfterDate(date, minDate) : false; return (hasMaxDate ? isBeforeDate(date, maxDate) : false) && minInRange; }; const sortDates = (dates, type = "asc") => { if (type === "asc") return dates.sort((a, b) => (0, dayjs.default)(a).isAfter(b, "date") ? 1 : -1); else return dates.sort((a, b) => (0, dayjs.default)(a).isBefore(b, "date") ? 1 : -1); }; const updateMaybeDateValue = (value, max) => (prev) => { if ((0, require_utils_index.utils_exports.isArray)(prev)) if (isIncludeDates(value, prev)) return prev.filter((prevValue) => !isSameDate(prevValue, value)); else if (!(0, require_utils_index.utils_exports.isNumber)(max) || prev.length < max) return [...prev, value]; else return prev; else if ((0, require_utils_index.utils_exports.isObject)(prev) && !(0, require_utils_index.utils_exports.isDate)(prev)) { const { end, start } = prev; if (start && end || !start) return { end: void 0, start: value }; else if (isSameDate(start, value)) return { end: void 0, start: void 0 }; else if (isBeforeDate(value, start)) return { end: start, start: value }; else return { end: value, start }; } else if (isSameDate(prev, value)) return; else return value; }; const getAdjustedMonth = (value, month) => { if ((0, require_utils_index.utils_exports.isDate)(value)) { if (!isSameMonth(value, month)) month = (0, dayjs.default)(value).set("date", 1).toDate(); } else if ((0, require_utils_index.utils_exports.isArray)(value)) { const lastValue = value.at(-1); if (lastValue && !isSameMonth(lastValue, month)) month = (0, dayjs.default)(lastValue).set("date", 1).toDate(); } else if ((0, require_utils_index.utils_exports.isObject)(value)) { if (value.end) month = (0, dayjs.default)(value.end).set("date", 1).toDate(); else if (value.start) month = (0, dayjs.default)(value.start).set("date", 1).toDate(); } return month; }; const { DescendantsContext: CalendarDescendantsContext, useDescendant: useCalendarDescendant, useDescendants: useCalendarDescendants } = require_hooks_use_descendants_index.createDescendants(); const [CalendarContext, useCalendarContext] = require_context.createContext({ name: "CalendarContext" }); const useCalendar = ({ defaultMonth = /* @__PURE__ */ new Date(), multiple = false, range = false, defaultValue = range ? { end: void 0, start: void 0 } : multiple ? [] : void 0, disabled = false, excludeDate, format = {}, holidays = DEFAULT_HOLIDAYS, locale: localeProp, max, maxDate = DEFAULT_MAX_DATE, minDate = DEFAULT_MIN_DATE, month: monthProp, startDayOfWeek = DEFAULT_FIRST_DAY_OF_WEEK, today = true, value: valueProp, weekendDays = DEFAULT_WEEKEND_DAYS, onChange: onChangeProp, onChangeMonth: onChangeMonthProp,...rest } = {}) => { if ((0, dayjs.default)(minDate).isAfter((0, dayjs.default)(maxDate))) maxDate = minDate; const { locale: defaultLocale, t } = require_i18n_provider.useI18n("calendar"); const locale = localeProp ?? defaultLocale; const dateTimeFormat = require_use_format_date_time.useDateTimeFormat({ locale }); const yearFormat = (0, react.useCallback)((value$1) => { if (format.year === null) return value$1.getFullYear().toString(); else return dateTimeFormat(value$1, { year: format.year ?? "numeric" }); }, [dateTimeFormat, format.year]); const monthFormat = (0, react.useCallback)((value$1) => { if (format.month === null) return (value$1.getMonth() + 1).toString(); else return dateTimeFormat(value$1, { month: format.month ?? "short" }); }, [dateTimeFormat, format.month]); const weekdayFormat = (0, react.useCallback)((value$1) => { return dateTimeFormat(value$1, { weekday: format.weekday ?? "short" }); }, [dateTimeFormat, format.weekday]); const dayFormat = (0, react.useCallback)((value$1) => { if (format.day) return dateTimeFormat(value$1, { day: format.day }); else return value$1.getDate().toString(); }, [dateTimeFormat, format.day]); const descendants = useCalendarDescendants(); const monthRef = (0, react.useRef)(null); const [value, setValue] = require_hooks_use_controllable_state_index.useControllableState({ defaultValue, value: valueProp, onChange: onChangeProp }); const [month, setMonth] = require_hooks_use_controllable_state_index.useControllableState({ defaultValue: () => { if ((0, dayjs.default)(minDate).isAfter((0, dayjs.default)(defaultMonth))) defaultMonth = (0, dayjs.default)(minDate).set("date", 1).toDate(); if (valueProp) defaultMonth = getAdjustedMonth(valueProp, defaultMonth); else if (defaultValue) defaultMonth = getAdjustedMonth(defaultValue, defaultMonth); return defaultMonth; }, value: monthProp, onChange: onChangeMonthProp }); const { endOfMonth, startOfMonth } = (0, react.useMemo)(() => { const startOfMonth$1 = (0, dayjs.default)(month).startOf("month").toDate(); return { endOfMonth: (0, dayjs.default)(month).endOf("month").toDate(), startOfMonth: startOfMonth$1 }; }, [month]); const weekdays = (0, react.useMemo)(() => getWeekdays(startDayOfWeek, weekdayFormat), [startDayOfWeek, weekdayFormat]); const monthDays = (0, react.useMemo)(() => getMonthDays(month, startDayOfWeek, dayFormat), [ month, startDayOfWeek, dayFormat ]); const yearItems = (0, react.useMemo)(() => { const minYear = (0, dayjs.default)(minDate).year(); const maxYear = (0, dayjs.default)(maxDate).year(); const yearItems$1 = []; for (let year = minYear; year <= maxYear; year++) { const label = yearFormat((0, dayjs.default)().set("year", year).toDate()); const value$1 = year.toString(); yearItems$1.push({ label, value: value$1 }); } return yearItems$1; }, [ maxDate, minDate, yearFormat ]); const monthItems = (0, react.useMemo)(() => { const monthItems$1 = []; const date = (0, dayjs.default)(month).toDate(); for (let month$1 = 0; month$1 < 12; month$1++) { date.setMonth(month$1); if (isAfterMonth(date, maxDate)) continue; if (isBeforeMonth(date, minDate)) continue; const label = monthFormat((0, dayjs.default)().set("month", month$1).toDate()); const value$1 = month$1.toString(); monthItems$1.push({ label, value: value$1 }); } return monthItems$1; }, [ month, maxDate, minDate, monthFormat ]); const onChange = (0, react.useCallback)((value$1) => { if (isBeforeDate(value$1, minDate)) return; if (isAfterDate(value$1, maxDate)) return; setValue((prev) => updateMaybeDateValue(value$1, max)(prev)); }, [ max, maxDate, minDate, setValue ]); const onMonthChange = (0, react.useCallback)((month$1) => { if (isAfterMonth(month$1, maxDate)) setMonth((0, dayjs.default)(maxDate).set("date", 1).toDate()); else if (isBeforeMonth(month$1, minDate)) setMonth((0, dayjs.default)(minDate).set("date", 1).toDate()); else setMonth((prev) => { if (isSameMonth(prev, month$1)) return prev; return month$1; }); }, [ maxDate, minDate, setMonth ]); const onPrevMonth = (0, react.useCallback)(() => { setMonth((prev) => { if (isSameMonth(prev, minDate)) return prev; return (0, dayjs.default)(prev).subtract(1, "month").toDate(); }); }, [minDate, setMonth]); const onNextMonth = (0, react.useCallback)(() => { setMonth((prev) => { if (isSameMonth(prev, maxDate)) return prev; return (0, dayjs.default)(prev).add(1, "month").toDate(); }); }, [maxDate, setMonth]); const onFocus = (0, react.useCallback)(() => { let index = null; let descendant; if (value) { if ((0, require_utils_index.utils_exports.isDate)(value)) { if (isSameMonth(month, /* @__PURE__ */ new Date())) index = (/* @__PURE__ */ new Date()).getDate() - 1; } else if ((0, require_utils_index.utils_exports.isArray)(value)) { const firstValue = value[0]; if (firstValue && isSameMonth(month, firstValue)) index = firstValue.getDate() - 1; } else if ((0, require_utils_index.utils_exports.isObject)(value)) { if (value.start && isSameMonth(month, value.start)) index = value.start.getDate() - 1; else if (value.end && isSameMonth(month, value.end)) index = value.end.getDate() - 1; } } else if (isSameMonth(month, /* @__PURE__ */ new Date())) index = (/* @__PURE__ */ new Date()).getDate() - 1; descendant = descendants.value(index); if (!descendant) descendant = descendants.enabledFirstValue(); if (!descendant) return; descendant.node.focus(); descendant.node.tabIndex = 0; if (monthRef.current) monthRef.current.tabIndex = -1; }, [ descendants, month, value ]); const onBlur = (0, react.useCallback)((ev) => { if ((0, require_utils_index.utils_exports.contains)(monthRef.current, ev.relatedTarget)) return; if (monthRef.current) monthRef.current.tabIndex = 0; }, []); require_effect.useUpdateEffect(() => { setMonth((prev) => getAdjustedMonth(value, prev)); }, [value]); const getRootProps = (0, react.useCallback)((props = {}) => ({ "data-disabled": (0, require_utils_index.utils_exports.dataAttr)(disabled), ...rest, ...props }), [disabled, rest]); const getNavigationProps = (0, react.useCallback)((props = {}) => ({ "data-disabled": (0, require_utils_index.utils_exports.dataAttr)(disabled), ...props }), [disabled]); const getYearSelectProps = (0, react.useCallback)((props = {}) => ({ "aria-label": t("Choose the year"), disabled, value: (0, dayjs.default)(month).get("year").toString(), ...props, onChange: (0, require_utils_index.utils_exports.handlerAll)(props.onChange, (value$1) => onMonthChange((0, dayjs.default)(month).set("year", parseInt(value$1)).toDate())) }), [ disabled, month, onMonthChange, t ]); const getMonthSelectProps = (0, react.useCallback)((props = {}) => ({ "aria-label": t("Choose the month"), disabled, value: (0, dayjs.default)(month).get("month").toString(), ...props, onChange: (0, require_utils_index.utils_exports.handlerAll)(props.onChange, (value$1) => onMonthChange((0, dayjs.default)(month).set("month", parseInt(value$1)).toDate())) }), [ disabled, month, onMonthChange, t ]); const getStatusProps = (0, react.useCallback)((props = {}) => ({ style: require_dom.visuallyHiddenAttributes.style, "aria-live": "polite", children: dateTimeFormat((0, dayjs.default)(month).toDate(), { month: "long", year: "numeric" }), role: "status", ...props }), [dateTimeFormat, month]); const getMonthProps = (0, react.useCallback)(({ ref,...props } = {}) => ({ ref: require_ref.mergeRefs(ref, monthRef), "aria-label": dateTimeFormat((0, dayjs.default)(month).toDate(), { month: "long", year: "numeric" }), "aria-multiselectable": (0, require_utils_index.utils_exports.ariaAttr)(multiple || range), "data-disabled": (0, require_utils_index.utils_exports.dataAttr)(disabled), role: "grid", tabIndex: disabled ? -1 : 0, ...props, onBlur: (0, require_utils_index.utils_exports.handlerAll)(props.onBlur, onBlur), onFocus: (0, require_utils_index.utils_exports.handlerAll)(props.onFocus, onFocus) }), [ dateTimeFormat, disabled, month, multiple, onBlur, onFocus, range ]); const getWeekdayProps = (0, react.useCallback)(({ value: value$1,...props }) => ({ "data-disabled": (0, require_utils_index.utils_exports.dataAttr)(disabled), "data-value": value$1.toString(), abbr: dateTimeFormat((0, dayjs.default)().set("day", value$1).toDate(), { weekday: "long" }), ...props }), [dateTimeFormat, disabled]); const getButtonProps = (0, react.useCallback)((props) => ({ type: "button", "data-disabled": (0, require_utils_index.utils_exports.dataAttr)(disabled), ...props }), [disabled]); const getPrevButtonProps = (0, react.useCallback)((props = {}) => getButtonProps({ "aria-label": t("Go to the previous month"), disabled: isSameBeforeMonth(month, minDate), ...props, onClick: (0, require_utils_index.utils_exports.handlerAll)(props.onClick, onPrevMonth) }), [ getButtonProps, minDate, month, onPrevMonth, t ]); const getNextButtonProps = (0, react.useCallback)((props = {}) => getButtonProps({ "aria-label": t("Go to the next month"), disabled: isSameAfterMonth(month, maxDate), ...props, onClick: (0, require_utils_index.utils_exports.handlerAll)(props.onClick, onNextMonth) }), [ getButtonProps, maxDate, month, onNextMonth, t ]); return { descendants, disabled, endOfMonth, excludeDate, holidays, locale, max, maxDate, minDate, month, monthDays, monthItems, multiple, range, startDayOfWeek, startOfMonth, today, value, weekdays, weekendDays, yearItems, getMonthProps, getMonthSelectProps, getNavigationProps, getNextButtonProps, getPrevButtonProps, getRootProps, getStatusProps, getWeekdayProps, getYearSelectProps, onChange, onMonthChange, onNextMonth, onPrevMonth }; }; const useCalendarDay = ({ value,...rest }) => { const { t } = require_i18n_provider.useI18n("calendar"); const { disabled: rootDisabled, excludeDate, holidays, locale, max, maxDate, minDate, month, startDayOfWeek, today: highlightToday, value: selectedValue, weekendDays, onChange, onMonthChange, onNextMonth, onPrevMonth } = useCalendarContext(); const dateTimeFormat = require_use_format_date_time.useDateTimeFormat({ locale }); const cellRef = (0, react.useRef)(null); const outside = (0, react.useMemo)(() => !isSameMonth(month, value), [month, value]); const holiday = (0, react.useMemo)(() => holidays.some((holiday$1) => isSameDate(holiday$1, value)), [holidays, value]); const weekend = (0, react.useMemo)(() => weekendDays.includes(value.getDay()), [weekendDays, value]); const today = (0, react.useMemo)(() => highlightToday && isSameDate(value, /* @__PURE__ */ new Date()), [highlightToday, value]); const selected = (0, react.useMemo)(() => { if ((0, require_utils_index.utils_exports.isDate)(selectedValue)) return isSameDate(selectedValue, value); else if ((0, require_utils_index.utils_exports.isArray)(selectedValue)) return selectedValue.some((selectedValue$1) => isSameDate(selectedValue$1, value)); else if ((0, require_utils_index.utils_exports.isObject)(selectedValue)) return isSameDate(selectedValue.start, value) || isSameDate(selectedValue.end, value); }, [selectedValue, value]); const disabled = (0, react.useMemo)(() => { if (rootDisabled) return true; if (isAfterDate(value, maxDate)) return true; if (isBeforeDate(value, minDate)) return true; if (excludeDate?.(value)) return true; if ((0, require_utils_index.utils_exports.isArray)(selectedValue) && (0, require_utils_index.utils_exports.isNumber)(max) && selectedValue.length >= max && !isIncludeDates(value, selectedValue)) return true; return false; }, [ excludeDate, max, maxDate, minDate, rootDisabled, selectedValue, value ]); const between = (0, react.useMemo)(() => { if ((0, require_utils_index.utils_exports.isDate)(selectedValue) || (0, require_utils_index.utils_exports.isArray)(selectedValue)) return false; return isInRange(value, selectedValue?.start, selectedValue?.end); }, [selectedValue, value]); const startValue = (0, react.useMemo)(() => { if ((0, require_utils_index.utils_exports.isDate)(selectedValue) || (0, require_utils_index.utils_exports.isArray)(selectedValue)) return false; const { end, start } = selectedValue ?? {}; return start && end && isSameDate(value, start); }, [selectedValue, value]); const endValue = (0, react.useMemo)(() => { if ((0, require_utils_index.utils_exports.isDate)(selectedValue) || (0, require_utils_index.utils_exports.isArray)(selectedValue)) return false; const { end, start } = selectedValue ?? {}; return start && end && isSameDate(value, end); }, [selectedValue, value]); const { descendants, register } = useCalendarDescendant({ disabled }); const onFocusDescendant = (0, react.useCallback)((descendant) => { if (!descendant) return; descendant.node.focus(); descendant.node.tabIndex = 0; }, []); const onBlur = (0, react.useCallback)(() => { if (cellRef.current) cellRef.current.tabIndex = -1; }, []); const onClick = (0, react.useCallback)(() => { if (disabled) return; onChange(value); }, [ disabled, onChange, value ]); const onPrevDate = (0, react.useCallback)(() => { const descendant = descendants.enabledPrevValue(cellRef.current, false); if (descendant) onFocusDescendant(descendant); else if (!isSameBeforeDate(value, minDate)) { onPrevMonth(); setTimeout(() => onFocusDescendant(descendants.enabledLastValue())); } }, [ descendants, minDate, onFocusDescendant, onPrevMonth, value ]); const onNextDate = (0, react.useCallback)(() => { const descendant = descendants.enabledNextValue(cellRef.current, false); if (descendant) onFocusDescendant(descendant); else if (!isSameAfterDate(value, maxDate)) { onNextMonth(); setTimeout(() => onFocusDescendant(descendants.enabledFirstValue())); } }, [ descendants, maxDate, onFocusDescendant, onNextMonth, value ]); const onPrevTraverseDate = (0, react.useCallback)((date) => { onMonthChange((0, dayjs.default)(date).set("date", 1).toDate()); setTimeout(() => { const descendant = isBeforeDate(date, minDate) ? descendants.enabledFirstValue() : descendants.value(date.getDate() - 1); if (!descendant) return; if (descendant.disabled) onFocusDescendant(descendants.enabledNextValue(descendant, false)); else onFocusDescendant(descendant); }); }, [ descendants, minDate, onFocusDescendant, onMonthChange ]); const onNextTraverseDate = (0, react.useCallback)((date) => { onMonthChange((0, dayjs.default)(date).set("date", 1).toDate()); setTimeout(() => { const descendant = isAfterDate(date, maxDate) ? descendants.enabledLastValue() : descendants.value(date.getDate() - 1); if (!descendant) return; if (descendant.disabled) onFocusDescendant(descendants.enabledPrevValue(descendant, false)); else onFocusDescendant(descendant); }); }, [ descendants, maxDate, onFocusDescendant, onMonthChange ]); const onKeyDown = (0, react.useCallback)((ev) => { require_dom.runKeyAction(ev, { ArrowDown: () => onNextTraverseDate((0, dayjs.default)(value).add(1, "week").toDate()), ArrowLeft: onPrevDate, ArrowRight: onNextDate, ArrowUp: () => onPrevTraverseDate((0, dayjs.default)(value).subtract(1, "week").toDate()), End: () => onNextTraverseDate(getEndOfWeek(value, startDayOfWeek)), Enter: onClick, Home: () => onPrevTraverseDate(getStartOfWeek(value, startDayOfWeek)), PageDown: (ev$1) => { if (ev$1.shiftKey) onNextTraverseDate((0, dayjs.default)(value).add(1, "year").toDate()); else onNextTraverseDate((0, dayjs.default)(value).add(1, "month").toDate()); }, PageUp: (ev$1) => { if (ev$1.shiftKey) onPrevTraverseDate((0, dayjs.default)(value).subtract(1, "year").toDate()); else onPrevTraverseDate((0, dayjs.default)(value).subtract(1, "month").toDate()); }, Space: onClick }); }, [ onClick, onNextDate, onNextTraverseDate, onPrevDate, onPrevTraverseDate, startDayOfWeek, value ]); return { outside, getDayProps: (0, react.useCallback)(({ ref, "aria-label": ariaLabel,...props } = {}) => { if (!ariaLabel) { ariaLabel = dateTimeFormat((0, dayjs.default)(value).toDate(), { day: "numeric", month: "long", weekday: "long", year: "numeric" }); if (today) ariaLabel = `${t("Today")}, ${ariaLabel}`; } return { "aria-disabled": (0, require_utils_index.utils_exports.ariaAttr)(disabled), "aria-label": ariaLabel, "aria-selected": (0, require_utils_index.utils_exports.ariaAttr)(selected), "data-between": (0, require_utils_index.utils_exports.dataAttr)(between), "data-disabled": (0, require_utils_index.utils_exports.dataAttr)(disabled), "data-end": (0, require_utils_index.utils_exports.dataAttr)(endValue), "data-holiday": (0, require_utils_index.utils_exports.dataAttr)(holiday), "data-outside": (0, require_utils_index.utils_exports.dataAttr)(outside), "data-selected": (0, require_utils_index.utils_exports.dataAttr)(selected), "data-start": (0, require_utils_index.utils_exports.dataAttr)(startValue), "data-today": (0, require_utils_index.utils_exports.dataAttr)(today), "data-value": (0, dayjs.default)(value).format("YYYY-MM-DD"), "data-weekend": (0, require_utils_index.utils_exports.dataAttr)(weekend), tabIndex: -1, ...rest, ...props, ref: require_ref.mergeRefs(ref, cellRef, outside ? null : register), onBlur: (0, require_utils_index.utils_exports.handlerAll)(props.onBlur, onBlur), onClick: (0, require_utils_index.utils_exports.handlerAll)(props.onClick, onClick), onFocus: (0, require_utils_index.utils_exports.handlerAll)(props.onFocus, (ev) => ev.preventDefault()), onKeyDown: (0, require_utils_index.utils_exports.handlerAll)(props.onKeyDown, onKeyDown) }; }, [ between, dateTimeFormat, disabled, endValue, holiday, onBlur, onClick, onKeyDown, outside, register, rest, selected, startValue, t, today, value, weekend ]) }; }; const calendarProps = [ "defaultMonth", "defaultValue", "disabled", "excludeDate", "format", "holidays", "locale", "max", "maxDate", "minDate", "month", "range", "startDayOfWeek", "today", "value", "weekendDays", "onChange", "onChangeMonth" ]; const useCalendarProps = (props, omitKeys) => { return require_props.useSplitProps(props, calendarProps.filter((key) => !omitKeys?.includes(key))); }; //#endregion exports.CalendarContext = CalendarContext; exports.CalendarDescendantsContext = CalendarDescendantsContext; exports.DEFAULT_FIRST_DAY_OF_WEEK = DEFAULT_FIRST_DAY_OF_WEEK; exports.DEFAULT_HOLIDAYS = DEFAULT_HOLIDAYS; exports.DEFAULT_MAX_DATE = DEFAULT_MAX_DATE; exports.DEFAULT_MIN_DATE = DEFAULT_MIN_DATE; exports.DEFAULT_WEEKEND_DAYS = DEFAULT_WEEKEND_DAYS; exports.getAdjustedMonth = getAdjustedMonth; exports.getEndOfWeek = getEndOfWeek; exports.getMonthDays = getMonthDays; exports.getStartOfWeek = getStartOfWeek; exports.getWeekdays = getWeekdays; exports.isAfterDate = isAfterDate; exports.isAfterMonth = isAfterMonth; exports.isAfterYear = isAfterYear; exports.isBeforeDate = isBeforeDate; exports.isBeforeMonth = isBeforeMonth; exports.isBeforeYear = isBeforeYear; exports.isInRange = isInRange; exports.isIncludeDates = isIncludeDates; exports.isSameAfterDate = isSameAfterDate; exports.isSameAfterMonth = isSameAfterMonth; exports.isSameAfterYear = isSameAfterYear; exports.isSameBeforeDate = isSameBeforeDate; exports.isSameBeforeMonth = isSameBeforeMonth; exports.isSameBeforeYear = isSameBeforeYear; exports.isSameDate = isSameDate; exports.isSameMonth = isSameMonth; exports.isSameYear = isSameYear; exports.sortDates = sortDates; exports.updateMaybeDateValue = updateMaybeDateValue; exports.useCalendar = useCalendar; exports.useCalendarContext = useCalendarContext; exports.useCalendarDay = useCalendarDay; exports.useCalendarDescendant = useCalendarDescendant; exports.useCalendarDescendants = useCalendarDescendants; exports.useCalendarProps = useCalendarProps; //# sourceMappingURL=use-calendar.cjs.map