Weekly Hours
Opening or working hours per weekday, with split shifts, copy to other days and overlap checks.
When can students book you?
Lessons are only offered inside these hours.
Unavailable
Unavailable
Keyboard
- Space
- Turn a day on or off
- ↑↓
- Change the focused time segment
- ←→
- Move between time segments
Installation
The CLI also installs the npm packages and registry items it builds on, and reads the style in your components.json to pick the Base UI or Radix build.
Usage
"use client"
import * as React from "react"
import {
WeeklyHours,
type WeeklyHoursRange,
} from "@/components/ui/weekly-hours"
export function OpeningHours() {
const [hours, setHours] = React.useState<WeeklyHoursRange[]>([
{ day: "MO", start: "09:00", end: "17:00" },
{ day: "TU", start: "09:00", end: "12:00" },
{ day: "TU", start: "13:00", end: "17:00" },
{ day: "SA", start: "10:00", end: "14:00" },
])
return <WeeklyHours value={hours} onValueChange={setHours} />
}Examples
Shop opening hours
The week starts on Sunday, times use a 12-hour clock, ArrowUp and ArrowDown on the minutes step by 30, and days with no hours read Closed.
Closed
Workweek, controlled
weekdays limits the rows to Monday to Friday. The value is a flat list of { day, start, end } entries, shown under the editor as it changes.
Unavailable
Unavailable
Unavailable
MO 10:00–16:00, WE 10:00–16:00
API reference
WeeklyHours
One row per weekday with a checkbox to mark the day available and one or more start and end times. Days can hold split shifts, and each day's hours can be copied to every other available day. Ranges that end at or before their start, or overlap another range on the same day, are flagged.
| Prop | Type | Default |
|---|---|---|
valueWeeklyHoursRange[]Controlled the hours as { day, start, end } entries, times as HH:mm. | WeeklyHoursRange[] | |
defaultValueWeeklyHoursRange[]Defaultan empty arrayInitial value when uncontrolled. | WeeklyHoursRange[] | an empty array |
onValueChange(value: WeeklyHoursRange[]) => voidCalled when hours change: a day is turned on or off, a time is edited, a range is added or removed, or a day's hours are copied. | (value: WeeklyHoursRange[]) => void | |
weekdaysWeekday[]DefaultWEEKDAYSDays to show, in order. Pass ["MO", "TU", "WE", "TH", "FR"] for a workweek or start with "SU". | Weekday[] | WEEKDAYS |
defaultRange{ start: string; end: string }Default{ start: "09:00", end: "17:00" }Hours given to a day when it is turned on. | { start: string; end: string } | { start: "09:00", end: "17:00" } |
hourCycle12 | 24Default24Shows times as 24-hour or with AM and PM. | 12 | 24 | 24 |
minuteStepnumberDefault15Minutes added or removed per arrow key press. | number | 15 |
disabledbooleanDefaultfalseDisables every control. | boolean | false |
unavailableLabelReactNodeDefault"Unavailable"Text shown for a day with no hours. | ReactNode | "Unavailable" |
Other props go to the <div>.