Import
import { DatePicker } from '@dnb/eufemia'
Description
The DatePicker component should be used whenever there is to enter a single date or a date range/period with a start and end date.
Date Object
The DatePicker operates with a default JavaScript Date instance as well as string (ISO 8601) like start_date="2019-05-05"
(yyyy-MM-dd).
For more DatePicker examples, have a look at this CodeSandbox.
Demos
English (US) is not included in Eufemia by default. You can include it like:
import enUS from '@dnb/eufemia/shared/locales/en-US'<EufemiaProvider locale={enUS} ...>App</EufemiaProvider>
Range DatePicker
Code Editor
<DatePicker label="DatePicker" startDate="2019-04-01" endDate="2019-05-17" range={true} showInput={true} onChange={({ start_date, end_date }) => { console.log('onChange', start_date, end_date) }} onSubmit={({ start_date, end_date }) => { console.log('onSubmit', start_date, end_date) }} onCancel={({ start_date, end_date }) => { console.log('onCancel', start_date, end_date) }} onBlur={({ start_date, end_date, partialStartDate, partialEndDate }) => { console.log('onBlurPartial', partialStartDate, partialEndDate) console.log('onBlurcomplete', start_date, end_date) }} shortcuts={[ { title: 'Set date period', start_date: '1969-07-15', end_date: '1969-08-15', }, { title: 'Today', start_date: new Date(), }, { title: 'This week', start_date: startOfWeek(new Date()), end_date: lastDayOfWeek(new Date()), }, { close_on_select: true, title: 'This month', start_date: startOfMonth(new Date()), end_date: lastDayOfMonth(new Date()), }, { title: 'Relative +3 days', start_date: ({ start_date }) => start_date || new Date(), end_date: ({ end_date }) => addDays(end_date || new Date(), 3), }, ]} />