feat: migrate RangeCalendar public components and demos

This commit is contained in:
maoyingjie
2026-10-26 21:25:25 +08:00
parent ebe81f28c7
commit 07f6aeadb6
43 changed files with 2420 additions and 53 deletions
+4
View File
@@ -40,6 +40,10 @@ for (const id of process.argv.slice(2)) {
.includes("hv-list-box-item__indicator"),
);
}
if (id === "range-calendar") {
assert(lib.RangeCalendar === lib.RangeCalendarRoot);
assert(lib.rangeCalendarVariants().cell() === "hv-range-calendar__cell");
}
if (id === "time-field") {
assert(lib.TimeField === lib.TimeFieldRoot);
assert(lib.TimeFieldGroup === lib.DateInputGroup);
+24
View File
@@ -373,5 +373,29 @@
".hv-date-input-group",
".hv-date-input-group__segment"
]
},
"range-calendar": {
"exports": [
"RangeCalendar",
"RangeCalendarRoot",
"RangeCalendarHeader",
"RangeCalendarHeading",
"RangeCalendarNavButton",
"RangeCalendarGrid",
"RangeCalendarGridHeader",
"RangeCalendarGridBody",
"RangeCalendarHeaderCell",
"RangeCalendarCell",
"RangeCalendarCellIndicator",
"rangeCalendarVariants"
],
"css": [
".hv-range-calendar__cell",
".hv-range-calendar__cell-button",
".hv-range-calendar--week-view",
".hv-range-calendar--day-view",
"data-selection-start",
"data-selection-end"
]
}
}
+137
View File
@@ -0,0 +1,137 @@
import { h } from "vue";
import {
CalendarDate,
CalendarDateTime,
type DateValue,
} from "@internationalized/date";
import {
RangeCalendar,
RangeCalendarRoot,
RangeCalendarCell,
RangeCalendarGrid,
CalendarYearPickerCell,
rangeCalendarVariants,
type RangeCalendarProps,
type RangeCalendarRootProps,
type RangeCalendarCellProps,
type RangeCalendarGridProps,
type RangeCalendarCellRenderProps,
type CalendarDateRange,
type CalendarRangeModel,
type RangeCalendarVariants,
} from "@heroui-vue/components";
const day = new CalendarDate(2024, 2, 10);
const range: CalendarDateRange<CalendarDate> = {
start: day,
end: day.add({ days: 2 }),
};
const mixed: CalendarDateRange = {
start: new CalendarDateTime(2024, 2, 10, 9),
end: day,
};
const props: RangeCalendarProps = {
modelValue: range,
defaultValue: null,
focusedValue: day,
allowsNonContiguousRanges: true,
firstDayOfWeek: "mon",
visibleDuration: { weeks: 2 },
isDateUnavailable: (date, anchor) => {
const value: DateValue = date;
const original: CalendarDate | null = anchor;
// @ts-expect-error anchor has calendar semantics, not a JS Date
const invalid: Date | null = anchor;
void [value, original, invalid];
return false;
},
"onUpdate:modelValue": (value) => {
const model: CalendarRangeModel = value;
// @ts-expect-error proposal is a range or null
const invalid: string = value;
void [model, invalid];
},
"onUpdate:focusedValue": (date) => {
const value: DateValue = date;
void value;
},
"onUpdate:isYearPickerOpen": (open) => {
const value: boolean = open;
void value;
},
};
const root: RangeCalendarRootProps = props;
const cell: RangeCalendarCellProps = { date: day };
const grid: RangeCalendarGridProps = {
offset: { months: 1 },
weekdayStyle: "long",
};
// @ts-expect-error a scalar DateValue is not a range
const scalar: RangeCalendarProps = { modelValue: day };
// @ts-expect-error ranges require both endpoints
const partial: RangeCalendarProps = { modelValue: { start: day } };
// @ts-expect-error a range is not an array
const array: RangeCalendarProps = { modelValue: [day, day] };
// @ts-expect-error dates must retain DateValue semantics
const native: RangeCalendarCellProps = { date: new Date() };
// @ts-expect-error no extra selection mode
const mode: RangeCalendarProps = { selectionMode: "multiple" };
const duration: RangeCalendarProps = {
// @ts-expect-error visible duration takes exactly one unit
visibleDuration: { months: 1, weeks: 1 },
};
type ActualRoot = InstanceType<typeof RangeCalendar>["$props"];
// @ts-expect-error actual component rejects partial values too
const actual: ActualRoot = { modelValue: { end: day } };
type RootSlot = Parameters<
NonNullable<InstanceType<typeof RangeCalendar>["$slots"]["default"]>
>[0];
const snapshot = {} as RootSlot;
const value: CalendarRangeModel = snapshot.value;
const anchor: CalendarDate | null = snapshot.anchorDate;
const focused: DateValue = snapshot.focusedValue;
// @ts-expect-error slot value is not any or a scalar
const badValue: DateValue = snapshot.value;
type CellSlot = Parameters<
NonNullable<InstanceType<typeof RangeCalendarCell>["$slots"]["default"]>
>[0];
const state = {} as CellSlot;
const renderProps: RangeCalendarCellRenderProps = state;
const start: boolean = state.isSelectionStart;
// @ts-expect-error cell states remain typed
const badStart: string = state.isSelectionStart;
const variants: RangeCalendarVariants = {};
const classes: string = rangeCalendarVariants(variants).cell();
h(RangeCalendarRoot, props);
h(RangeCalendarGrid, grid);
h(CalendarYearPickerCell, { year: 2024 });
void [
range,
mixed,
root,
cell,
scalar,
partial,
array,
native,
mode,
duration,
actual,
value,
anchor,
focused,
badValue,
renderProps,
start,
badStart,
classes,
];
const instance = {} as InstanceType<typeof RangeCalendar>;
instance.focus();
const element: HTMLElement | undefined = instance.element;
const cellInstance = {} as InstanceType<typeof RangeCalendarCell>;
cellInstance.focus();
const button: HTMLButtonElement | undefined = cellInstance.element;
// @ts-expect-error a button ref is not an input
const input: HTMLInputElement | undefined = cellInstance.element;
void [element, button, input];