use-date-input - Build Your Own Date Picker
Getting StartedStateThemingCompositionDate FrameworksLocalization
Components
Hooks
AnimatedGroupAnimatedMonthGroupCalendarCalendarProviderClickOutsideDayDayOfWeekHeaderHomeMonthMonthGroupPopperRootWeekWeekHeaderuseCalendarDispatchuseCalendarPropsuseCalendarStateuseDateAPIuseDateInputuseDateRangeInput

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 (
<Calendar
adapter={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

2021
June
Su
Mo
Tu
We
Th
Fr
Sa
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910
July
Su
Mo
Tu
We
Th
Fr
Sa
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

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.

June
2021
June
Su
Mo
Tu
We
Th
Fr
Sa
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910
July
Su
Mo
Tu
We
Th
Fr
Sa
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567
August
Su
Mo
Tu
We
Th
Fr
Sa
1234567
891011121314
15161718192021
22232425262728
2930311234
567891011
September
Su
Mo
Tu
We
Th
Fr
Sa
2930311234
567891011
12131415161718
19202122232425
262728293012
3456789
October
Su
Mo
Tu
We
Th
Fr
Sa
262728293012
3456789
10111213141516
17181920212223
24252627282930
31123456
November
Su
Mo
Tu
We
Th
Fr
Sa
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011
December
Su
Mo
Tu
We
Th
Fr
Sa
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678
January
Su
Mo
Tu
We
Th
Fr
Sa
2627282930311
2345678
9101112131415
16171819202122
23242526272829
303112345
February
Su
Mo
Tu
We
Th
Fr
Sa
303112345
6789101112
13141516171819
20212223242526
272812345
6789101112
March
Su
Mo
Tu
We
Th
Fr
Sa
272812345
6789101112
13141516171819
20212223242526
272829303112
3456789
April
Su
Mo
Tu
We
Th
Fr
Sa
272829303112
3456789
10111213141516
17181920212223
24252627282930
1234567
May
Su
Mo
Tu
We
Th
Fr
Sa
1234567
891011121314
15161718192021
22232425262728
2930311234
567891011