feat: migrate Calendar and calendar year picker

This commit is contained in:
maoyingjie
2026-10-24 20:59:19 +08:00
parent 1c4ecc3def
commit 835d2e4d90
47 changed files with 4283 additions and 87 deletions
+66
View File
@@ -0,0 +1,66 @@
import { afterEach, expect, it, vi } from "vitest";
import { mount, flushPromises } from "@vue/test-utils";
import { createSSRApp, defineComponent, h, type Component } from "vue";
import { renderToString } from "@vue/server-renderer";
import { CalendarDate } from "@internationalized/date";
import {
Calendar,
CalendarGrid,
CalendarGridHeader,
CalendarGridBody,
} from "../packages/vue/src/index";
const demos = import.meta.glob("../apps/docs/demos/calendar-*.vue", {
eager: true,
import: "default",
}) as Record<string, Component>;
const wrappers: ReturnType<typeof mount>[] = [];
afterEach(() => {
wrappers.splice(0).forEach((w) => w.unmount());
document.body.innerHTML = "";
vi.restoreAllMocks();
});
it("mounts all nineteen baseline demos together without duplicate IDs or Vue warnings", async () => {
expect(Object.keys(demos)).toHaveLength(19);
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
const w = mount(
defineComponent({
render: () =>
h(
"div",
Object.entries(demos).map(([key, demo]) => h(demo, { key })),
),
}),
{ attachTo: document.body },
);
wrappers.push(w);
await flushPromises();
const ids = Array.from(document.querySelectorAll("[id]")).map((e) => e.id);
expect(new Set(ids).size).toBe(ids.length);
expect(warn).not.toHaveBeenCalled();
});
it("hydrates an explicitly dated calendar without replacing the server grid", async () => {
const Root = defineComponent({
render: () =>
h(
Calendar,
{
defaultFocusedValue: new CalendarDate(2024, 2, 10),
locale: "en-US",
timeZone: "UTC",
},
() =>
h(CalendarGrid, () => [h(CalendarGridHeader), h(CalendarGridBody)]),
),
});
const host = document.createElement("div");
host.innerHTML = await renderToString(createSSRApp(Root));
document.body.append(host);
const grid = host.querySelector("table");
const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
const app = createSSRApp(Root);
app.mount(host);
await flushPromises();
expect(host.querySelector("table")).toBe(grid);
expect(warn).not.toHaveBeenCalled();
app.unmount();
});
+61
View File
@@ -0,0 +1,61 @@
// @vitest-environment node
import { expect, it } from "vitest";
import { createSSRApp, h } from "vue";
import { renderToString } from "@vue/server-renderer";
import { CalendarDate } from "@internationalized/date";
import {
Calendar,
CalendarHeader,
CalendarHeading,
CalendarGrid,
CalendarGridHeader,
CalendarGridBody,
CalendarYearPickerGrid,
CalendarYearPickerGridBody,
} from "../packages/vue/src/index";
it("renders month and year markup without browser globals and stable explicit dates", async () => {
const value = new CalendarDate(2024, 2, 29);
const app = createSSRApp({
render: () =>
h(
Calendar,
{
defaultValue: value,
defaultFocusedValue: value,
locale: "en-US",
timeZone: "UTC",
},
() => [
h(CalendarHeader, () => h(CalendarHeading)),
h(CalendarGrid, () => [h(CalendarGridHeader), h(CalendarGridBody)]),
h(CalendarYearPickerGrid, () => h(CalendarYearPickerGridBody)),
],
),
});
const html = await renderToString(app);
expect(html).toContain('data-date="2024-02-29"');
expect(html).toContain('data-selected="true"');
expect(html).toContain("February 2024");
expect(html).toContain("inert");
});
it("renders the actual non-Gregorian weekday/month view and day windows on the server", async () => {
const html = await renderToString(
createSSRApp({
render: () =>
h(
Calendar,
{
defaultFocusedValue: new CalendarDate(2024, 2, 10),
locale: "hi-IN-u-ca-indian",
visibleDuration: { days: 3 },
selectionAlignment: "start",
},
() =>
h(CalendarGrid, () => [h(CalendarGridHeader), h(CalendarGridBody)]),
),
}),
);
expect(html.match(/data-slot="calendar-cell"/g) ?? []).toHaveLength(3);
expect(html).toContain("2024-02-10");
expect(html).not.toContain("Sunday");
});
+102
View File
@@ -0,0 +1,102 @@
import { describe, expect, it } from "vitest";
import {
CalendarDate,
HebrewCalendar,
PersianCalendar,
toCalendar,
} from "@internationalized/date";
import {
calendarDuration,
calendarRange,
calendarRows,
calendarWeekdays,
calendarHeading,
calendarYears,
} from "../packages/vue/src/components/date/calendar";
const date = new CalendarDate(2024, 2, 10);
const options = { locale: "en-US" };
describe("calendar view adapter", () => {
it("renders leap-month rows and offset grids with real calendar arithmetic", () => {
const view = calendarRows(date, options);
expect(view.rows.flat().some((d) => d?.toString() === "2024-02-29")).toBe(
true,
);
expect(view.rows).toHaveLength(5);
expect(
calendarRows(date, { ...options, weeksInMonth: 6 }).rows,
).toHaveLength(6);
expect(calendarRows(date, options, { months: 1 }).month.toString()).toBe(
"2024-03-01",
);
});
it("generates true week views across month boundaries", () => {
const view = calendarRows(new CalendarDate(2024, 2, 29), {
...options,
visibleDuration: { weeks: 2 },
firstDayOfWeek: "mon",
});
expect(view.rows).toHaveLength(2);
expect(view.range.start.toString()).toBe("2024-02-26");
expect(view.range.end.toString()).toBe("2024-03-10");
});
it("keeps short day views compact and long day views aligned with empty trailing cells", () => {
const short = calendarRows(date, {
...options,
visibleDuration: { days: 3 },
});
expect(short.rows[0]!.map((d) => d?.day ?? null)).toEqual([
10,
11,
12,
null,
null,
null,
null,
]);
const long = calendarRows(date, {
...options,
visibleDuration: { days: 10 },
});
expect(long.rows).toHaveLength(3);
expect(long.rows.at(-1)!.filter(Boolean)).toHaveLength(2);
expect(
calendarWeekdays(date, { ...options, visibleDuration: { days: 3 } }),
).toEqual(["Sat", "Sun", "Mon"]);
});
it("converts the view to the locale calendar without mutating a Gregorian value", () => {
const view = calendarRange(date, { locale: "fa-IR-u-ca-persian" });
expect(view.start.calendar.identifier).toBe("persian");
expect(view.start.month).toBe(
toCalendar(date, new PersianCalendar()).month,
);
expect(date.calendar.identifier).toBe("gregory");
});
it("includes 13-month calendar dates and calendar-aware year entries", () => {
const hebrew = toCalendar(
new CalendarDate(2024, 9, 10),
new HebrewCalendar(),
);
expect(hebrew.calendar.getMonthsInYear(hebrew)).toBe(13);
const view = calendarRows(hebrew.set({ month: 13 }), {
locale: "he-IL-u-ca-hebrew",
});
expect(view.month.month).toBe(13);
const years = calendarYears(hebrew, hebrew.add({ years: 2 }));
expect(years).toHaveLength(3);
expect(years.every((y) => y.month === 1 && y.day === 1)).toBe(true);
});
it("formats ranges and rejects ambiguous or invalid durations", () => {
expect(calendarHeading(date, options)).toBe("February 2024");
expect(
calendarHeading(date, { ...options, visibleDuration: { months: 2 } }),
).toContain("March");
for (const value of [
{ days: 0 },
{ days: -1 },
{ months: 1.5 },
{ weeks: 1, days: 1 },
{},
])
expect(() => calendarDuration(value as never)).toThrow(RangeError);
});
});
+290
View File
@@ -0,0 +1,290 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { mount, flushPromises } from "@vue/test-utils";
import { defineComponent, shallowRef, type Component } from "vue";
import {
CalendarDate,
CalendarDateTime,
PersianCalendar,
toCalendar,
parseZonedDateTime,
type DateValue,
} from "@internationalized/date";
import * as library from "../packages/vue/src/index";
const wrappers: ReturnType<typeof mount>[] = [];
afterEach(() => {
wrappers.splice(0).forEach((w) => w.unmount());
document.body.innerHTML = "";
vi.restoreAllMocks();
});
const initial = new CalendarDate(2024, 2, 10);
const parts = `<CalendarHeader><CalendarHeading/><CalendarNavButton slot="previous"/><CalendarNavButton slot="next"/></CalendarHeader><CalendarGrid><CalendarGridHeader/><CalendarGridBody/></CalendarGrid>`;
function fixture(attributes = "", setup = () => ({}), children = parts) {
const w = mount(
defineComponent({
components: Object.fromEntries(
Object.entries(library).filter(([name]) => name.startsWith("Calendar")),
) as Record<string, Component>,
setup: () => ({ initial, ...setup() }),
template: `<Calendar aria-label="Date" :default-focused-value="initial" ${attributes}>${children}</Calendar>`,
}),
{ attachTo: document.body },
);
wrappers.push(w);
return w;
}
const cell = (w: ReturnType<typeof mount>, iso: string) =>
w.get<HTMLElement>(
`[data-slot="calendar-cell"][data-date="${iso}"]:not([data-outside-month])`,
);
const calendar = (w: ReturnType<typeof mount>) =>
w.findComponent(library.Calendar);
async function key(
w: ReturnType<typeof mount>,
iso: string,
key: string,
extra = {},
) {
cell(w, iso).element.focus();
await cell(w, iso).trigger("keydown", { key, code: key, ...extra });
await flushPromises();
}
describe("Calendar public contract", () => {
it("renders semantic grids and selects a date without named native submission", async () => {
const w = fixture();
expect(w.find('table[role="grid"]').exists()).toBe(true);
expect(w.findAll("th")).toHaveLength(7);
await cell(w, "2024-02-29").trigger("click");
expect(cell(w, "2024-02-29").attributes("data-selected")).toBe("true");
expect(calendar(w).emitted("change")![0]![0]).toBeInstanceOf(CalendarDate);
expect(w.find("input[name]").exists()).toBe(false);
});
it("keeps controlled rejected values and allows the same proposal again", async () => {
const w = fixture(':model-value="initial"');
await cell(w, "2024-02-11").trigger("click");
await cell(w, "2024-02-11").trigger("click");
expect(calendar(w).emitted("change")).toHaveLength(2);
expect(cell(w, "2024-02-10").attributes("data-selected")).toBe("true");
expect(cell(w, "2024-02-11").attributes("data-selected")).toBeUndefined();
});
it("supports multiple toggling and copies proposals without mutating parent dates", async () => {
const w = fixture('selection-mode="multiple" :default-value="[initial]"');
await cell(w, "2024-02-11").trigger("click");
expect(
(calendar(w).emitted("change")![0]![0] as DateValue[]).map((d) =>
d.toString(),
),
).toEqual(["2024-02-10", "2024-02-11"]);
await cell(w, "2024-02-10").trigger("click");
expect(cell(w, "2024-02-10").attributes("data-selected")).toBeUndefined();
expect(initial.toString()).toBe("2024-02-10");
});
it("exposes actual hover, focus and pressed slot state without repeating a held selection", async () => {
const w = fixture(
'selection-mode="multiple"',
() => ({}),
`<CalendarGrid><CalendarGridHeader/><CalendarGridBody v-slot="{date}"><CalendarCell :date="date" v-slot="{formattedDate,isHovered,isPressed,isFocused}"><span>{{ formattedDate }}:{{ isHovered }}:{{ isPressed }}:{{ isFocused }}</span></CalendarCell></CalendarGridBody></CalendarGrid>`,
);
const day = cell(w, "2024-02-10");
await day.trigger("pointerenter");
expect(day.text()).toContain(":true:false:false");
day.element.focus();
await flushPromises();
expect(day.text()).toContain(":true:false:true");
await day.trigger("keydown", { key: " ", code: "Space" });
expect(day.attributes("data-pressed")).toBe("true");
await day.trigger("keydown", { key: " ", code: "Space", repeat: true });
expect(calendar(w).emitted("change")).toHaveLength(1);
await day.trigger("keyup", { key: " ", code: "Space" });
expect(day.attributes("data-pressed")).toBeUndefined();
});
it("preserves time precision and zone in date-only selection", async () => {
for (const value of [
new CalendarDateTime(2024, 2, 10, 13, 14, 45, 123),
parseZonedDateTime("2024-02-10T13:14:45.123-08:00[America/Los_Angeles]"),
]) {
const w = fixture(':default-value="value"', () => ({ value }));
await cell(w, "2024-02-11").trigger("click");
const next = calendar(w).emitted("change")![0]![0] as DateValue;
expect(next.toString()).toBe(value.set({ day: 11 }).toString());
}
});
it("distinguishes disabled from focusable unavailable dates and honors actual keyboard cancellation", async () => {
const w = fixture(
':is-date-disabled="d=>d.day===11" :is-date-unavailable="d=>d.day===12"',
);
await key(w, "2024-02-10", "ArrowRight");
expect(document.activeElement).toBe(cell(w, "2024-02-12").element);
await cell(w, "2024-02-12").trigger("click");
expect(calendar(w).emitted("change")).toBeUndefined();
const cancelled = fixture(
"",
() => ({}),
`<CalendarGrid><CalendarGridHeader/><CalendarGridBody v-slot="{date}"><CalendarCell :date="date" @keydown.prevent /></CalendarGridBody></CalendarGrid>`,
);
await key(cancelled, "2024-02-10", "ArrowRight");
expect(document.activeElement).toBe(cell(cancelled, "2024-02-10").element);
});
it("supports readonly navigation and fully disabled controls", async () => {
const ro = fixture("is-read-only");
await key(ro, "2024-02-10", "ArrowRight");
expect(document.activeElement).toBe(cell(ro, "2024-02-11").element);
await cell(ro, "2024-02-11").trigger("click");
expect(calendar(ro).emitted("change")).toBeUndefined();
const disabled = fixture("is-disabled");
expect(disabled.findAll("button:not(:disabled)")).toHaveLength(0);
});
it("pages with bounds, RTL keyboard movement and programmatic focused values", async () => {
const focus = shallowRef<DateValue>(initial);
const w = fixture(
'v-model:focused-value="focus" dir="rtl" :min-value="initial" :max-value="initial.add({months:1})"',
() => ({ focus }),
);
await key(w, "2024-02-10", "ArrowLeft");
expect(focus.value.day).toBe(11);
await key(w, "2024-02-11", "PageDown");
expect(w.get('[data-slot="calendar-heading"]').text()).toContain("March");
focus.value = new CalendarDate(2024, 2, 15);
await flushPromises();
expect(w.get('[data-slot="calendar-heading"]').text()).toBe(
"February 2024",
);
});
it("pages a single unit even when the proposed focus remains inside a multi-unit view", async () => {
const w = fixture(':visible-duration="{months:2}" page-behavior="single"');
await w.get('[aria-label="Next"]').trigger("click");
await flushPromises();
expect(w.get('[data-slot="calendar-heading"]').text()).toContain("March");
expect(w.get('[data-slot="calendar-heading"]').text()).toContain("April");
const rejected = fixture(
':focused-value="initial" :visible-duration="{weeks:2}" page-behavior="single"',
);
const heading = rejected.get('[data-slot="calendar-heading"]').text();
await rejected.get('[aria-label="Next"]').trigger("click");
await flushPromises();
expect(rejected.get('[data-slot="calendar-heading"]').text()).toBe(heading);
});
it("keeps one Tab stop when the initial focused day is disabled", () => {
const w = fixture(':is-date-disabled="d=>d.day===10"');
expect(w.findAll('[data-slot="calendar-cell"][tabindex="0"]')).toHaveLength(
1,
);
expect(cell(w, "2024-02-01").attributes("tabindex")).toBe("0");
});
it("retains keyboard focus across programmatic month changes without stealing outside focus", async () => {
const focused = shallowRef<DateValue>(initial);
const w = fixture('v-model:focused-value="focused"', () => ({ focused }));
cell(w, "2024-02-10").element.focus();
focused.value = new CalendarDate(2025, 6, 15);
await flushPromises();
expect(document.activeElement).toBe(cell(w, "2025-06-15").element);
const outside = document.createElement("button");
document.body.append(outside);
outside.focus();
focused.value = new CalendarDate(2024, 2, 20);
await flushPromises();
expect(document.activeElement).toBe(outside);
});
it("honors per-control disabled state and native event cancellation on navigation", async () => {
const w = fixture(
"",
() => ({}),
`<CalendarHeader><CalendarHeading/><CalendarNavButton disabled slot="next"/><CalendarNavButton slot="previous" @click.prevent/></CalendarHeader><CalendarGrid><CalendarGridHeader/><CalendarGridBody/></CalendarGrid>`,
);
expect(w.get('[aria-label="Next"]').attributes("disabled")).toBe("");
await w.get('[aria-label="Previous"]').trigger("click");
expect(w.get('[data-slot="calendar-heading"]').text()).toBe(
"February 2024",
);
});
it("renders true weekly, daily and offset multi-month layouts", () => {
expect(
fixture(':visible-duration="{weeks:2}"').findAll("tbody tr"),
).toHaveLength(2);
expect(
fixture(
':visible-duration="{days:3}" selection-alignment="start"',
).findAll('[data-slot="calendar-cell"]'),
).toHaveLength(3);
const two = fixture(
':visible-duration="{months:2}"',
() => ({}),
`${parts}<CalendarGrid :offset="{months:1}"><CalendarGridHeader/><CalendarGridBody/></CalendarGrid>`,
);
expect(two.findAll("table")).toHaveLength(2);
expect(cell(two, "2024-03-15").element.tagName === "BUTTON").toBe(true);
expect(two.findAll('[data-date="2024-03-01"]:not(:disabled)')).toHaveLength(
1,
);
});
it("keeps empty selection Gregorian independently of the focused view calendar", async () => {
const persian = toCalendar(initial, new PersianCalendar());
const w = fixture(
':focused-value="persian" locale="fa-IR-u-ca-persian"',
() => ({ persian }),
);
await cell(w, "2024-02-11").trigger("click");
const value = calendar(w).emitted("change")![0]![0] as DateValue;
expect(value.calendar.identifier).toBe("gregory");
expect(value.toString()).toBe("2024-02-11");
});
it("restores accepted DOM focus after a controlled pointer focus is rejected", async () => {
const w = fixture(':focused-value="initial"');
cell(w, "2024-02-11").element.focus();
await flushPromises();
expect(document.activeElement).toBe(cell(w, "2024-02-10").element);
});
it("translates the actual calendar view and selection back to the public Gregorian model", async () => {
const w = fixture(':default-value="initial" locale="hi-IN-u-ca-indian"');
expect(w.get('[data-slot="calendar-heading"]').text()).not.toContain(
"February",
);
await cell(w, "2024-02-11").trigger("click");
const next = calendar(w).emitted("change")![0]![0] as DateValue;
expect(next.calendar.identifier).toBe("gregory");
expect(next.toString()).toBe("2024-02-11");
});
});
describe("CalendarYearPicker", () => {
const children = `<CalendarHeader><CalendarYearPickerTrigger><CalendarYearPickerTriggerHeading/><CalendarYearPickerTriggerIndicator/></CalendarYearPickerTrigger><CalendarNavButton slot="previous"/><CalendarNavButton slot="next"/></CalendarHeader><CalendarGrid><CalendarGridHeader/><CalendarGridBody/></CalendarGrid><CalendarYearPickerGrid><CalendarYearPickerGridBody/></CalendarYearPickerGrid>`;
it("keeps hidden years out of Tab, focuses the selected year and escapes back to the trigger", async () => {
const w = fixture("", () => ({}), children);
expect(
w.get('[data-slot="calendar-year-picker-grid"]').attributes("inert"),
).toBe("");
await w.get('[data-slot="calendar-year-picker-trigger"]').trigger("click");
await flushPromises();
expect(document.activeElement?.getAttribute("data-year")).toBe("2024");
await w.get('[data-year="2024"]').trigger("keydown", { key: "ArrowDown" });
expect(document.activeElement?.getAttribute("data-year")).toBe("2027");
await w.get('[data-year="2027"]').trigger("keydown", { key: "Escape" });
await flushPromises();
expect(document.activeElement).toBe(
w.get('[data-slot="calendar-year-picker-trigger"]').element,
);
});
it("selects a year without changing the selected day value, and respects close rejection", async () => {
const w = fixture(':default-value="initial"', () => ({}), children);
await w.get('[data-slot="calendar-year-picker-trigger"]').trigger("click");
await flushPromises();
await w.get('[data-year="2026"]').trigger("click");
await flushPromises();
expect(w.find('[data-slot="calendar-heading"]').exists()).toBe(false);
expect(
w.get('[data-slot="calendar-year-picker-trigger-heading"]').text(),
).toContain("2026");
expect(calendar(w).emitted("change")).toBeUndefined();
const rejected = fixture(
':is-year-picker-open="true"',
() => ({}),
children,
);
await flushPromises();
await rejected.get('[data-year="2026"]').trigger("click");
await flushPromises();
expect(
rejected
.get('[data-slot="calendar-year-picker-grid"]')
.attributes("data-open"),
).toBe("true");
});
});
+2
View File
@@ -25,3 +25,5 @@ SELECT-01 增加 `consume-select.mjs` / `select-contract.ts`。新 tarball 安
DATE-02 增加 `consume-date-field.mjs` / `date-field-contract.ts`。独立消费者显式安装 `@internationalized/date@3.12.4`,运行完整 ISO 时区提交/SSR/样式检查,分别用 NodeNext 与 bundler 验证 DateValue、粒度、变体、范围和 segment 的正反类型,不从源码 alias 取公共类型。
M35–M36 使用 `consume-m35-m36.mjs` / `m35-m36-contract.ts`,新建 `/private/tmp/heroui-m35-consumer`。pnpm 11 的本地样式 tarball override 写在消费者 `pnpm-workspace.yaml`;不依赖已弃用的 package.json pnpm 字段。分别验证 ESM/CSS、真正 node SSR、所有部件导出,以及 bundler/NodeNext 类型正反例(含 Promise 参数推断)。
DATE-03 新增 `consume-calendar.mjs` / `calendar-contract.ts`,安装两份新 tarball 后运行 Node ESM/SSR/CSS 与 NodeNext/bundler 类型正反例,保留 DateField/Select 回归。Calendar 的泛型 Root 使用实际 SFC 参数类型核对单选、事件推断与错误模型,Cell/YearPicker Props 和作用域插槽不能退化为 any。
+84
View File
@@ -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;
+63
View File
@@ -0,0 +1,63 @@
import assert from "node:assert/strict";
import fs from "node:fs";
import { createSSRApp, h } from "vue";
import { renderToString } from "@vue/server-renderer";
import { CalendarDate } from "@internationalized/date";
import * as ui from "@heroui-vue/components";
const names = [
"Calendar",
"CalendarRoot",
"CalendarHeader",
"CalendarHeading",
"CalendarNavButton",
"CalendarGrid",
"CalendarGridHeader",
"CalendarGridBody",
"CalendarHeaderCell",
"CalendarCell",
"CalendarCellIndicator",
"CalendarYearPickerTrigger",
"CalendarYearPickerTriggerHeading",
"CalendarYearPickerTriggerIndicator",
"CalendarYearPickerGrid",
"CalendarYearPickerGridBody",
"CalendarYearPickerCell",
];
for (const name of names) assert.ok(ui[name], name);
const html = await renderToString(
createSSRApp({
render: () =>
h(
ui.Calendar,
{
defaultValue: new CalendarDate(2024, 2, 29),
defaultFocusedValue: new CalendarDate(2024, 2, 29),
locale: "en-US",
timeZone: "UTC",
},
() => [
h(ui.CalendarHeading),
h(ui.CalendarGrid, () => [
h(ui.CalendarGridHeader),
h(ui.CalendarGridBody),
]),
h(ui.CalendarYearPickerGrid, () => h(ui.CalendarYearPickerGridBody)),
],
),
}),
);
assert.match(html, /2024-02-29/);
assert.match(html, /data-selected="true"/);
assert.match(html, /February 2024/);
const css = fs.readFileSync(
import.meta.resolve("@heroui-vue/styles/css").replace("file://", ""),
"utf8",
);
for (const token of [
".hv-calendar__cell",
".hv-calendar--week-view",
".hv-calendar--day-view",
".hv-calendar-year-picker__year-cell",
])
assert.ok(css.includes(token), token);
console.log("Calendar independent tarball ESM/Node SSR/CSS passed");