Year view
The year view shows the twelve months side by side, with a dot on each day that has events, stronger from three. A clicked day opens in the day view, else the week view, else the month view, whichever is offered; a month’s name opens the month view. The toolbar goes a year back or forward. One day is in the tab order, today or 1 January, and the arrow keys move between days.
Calendar and createCalendar offer the year with the other views; views.year takes its
options. With CalendarBase or createCalendarBase, yearView() adds it next to the other
views you offer:
import { CalendarBase, dayView, monthView, weekView, yearView } from "@weekwise/react";
<CalendarBase<Event> defaultView="year" items={events} renderEvent={(event) => event.title} views={{ day: dayView(), week: weekView(), month: monthView(), year: yearView() }}/>;In the DOM package:
import { createCalendarBase, dayView, monthView, weekView, yearView } from "@weekwise/dom";
const calendar = createCalendarBase<Event>(element, { ...options, view: "year", views: { day: dayView(), week: weekView(), month: monthView(), year: yearView() },});Day marks and day clicks
Section titled “Day marks and day clicks”renderDay draws a day’s mark in place of the dot, e.g. a count; it is called for every day and
gets the events that touch it. onDayClick takes over a click on a day (or Enter /
Space on it), e.g. to open the week instead of the day.
const [view, setView] = useState<CalendarView>("year");const [viewValue, setViewValue] = useState(new Date());
<CalendarBase<Event> {...props} view={view} onChangeView={setView} viewValue={viewValue} onChangeViewValue={setViewValue} views={{ week: weekView(), year: yearView({ renderDay: (date, items) => (items.length ? items.length : null), onDayClick: (date) => { setView("week"); setViewValue(date); }, }), }}/>;const calendar = createCalendarBase<Event>(element, { ...options, views: { week: weekView(), year: yearView({ renderDay: (date, items) => (items.length ? String(items.length) : null), onDayClick: (date) => calendar.update({ view: "week", viewValue: date }), }), },});