Composition
When you want to do more than style the default components through theming you can replace the default components, with either your own components or use the default components to build a new composition.
CalendarProvider
provides a components
prop to replace named components with your own version.
This provides several options
- you can change change behavior of the default components
- you can create new compositions of the default components with your own components
Common use-cases might be to build a composition of a Calendar
and a shortcut list or compose the Calendar
together with other UI controls or branding.
If you want to extend/replace components then redefine those components via their name, using the components
prop.
import { adapter as dateAdapter } from '@use-date-input/date-fns-adapter';import { Calendar } from "../packages/core";const myComponents = {Root: props => { /* My component */ },Header: props => {},AnimatedMonthGroup: props => {},AnimatedGroup: props => {},MonthGroup: props => {},Month: props => {},MonthHeader: props => {},Week: props => {},WeekHeader: props => {},DayOfWeek: props => {},Day: props => {}};const MyCalendar = () => {return (<Calendaradapter={dateAdapter}components={myComponents}/>);};
For instance, if you want to style days with your own state (such as blocked or un-available), then you simply replace or
extend the current Day
component
Here is an example of Calendar
composed together with components from Material-UI.
- A custom header has been added to add Month and Year dropdowns using Material-UI's Formfield component.
- A set of shortcuts have been added using Material-UI's List component.
This example uses a hook called useCalendarDispatch
, to access dispatch methods, allowing you to dispatch actions to the reducer
from your custom Root.
For brevity, additional source for the custom Header can be found here
In the example below, select a startDate, to see a list of shortcuts appear.