API: primitives (@fragiola/calendar-react)
Calendar.ViewButton
A toggle button that shows a view with `view.set`, pressed while that view is shown, for a month, week, day, n-day or list switcher.
Calendar.ViewButton is a toggle button for a view switcher. It runs view.set with its
view (and days), and says whether its view is the one shown. The labels, the group around the
buttons and their look are yours.
Behaviour
- A press runs
view.setwith{ type: view }, or{ type: view, days }for adaysview. The anchor date stays, so the new view shows the same date. - It is pressed (
aria-pressed="true",data-pressed) while the view shown is its view (and, for adaysview withdays, the same count);aria-pressed="false"otherwise. - It is disabled (
disabled,data-disabled) whenmodel.can("view.set", …)says no.
It renders data-calendar-part="view-button" on a button with type="button".
Usage
import { Calendar } from "@fragiola/calendar-react";
function ViewSwitcher() {
return (
<div role="group" aria-label="View">
<Calendar.ViewButton view="month" className="segment">
Month
</Calendar.ViewButton>
<Calendar.ViewButton view="week" className="segment">
Week
</Calendar.ViewButton>
<Calendar.ViewButton view="days" days={3} className="segment">
3 days
</Calendar.ViewButton>
<Calendar.ViewButton view="list" className="segment">
Agenda
</Calendar.ViewButton>
</div>
);
}Style the pressed one with [data-pressed] or [aria-pressed="true"].
Props
ViewButtonProps; it also takes the common props and every
button attribute.
In Vue: the same props (in kebab-case in a template), and slots in place of children; see
Vue primitives.
In Angular: a directive on your element, the props as its inputs, templates in place of
children; see Angular primitives.
| prop | type | description |
|---|---|---|
view | ViewType | the view it shows: "month", "week", "day", "days" or "list" |
days | number | a days view's number of days |
children | ReactNode | its label |
State
ViewButtonState extends CommandButtonState:
| field | type | description |
|---|---|---|
pressed | boolean | its view is the one shown (aria-pressed, data-pressed) |
disabled | boolean | view.set cannot run now (data-disabled) |