use-date-input - Build Your Own Date Picker
Getting StartedStateThemingCompositionDate FrameworksWith date-fnsWith dayjsWith luxonWith momentWeek OffsetWrite Your Own AdapterLocalization
Components
Hooks
AnimatedGroupAnimatedMonthGroupCalendarCalendarProviderClickOutsideDayDayOfWeekHeaderHomeMonthMonthGroupPopperRootWeekWeekHeaderuseCalendarDispatchuseCalendarPropsuseCalendarStateuseDateAPIuseDateInputuseDateRangeInput

Date Frameworks

use-date-input provides an adapter API that enables it to work with any date framework.

The adapter interface is provided to use-date-input components through the adapter prop.

Adapters have been created for all the popular Date frameworks. To keep the bundle size low and to let the user manage versioning, the provided adapters require peer dependencies to specify the date API.

  • date-fns
  • dayjs
  • luxon
  • moment
  • ... or write your own

With date-fns

Install the dependencies with

yarn add @date-fns
yarn add @use-date-input/date-fns-adapter

OR

npm install -s @date-fns
npm install -s @use-date-input/date-fns-adapter

Import the adapter into your component

import { adapter as dateFnsAdapter } from "@use-date-input/date-fns-adapter";

Use the adapter prop with the use-date-input components.

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

With dayjs

Install the dependencies with

yarn add @dayjs
yarn add @use-date-input/dayjs-adapter

OR

npm install -s @dayjs
npm install -s @use-date-input/dayjs-adapter

Import the adapter into your component

import { adapter as dayjsAdapter } from "@use-date-input/dayjs-adapter";

Use the adapter prop with the use-date-input components.

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

With luxon

Install the dependencies with

yarn add @luxon
yarn add @use-date-input/luxon-adapter

OR

npm install -s @luxon
npm install -s @use-date-input/luxon-adapter

Import the adapter into your component

import { adapter as luxonAdapter } from "@use-date-input/dayjs-adapter";

Use the adapter prop with the use-date-input components.

2021
June
M
T
W
T
F
S
S
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011
July
M
T
W
T
F
S
S
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

With moment

Install the dependencies with

yarn add @moment
yarn add @use-date-input/moment-adapter

OR

npm install -s @moment
npm install -s @use-date-input/moment-adapter

Import the adapter into your component

import { adapter as momentAdapter } from "@use-date-input/moment-adapter";

Use the adapter prop with the use-date-input components.

2021
June
Mo
Tu
We
Th
Fr
Sa
Su
31123456
78910111213
14151617181920
21222324252627
2829301234
567891011
July
Mo
Tu
We
Th
Fr
Sa
Su
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

Week Offset

Date frameworks use different week offsets, so you can customize on use-date-input components through the use of the weekOffset prop

2021
June
S
M
T
W
T
F
S
1234567
891011121314
15161718192021
22232425262728
293012345
6789101112
1314151617
July
S
M
T
W
T
F
S
1234567
891011121314
15161718192021
22232425262728
2930311234
567891011
121314

Write Your Own Adapter

To write your own adapter or customize the existing adapters, you need to build this interface and provide it through the adapter prop.

const adapter = ({ weekOffset = 0 } = {}) => ({
addDays,
addMonths,
addWeeks,
addYears,
createDate,
daysInMonth,
dayOfWeek,
diffInDays,
diffInMonths,
endOfMonth,
endOfWeek,
endOfYear,
format,
getDateFormat,
isAfter,
isBefore,
isSameDay,
isSameMonth,
isValid:
set,
startOfMonth,
startOfWeek,
startOfYear,
subtractDays,
subtractMonths,
subtractWeeks,
subtractYears
});

For the most cases, this just requires mapping these callbacks to the equivalent date framework call.

For further examples, refer to the provided adapters code, such as @use-date-input/dayjs-adapter.