Fragiola

API: primitives (@fragiola/calendar-react)

Calendar.SlotLabel

A slot row's label, the row header that shows the time you format, read as data from useSlotLabel and never rendered by the library.

Calendar.SlotLabel is the header of a slot row: a div with role="rowheader" and data-time. It renders what you give it; the library writes no time as text. The time's words come from useSlotLabel(time) (Intl parts in the calendar's locale) or your own formatting.

Behaviour

  • The row's rowheader in the APG grid pattern: screen readers announce it with the row's cells.
  • It is outside the roving focus (the slots are the cells you move over).
  • It must be inside a Calendar.SlotRow.

Usage

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

function HourText(props: { time: string }) {
    // Intl parts in the calendar's locale: "9 AM", "09"
    const parts = useSlotLabel(props.time, { hour: "numeric" });
    return <span>{parts.map((part) => part.value).join("")}</span>;
}

export function Label() {
    return (
        <Calendar.SlotLabel className="slot-label">
            {({ time }) => (time.endsWith(":00") ? <HourText time={time} /> : null)}
        </Calendar.SlotLabel>
    );
}

It shows the hour on the full hours and nothing on the other slots. See useSlotLabel.

Attributes

attributevalue
data-calendar-partdata-calendar-part="slot-label"
data-timethe slot's start, HH:mm
rolerowheader

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.

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

proptypedescription
childrenReactNode, or (state: SlotLabelState) => ReactNodewhat it shows: elements, or a function of its state

State

SlotLabelState:

fieldtypedescription
timestringthe slot's wall-clock start, HH:mm (useSlotLabel(time) gives it as parts)