|
| 1 | +import React, {lazy, Suspense} from 'react'; |
| 2 | +import datePickerRange from '../utils/LazyLoader/datePickerRange'; |
| 3 | +import transformDate from '../utils/DatePickerPersistence'; |
| 4 | +import {DatePickerRangeProps, PersistedProps, PersistenceTypes} from '../types'; |
| 5 | + |
| 6 | +const RealDatePickerRange = lazy(datePickerRange); |
| 7 | + |
| 8 | +/** |
| 9 | + * DatePickerRange is a tailor made component designed for selecting |
| 10 | + * timespan across multiple days off of a calendar. |
| 11 | + * |
| 12 | + * The DatePicker integrates well with the Python datetime module with the |
| 13 | + * startDate and endDate being returned in a string format suitable for |
| 14 | + * creating datetime objects. |
| 15 | + * |
| 16 | + */ |
| 17 | +export default function DatePickerRange({ |
| 18 | + calendar_orientation = 'horizontal', |
| 19 | + is_RTL = false, |
| 20 | + // eslint-disable-next-line no-magic-numbers |
| 21 | + day_size = 34, |
| 22 | + with_portal = false, |
| 23 | + with_full_screen_portal = false, |
| 24 | + first_day_of_week = 0, |
| 25 | + number_of_months_shown = 2, |
| 26 | + stay_open_on_select = false, |
| 27 | + reopen_calendar_on_clear = false, |
| 28 | + clearable = false, |
| 29 | + disabled = false, |
| 30 | + updatemode = 'singledate', |
| 31 | + // eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 32 | + persisted_props = [PersistedProps.start_date, PersistedProps.end_date], |
| 33 | + // eslint-disable-next-line @typescript-eslint/no-unused-vars |
| 34 | + persistence_type = PersistenceTypes.local, |
| 35 | + disabled_days = [], |
| 36 | + ...props |
| 37 | +}: DatePickerRangeProps) { |
| 38 | + return ( |
| 39 | + <Suspense fallback={null}> |
| 40 | + <RealDatePickerRange |
| 41 | + calendar_orientation={calendar_orientation} |
| 42 | + is_RTL={is_RTL} |
| 43 | + day_size={day_size} |
| 44 | + with_portal={with_portal} |
| 45 | + with_full_screen_portal={with_full_screen_portal} |
| 46 | + first_day_of_week={first_day_of_week} |
| 47 | + number_of_months_shown={number_of_months_shown} |
| 48 | + stay_open_on_select={stay_open_on_select} |
| 49 | + reopen_calendar_on_clear={reopen_calendar_on_clear} |
| 50 | + clearable={clearable} |
| 51 | + disabled={disabled} |
| 52 | + disabled_days={disabled_days} |
| 53 | + updatemode={updatemode} |
| 54 | + {...props} |
| 55 | + /> |
| 56 | + </Suspense> |
| 57 | + ); |
| 58 | +} |
| 59 | + |
| 60 | +DatePickerRange.dashPersistence = { |
| 61 | + persisted_props: [PersistedProps.start_date, PersistedProps.end_date], |
| 62 | + persistence_type: PersistenceTypes.local, |
| 63 | +}; |
| 64 | + |
| 65 | +DatePickerRange.persistenceTransforms = { |
| 66 | + end_date: transformDate, |
| 67 | + start_date: transformDate, |
| 68 | +}; |
0 commit comments