@super-calendar/dom 2.5.0 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -121,6 +121,47 @@ interface AgendaProps<T = unknown> extends SlotStyleProps<AgendaSlot> {
121
121
  */
122
122
  declare function Agenda<T = unknown>({ events, locale, ampm, activeDate, theme: themeOverrides, height, renderEvent, eventAccessibilityLabel, onPressEvent, onPressDay, className, style, classNames, styles }: AgendaProps<T>): ReactElement;
123
123
  //#endregion
124
+ //#region src/YearView.d.ts
125
+ /**
126
+ * Styleable parts of {@link YearView}. Pass a class or inline style per slot
127
+ * via the `classNames` / `styles` props; day cells carry `data-today` and
128
+ * `data-events` state attributes for variants.
129
+ */
130
+ type YearViewSlot = "grid" | "month" | "monthTitle" | "weekdays" | "weekday" | "week" | "day" | "eventDot";
131
+ /** Props for {@link YearView}, the twelve mini-month year grid. */
132
+ interface YearViewProps<T = unknown> extends SlotStyleProps<YearViewSlot> {
133
+ /** Any date inside the year to render. */
134
+ date: Date;
135
+ /** Days holding at least one event get a dot. Omit for a plain year. */
136
+ events?: CalendarEvent$1<T>[];
137
+ /** First day of the week. Sunday = 0 (default) … Saturday = 6. */
138
+ weekStartsOn?: WeekStartsOn$1;
139
+ locale?: Locale;
140
+ /** Highlight this date instead of the real "today". */
141
+ activeDate?: Date;
142
+ /**
143
+ * Smallest width a mini month may take before the grid drops a column
144
+ * (default 150). The grid fits as many columns as the container allows.
145
+ */
146
+ minMonthWidth?: number;
147
+ /** Tap a day cell (e.g. to drill into the day or month view). */
148
+ onPressDay?: (date: Date) => void;
149
+ /** Tap a month's title (e.g. to jump to that month's view). */
150
+ onPressMonth?: (month: Date) => void;
151
+ /** Theme overrides; falls back to the default light theme. */
152
+ theme?: Partial<DomCalendarTheme>;
153
+ /** Class applied to the root element. */
154
+ className?: string;
155
+ /** Inline styles applied to the root element. */
156
+ style?: CSSProperties;
157
+ }
158
+ /**
159
+ * A year at a glance: the twelve months as compact mini grids, with today
160
+ * highlighted and a dot under days that hold events. It's the view `Calendar`
161
+ * renders for `mode="year"`.
162
+ */
163
+ declare function YearView<T = unknown>({ date, events, weekStartsOn, locale, activeDate, minMonthWidth, onPressDay, onPressMonth, theme: themeOverrides, className, style, classNames, styles }: YearViewProps<T>): ReactElement;
164
+ //#endregion
124
165
  //#region src/MonthView.d.ts
125
166
  /**
126
167
  * Styleable parts of {@link MonthView}. Pass a class or inline style per slot via
@@ -357,14 +398,14 @@ declare function TimeGrid<T = unknown>({ date, events, mode, numberOfDays, weekS
357
398
  * for the active `mode` apply; the rest are ignored. See {@link MonthViewSlot},
358
399
  * {@link TimeGridSlot}, and {@link AgendaSlot}.
359
400
  */
360
- type CalendarSlot = MonthViewSlot | TimeGridSlot | AgendaSlot;
401
+ type CalendarSlot = MonthViewSlot | TimeGridSlot | AgendaSlot | YearViewSlot;
361
402
  /** Props for {@link Calendar}. */
362
403
  interface CalendarProps<T = unknown> extends DateSelectionConstraints$1, SlotStyleProps<CalendarSlot> {
363
404
  /**
364
405
  * The view to render (default "week"). `month` renders a month grid, `schedule`
365
406
  * a day-grouped agenda list, and the others a time grid.
366
407
  */
367
- mode?: "month" | "schedule" | TimeGridMode$1;
408
+ mode?: CalendarMode$1;
368
409
  /** Controlled anchor date. Change it (e.g. from your own header) to navigate. */
369
410
  date: Date;
370
411
  /**
@@ -471,6 +512,8 @@ interface CalendarProps<T = unknown> extends DateSelectionConstraints$1, SlotSty
471
512
  keyboardDayNavigation?: boolean;
472
513
  /** Tap a day cell. */
473
514
  onPressDay?: (date: Date) => void;
515
+ /** Tap a month's title in the year view — e.g. jump to that month. */
516
+ onPressMonth?: (month: Date) => void;
474
517
  /** Tap the "+N more" overflow row. */
475
518
  onPressMore?: (events: CalendarEvent$1<T>[], date: Date) => void;
476
519
  /** Custom month chip renderer. */
@@ -489,7 +532,7 @@ interface CalendarProps<T = unknown> extends DateSelectionConstraints$1, SlotSty
489
532
  * <Calendar mode="week" date={new Date()} events={events} />
490
533
  * ```
491
534
  */
492
- declare function Calendar<T = unknown>({ mode, date, events, onChangeDate, weekStartsOn, numberOfDays, locale, timeZone, theme, height, className, style, onPressEvent, eventAccessibilityLabel, ampm, hourHeight, scrollOffsetMinutes, timeslots, minHour, maxHour, hideHours, showWeekNumber, weekNumberPrefix, businessHours, showNowIndicator, showAllDayEventCell, dragStepMinutes, onPressCell, onCreateEvent, onDragStart, onDragEvent, onPressDateHeader, renderTimeEvent, hourComponent, keyboardEventNavigation, maxVisibleEventCount, moreLabel, showAdjacentMonths, weekdayFormat, fillCellOnSelection, selectedRange, selectedDates, minDate, maxDate, isDateDisabled, keyboardDayNavigation, onPressDay, onPressMore, renderMonthEvent, renderScheduleEvent, classNames, styles }: CalendarProps<T>): ReactElement;
535
+ declare function Calendar<T = unknown>({ mode, date, events, onChangeDate, weekStartsOn, numberOfDays, locale, timeZone, theme, height, className, style, onPressEvent, eventAccessibilityLabel, ampm, hourHeight, scrollOffsetMinutes, timeslots, minHour, maxHour, hideHours, showWeekNumber, weekNumberPrefix, businessHours, showNowIndicator, showAllDayEventCell, dragStepMinutes, onPressCell, onCreateEvent, onDragStart, onDragEvent, onPressDateHeader, renderTimeEvent, hourComponent, keyboardEventNavigation, maxVisibleEventCount, moreLabel, showAdjacentMonths, weekdayFormat, fillCellOnSelection, selectedRange, selectedDates, minDate, maxDate, isDateDisabled, keyboardDayNavigation, onPressDay, onPressMonth, onPressMore, renderMonthEvent, renderScheduleEvent, classNames, styles }: CalendarProps<T>): ReactElement;
493
536
  //#endregion
494
537
  //#region src/MonthList.d.ts
495
538
  /**
@@ -727,4 +770,4 @@ interface ResourceTimelineProps<T = unknown> extends SlotStyleProps<ResourceTime
727
770
  */
728
771
  declare function ResourceTimeline<T = unknown>({ date, orientation, resources, events, resourceId, startHour, endHour, hourWidth, hourHeight, rowHeight, labelWidth, ampm, theme: themeOverrides, renderEvent, onPressEvent, onDragEvent, onPressCell, onCreateEvent, businessHours, dragStepMinutes, className, style, classNames, styles }: ResourceTimelineProps<T>): ReactElement;
729
772
  //#endregion
730
- export { Agenda, type AgendaProps, type AgendaSlot, type BusinessHours, Calendar, type CalendarEvent, type CalendarMode, type CalendarProps, type CalendarSlot, DatePicker, type DatePickerProps, type DatePickerSlot, type DateRange, DateRangePicker, type DateRangePickerProps, type DateSelectionConstraints, type DaySelectionState, type DomAgendaEvent, type DomAgendaEventArgs, type DomCalendarTheme, type DomMonthEvent, type DomMonthEventArgs, type DomRenderEvent, type DomRenderEventArgs, type EventAccessibilityLabelContext, type EventAccessibilityLabeler, type ICalEvent, type ICalendarEvent, type MonthGrid, type MonthGridDay, type MonthGridWeek, type MonthGridWeekday, MonthList, type MonthListProps, type MonthListSlot, MonthView, type MonthViewProps, type MonthViewSlot, type PositionedEvent, type RecurrenceFrequency, type RecurrenceRule, type ResolvedSlot, type Resource, type ResourceEventArgs, ResourceTimeline, type ResourceTimelineProps, type ResourceTimelineSlot, type SlotDefault, type SlotStyleProps, TimeGrid, type TimeGridMode, type TimeGridProps, type TimeGridSlot, type ToICalendarOptions, type UseDateRangeOptions, type UseMonthGridOptions, type WeekStartsOn, type WeekdayFormat, buildMonthGrid, darkDomTheme, daySelectionState, defaultDomTheme, expandRecurringEvents, getViewDays, isAllDayEvent, isDateSelectable, isRangeEndpoint, isWithinDateRange, layoutDayEvents, mergeDomTheme, nextDateRange, parseICalendar, toICalendar, useDateRange, useMonthGrid, weekdayFormatToken };
773
+ export { Agenda, type AgendaProps, type AgendaSlot, type BusinessHours, Calendar, type CalendarEvent, type CalendarMode, type CalendarProps, type CalendarSlot, DatePicker, type DatePickerProps, type DatePickerSlot, type DateRange, DateRangePicker, type DateRangePickerProps, type DateSelectionConstraints, type DaySelectionState, type DomAgendaEvent, type DomAgendaEventArgs, type DomCalendarTheme, type DomMonthEvent, type DomMonthEventArgs, type DomRenderEvent, type DomRenderEventArgs, type EventAccessibilityLabelContext, type EventAccessibilityLabeler, type ICalEvent, type ICalendarEvent, type MonthGrid, type MonthGridDay, type MonthGridWeek, type MonthGridWeekday, MonthList, type MonthListProps, type MonthListSlot, MonthView, type MonthViewProps, type MonthViewSlot, type PositionedEvent, type RecurrenceFrequency, type RecurrenceRule, type ResolvedSlot, type Resource, type ResourceEventArgs, ResourceTimeline, type ResourceTimelineProps, type ResourceTimelineSlot, type SlotDefault, type SlotStyleProps, TimeGrid, type TimeGridMode, type TimeGridProps, type TimeGridSlot, type ToICalendarOptions, type UseDateRangeOptions, type UseMonthGridOptions, type WeekStartsOn, type WeekdayFormat, YearView, type YearViewProps, type YearViewSlot, buildMonthGrid, darkDomTheme, daySelectionState, defaultDomTheme, expandRecurringEvents, getViewDays, isAllDayEvent, isDateSelectable, isRangeEndpoint, isWithinDateRange, layoutDayEvents, mergeDomTheme, nextDateRange, parseICalendar, toICalendar, useDateRange, useMonthGrid, weekdayFormatToken };
package/dist/index.d.ts CHANGED
@@ -121,6 +121,47 @@ interface AgendaProps<T = unknown> extends SlotStyleProps<AgendaSlot> {
121
121
  */
122
122
  declare function Agenda<T = unknown>({ events, locale, ampm, activeDate, theme: themeOverrides, height, renderEvent, eventAccessibilityLabel, onPressEvent, onPressDay, className, style, classNames, styles }: AgendaProps<T>): ReactElement;
123
123
  //#endregion
124
+ //#region src/YearView.d.ts
125
+ /**
126
+ * Styleable parts of {@link YearView}. Pass a class or inline style per slot
127
+ * via the `classNames` / `styles` props; day cells carry `data-today` and
128
+ * `data-events` state attributes for variants.
129
+ */
130
+ type YearViewSlot = "grid" | "month" | "monthTitle" | "weekdays" | "weekday" | "week" | "day" | "eventDot";
131
+ /** Props for {@link YearView}, the twelve mini-month year grid. */
132
+ interface YearViewProps<T = unknown> extends SlotStyleProps<YearViewSlot> {
133
+ /** Any date inside the year to render. */
134
+ date: Date;
135
+ /** Days holding at least one event get a dot. Omit for a plain year. */
136
+ events?: CalendarEvent$1<T>[];
137
+ /** First day of the week. Sunday = 0 (default) … Saturday = 6. */
138
+ weekStartsOn?: WeekStartsOn$1;
139
+ locale?: Locale;
140
+ /** Highlight this date instead of the real "today". */
141
+ activeDate?: Date;
142
+ /**
143
+ * Smallest width a mini month may take before the grid drops a column
144
+ * (default 150). The grid fits as many columns as the container allows.
145
+ */
146
+ minMonthWidth?: number;
147
+ /** Tap a day cell (e.g. to drill into the day or month view). */
148
+ onPressDay?: (date: Date) => void;
149
+ /** Tap a month's title (e.g. to jump to that month's view). */
150
+ onPressMonth?: (month: Date) => void;
151
+ /** Theme overrides; falls back to the default light theme. */
152
+ theme?: Partial<DomCalendarTheme>;
153
+ /** Class applied to the root element. */
154
+ className?: string;
155
+ /** Inline styles applied to the root element. */
156
+ style?: CSSProperties;
157
+ }
158
+ /**
159
+ * A year at a glance: the twelve months as compact mini grids, with today
160
+ * highlighted and a dot under days that hold events. It's the view `Calendar`
161
+ * renders for `mode="year"`.
162
+ */
163
+ declare function YearView<T = unknown>({ date, events, weekStartsOn, locale, activeDate, minMonthWidth, onPressDay, onPressMonth, theme: themeOverrides, className, style, classNames, styles }: YearViewProps<T>): ReactElement;
164
+ //#endregion
124
165
  //#region src/MonthView.d.ts
125
166
  /**
126
167
  * Styleable parts of {@link MonthView}. Pass a class or inline style per slot via
@@ -357,14 +398,14 @@ declare function TimeGrid<T = unknown>({ date, events, mode, numberOfDays, weekS
357
398
  * for the active `mode` apply; the rest are ignored. See {@link MonthViewSlot},
358
399
  * {@link TimeGridSlot}, and {@link AgendaSlot}.
359
400
  */
360
- type CalendarSlot = MonthViewSlot | TimeGridSlot | AgendaSlot;
401
+ type CalendarSlot = MonthViewSlot | TimeGridSlot | AgendaSlot | YearViewSlot;
361
402
  /** Props for {@link Calendar}. */
362
403
  interface CalendarProps<T = unknown> extends DateSelectionConstraints$1, SlotStyleProps<CalendarSlot> {
363
404
  /**
364
405
  * The view to render (default "week"). `month` renders a month grid, `schedule`
365
406
  * a day-grouped agenda list, and the others a time grid.
366
407
  */
367
- mode?: "month" | "schedule" | TimeGridMode$1;
408
+ mode?: CalendarMode$1;
368
409
  /** Controlled anchor date. Change it (e.g. from your own header) to navigate. */
369
410
  date: Date;
370
411
  /**
@@ -471,6 +512,8 @@ interface CalendarProps<T = unknown> extends DateSelectionConstraints$1, SlotSty
471
512
  keyboardDayNavigation?: boolean;
472
513
  /** Tap a day cell. */
473
514
  onPressDay?: (date: Date) => void;
515
+ /** Tap a month's title in the year view — e.g. jump to that month. */
516
+ onPressMonth?: (month: Date) => void;
474
517
  /** Tap the "+N more" overflow row. */
475
518
  onPressMore?: (events: CalendarEvent$1<T>[], date: Date) => void;
476
519
  /** Custom month chip renderer. */
@@ -489,7 +532,7 @@ interface CalendarProps<T = unknown> extends DateSelectionConstraints$1, SlotSty
489
532
  * <Calendar mode="week" date={new Date()} events={events} />
490
533
  * ```
491
534
  */
492
- declare function Calendar<T = unknown>({ mode, date, events, onChangeDate, weekStartsOn, numberOfDays, locale, timeZone, theme, height, className, style, onPressEvent, eventAccessibilityLabel, ampm, hourHeight, scrollOffsetMinutes, timeslots, minHour, maxHour, hideHours, showWeekNumber, weekNumberPrefix, businessHours, showNowIndicator, showAllDayEventCell, dragStepMinutes, onPressCell, onCreateEvent, onDragStart, onDragEvent, onPressDateHeader, renderTimeEvent, hourComponent, keyboardEventNavigation, maxVisibleEventCount, moreLabel, showAdjacentMonths, weekdayFormat, fillCellOnSelection, selectedRange, selectedDates, minDate, maxDate, isDateDisabled, keyboardDayNavigation, onPressDay, onPressMore, renderMonthEvent, renderScheduleEvent, classNames, styles }: CalendarProps<T>): ReactElement;
535
+ declare function Calendar<T = unknown>({ mode, date, events, onChangeDate, weekStartsOn, numberOfDays, locale, timeZone, theme, height, className, style, onPressEvent, eventAccessibilityLabel, ampm, hourHeight, scrollOffsetMinutes, timeslots, minHour, maxHour, hideHours, showWeekNumber, weekNumberPrefix, businessHours, showNowIndicator, showAllDayEventCell, dragStepMinutes, onPressCell, onCreateEvent, onDragStart, onDragEvent, onPressDateHeader, renderTimeEvent, hourComponent, keyboardEventNavigation, maxVisibleEventCount, moreLabel, showAdjacentMonths, weekdayFormat, fillCellOnSelection, selectedRange, selectedDates, minDate, maxDate, isDateDisabled, keyboardDayNavigation, onPressDay, onPressMonth, onPressMore, renderMonthEvent, renderScheduleEvent, classNames, styles }: CalendarProps<T>): ReactElement;
493
536
  //#endregion
494
537
  //#region src/MonthList.d.ts
495
538
  /**
@@ -727,4 +770,4 @@ interface ResourceTimelineProps<T = unknown> extends SlotStyleProps<ResourceTime
727
770
  */
728
771
  declare function ResourceTimeline<T = unknown>({ date, orientation, resources, events, resourceId, startHour, endHour, hourWidth, hourHeight, rowHeight, labelWidth, ampm, theme: themeOverrides, renderEvent, onPressEvent, onDragEvent, onPressCell, onCreateEvent, businessHours, dragStepMinutes, className, style, classNames, styles }: ResourceTimelineProps<T>): ReactElement;
729
772
  //#endregion
730
- export { Agenda, type AgendaProps, type AgendaSlot, type BusinessHours, Calendar, type CalendarEvent, type CalendarMode, type CalendarProps, type CalendarSlot, DatePicker, type DatePickerProps, type DatePickerSlot, type DateRange, DateRangePicker, type DateRangePickerProps, type DateSelectionConstraints, type DaySelectionState, type DomAgendaEvent, type DomAgendaEventArgs, type DomCalendarTheme, type DomMonthEvent, type DomMonthEventArgs, type DomRenderEvent, type DomRenderEventArgs, type EventAccessibilityLabelContext, type EventAccessibilityLabeler, type ICalEvent, type ICalendarEvent, type MonthGrid, type MonthGridDay, type MonthGridWeek, type MonthGridWeekday, MonthList, type MonthListProps, type MonthListSlot, MonthView, type MonthViewProps, type MonthViewSlot, type PositionedEvent, type RecurrenceFrequency, type RecurrenceRule, type ResolvedSlot, type Resource, type ResourceEventArgs, ResourceTimeline, type ResourceTimelineProps, type ResourceTimelineSlot, type SlotDefault, type SlotStyleProps, TimeGrid, type TimeGridMode, type TimeGridProps, type TimeGridSlot, type ToICalendarOptions, type UseDateRangeOptions, type UseMonthGridOptions, type WeekStartsOn, type WeekdayFormat, buildMonthGrid, darkDomTheme, daySelectionState, defaultDomTheme, expandRecurringEvents, getViewDays, isAllDayEvent, isDateSelectable, isRangeEndpoint, isWithinDateRange, layoutDayEvents, mergeDomTheme, nextDateRange, parseICalendar, toICalendar, useDateRange, useMonthGrid, weekdayFormatToken };
773
+ export { Agenda, type AgendaProps, type AgendaSlot, type BusinessHours, Calendar, type CalendarEvent, type CalendarMode, type CalendarProps, type CalendarSlot, DatePicker, type DatePickerProps, type DatePickerSlot, type DateRange, DateRangePicker, type DateRangePickerProps, type DateSelectionConstraints, type DaySelectionState, type DomAgendaEvent, type DomAgendaEventArgs, type DomCalendarTheme, type DomMonthEvent, type DomMonthEventArgs, type DomRenderEvent, type DomRenderEventArgs, type EventAccessibilityLabelContext, type EventAccessibilityLabeler, type ICalEvent, type ICalendarEvent, type MonthGrid, type MonthGridDay, type MonthGridWeek, type MonthGridWeekday, MonthList, type MonthListProps, type MonthListSlot, MonthView, type MonthViewProps, type MonthViewSlot, type PositionedEvent, type RecurrenceFrequency, type RecurrenceRule, type ResolvedSlot, type Resource, type ResourceEventArgs, ResourceTimeline, type ResourceTimelineProps, type ResourceTimelineSlot, type SlotDefault, type SlotStyleProps, TimeGrid, type TimeGridMode, type TimeGridProps, type TimeGridSlot, type ToICalendarOptions, type UseDateRangeOptions, type UseMonthGridOptions, type WeekStartsOn, type WeekdayFormat, YearView, type YearViewProps, type YearViewSlot, buildMonthGrid, darkDomTheme, daySelectionState, defaultDomTheme, expandRecurringEvents, getViewDays, isAllDayEvent, isDateSelectable, isRangeEndpoint, isWithinDateRange, layoutDayEvents, mergeDomTheme, nextDateRange, parseICalendar, toICalendar, useDateRange, useMonthGrid, weekdayFormatToken };
package/dist/index.js CHANGED
@@ -235,6 +235,183 @@ function Agenda({ events, locale, ampm = false, activeDate, theme: themeOverride
235
235
  });
236
236
  }
237
237
  //#endregion
238
+ //#region src/YearView.tsx
239
+ /**
240
+ * A year at a glance: the twelve months as compact mini grids, with today
241
+ * highlighted and a dot under days that hold events. It's the view `Calendar`
242
+ * renders for `mode="year"`.
243
+ */
244
+ function YearView({ date, events, weekStartsOn = 0, locale, activeDate, minMonthWidth = 150, onPressDay, onPressMonth, theme: themeOverrides, className, style, classNames, styles }) {
245
+ const theme = (0, react.useMemo)(() => mergeDomTheme(themeOverrides), [themeOverrides]);
246
+ const slot = createSlots({
247
+ classNames,
248
+ styles
249
+ });
250
+ const months = (0, react.useMemo)(() => (0, _super_calendar_core.getYearMonths)(date), [date]);
251
+ const weekdayLabels = (0, react.useMemo)(() => (0, _super_calendar_core.getWeekDays)(date, weekStartsOn).map((d) => (0, date_fns.format)(d, (0, _super_calendar_core.weekdayFormatToken)("narrow"), { locale })), [
252
+ date,
253
+ weekStartsOn,
254
+ locale
255
+ ]);
256
+ const eventDays = (0, react.useMemo)(() => new Set(events && events.length > 0 ? (0, _super_calendar_core.groupEventsByDay)(events).keys() : []), [events]);
257
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
258
+ className,
259
+ style: {
260
+ fontFamily: theme.fontFamily,
261
+ color: theme.text,
262
+ overflowY: "auto",
263
+ ...style
264
+ },
265
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
266
+ ...slot("grid", { base: {
267
+ display: "grid",
268
+ gridTemplateColumns: `repeat(auto-fill, minmax(${minMonthWidth}px, 1fr))`
269
+ } }),
270
+ children: months.map((month) => {
271
+ const weeks = (0, _super_calendar_core.buildMonthWeeks)(month, weekStartsOn);
272
+ const monthLabel = (0, date_fns.format)(month, "MMMM yyyy", { locale });
273
+ const titleContent = (0, date_fns.format)(month, "MMMM", { locale });
274
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
275
+ ...slot("month", { base: { padding: 8 } }),
276
+ children: [
277
+ onPressMonth ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
278
+ type: "button",
279
+ onClick: () => onPressMonth(month),
280
+ "aria-label": monthLabel,
281
+ ...slot("monthTitle", {
282
+ base: {
283
+ display: "block",
284
+ border: "none",
285
+ background: "transparent",
286
+ padding: "0 0 4px",
287
+ cursor: "pointer",
288
+ font: "inherit",
289
+ textAlign: "left"
290
+ },
291
+ themed: {
292
+ fontSize: 13,
293
+ fontWeight: 700,
294
+ color: theme.todayBackground
295
+ }
296
+ }),
297
+ children: titleContent
298
+ }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
299
+ role: "heading",
300
+ "aria-level": 3,
301
+ "aria-label": monthLabel,
302
+ ...slot("monthTitle", {
303
+ base: { paddingBottom: 4 },
304
+ themed: {
305
+ fontSize: 13,
306
+ fontWeight: 700,
307
+ color: theme.todayBackground
308
+ }
309
+ }),
310
+ children: titleContent
311
+ }),
312
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
313
+ ...slot("weekdays", { base: {
314
+ display: "grid",
315
+ gridTemplateColumns: "repeat(7, 1fr)"
316
+ } }),
317
+ children: weekdayLabels.map((label, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
318
+ "aria-hidden": true,
319
+ ...slot("weekday", {
320
+ base: { textAlign: "center" },
321
+ themed: {
322
+ fontSize: 9,
323
+ fontWeight: 600,
324
+ color: theme.textMuted
325
+ }
326
+ }),
327
+ children: label
328
+ }, i))
329
+ }),
330
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
331
+ role: "grid",
332
+ "aria-label": monthLabel,
333
+ children: weeks.map((week) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
334
+ role: "row",
335
+ ...slot("week", { base: {
336
+ display: "grid",
337
+ gridTemplateColumns: "repeat(7, 1fr)"
338
+ } }),
339
+ children: week.map((day) => {
340
+ if (day.getMonth() !== month.getMonth()) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
341
+ role: "gridcell",
342
+ "aria-hidden": true,
343
+ style: { aspectRatio: "1" }
344
+ }, day.toISOString());
345
+ const isHighlighted = activeDate ? (0, _super_calendar_core.isSameCalendarDay)(day, activeDate) : (0, _super_calendar_core.getIsToday)(day);
346
+ const hasEvents = eventDays.has((0, date_fns.startOfDay)(day).toISOString());
347
+ const label = `${(0, date_fns.format)(day, "EEEE, d LLLL yyyy", { locale })}${(0, _super_calendar_core.getIsToday)(day) ? ", today" : ""}${hasEvents ? ", has events" : ""}`;
348
+ const daySlot = slot("day", {
349
+ base: {
350
+ position: "relative",
351
+ aspectRatio: "1",
352
+ display: "flex",
353
+ alignItems: "center",
354
+ justifyContent: "center",
355
+ padding: 0,
356
+ border: "none",
357
+ background: "transparent",
358
+ font: "inherit",
359
+ cursor: onPressDay ? "pointer" : "default",
360
+ boxSizing: "border-box"
361
+ },
362
+ themed: {
363
+ fontSize: 11,
364
+ borderRadius: "50%",
365
+ ...isHighlighted ? {
366
+ background: theme.todayBackground,
367
+ color: theme.todayText
368
+ } : { color: theme.text }
369
+ }
370
+ });
371
+ const states = dataState({
372
+ "data-today": (0, _super_calendar_core.getIsToday)(day),
373
+ "data-events": hasEvents
374
+ });
375
+ const dot = hasEvents ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
376
+ "aria-hidden": true,
377
+ ...slot("eventDot", {
378
+ base: {
379
+ position: "absolute",
380
+ bottom: 1,
381
+ left: "50%",
382
+ marginLeft: -1.5,
383
+ width: 3,
384
+ height: 3,
385
+ borderRadius: 2
386
+ },
387
+ themed: { background: isHighlighted ? theme.todayText : theme.todayBackground }
388
+ })
389
+ }) : null;
390
+ return onPressDay ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("button", {
391
+ type: "button",
392
+ role: "gridcell",
393
+ onClick: () => onPressDay(day),
394
+ "aria-label": label,
395
+ ...states,
396
+ ...daySlot,
397
+ children: [day.getDate(), dot]
398
+ }, day.toISOString()) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
399
+ role: "gridcell",
400
+ "aria-label": label,
401
+ ...states,
402
+ ...daySlot,
403
+ children: [day.getDate(), dot]
404
+ }, day.toISOString());
405
+ })
406
+ }, week[0].toISOString()))
407
+ })
408
+ ]
409
+ }, month.toISOString());
410
+ })
411
+ })
412
+ });
413
+ }
414
+ //#endregion
238
415
  //#region src/MonthView.tsx
239
416
  const DATE_ROW = 24;
240
417
  const CHIP_HEIGHT = 18;
@@ -1533,11 +1710,13 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
1533
1710
  const EMPTY_EVENTS = [];
1534
1711
  function expansionRange(mode, date, weekStartsOn, numberOfDays) {
1535
1712
  if (mode === "month") return [(0, date_fns.startOfWeek)((0, date_fns.startOfMonth)(date), { weekStartsOn }), (0, date_fns.endOfWeek)((0, date_fns.endOfMonth)(date), { weekStartsOn })];
1713
+ if (mode === "year") return [(0, date_fns.startOfWeek)((0, date_fns.startOfYear)(date), { weekStartsOn }), (0, date_fns.endOfWeek)((0, date_fns.endOfYear)(date), { weekStartsOn })];
1536
1714
  if (mode === "schedule") return [(0, date_fns.startOfDay)(date), (0, date_fns.endOfDay)((0, date_fns.addMonths)(date, 3))];
1537
1715
  const days = (0, _super_calendar_core.getViewDays)(mode, date, weekStartsOn, numberOfDays ?? 1);
1538
1716
  return [(0, date_fns.startOfDay)(days[0]), (0, date_fns.endOfDay)(days[days.length - 1])];
1539
1717
  }
1540
1718
  function pageStep(mode, date, direction, weekStartsOn, numberOfDays) {
1719
+ if (mode === "year") return (0, date_fns.addYears)(date, direction);
1541
1720
  if (mode === "month") return (0, date_fns.addMonths)(date, direction);
1542
1721
  if (mode === "schedule") return (0, date_fns.addDays)(date, direction * 7);
1543
1722
  return (0, date_fns.addDays)(date, direction * (0, _super_calendar_core.getViewDays)(mode, date, weekStartsOn, numberOfDays ?? 1).length);
@@ -1553,7 +1732,7 @@ function pageStep(mode, date, direction, weekStartsOn, numberOfDays) {
1553
1732
  * <Calendar mode="week" date={new Date()} events={events} />
1554
1733
  * ```
1555
1734
  */
1556
- function Calendar({ mode = "week", date, events, onChangeDate, weekStartsOn = 0, numberOfDays, locale, timeZone, theme, height, className, style, onPressEvent, eventAccessibilityLabel, ampm, hourHeight, scrollOffsetMinutes, timeslots, minHour, maxHour, hideHours, showWeekNumber, weekNumberPrefix, businessHours, showNowIndicator, showAllDayEventCell, dragStepMinutes, onPressCell, onCreateEvent, onDragStart, onDragEvent, onPressDateHeader, renderTimeEvent, hourComponent, keyboardEventNavigation, maxVisibleEventCount, moreLabel, showAdjacentMonths, weekdayFormat, fillCellOnSelection, selectedRange, selectedDates, minDate, maxDate, isDateDisabled, keyboardDayNavigation, onPressDay, onPressMore, renderMonthEvent, renderScheduleEvent, classNames, styles }) {
1735
+ function Calendar({ mode = "week", date, events, onChangeDate, weekStartsOn = 0, numberOfDays, locale, timeZone, theme, height, className, style, onPressEvent, eventAccessibilityLabel, ampm, hourHeight, scrollOffsetMinutes, timeslots, minHour, maxHour, hideHours, showWeekNumber, weekNumberPrefix, businessHours, showNowIndicator, showAllDayEventCell, dragStepMinutes, onPressCell, onCreateEvent, onDragStart, onDragEvent, onPressDateHeader, renderTimeEvent, hourComponent, keyboardEventNavigation, maxVisibleEventCount, moreLabel, showAdjacentMonths, weekdayFormat, fillCellOnSelection, selectedRange, selectedDates, minDate, maxDate, isDateDisabled, keyboardDayNavigation, onPressDay, onPressMonth, onPressMore, renderMonthEvent, renderScheduleEvent, classNames, styles }) {
1557
1736
  const displayEvents = (0, react.useMemo)(() => {
1558
1737
  let out = events ?? EMPTY_EVENTS;
1559
1738
  if (out.some((e) => e.recurrence)) {
@@ -1582,7 +1761,23 @@ function Calendar({ mode = "week", date, events, onChangeDate, weekStartsOn = 0,
1582
1761
  e.preventDefault();
1583
1762
  };
1584
1763
  let view;
1585
- if (mode === "schedule") view = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Agenda, {
1764
+ if (mode === "year") view = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(YearView, {
1765
+ date,
1766
+ events: displayEvents,
1767
+ weekStartsOn,
1768
+ locale,
1769
+ theme,
1770
+ className,
1771
+ style: height != null ? {
1772
+ height,
1773
+ ...style
1774
+ } : style,
1775
+ classNames,
1776
+ styles,
1777
+ onPressDay,
1778
+ onPressMonth
1779
+ });
1780
+ else if (mode === "schedule") view = /* @__PURE__ */ (0, react_jsx_runtime.jsx)(Agenda, {
1586
1781
  events: displayEvents,
1587
1782
  locale,
1588
1783
  ampm,
@@ -2654,6 +2849,7 @@ exports.MonthList = MonthList;
2654
2849
  exports.MonthView = MonthView;
2655
2850
  exports.ResourceTimeline = ResourceTimeline;
2656
2851
  exports.TimeGrid = TimeGrid;
2852
+ exports.YearView = YearView;
2657
2853
  Object.defineProperty(exports, "buildMonthGrid", {
2658
2854
  enumerable: true,
2659
2855
  get: function() {
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
1
  import { LegendList } from "@legendapp/list/react";
2
- import { addDays, addMinutes, addMonths, endOfDay, endOfMonth, endOfWeek, format, getISOWeek, isSameDay, isSameMonth, startOfDay, startOfMonth, startOfWeek } from "date-fns";
2
+ import { addDays, addMinutes, addMonths, addYears, endOfDay, endOfMonth, endOfWeek, endOfYear, format, getISOWeek, isSameDay, isSameMonth, startOfDay, startOfMonth, startOfWeek, startOfYear } from "date-fns";
3
3
  import { useEffect, useId, useMemo, useRef, useState } from "react";
4
- import { bandRounding, buildMonthGrid, buildMonthGrid as buildMonthGrid$1, cellRangeFromDrag, closedHourBands, compareDayEvents, darkColors, dayBadgeKind, daySelectionState, eventAccessibilityLabel, eventChipLayout, eventTimeLabel, eventsInTimeZone, expandRecurringEvents, expandRecurringEvents as expandRecurringEvents$1, formatHour, getIsToday, getViewDays, getViewDays as getViewDays$1, groupEventsByDay, isAllDayEvent, isAllDayEvent as isAllDayEvent$1, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isWeekend, isWithinDateRange, layoutDayEvents, layoutDayEvents as layoutDayEvents$1, lightColors, monthVisibleCount, nextDateRange, nextDateRange as nextDateRange$1, parseICalendar, rangeBandKind, titleNumberOfLines, toICalendar, useDateRange, useMonthGrid, weekdayFormatToken, weekdayFormatToken as weekdayFormatToken$1 } from "@super-calendar/core";
4
+ import { bandRounding, buildMonthGrid, buildMonthGrid as buildMonthGrid$1, buildMonthWeeks, cellRangeFromDrag, closedHourBands, compareDayEvents, darkColors, dayBadgeKind, daySelectionState, eventAccessibilityLabel, eventChipLayout, eventTimeLabel, eventsInTimeZone, expandRecurringEvents, expandRecurringEvents as expandRecurringEvents$1, formatHour, getIsToday, getViewDays, getViewDays as getViewDays$1, getWeekDays, getYearMonths, groupEventsByDay, isAllDayEvent, isAllDayEvent as isAllDayEvent$1, isDateSelectable, isRangeEndpoint, isSameCalendarDay, isWeekend, isWithinDateRange, layoutDayEvents, layoutDayEvents as layoutDayEvents$1, lightColors, monthVisibleCount, nextDateRange, nextDateRange as nextDateRange$1, parseICalendar, rangeBandKind, titleNumberOfLines, toICalendar, useDateRange, useMonthGrid, weekdayFormatToken, weekdayFormatToken as weekdayFormatToken$1 } from "@super-calendar/core";
5
5
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
6
6
  //#region src/slots.ts
7
7
  /** Join truthy class names (a dependency-free clsx-lite). */
@@ -234,6 +234,183 @@ function Agenda({ events, locale, ampm = false, activeDate, theme: themeOverride
234
234
  });
235
235
  }
236
236
  //#endregion
237
+ //#region src/YearView.tsx
238
+ /**
239
+ * A year at a glance: the twelve months as compact mini grids, with today
240
+ * highlighted and a dot under days that hold events. It's the view `Calendar`
241
+ * renders for `mode="year"`.
242
+ */
243
+ function YearView({ date, events, weekStartsOn = 0, locale, activeDate, minMonthWidth = 150, onPressDay, onPressMonth, theme: themeOverrides, className, style, classNames, styles }) {
244
+ const theme = useMemo(() => mergeDomTheme(themeOverrides), [themeOverrides]);
245
+ const slot = createSlots({
246
+ classNames,
247
+ styles
248
+ });
249
+ const months = useMemo(() => getYearMonths(date), [date]);
250
+ const weekdayLabels = useMemo(() => getWeekDays(date, weekStartsOn).map((d) => format(d, weekdayFormatToken$1("narrow"), { locale })), [
251
+ date,
252
+ weekStartsOn,
253
+ locale
254
+ ]);
255
+ const eventDays = useMemo(() => new Set(events && events.length > 0 ? groupEventsByDay(events).keys() : []), [events]);
256
+ return /* @__PURE__ */ jsx("div", {
257
+ className,
258
+ style: {
259
+ fontFamily: theme.fontFamily,
260
+ color: theme.text,
261
+ overflowY: "auto",
262
+ ...style
263
+ },
264
+ children: /* @__PURE__ */ jsx("div", {
265
+ ...slot("grid", { base: {
266
+ display: "grid",
267
+ gridTemplateColumns: `repeat(auto-fill, minmax(${minMonthWidth}px, 1fr))`
268
+ } }),
269
+ children: months.map((month) => {
270
+ const weeks = buildMonthWeeks(month, weekStartsOn);
271
+ const monthLabel = format(month, "MMMM yyyy", { locale });
272
+ const titleContent = format(month, "MMMM", { locale });
273
+ return /* @__PURE__ */ jsxs("div", {
274
+ ...slot("month", { base: { padding: 8 } }),
275
+ children: [
276
+ onPressMonth ? /* @__PURE__ */ jsx("button", {
277
+ type: "button",
278
+ onClick: () => onPressMonth(month),
279
+ "aria-label": monthLabel,
280
+ ...slot("monthTitle", {
281
+ base: {
282
+ display: "block",
283
+ border: "none",
284
+ background: "transparent",
285
+ padding: "0 0 4px",
286
+ cursor: "pointer",
287
+ font: "inherit",
288
+ textAlign: "left"
289
+ },
290
+ themed: {
291
+ fontSize: 13,
292
+ fontWeight: 700,
293
+ color: theme.todayBackground
294
+ }
295
+ }),
296
+ children: titleContent
297
+ }) : /* @__PURE__ */ jsx("div", {
298
+ role: "heading",
299
+ "aria-level": 3,
300
+ "aria-label": monthLabel,
301
+ ...slot("monthTitle", {
302
+ base: { paddingBottom: 4 },
303
+ themed: {
304
+ fontSize: 13,
305
+ fontWeight: 700,
306
+ color: theme.todayBackground
307
+ }
308
+ }),
309
+ children: titleContent
310
+ }),
311
+ /* @__PURE__ */ jsx("div", {
312
+ ...slot("weekdays", { base: {
313
+ display: "grid",
314
+ gridTemplateColumns: "repeat(7, 1fr)"
315
+ } }),
316
+ children: weekdayLabels.map((label, i) => /* @__PURE__ */ jsx("div", {
317
+ "aria-hidden": true,
318
+ ...slot("weekday", {
319
+ base: { textAlign: "center" },
320
+ themed: {
321
+ fontSize: 9,
322
+ fontWeight: 600,
323
+ color: theme.textMuted
324
+ }
325
+ }),
326
+ children: label
327
+ }, i))
328
+ }),
329
+ /* @__PURE__ */ jsx("div", {
330
+ role: "grid",
331
+ "aria-label": monthLabel,
332
+ children: weeks.map((week) => /* @__PURE__ */ jsx("div", {
333
+ role: "row",
334
+ ...slot("week", { base: {
335
+ display: "grid",
336
+ gridTemplateColumns: "repeat(7, 1fr)"
337
+ } }),
338
+ children: week.map((day) => {
339
+ if (day.getMonth() !== month.getMonth()) return /* @__PURE__ */ jsx("div", {
340
+ role: "gridcell",
341
+ "aria-hidden": true,
342
+ style: { aspectRatio: "1" }
343
+ }, day.toISOString());
344
+ const isHighlighted = activeDate ? isSameCalendarDay(day, activeDate) : getIsToday(day);
345
+ const hasEvents = eventDays.has(startOfDay(day).toISOString());
346
+ const label = `${format(day, "EEEE, d LLLL yyyy", { locale })}${getIsToday(day) ? ", today" : ""}${hasEvents ? ", has events" : ""}`;
347
+ const daySlot = slot("day", {
348
+ base: {
349
+ position: "relative",
350
+ aspectRatio: "1",
351
+ display: "flex",
352
+ alignItems: "center",
353
+ justifyContent: "center",
354
+ padding: 0,
355
+ border: "none",
356
+ background: "transparent",
357
+ font: "inherit",
358
+ cursor: onPressDay ? "pointer" : "default",
359
+ boxSizing: "border-box"
360
+ },
361
+ themed: {
362
+ fontSize: 11,
363
+ borderRadius: "50%",
364
+ ...isHighlighted ? {
365
+ background: theme.todayBackground,
366
+ color: theme.todayText
367
+ } : { color: theme.text }
368
+ }
369
+ });
370
+ const states = dataState({
371
+ "data-today": getIsToday(day),
372
+ "data-events": hasEvents
373
+ });
374
+ const dot = hasEvents ? /* @__PURE__ */ jsx("span", {
375
+ "aria-hidden": true,
376
+ ...slot("eventDot", {
377
+ base: {
378
+ position: "absolute",
379
+ bottom: 1,
380
+ left: "50%",
381
+ marginLeft: -1.5,
382
+ width: 3,
383
+ height: 3,
384
+ borderRadius: 2
385
+ },
386
+ themed: { background: isHighlighted ? theme.todayText : theme.todayBackground }
387
+ })
388
+ }) : null;
389
+ return onPressDay ? /* @__PURE__ */ jsxs("button", {
390
+ type: "button",
391
+ role: "gridcell",
392
+ onClick: () => onPressDay(day),
393
+ "aria-label": label,
394
+ ...states,
395
+ ...daySlot,
396
+ children: [day.getDate(), dot]
397
+ }, day.toISOString()) : /* @__PURE__ */ jsxs("div", {
398
+ role: "gridcell",
399
+ "aria-label": label,
400
+ ...states,
401
+ ...daySlot,
402
+ children: [day.getDate(), dot]
403
+ }, day.toISOString());
404
+ })
405
+ }, week[0].toISOString()))
406
+ })
407
+ ]
408
+ }, month.toISOString());
409
+ })
410
+ })
411
+ });
412
+ }
413
+ //#endregion
237
414
  //#region src/MonthView.tsx
238
415
  const DATE_ROW = 24;
239
416
  const CHIP_HEIGHT = 18;
@@ -1532,11 +1709,13 @@ function TimeGrid({ date, events = [], mode = "day", numberOfDays = 1, weekStart
1532
1709
  const EMPTY_EVENTS = [];
1533
1710
  function expansionRange(mode, date, weekStartsOn, numberOfDays) {
1534
1711
  if (mode === "month") return [startOfWeek(startOfMonth(date), { weekStartsOn }), endOfWeek(endOfMonth(date), { weekStartsOn })];
1712
+ if (mode === "year") return [startOfWeek(startOfYear(date), { weekStartsOn }), endOfWeek(endOfYear(date), { weekStartsOn })];
1535
1713
  if (mode === "schedule") return [startOfDay(date), endOfDay(addMonths(date, 3))];
1536
1714
  const days = getViewDays$1(mode, date, weekStartsOn, numberOfDays ?? 1);
1537
1715
  return [startOfDay(days[0]), endOfDay(days[days.length - 1])];
1538
1716
  }
1539
1717
  function pageStep(mode, date, direction, weekStartsOn, numberOfDays) {
1718
+ if (mode === "year") return addYears(date, direction);
1540
1719
  if (mode === "month") return addMonths(date, direction);
1541
1720
  if (mode === "schedule") return addDays(date, direction * 7);
1542
1721
  return addDays(date, direction * getViewDays$1(mode, date, weekStartsOn, numberOfDays ?? 1).length);
@@ -1552,7 +1731,7 @@ function pageStep(mode, date, direction, weekStartsOn, numberOfDays) {
1552
1731
  * <Calendar mode="week" date={new Date()} events={events} />
1553
1732
  * ```
1554
1733
  */
1555
- function Calendar({ mode = "week", date, events, onChangeDate, weekStartsOn = 0, numberOfDays, locale, timeZone, theme, height, className, style, onPressEvent, eventAccessibilityLabel, ampm, hourHeight, scrollOffsetMinutes, timeslots, minHour, maxHour, hideHours, showWeekNumber, weekNumberPrefix, businessHours, showNowIndicator, showAllDayEventCell, dragStepMinutes, onPressCell, onCreateEvent, onDragStart, onDragEvent, onPressDateHeader, renderTimeEvent, hourComponent, keyboardEventNavigation, maxVisibleEventCount, moreLabel, showAdjacentMonths, weekdayFormat, fillCellOnSelection, selectedRange, selectedDates, minDate, maxDate, isDateDisabled, keyboardDayNavigation, onPressDay, onPressMore, renderMonthEvent, renderScheduleEvent, classNames, styles }) {
1734
+ function Calendar({ mode = "week", date, events, onChangeDate, weekStartsOn = 0, numberOfDays, locale, timeZone, theme, height, className, style, onPressEvent, eventAccessibilityLabel, ampm, hourHeight, scrollOffsetMinutes, timeslots, minHour, maxHour, hideHours, showWeekNumber, weekNumberPrefix, businessHours, showNowIndicator, showAllDayEventCell, dragStepMinutes, onPressCell, onCreateEvent, onDragStart, onDragEvent, onPressDateHeader, renderTimeEvent, hourComponent, keyboardEventNavigation, maxVisibleEventCount, moreLabel, showAdjacentMonths, weekdayFormat, fillCellOnSelection, selectedRange, selectedDates, minDate, maxDate, isDateDisabled, keyboardDayNavigation, onPressDay, onPressMonth, onPressMore, renderMonthEvent, renderScheduleEvent, classNames, styles }) {
1556
1735
  const displayEvents = useMemo(() => {
1557
1736
  let out = events ?? EMPTY_EVENTS;
1558
1737
  if (out.some((e) => e.recurrence)) {
@@ -1581,7 +1760,23 @@ function Calendar({ mode = "week", date, events, onChangeDate, weekStartsOn = 0,
1581
1760
  e.preventDefault();
1582
1761
  };
1583
1762
  let view;
1584
- if (mode === "schedule") view = /* @__PURE__ */ jsx(Agenda, {
1763
+ if (mode === "year") view = /* @__PURE__ */ jsx(YearView, {
1764
+ date,
1765
+ events: displayEvents,
1766
+ weekStartsOn,
1767
+ locale,
1768
+ theme,
1769
+ className,
1770
+ style: height != null ? {
1771
+ height,
1772
+ ...style
1773
+ } : style,
1774
+ classNames,
1775
+ styles,
1776
+ onPressDay,
1777
+ onPressMonth
1778
+ });
1779
+ else if (mode === "schedule") view = /* @__PURE__ */ jsx(Agenda, {
1585
1780
  events: displayEvents,
1586
1781
  locale,
1587
1782
  ampm,
@@ -2645,4 +2840,4 @@ function ResourceTimeline({ date, orientation = "horizontal", resources, events,
2645
2840
  });
2646
2841
  }
2647
2842
  //#endregion
2648
- export { Agenda, Calendar, DatePicker, DateRangePicker, MonthList, MonthView, ResourceTimeline, TimeGrid, buildMonthGrid, darkDomTheme, daySelectionState, defaultDomTheme, expandRecurringEvents, getViewDays, isAllDayEvent, isDateSelectable, isRangeEndpoint, isWithinDateRange, layoutDayEvents, mergeDomTheme, nextDateRange, parseICalendar, toICalendar, useDateRange, useMonthGrid, weekdayFormatToken };
2843
+ export { Agenda, Calendar, DatePicker, DateRangePicker, MonthList, MonthView, ResourceTimeline, TimeGrid, YearView, buildMonthGrid, darkDomTheme, daySelectionState, defaultDomTheme, expandRecurringEvents, getViewDays, isAllDayEvent, isDateSelectable, isRangeEndpoint, isWithinDateRange, layoutDayEvents, mergeDomTheme, nextDateRange, parseICalendar, toICalendar, useDateRange, useMonthGrid, weekdayFormatToken };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@super-calendar/dom",
3
- "version": "2.5.0",
3
+ "version": "2.6.0",
4
4
  "description": "Virtualized month / week / day calendar and date picker for react-dom. No React Native, no react-native-web.",
5
5
  "keywords": [
6
6
  "calendar",
@@ -48,7 +48,7 @@
48
48
  "access": "public"
49
49
  },
50
50
  "dependencies": {
51
- "@super-calendar/core": "2.5.0"
51
+ "@super-calendar/core": "2.6.0"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "@legendapp/list": ">=3",
package/src/Calendar.tsx CHANGED
@@ -8,6 +8,9 @@ import {
8
8
  startOfDay,
9
9
  startOfMonth,
10
10
  startOfWeek,
11
+ addYears,
12
+ endOfYear,
13
+ startOfYear,
11
14
  } from "date-fns";
12
15
  import {
13
16
  type CSSProperties,
@@ -17,6 +20,7 @@ import {
17
20
  useMemo,
18
21
  } from "react";
19
22
  import {
23
+ type CalendarMode,
20
24
  type BusinessHours,
21
25
  type CalendarEvent,
22
26
  type DateRange,
@@ -25,11 +29,11 @@ import {
25
29
  eventsInTimeZone,
26
30
  expandRecurringEvents,
27
31
  getViewDays,
28
- type TimeGridMode,
29
32
  type WeekdayFormat,
30
33
  type WeekStartsOn,
31
34
  } from "@super-calendar/core";
32
35
  import { Agenda, type AgendaSlot, type DomAgendaEvent } from "./Agenda";
36
+ import { YearView, type YearViewSlot } from "./YearView";
33
37
  import { type DomMonthEvent, MonthView, type MonthViewSlot } from "./MonthView";
34
38
  import type { SlotStyleProps } from "./slots";
35
39
  import { type DomRenderEvent, TimeGrid, type TimeGridSlot } from "./TimeGrid";
@@ -40,7 +44,7 @@ import type { DomCalendarTheme } from "./theme";
40
44
  * for the active `mode` apply; the rest are ignored. See {@link MonthViewSlot},
41
45
  * {@link TimeGridSlot}, and {@link AgendaSlot}.
42
46
  */
43
- export type CalendarSlot = MonthViewSlot | TimeGridSlot | AgendaSlot;
47
+ export type CalendarSlot = MonthViewSlot | TimeGridSlot | AgendaSlot | YearViewSlot;
44
48
 
45
49
  /** Props for {@link Calendar}. */
46
50
  export interface CalendarProps<T = unknown>
@@ -49,7 +53,7 @@ export interface CalendarProps<T = unknown>
49
53
  * The view to render (default "week"). `month` renders a month grid, `schedule`
50
54
  * a day-grouped agenda list, and the others a time grid.
51
55
  */
52
- mode?: "month" | "schedule" | TimeGridMode;
56
+ mode?: CalendarMode;
53
57
  /** Controlled anchor date. Change it (e.g. from your own header) to navigate. */
54
58
  date: Date;
55
59
  /**
@@ -161,6 +165,8 @@ export interface CalendarProps<T = unknown>
161
165
  keyboardDayNavigation?: boolean;
162
166
  /** Tap a day cell. */
163
167
  onPressDay?: (date: Date) => void;
168
+ /** Tap a month's title in the year view — e.g. jump to that month. */
169
+ onPressMonth?: (month: Date) => void;
164
170
  /** Tap the "+N more" overflow row. */
165
171
  onPressMore?: (events: CalendarEvent<T>[], date: Date) => void;
166
172
  /** Custom month chip renderer. */
@@ -179,7 +185,7 @@ const EMPTY_EVENTS: CalendarEvent<never>[] = [];
179
185
  // `month`, the day columns for the time-grid modes, and a forward window for the
180
186
  // `schedule` agenda (which has no bounded viewport of its own).
181
187
  function expansionRange(
182
- mode: "month" | "schedule" | TimeGridMode,
188
+ mode: CalendarMode,
183
189
  date: Date,
184
190
  weekStartsOn: WeekStartsOn,
185
191
  numberOfDays: number | undefined,
@@ -190,6 +196,12 @@ function expansionRange(
190
196
  endOfWeek(endOfMonth(date), { weekStartsOn }),
191
197
  ];
192
198
  }
199
+ if (mode === "year") {
200
+ return [
201
+ startOfWeek(startOfYear(date), { weekStartsOn }),
202
+ endOfWeek(endOfYear(date), { weekStartsOn }),
203
+ ];
204
+ }
193
205
  if (mode === "schedule") {
194
206
  // The agenda lists forward from the anchor date; three months is a sensible
195
207
  // default look-ahead. Pre-expand for a different window.
@@ -199,15 +211,16 @@ function expansionRange(
199
211
  return [startOfDay(days[0]), endOfDay(days[days.length - 1])];
200
212
  }
201
213
 
202
- // The date one page away in `direction` (+1 next, −1 previous): a month for
203
- // `month`, a week for `schedule`, else the view's day span.
214
+ // The date one page away in `direction` (+1 next, −1 previous): a year for
215
+ // `year`, a month for `month`, a week for `schedule`, else the view's day span.
204
216
  function pageStep(
205
- mode: "month" | "schedule" | TimeGridMode,
217
+ mode: CalendarMode,
206
218
  date: Date,
207
219
  direction: number,
208
220
  weekStartsOn: WeekStartsOn,
209
221
  numberOfDays: number | undefined,
210
222
  ): Date {
223
+ if (mode === "year") return addYears(date, direction);
211
224
  if (mode === "month") return addMonths(date, direction);
212
225
  if (mode === "schedule") return addDays(date, direction * 7);
213
226
  return addDays(date, direction * getViewDays(mode, date, weekStartsOn, numberOfDays ?? 1).length);
@@ -274,6 +287,7 @@ export function Calendar<T = unknown>({
274
287
  isDateDisabled,
275
288
  keyboardDayNavigation,
276
289
  onPressDay,
290
+ onPressMonth,
277
291
  onPressMore,
278
292
  renderMonthEvent,
279
293
  // schedule
@@ -313,7 +327,23 @@ export function Calendar<T = unknown>({
313
327
  };
314
328
 
315
329
  let view: ReactElement;
316
- if (mode === "schedule") {
330
+ if (mode === "year") {
331
+ view = (
332
+ <YearView<T>
333
+ date={date}
334
+ events={displayEvents}
335
+ weekStartsOn={weekStartsOn}
336
+ locale={locale}
337
+ theme={theme}
338
+ className={className}
339
+ style={height != null ? { height, ...style } : style}
340
+ classNames={classNames}
341
+ styles={styles}
342
+ onPressDay={onPressDay}
343
+ onPressMonth={onPressMonth}
344
+ />
345
+ );
346
+ } else if (mode === "schedule") {
317
347
  view = (
318
348
  <Agenda<T>
319
349
  events={displayEvents}
@@ -0,0 +1,283 @@
1
+ import { format, startOfDay, type Locale } from "date-fns";
2
+ import type { CSSProperties, ReactElement } from "react";
3
+ import { useMemo } from "react";
4
+ import {
5
+ buildMonthWeeks,
6
+ type CalendarEvent,
7
+ getIsToday,
8
+ getWeekDays,
9
+ getYearMonths,
10
+ groupEventsByDay,
11
+ isSameCalendarDay,
12
+ type WeekStartsOn,
13
+ weekdayFormatToken,
14
+ } from "@super-calendar/core";
15
+ import { createSlots, dataState, type SlotStyleProps } from "./slots";
16
+ import { type DomCalendarTheme, mergeDomTheme } from "./theme";
17
+
18
+ /**
19
+ * Styleable parts of {@link YearView}. Pass a class or inline style per slot
20
+ * via the `classNames` / `styles` props; day cells carry `data-today` and
21
+ * `data-events` state attributes for variants.
22
+ */
23
+ export type YearViewSlot =
24
+ | "grid"
25
+ | "month"
26
+ | "monthTitle"
27
+ | "weekdays"
28
+ | "weekday"
29
+ | "week"
30
+ | "day"
31
+ | "eventDot";
32
+
33
+ /** Props for {@link YearView}, the twelve mini-month year grid. */
34
+ export interface YearViewProps<T = unknown> extends SlotStyleProps<YearViewSlot> {
35
+ /** Any date inside the year to render. */
36
+ date: Date;
37
+ /** Days holding at least one event get a dot. Omit for a plain year. */
38
+ events?: CalendarEvent<T>[];
39
+ /** First day of the week. Sunday = 0 (default) … Saturday = 6. */
40
+ weekStartsOn?: WeekStartsOn;
41
+ locale?: Locale;
42
+ /** Highlight this date instead of the real "today". */
43
+ activeDate?: Date;
44
+ /**
45
+ * Smallest width a mini month may take before the grid drops a column
46
+ * (default 150). The grid fits as many columns as the container allows.
47
+ */
48
+ minMonthWidth?: number;
49
+ /** Tap a day cell (e.g. to drill into the day or month view). */
50
+ onPressDay?: (date: Date) => void;
51
+ /** Tap a month's title (e.g. to jump to that month's view). */
52
+ onPressMonth?: (month: Date) => void;
53
+ /** Theme overrides; falls back to the default light theme. */
54
+ theme?: Partial<DomCalendarTheme>;
55
+ /** Class applied to the root element. */
56
+ className?: string;
57
+ /** Inline styles applied to the root element. */
58
+ style?: CSSProperties;
59
+ }
60
+
61
+ /**
62
+ * A year at a glance: the twelve months as compact mini grids, with today
63
+ * highlighted and a dot under days that hold events. It's the view `Calendar`
64
+ * renders for `mode="year"`.
65
+ */
66
+ export function YearView<T = unknown>({
67
+ date,
68
+ events,
69
+ weekStartsOn = 0,
70
+ locale,
71
+ activeDate,
72
+ minMonthWidth = 150,
73
+ onPressDay,
74
+ onPressMonth,
75
+ theme: themeOverrides,
76
+ className,
77
+ style,
78
+ classNames,
79
+ styles,
80
+ }: YearViewProps<T>): ReactElement {
81
+ const theme = useMemo(() => mergeDomTheme(themeOverrides), [themeOverrides]);
82
+ const slot = createSlots<YearViewSlot>({ classNames, styles });
83
+
84
+ const months = useMemo(() => getYearMonths(date), [date]);
85
+ const weekdayLabels = useMemo(
86
+ () =>
87
+ getWeekDays(date, weekStartsOn).map((d) =>
88
+ format(d, weekdayFormatToken("narrow"), { locale }),
89
+ ),
90
+ [date, weekStartsOn, locale],
91
+ );
92
+ // Days that hold at least one event, keyed like `groupEventsByDay`.
93
+ const eventDays = useMemo(
94
+ () => new Set(events && events.length > 0 ? groupEventsByDay(events).keys() : []),
95
+ [events],
96
+ );
97
+
98
+ return (
99
+ <div
100
+ className={className}
101
+ style={{ fontFamily: theme.fontFamily, color: theme.text, overflowY: "auto", ...style }}
102
+ >
103
+ <div
104
+ {...slot("grid", {
105
+ base: {
106
+ display: "grid",
107
+ gridTemplateColumns: `repeat(auto-fill, minmax(${minMonthWidth}px, 1fr))`,
108
+ },
109
+ })}
110
+ >
111
+ {months.map((month) => {
112
+ const weeks = buildMonthWeeks(month, weekStartsOn);
113
+ const monthLabel = format(month, "MMMM yyyy", { locale });
114
+ const titleContent = format(month, "MMMM", { locale });
115
+ return (
116
+ <div key={month.toISOString()} {...slot("month", { base: { padding: 8 } })}>
117
+ {onPressMonth ? (
118
+ <button
119
+ type="button"
120
+ onClick={() => onPressMonth(month)}
121
+ aria-label={monthLabel}
122
+ {...slot("monthTitle", {
123
+ base: {
124
+ display: "block",
125
+ border: "none",
126
+ background: "transparent",
127
+ padding: "0 0 4px",
128
+ cursor: "pointer",
129
+ font: "inherit",
130
+ textAlign: "left",
131
+ },
132
+ themed: {
133
+ fontSize: 13,
134
+ fontWeight: 700,
135
+ color: theme.todayBackground,
136
+ },
137
+ })}
138
+ >
139
+ {titleContent}
140
+ </button>
141
+ ) : (
142
+ <div
143
+ role="heading"
144
+ aria-level={3}
145
+ aria-label={monthLabel}
146
+ {...slot("monthTitle", {
147
+ base: { paddingBottom: 4 },
148
+ themed: { fontSize: 13, fontWeight: 700, color: theme.todayBackground },
149
+ })}
150
+ >
151
+ {titleContent}
152
+ </div>
153
+ )}
154
+ <div
155
+ {...slot("weekdays", {
156
+ base: { display: "grid", gridTemplateColumns: "repeat(7, 1fr)" },
157
+ })}
158
+ >
159
+ {weekdayLabels.map((label, i) => (
160
+ <div
161
+ key={i}
162
+ aria-hidden
163
+ {...slot("weekday", {
164
+ base: { textAlign: "center" },
165
+ themed: { fontSize: 9, fontWeight: 600, color: theme.textMuted },
166
+ })}
167
+ >
168
+ {label}
169
+ </div>
170
+ ))}
171
+ </div>
172
+ <div role="grid" aria-label={monthLabel}>
173
+ {weeks.map((week) => (
174
+ <div
175
+ key={week[0].toISOString()}
176
+ role="row"
177
+ {...slot("week", {
178
+ base: { display: "grid", gridTemplateColumns: "repeat(7, 1fr)" },
179
+ })}
180
+ >
181
+ {week.map((day) => {
182
+ // Adjacent-month days keep the grid shape but stay blank,
183
+ // like the mini months of other year views.
184
+ if (day.getMonth() !== month.getMonth()) {
185
+ return (
186
+ <div
187
+ key={day.toISOString()}
188
+ role="gridcell"
189
+ aria-hidden
190
+ style={{ aspectRatio: "1" }}
191
+ />
192
+ );
193
+ }
194
+ const isHighlighted = activeDate
195
+ ? isSameCalendarDay(day, activeDate)
196
+ : getIsToday(day);
197
+ const hasEvents = eventDays.has(startOfDay(day).toISOString());
198
+ const label = `${format(day, "EEEE, d LLLL yyyy", { locale })}${
199
+ getIsToday(day) ? ", today" : ""
200
+ }${hasEvents ? ", has events" : ""}`;
201
+ const daySlot = slot("day", {
202
+ base: {
203
+ position: "relative",
204
+ aspectRatio: "1",
205
+ display: "flex",
206
+ alignItems: "center",
207
+ justifyContent: "center",
208
+ padding: 0,
209
+ border: "none",
210
+ background: "transparent",
211
+ font: "inherit",
212
+ cursor: onPressDay ? "pointer" : "default",
213
+ boxSizing: "border-box",
214
+ },
215
+ themed: {
216
+ fontSize: 11,
217
+ borderRadius: "50%",
218
+ ...(isHighlighted
219
+ ? { background: theme.todayBackground, color: theme.todayText }
220
+ : { color: theme.text }),
221
+ },
222
+ });
223
+ const states = dataState({
224
+ // `data-today` states the fact; the activeDate highlight is
225
+ // visual only (themed), so the two can differ.
226
+ "data-today": getIsToday(day),
227
+ "data-events": hasEvents,
228
+ });
229
+ const dot = hasEvents ? (
230
+ <span
231
+ aria-hidden
232
+ {...slot("eventDot", {
233
+ base: {
234
+ position: "absolute",
235
+ bottom: 1,
236
+ left: "50%",
237
+ marginLeft: -1.5,
238
+ width: 3,
239
+ height: 3,
240
+ borderRadius: 2,
241
+ },
242
+ themed: {
243
+ background: isHighlighted ? theme.todayText : theme.todayBackground,
244
+ },
245
+ })}
246
+ />
247
+ ) : null;
248
+ return onPressDay ? (
249
+ <button
250
+ key={day.toISOString()}
251
+ type="button"
252
+ role="gridcell"
253
+ onClick={() => onPressDay(day)}
254
+ aria-label={label}
255
+ {...states}
256
+ {...daySlot}
257
+ >
258
+ {day.getDate()}
259
+ {dot}
260
+ </button>
261
+ ) : (
262
+ <div
263
+ key={day.toISOString()}
264
+ role="gridcell"
265
+ aria-label={label}
266
+ {...states}
267
+ {...daySlot}
268
+ >
269
+ {day.getDate()}
270
+ {dot}
271
+ </div>
272
+ );
273
+ })}
274
+ </div>
275
+ ))}
276
+ </div>
277
+ </div>
278
+ );
279
+ })}
280
+ </div>
281
+ </div>
282
+ );
283
+ }
package/src/index.ts CHANGED
@@ -42,6 +42,7 @@ export {
42
42
  type MonthViewSlot,
43
43
  } from "./MonthView";
44
44
  export { MonthList, type MonthListProps, type MonthListSlot } from "./MonthList";
45
+ export { YearView, type YearViewProps, type YearViewSlot } from "./YearView";
45
46
  export {
46
47
  type Resource,
47
48
  type ResourceEventArgs,