Fragiola

API: primitives (@fragiola/calendar-react)

Calendar.Slot

A day's cell of a slot row, a cell of the grid's roving focus, marked with its date, its time and its selected or business-hours state.

Calendar.Slot is one cell of the time grid: a day at a slot's time. It renders a div with role="gridcell", data-date and data-time. A press on it is a date-click (with the time), selects from it with selection(), and is where a drag drops. Its look, and any text inside it, are yours.

Behaviour

  • A cell of the APG grid pattern: the slots are the time grid's roving focus (tabindex 0 on the tab stop, -1 on the others, data-focused on the focused one).
  • Enter on a focused slot moves the focus into the events that start in it.
  • With selection(), a press and drag selects a range, Shift + arrows extend it from the focused slot, Enter confirms it; the covered slots carry data-selected.
  • With constraints(), a slot whose start is within the day's business hours carries data-business-hours.
  • A day outside validRange carries data-disabled.
  • Its date is data for your visually hidden text: the library names no cell. Give it an aria-label (or hidden text) when your design has no visible date in it.

Usage

import { Calendar } from "@fragiola/calendar-react";

export function Cell(props: { date: string; time: string }) {
    return (
        <Calendar.Slot
            date={props.date}
            aria-label={`${props.date} ${props.time}`}
            className={(state) =>
                [
                    "slot",
                    state.selected ? "slot-selected" : "",
                    state.businessHours ? "" : "slot-closed",
                ].join(" ")
            }
        />
    );
}

The cell's state (SlotState, on the hooks page) styles it; or style [data-selected] and [data-business-hours] in CSS. useSlot gives the same props for an element of your own.

Attributes

attributevalue
data-calendar-partdata-calendar-part="slot"
data-date, data-timeits day (YYYY-MM-DD) and its start (HH:mm)
data-focused, data-selected, data-business-hours, data-disabledpresent when on
role, tabindexgridcell, the roving focus

Props

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.

SlotProps takes the common props and any div attribute, and:

proptypedescription
datestringits day, from Calendar.SlotRow's children function (column.date)
childrenReactNode, or (state: SlotState) => ReactNodewhat it shows: elements, or a function of its state