To change the timezone of the calendar, pass a time to the prop timezone
on the Calendar.Root
.
A list of valid timezones can be found in the IANA Database.
UTC
as timezone, do not use .tz("UTC")
, instead use dayjs().utc()
.defaultValue
, ensure the date provided is set to the same timezone.import dayjs from "dayjs";
import timezone from "dayjs/plugin/timezone";
import utc from "dayjs/plugin/utc";
import { useState } from "react";
import * as Calendar from "react-composable-calendar";
import type { CalendarSingleValue } from "react-composable-calendar/types";
dayjs.extend(timezone);
dayjs.extend(utc);
const [value, setValue] = useState<CalendarSingleValue>(
dayjs().tz("Europe/Stockholm"),
);
export function Component() {
return (
<Calendar.Root
mode="single"
value={value}
onValueChange={setValue}
timezone="Europe/Stockholm"
>
{/* ... */}
</Calendar.Root>
);
}
To use the calendar as a uncontrolled input field, make sure you render the Calendar.FormInput
somewhere inside the root.
Then all you need to do is pass a name for the form input. (If in range
mode you need to pass two names)
import * as Calendar from "react-composable-calendar";
export function ComponentSingle() {
return (
<Calendar.Root mode="single" name="date">
<Calendar.FormInput />
{/* ... */}
</Calendar.Root>
);
}
export function ComponentRange() {
return (
<Calendar.Root mode="range" name={["dateFrom", "dateTo"]}>
<Calendar.FormInput />
{/* ... */}
</Calendar.Root>
);
}
The Root component is the foundational wrapper for the calendar. It manages the calendar’s state, including the current view, selected date(s), and mode (single or range). It also provides context to its child components, allowing them to access and modify the calendar’s state.
Provides context for a view. A view is a month that is being viewed. You can have multiple views within a calendar root.
A Button that offset the current view but a number.
This will offset all children with an amount. Useful if you for example want to show two views next to each other where one of them is them next month.
The Weekdays component is responsible for rendering the weekday labels (e.g., Monday, Tuesday, etc.) in the calendar.
The WeekdayLabel component is used to display the name of a weekday (e.g., “Monday”, “Tuesday”) within the calendar. It retrieves the current weekday index from the WeekdayContext.
Shows the name of the month that the view is currently in.
Will render all days of the month as children.
A button that represents a day of the month. If clicked, value is changed to that day.
Renders the day’s number in the month.
Renders an <input />
with the calendars value. If in range
mode, two inputs will be rendered.
A button that when clicked clears the selected value of the calendar.
Conditionally rendered if a day is within the selected range.
Conditionally rendered if a day is today.
Conditionally rendered if a day is selected.
Shows the selected value formatted as a string.
Renders a Button that changes the view’s year when clicked.