Skip to main content

WeekViewModel

ViewModel subclass that powers the built-in "week" view. It returns two sections - a multiday bar and a 7-day timeGrid - and aligns the visible range to weekStartDay. Subclass it to build workweek, two-week, or schedule-only variants while reusing the standard week layout.

Usage

import { WeekViewModel, registerCalendarView } from "@svar-ui/vue-calendar";

class WorkWeek extends WeekViewModel {
// override points
}

registerCalendarView("workweek", WorkWeek);

Override points

Same set as DayViewModel and MonthViewModel:

MethodSignaturePurpose
getSections() => Section[]Declare the layout sections (defaults to multiday + 7-day timeGrid).
rangeStart(date: Date) => DateAlign an arbitrary date to the first day of the visible range.
addRange(date: Date, n: number) => DateStep n periods forward or back; defaults to n * 7 days.
getRangeLabel() => stringFormat the toolbar's date range label.
configure(sections) => voidApply section-level overrides supplied via views[].sections.

Common overrides:

  • addRange for multi-week ranges (two-week, four-week).
  • getSections for column count (workweek = 5 columns).
  • getRangeLabel for custom range formatting.

Registration

Already registered as "week" when the package loads. To add a subclass under a new id:

import { WeekViewModel, registerCalendarView } from "@svar-ui/vue-calendar";
import type { Section } from "@wx/calendar-store";

class WorkWeekViewModel extends WeekViewModel {
getSections(): Section[] {
const [multiday, timeGrid] = super.getSections();
return [
{ ...multiday, xScale: { ...multiday.xScale, length: 5 } },
{ ...timeGrid, xScale: { ...timeGrid.xScale, length: 5 } },
];
}
}

registerCalendarView("workweek", WorkWeekViewModel);
<Calendar :events="events" view="workweek" :views="['workweek', 'week', 'month']" />

Calling registerCalendarView again with an existing id ("week") replaces the implementation for every Calendar mount.