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
rowheaderin 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
| attribute | value |
|---|---|
data-calendar-part | data-calendar-part="slot-label" |
data-time | the slot's start, HH:mm |
role | rowheader |
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:
| prop | type | description |
|---|---|---|
children | ReactNode, or (state: SlotLabelState) => ReactNode | what it shows: elements, or a function of its state |
State
SlotLabelState:
| field | type | description |
|---|---|---|
time | string | the slot's wall-clock start, HH:mm (useSlotLabel(time) gives it as parts) |