feat: migrate Calendar and calendar year picker
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
import { h } from "vue";
|
||||
import { CalendarDate, type DateValue } from "@internationalized/date";
|
||||
import {
|
||||
Calendar,
|
||||
CalendarCell,
|
||||
CalendarGrid,
|
||||
CalendarYearPickerCell,
|
||||
type CalendarProps,
|
||||
type CalendarCellProps,
|
||||
type CalendarGridProps,
|
||||
type CalendarYearPickerGridProps,
|
||||
type CalendarYearPickerCellProps,
|
||||
} from "@heroui-vue/components";
|
||||
const date = new CalendarDate(2024, 2, 10);
|
||||
const single: CalendarProps = {
|
||||
modelValue: date,
|
||||
visibleDuration: { months: 2 },
|
||||
firstDayOfWeek: "mon",
|
||||
};
|
||||
const multiple: CalendarProps<"multiple"> = {
|
||||
selectionMode: "multiple",
|
||||
modelValue: [date],
|
||||
};
|
||||
const grid: CalendarGridProps = { offset: { months: 1 }, weekdayStyle: "long" };
|
||||
const cell: CalendarCellProps = { date };
|
||||
const year: CalendarYearPickerGridProps = {
|
||||
visibleYears: 20,
|
||||
format: { era: "short", year: "numeric" },
|
||||
};
|
||||
// @ts-expect-error single mode is not an array model
|
||||
const wrong: CalendarProps = { modelValue: [date] };
|
||||
const wrongMultiple: CalendarProps<"multiple"> = {
|
||||
selectionMode: "multiple",
|
||||
// @ts-expect-error multiple mode is not a scalar model
|
||||
modelValue: date,
|
||||
};
|
||||
// @ts-expect-error visible duration has a single unit
|
||||
const mixed: CalendarProps = { visibleDuration: { months: 1, weeks: 1 } };
|
||||
// @ts-expect-error DateValue is not JS Date
|
||||
const wrongDate: CalendarCellProps = { date: new Date() };
|
||||
// @ts-expect-error weekday format is explicit
|
||||
const wrongGrid: CalendarGridProps = { weekdayStyle: "numeric" };
|
||||
// @ts-expect-error no text selection mode
|
||||
const wrongMode: CalendarProps = { selectionMode: "none" };
|
||||
type RootProps = Parameters<typeof Calendar<"single">>[0];
|
||||
// @ts-expect-error actual SFC single mode keeps the scalar constraint
|
||||
const invalidRoot: RootProps = { modelValue: [date] };
|
||||
void invalidRoot;
|
||||
const rootProps: RootProps = {
|
||||
modelValue: date,
|
||||
"onUpdate:modelValue": (value) => {
|
||||
const expected: DateValue | null = value;
|
||||
// @ts-expect-error event payload is not a string
|
||||
const invalid: string = value;
|
||||
void [expected, invalid];
|
||||
},
|
||||
};
|
||||
type CellSlot = Parameters<
|
||||
NonNullable<InstanceType<typeof CalendarCell>["$slots"]["default"]>
|
||||
>[0];
|
||||
const state = {} as CellSlot;
|
||||
const selected: boolean = state.isSelected;
|
||||
// @ts-expect-error slot state retains boolean, not any
|
||||
const invalidSlot: number = state.isSelected;
|
||||
void [rootProps, selected, invalidSlot];
|
||||
h(CalendarGrid, grid);
|
||||
h(CalendarYearPickerCell, { year: 2024 });
|
||||
void [
|
||||
single,
|
||||
multiple,
|
||||
grid,
|
||||
cell,
|
||||
year,
|
||||
wrong,
|
||||
wrongMultiple,
|
||||
mixed,
|
||||
wrongDate,
|
||||
wrongGrid,
|
||||
wrongMode,
|
||||
];
|
||||
|
||||
// @ts-expect-error a year cell requires a numeric year
|
||||
const missingYear: CalendarYearPickerCellProps = {};
|
||||
void missingYear;
|
||||
Reference in New Issue
Block a user