@gravity-ui/date-components 1.6.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/Calendar/Calendar.d.ts +6 -5
- package/dist/cjs/components/Calendar/Calendar.js +4 -4
- package/dist/cjs/components/Calendar/index.d.ts +6 -6
- package/dist/cjs/components/Calendar/index.js +5 -5
- package/dist/cjs/components/{CalendarBase → CalendarView}/Calendar.css +9 -6
- package/dist/cjs/components/{CalendarBase/CalendarBase.d.ts → CalendarView/CalendarView.d.ts} +2 -2
- package/dist/cjs/components/{CalendarBase/CalendarBase.js → CalendarView/CalendarView.js} +4 -3
- package/dist/{esm/components/CalendarBase → cjs/components/CalendarView}/hooks/types.d.ts +37 -31
- package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/useCalendarCellProps.js +1 -2
- package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/useCalendarGridProps.d.ts +2 -2
- package/dist/{esm/components/CalendarBase → cjs/components/CalendarView}/hooks/useCalendarState.d.ts +1 -1
- package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/useCalendarState.js +45 -23
- package/dist/cjs/components/CalendarView/hooks/useRangeCalendarState.d.ts +8 -0
- package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/useRangeCalendarState.js +25 -14
- package/dist/cjs/components/DateField/DateField.d.ts +1 -4
- package/dist/cjs/components/DateField/DateField.js +3 -1
- package/dist/cjs/components/DateField/hooks/useBaseDateFieldState.d.ts +97 -0
- package/dist/cjs/components/DateField/hooks/useBaseDateFieldState.js +316 -0
- package/dist/cjs/components/DateField/hooks/useDateFieldProps.d.ts +6 -3
- package/dist/cjs/components/DateField/hooks/useDateFieldProps.js +14 -12
- package/dist/cjs/components/DateField/hooks/useDateFieldState.d.ts +2 -65
- package/dist/cjs/components/DateField/hooks/useDateFieldState.js +98 -410
- package/dist/cjs/components/DateField/index.d.ts +1 -0
- package/dist/cjs/components/DateField/index.js +1 -0
- package/dist/cjs/components/DateField/utils.d.ts +10 -1
- package/dist/cjs/components/DateField/utils.js +114 -2
- package/dist/cjs/components/DatePicker/DatePicker.d.ts +4 -4
- package/dist/cjs/components/DatePicker/DatePicker.js +6 -6
- package/dist/cjs/components/DatePicker/MobileCalendar.css +6 -6
- package/dist/cjs/components/DatePicker/MobileCalendar.js +17 -12
- package/dist/cjs/components/DatePicker/hooks/useDatePickerProps.js +5 -16
- package/dist/cjs/components/DatePicker/hooks/useDatePickerState.d.ts +5 -4
- package/dist/cjs/components/DatePicker/hooks/useDatePickerState.js +71 -56
- package/dist/cjs/components/RangeCalendar/RangeCalendar.d.ts +3 -3
- package/dist/cjs/components/RangeCalendar/RangeCalendar.js +4 -4
- package/dist/cjs/components/RangeDateField/RangeDateField.css +4 -0
- package/dist/cjs/components/RangeDateField/RangeDateField.d.ts +12 -0
- package/dist/cjs/components/RangeDateField/RangeDateField.js +25 -0
- package/dist/cjs/components/RangeDateField/hooks/useRangeDateFieldState.d.ts +9 -0
- package/dist/cjs/components/RangeDateField/hooks/useRangeDateFieldState.js +227 -0
- package/dist/cjs/components/RangeDateField/index.d.ts +2 -0
- package/dist/cjs/components/RangeDateField/index.js +5 -0
- package/dist/cjs/components/RangeDateField/utils/createPlaceholderRangeValue.d.ts +5 -0
- package/dist/cjs/components/RangeDateField/utils/createPlaceholderRangeValue.js +9 -0
- package/dist/cjs/components/RangeDateField/utils/getRangeEditableSections.d.ts +5 -0
- package/dist/cjs/components/RangeDateField/utils/getRangeEditableSections.js +42 -0
- package/dist/cjs/components/RangeDateField/utils/index.d.ts +3 -0
- package/dist/cjs/components/RangeDateField/utils/index.js +6 -0
- package/dist/cjs/components/RangeDateField/utils/isValidRange.d.ts +3 -0
- package/dist/cjs/components/RangeDateField/utils/isValidRange.js +8 -0
- package/dist/cjs/components/RelativeDateField/RelativeDateField.d.ts +2 -2
- package/dist/cjs/components/RelativeDateField/RelativeDateField.js +5 -2
- package/dist/cjs/components/RelativeDateField/hooks/useRelativeDateFieldProps.js +5 -11
- package/dist/cjs/components/RelativeDateField/hooks/useRelativeDateFieldState.d.ts +3 -1
- package/dist/cjs/components/RelativeDateField/hooks/useRelativeDateFieldState.js +5 -4
- package/dist/cjs/components/RelativeDatePicker/RelativeDatePicker.css +3 -0
- package/dist/cjs/components/RelativeDatePicker/RelativeDatePicker.d.ts +2 -2
- package/dist/cjs/components/RelativeDatePicker/RelativeDatePicker.js +13 -2
- package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerProps.js +35 -27
- package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerState.d.ts +2 -2
- package/dist/cjs/components/RelativeDatePicker/hooks/useRelativeDatePickerState.js +12 -16
- package/dist/cjs/components/RelativeRangeDatePicker/RelativeRangeDatePicker.css +56 -0
- package/dist/cjs/components/RelativeRangeDatePicker/RelativeRangeDatePicker.d.ts +27 -0
- package/dist/cjs/components/RelativeRangeDatePicker/RelativeRangeDatePicker.js +90 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.css +32 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.d.ts +14 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.js +43 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/i18n/en.json +8 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/i18n/index.d.ts +1 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/i18n/index.js +9 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/i18n/ru.json +8 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.d.ts +16 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.js +104 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/Presets.css +26 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/Presets.d.ts +18 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/Presets.js +67 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/PresetsDoc.css +14 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/PresetsDoc.d.ts +7 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/PresetsDoc.js +90 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/defaultPresets.d.ts +9 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/defaultPresets.js +186 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/i18n/en.json +40 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/i18n/index.d.ts +1 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/i18n/index.js +9 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/i18n/ru.json +40 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/utils.d.ts +16 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/Presets/utils.js +85 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/Zones.css +3 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/Zones.d.ts +9 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/Zones.js +62 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/i18n/en.json +4 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/i18n/index.d.ts +1 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/i18n/index.js +9 -0
- package/dist/cjs/components/RelativeRangeDatePicker/components/Zones/i18n/ru.json +4 -0
- package/dist/cjs/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.d.ts +26 -0
- package/dist/cjs/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.js +58 -0
- package/dist/cjs/components/RelativeRangeDatePicker/i18n/en.json +8 -0
- package/dist/cjs/components/RelativeRangeDatePicker/i18n/index.d.ts +1 -0
- package/dist/cjs/components/RelativeRangeDatePicker/i18n/index.js +9 -0
- package/dist/cjs/components/RelativeRangeDatePicker/i18n/ru.json +8 -0
- package/dist/cjs/components/RelativeRangeDatePicker/index.d.ts +4 -0
- package/dist/cjs/components/RelativeRangeDatePicker/index.js +8 -0
- package/dist/cjs/components/RelativeRangeDatePicker/utils.d.ts +15 -0
- package/dist/cjs/components/RelativeRangeDatePicker/utils.js +53 -0
- package/dist/cjs/components/index.d.ts +3 -0
- package/dist/cjs/components/index.js +2 -0
- package/dist/cjs/components/types/datePicker.d.ts +5 -2
- package/dist/cjs/components/types/events.d.ts +4 -4
- package/dist/cjs/components/types/inputs.d.ts +10 -9
- package/dist/cjs/components/utils/dates.d.ts +1 -2
- package/dist/cjs/components/utils/useDefaultTimeZone.d.ts +2 -0
- package/dist/cjs/components/utils/useDefaultTimeZone.js +15 -0
- package/dist/cjs/components/utils/validation/datePicker.d.ts +6 -0
- package/dist/cjs/components/utils/validation/datePicker.js +30 -0
- package/dist/cjs/components/utils/validation/i18n/en.json +6 -0
- package/dist/cjs/components/utils/validation/i18n/index.d.ts +1 -0
- package/dist/cjs/components/utils/validation/i18n/index.js +9 -0
- package/dist/cjs/components/utils/validation/i18n/ru.json +6 -0
- package/dist/esm/components/Calendar/Calendar.d.ts +6 -5
- package/dist/esm/components/Calendar/Calendar.js +4 -4
- package/dist/esm/components/Calendar/index.d.ts +6 -6
- package/dist/esm/components/Calendar/index.js +5 -5
- package/dist/esm/components/{CalendarBase → CalendarView}/Calendar.css +9 -6
- package/dist/esm/components/{CalendarBase/CalendarBase.d.ts → CalendarView/CalendarView.d.ts} +2 -2
- package/dist/esm/components/{CalendarBase/CalendarBase.js → CalendarView/CalendarView.js} +3 -2
- package/dist/{cjs/components/CalendarBase → esm/components/CalendarView}/hooks/types.d.ts +37 -31
- package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useCalendarCellProps.js +1 -2
- package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useCalendarGridProps.d.ts +2 -2
- package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useCalendarGridProps.js +0 -1
- package/dist/{cjs/components/CalendarBase → esm/components/CalendarView}/hooks/useCalendarState.d.ts +1 -1
- package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useCalendarState.js +46 -24
- package/dist/esm/components/CalendarView/hooks/useRangeCalendarState.d.ts +8 -0
- package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useRangeCalendarState.js +24 -13
- package/dist/esm/components/DateField/DateField.d.ts +1 -4
- package/dist/esm/components/DateField/DateField.js +4 -2
- package/dist/esm/components/DateField/hooks/useBaseDateFieldState.d.ts +97 -0
- package/dist/esm/components/DateField/hooks/useBaseDateFieldState.js +311 -0
- package/dist/esm/components/DateField/hooks/useDateFieldProps.d.ts +6 -3
- package/dist/esm/components/DateField/hooks/useDateFieldProps.js +14 -12
- package/dist/esm/components/DateField/hooks/useDateFieldState.d.ts +2 -65
- package/dist/esm/components/DateField/hooks/useDateFieldState.js +97 -409
- package/dist/esm/components/DateField/index.d.ts +1 -0
- package/dist/esm/components/DateField/index.js +1 -0
- package/dist/esm/components/DateField/utils.d.ts +10 -1
- package/dist/esm/components/DateField/utils.js +105 -2
- package/dist/esm/components/DatePicker/DatePicker.d.ts +4 -4
- package/dist/esm/components/DatePicker/DatePicker.js +6 -6
- package/dist/esm/components/DatePicker/MobileCalendar.css +6 -6
- package/dist/esm/components/DatePicker/MobileCalendar.js +17 -12
- package/dist/esm/components/DatePicker/hooks/useDatePickerProps.js +5 -16
- package/dist/esm/components/DatePicker/hooks/useDatePickerState.d.ts +5 -4
- package/dist/esm/components/DatePicker/hooks/useDatePickerState.js +71 -56
- package/dist/esm/components/RangeCalendar/RangeCalendar.d.ts +3 -3
- package/dist/esm/components/RangeCalendar/RangeCalendar.js +4 -4
- package/dist/esm/components/RangeDateField/RangeDateField.css +4 -0
- package/dist/esm/components/RangeDateField/RangeDateField.d.ts +12 -0
- package/dist/esm/components/RangeDateField/RangeDateField.js +21 -0
- package/dist/esm/components/RangeDateField/hooks/useRangeDateFieldState.d.ts +9 -0
- package/dist/esm/components/RangeDateField/hooks/useRangeDateFieldState.js +222 -0
- package/dist/esm/components/RangeDateField/index.d.ts +2 -0
- package/dist/esm/components/RangeDateField/index.js +2 -0
- package/dist/esm/components/RangeDateField/utils/createPlaceholderRangeValue.d.ts +5 -0
- package/dist/esm/components/RangeDateField/utils/createPlaceholderRangeValue.js +5 -0
- package/dist/esm/components/RangeDateField/utils/getRangeEditableSections.d.ts +5 -0
- package/dist/esm/components/RangeDateField/utils/getRangeEditableSections.js +38 -0
- package/dist/esm/components/RangeDateField/utils/index.d.ts +3 -0
- package/dist/esm/components/RangeDateField/utils/index.js +3 -0
- package/dist/esm/components/RangeDateField/utils/isValidRange.d.ts +3 -0
- package/dist/esm/components/RangeDateField/utils/isValidRange.js +4 -0
- package/dist/esm/components/RelativeDateField/RelativeDateField.d.ts +2 -2
- package/dist/esm/components/RelativeDateField/RelativeDateField.js +5 -2
- package/dist/esm/components/RelativeDateField/hooks/useRelativeDateFieldProps.js +5 -11
- package/dist/esm/components/RelativeDateField/hooks/useRelativeDateFieldState.d.ts +3 -1
- package/dist/esm/components/RelativeDateField/hooks/useRelativeDateFieldState.js +5 -4
- package/dist/esm/components/RelativeDatePicker/RelativeDatePicker.css +3 -0
- package/dist/esm/components/RelativeDatePicker/RelativeDatePicker.d.ts +2 -2
- package/dist/esm/components/RelativeDatePicker/RelativeDatePicker.js +13 -2
- package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerProps.js +35 -27
- package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerState.d.ts +2 -2
- package/dist/esm/components/RelativeDatePicker/hooks/useRelativeDatePickerState.js +12 -16
- package/dist/esm/components/RelativeRangeDatePicker/RelativeRangeDatePicker.css +56 -0
- package/dist/esm/components/RelativeRangeDatePicker/RelativeRangeDatePicker.d.ts +27 -0
- package/dist/esm/components/RelativeRangeDatePicker/RelativeRangeDatePicker.js +85 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.css +32 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.d.ts +14 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/PickerDialog.js +39 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/i18n/en.json +8 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/i18n/index.d.ts +1 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/i18n/index.js +5 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/i18n/ru.json +8 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.d.ts +16 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/PickerDialog/useRelativeRangeDatePickerDialogState.js +99 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/Presets/Presets.css +26 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/Presets/Presets.d.ts +18 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/Presets/Presets.js +62 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/Presets/PresetsDoc.css +14 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/Presets/PresetsDoc.d.ts +7 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/Presets/PresetsDoc.js +85 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/Presets/defaultPresets.d.ts +9 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/Presets/defaultPresets.js +183 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/Presets/i18n/en.json +40 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/Presets/i18n/index.d.ts +1 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/Presets/i18n/index.js +5 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/Presets/i18n/ru.json +40 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/Presets/utils.d.ts +16 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/Presets/utils.js +78 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/Zones/Zones.css +3 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/Zones/Zones.d.ts +9 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/Zones/Zones.js +58 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/Zones/i18n/en.json +4 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/Zones/i18n/index.d.ts +1 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/Zones/i18n/index.js +5 -0
- package/dist/esm/components/RelativeRangeDatePicker/components/Zones/i18n/ru.json +4 -0
- package/dist/esm/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.d.ts +26 -0
- package/dist/esm/components/RelativeRangeDatePicker/hooks/useRelativeRangeDatePickerState.js +53 -0
- package/dist/esm/components/RelativeRangeDatePicker/i18n/en.json +8 -0
- package/dist/esm/components/RelativeRangeDatePicker/i18n/index.d.ts +1 -0
- package/dist/esm/components/RelativeRangeDatePicker/i18n/index.js +5 -0
- package/dist/esm/components/RelativeRangeDatePicker/i18n/ru.json +8 -0
- package/dist/esm/components/RelativeRangeDatePicker/index.d.ts +4 -0
- package/dist/esm/components/RelativeRangeDatePicker/index.js +3 -0
- package/dist/esm/components/RelativeRangeDatePicker/utils.d.ts +15 -0
- package/dist/esm/components/RelativeRangeDatePicker/utils.js +46 -0
- package/dist/esm/components/index.d.ts +3 -0
- package/dist/esm/components/index.js +2 -0
- package/dist/esm/components/types/datePicker.d.ts +5 -2
- package/dist/esm/components/types/events.d.ts +4 -4
- package/dist/esm/components/types/inputs.d.ts +10 -9
- package/dist/esm/components/utils/dates.d.ts +1 -2
- package/dist/esm/components/utils/useDefaultTimeZone.d.ts +2 -0
- package/dist/esm/components/utils/useDefaultTimeZone.js +10 -0
- package/dist/esm/components/utils/validation/datePicker.d.ts +6 -0
- package/dist/esm/components/utils/validation/datePicker.js +26 -0
- package/dist/esm/components/utils/validation/i18n/en.json +6 -0
- package/dist/esm/components/utils/validation/i18n/index.d.ts +1 -0
- package/dist/esm/components/utils/validation/i18n/index.js +5 -0
- package/dist/esm/components/utils/validation/i18n/ru.json +6 -0
- package/package.json +27 -27
- package/dist/cjs/components/CalendarBase/hooks/useRangeCalendarState.d.ts +0 -7
- package/dist/cjs/components/hooks/useControlledState.d.ts +0 -1
- package/dist/cjs/components/hooks/useControlledState.js +0 -28
- package/dist/esm/components/CalendarBase/hooks/useRangeCalendarState.d.ts +0 -7
- package/dist/esm/components/hooks/useControlledState.d.ts +0 -1
- package/dist/esm/components/hooks/useControlledState.js +0 -23
- /package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/types.js +0 -0
- /package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/useCalendarCellProps.d.ts +0 -0
- /package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/useCalendarGridProps.js +0 -0
- /package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/useCalendarProps.d.ts +0 -0
- /package/dist/cjs/components/{CalendarBase → CalendarView}/hooks/useCalendarProps.js +0 -0
- /package/dist/cjs/components/{CalendarBase → CalendarView}/i18n/en.json +0 -0
- /package/dist/cjs/components/{CalendarBase → CalendarView}/i18n/index.d.ts +0 -0
- /package/dist/cjs/components/{CalendarBase → CalendarView}/i18n/index.js +0 -0
- /package/dist/cjs/components/{CalendarBase → CalendarView}/i18n/ru.json +0 -0
- /package/dist/cjs/components/{CalendarBase → CalendarView}/utils.d.ts +0 -0
- /package/dist/cjs/components/{CalendarBase → CalendarView}/utils.js +0 -0
- /package/dist/esm/components/{CalendarBase → CalendarView}/hooks/types.js +0 -0
- /package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useCalendarCellProps.d.ts +0 -0
- /package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useCalendarProps.d.ts +0 -0
- /package/dist/esm/components/{CalendarBase → CalendarView}/hooks/useCalendarProps.js +0 -0
- /package/dist/esm/components/{CalendarBase → CalendarView}/i18n/en.json +0 -0
- /package/dist/esm/components/{CalendarBase → CalendarView}/i18n/index.d.ts +0 -0
- /package/dist/esm/components/{CalendarBase → CalendarView}/i18n/index.js +0 -0
- /package/dist/esm/components/{CalendarBase → CalendarView}/i18n/ru.json +0 -0
- /package/dist/esm/components/{CalendarBase → CalendarView}/utils.d.ts +0 -0
- /package/dist/esm/components/{CalendarBase → CalendarView}/utils.js +0 -0
|
@@ -8,7 +8,10 @@ export interface CalendarStateOptionsBase extends InputBase {
|
|
|
8
8
|
maxValue?: DateTime;
|
|
9
9
|
/** Callback that is called for each date of the calendar. If it returns true, then the date is unavailable. */
|
|
10
10
|
isDateUnavailable?: (date: DateTime) => boolean;
|
|
11
|
-
/**
|
|
11
|
+
/**
|
|
12
|
+
* Which timezone use to show values. Example: 'default', 'system', 'Europe/Amsterdam'.
|
|
13
|
+
* @default The timezone of the `value` or `defaultValue` or `focusedValue` or `defaultFocusedValue`, 'default' otherwise.
|
|
14
|
+
*/
|
|
12
15
|
timeZone?: string;
|
|
13
16
|
/**
|
|
14
17
|
* Whether to automatically focus the calendar when it mounts.
|
|
@@ -35,7 +38,8 @@ interface CalendarStateBase {
|
|
|
35
38
|
readonly disabled?: boolean;
|
|
36
39
|
/** Whether the calendar is in a read only state. */
|
|
37
40
|
readonly readOnly?: boolean;
|
|
38
|
-
|
|
41
|
+
/** Which timezone use to show values. */
|
|
42
|
+
readonly timeZone: string;
|
|
39
43
|
/** The minimum allowed date that a user may select. */
|
|
40
44
|
readonly minValue?: DateTime;
|
|
41
45
|
/** The maximum allowed date that a user may select. */
|
|
@@ -43,85 +47,87 @@ interface CalendarStateBase {
|
|
|
43
47
|
/** The currently focused date. */
|
|
44
48
|
readonly focusedDate: DateTime;
|
|
45
49
|
/** Sets the focused date. */
|
|
46
|
-
setFocusedDate(date: DateTime)
|
|
50
|
+
setFocusedDate: (date: DateTime) => void;
|
|
47
51
|
/** Selects the currently focused date. */
|
|
48
|
-
selectFocusedDate()
|
|
52
|
+
selectFocusedDate: () => void;
|
|
49
53
|
/** Selects the given date. */
|
|
50
|
-
selectDate(date: DateTime, force?: boolean)
|
|
54
|
+
selectDate: (date: DateTime, force?: boolean) => void;
|
|
51
55
|
/** Moves focus to the next calendar date. */
|
|
52
|
-
focusNextCell()
|
|
56
|
+
focusNextCell: () => void;
|
|
53
57
|
/** Moves focus to the previous calendar date. */
|
|
54
|
-
focusPreviousCell()
|
|
58
|
+
focusPreviousCell: () => void;
|
|
55
59
|
/** Moves focus to the next row of dates, e.g. the next week. */
|
|
56
|
-
focusNextRow()
|
|
60
|
+
focusNextRow: () => void;
|
|
57
61
|
/** Moves focus to the previous row of dates, e.g. the previous work. */
|
|
58
|
-
focusPreviousRow()
|
|
62
|
+
focusPreviousRow: () => void;
|
|
59
63
|
/**
|
|
60
64
|
* Moves focus to the next page of dates, e.g. the next month.
|
|
61
65
|
* If the `larger` option is `true`, the focus is moved by the next larger unit.
|
|
62
66
|
* For example, if days are displayed, then focus moves to the next year.
|
|
63
67
|
*/
|
|
64
|
-
focusNextPage(larger?: boolean)
|
|
68
|
+
focusNextPage: (larger?: boolean) => void;
|
|
65
69
|
/**
|
|
66
70
|
* Moves focus to the previous page of dates, e.g. the previous month.
|
|
67
71
|
* If the `larger` option is `true`, the focus is moved by the next larger unit.
|
|
68
72
|
* For example, if days are displayed, then focus moves to the previous year.
|
|
69
73
|
*/
|
|
70
|
-
focusPreviousPage(larger?: boolean)
|
|
74
|
+
focusPreviousPage: (larger?: boolean) => void;
|
|
71
75
|
/** Moves focus to the start of the current section of dates, e.g. the start of the current month. */
|
|
72
|
-
focusSectionStart()
|
|
76
|
+
focusSectionStart: () => void;
|
|
73
77
|
/** Moves focus to the end of the current section of dates, e.g. the end of the current month month. */
|
|
74
|
-
focusSectionEnd()
|
|
78
|
+
focusSectionEnd: () => void;
|
|
75
79
|
/** Switches to more detailed layout. */
|
|
76
|
-
zoomIn()
|
|
80
|
+
zoomIn: () => void;
|
|
77
81
|
/** Switches to less detailed layout. */
|
|
78
|
-
zoomOut()
|
|
82
|
+
zoomOut: () => void;
|
|
79
83
|
/** Whether focus is currently within the calendar. */
|
|
80
84
|
readonly isFocused: boolean;
|
|
81
85
|
/** Sets whether focus is currently within the calendar. */
|
|
82
|
-
setFocused(isFocused: boolean)
|
|
86
|
+
setFocused: (isFocused: boolean) => void;
|
|
83
87
|
/** Returns whether the given date is invalid according to the `minValue` and `maxValue` props. */
|
|
84
|
-
isInvalid(date: DateTime)
|
|
88
|
+
isInvalid: (date: DateTime) => boolean;
|
|
85
89
|
/** Returns whether the previous page is allowed to be selected according to the `minValue` prop. */
|
|
86
|
-
isPreviousPageInvalid()
|
|
90
|
+
isPreviousPageInvalid: () => boolean;
|
|
87
91
|
/** Returns whether the next page is allowed to be selected according to the `maxValue` prop. */
|
|
88
|
-
isNextPageInvalid()
|
|
92
|
+
isNextPageInvalid: () => boolean;
|
|
89
93
|
/** Returns whether the given date is currently selected. */
|
|
90
|
-
isSelected(date: DateTime)
|
|
94
|
+
isSelected: (date: DateTime) => boolean;
|
|
91
95
|
/** Returns whether the given date is unavailable according to the `isDateUnavailable` prop. */
|
|
92
|
-
isCellUnavailable(date: DateTime)
|
|
96
|
+
isCellUnavailable: (date: DateTime) => boolean;
|
|
93
97
|
/** Returns whether the given date is currently focused. */
|
|
94
|
-
isCellFocused(date: DateTime)
|
|
98
|
+
isCellFocused: (date: DateTime) => boolean;
|
|
95
99
|
/** Returns whether the given date is disabled according to the `minValue, `maxValue`, and `isDisabled` props. */
|
|
96
|
-
isCellDisabled(date: DateTime)
|
|
100
|
+
isCellDisabled: (date: DateTime) => boolean;
|
|
97
101
|
/** Returns whether the given date is weekend */
|
|
98
|
-
isWeekend(date: DateTime)
|
|
102
|
+
isWeekend: (date: DateTime) => boolean;
|
|
103
|
+
/** Returns whether the given date is in current period */
|
|
104
|
+
isCurrent: (date: DateTime) => boolean;
|
|
99
105
|
/** Current calendar layout */
|
|
100
106
|
readonly mode: CalendarLayout;
|
|
101
107
|
/** Sets calendar layout */
|
|
102
|
-
setMode(mode: CalendarLayout)
|
|
108
|
+
setMode: (mode: CalendarLayout) => void;
|
|
103
109
|
readonly availableModes: CalendarLayout[];
|
|
104
110
|
readonly startDate: DateTime;
|
|
105
111
|
readonly endDate: DateTime;
|
|
106
112
|
}
|
|
107
113
|
export interface CalendarState extends CalendarStateBase {
|
|
108
114
|
/** The currently selected date. */
|
|
109
|
-
readonly value
|
|
115
|
+
readonly value: DateTime | null;
|
|
110
116
|
/** Sets the currently selected date. */
|
|
111
|
-
setValue(value: DateTime)
|
|
117
|
+
setValue: (value: DateTime) => void;
|
|
112
118
|
}
|
|
113
119
|
export interface RangeCalendarState extends CalendarStateBase {
|
|
114
120
|
/** The currently selected range. */
|
|
115
|
-
readonly value
|
|
121
|
+
readonly value: RangeValue<DateTime> | null;
|
|
116
122
|
/** Sets the currently selected range. */
|
|
117
|
-
setValue(value: RangeValue<DateTime>)
|
|
123
|
+
setValue: (value: RangeValue<DateTime>) => void;
|
|
118
124
|
/** The current anchor date that the user clicked on to begin range selection. */
|
|
119
125
|
readonly anchorDate: DateTime | undefined;
|
|
120
126
|
/** Sets the anchor date that the user clicked on to begin range selection. */
|
|
121
|
-
setAnchorDate(date: DateTime | undefined)
|
|
127
|
+
setAnchorDate: (date: DateTime | undefined) => void;
|
|
122
128
|
/** The currently highlighted date range. */
|
|
123
129
|
readonly highlightedRange: RangeValue<DateTime> | undefined;
|
|
124
130
|
/** Highlights the given date during selection, e.g. by hovering. */
|
|
125
|
-
highlightDate(date: DateTime)
|
|
131
|
+
highlightDate: (date: DateTime) => void;
|
|
126
132
|
}
|
|
127
133
|
export {};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { dateTime } from '@gravity-ui/date-utils';
|
|
3
2
|
export function useCalendarCellProps(date, state) {
|
|
4
3
|
const ref = React.useRef(null);
|
|
5
4
|
const isFocused = state.isCellFocused(date);
|
|
@@ -19,7 +18,7 @@ export function useCalendarCellProps(date, state) {
|
|
|
19
18
|
const isOutsideCurrentRange = state.mode === 'days' ? !state.focusedDate.isSame(date, 'month') : false;
|
|
20
19
|
const isUnavailable = state.isCellUnavailable(date);
|
|
21
20
|
const isSelectable = !isDisabled && !isUnavailable;
|
|
22
|
-
const isCurrent =
|
|
21
|
+
const isCurrent = state.isCurrent(date);
|
|
23
22
|
const isWeekend = state.isWeekend(date);
|
|
24
23
|
const label = getDateLabel(date, state.mode);
|
|
25
24
|
const cellProps = {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="react" />
|
|
2
2
|
import type { CalendarState, RangeCalendarState } from './types';
|
|
3
3
|
export declare function useCalendarGridProps(state: CalendarState | RangeCalendarState): {
|
|
4
|
-
gridProps:
|
|
4
|
+
gridProps: import("react").HTMLAttributes<HTMLElement>;
|
|
5
5
|
};
|
package/dist/{cjs/components/CalendarBase → esm/components/CalendarView}/hooks/useCalendarState.d.ts
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { DateTime } from '@gravity-ui/date-utils';
|
|
2
2
|
import type { ValueBase } from '../../types';
|
|
3
3
|
import type { CalendarState, CalendarStateOptionsBase } from './types';
|
|
4
|
-
export interface CalendarStateOptions extends ValueBase<
|
|
4
|
+
export interface CalendarStateOptions<T = DateTime> extends ValueBase<T | null, T>, CalendarStateOptionsBase {
|
|
5
5
|
}
|
|
6
6
|
export type { CalendarState } from './types';
|
|
7
7
|
export declare function useCalendarState(props: CalendarStateOptions): CalendarState;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { dateTime } from '@gravity-ui/date-utils';
|
|
3
|
+
import { useControlledState } from '@gravity-ui/uikit';
|
|
4
|
+
import { createPlaceholderValue, mergeDateTime } from '../../utils/dates';
|
|
5
|
+
import { useDefaultTimeZone } from '../../utils/useDefaultTimeZone';
|
|
4
6
|
import { calendarLayouts, constrainValue } from '../utils';
|
|
5
7
|
const defaultModes = {
|
|
6
8
|
days: true,
|
|
@@ -9,25 +11,34 @@ const defaultModes = {
|
|
|
9
11
|
years: true,
|
|
10
12
|
};
|
|
11
13
|
export function useCalendarState(props) {
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const [
|
|
14
|
+
var _a, _b, _c;
|
|
15
|
+
const { disabled, readOnly, modes = defaultModes } = props;
|
|
16
|
+
const [value, setValue] = useControlledState(props.value, (_a = props.defaultValue) !== null && _a !== void 0 ? _a : null, props.onUpdate);
|
|
15
17
|
const availableModes = calendarLayouts.filter((l) => modes[l]);
|
|
16
18
|
const minMode = availableModes[0] || 'days';
|
|
19
|
+
const [mode, setMode] = useControlledState(props.mode, (_b = props.defaultMode) !== null && _b !== void 0 ? _b : minMode, props.onUpdateMode);
|
|
17
20
|
const currentMode = mode && availableModes.includes(mode) ? mode : minMode;
|
|
21
|
+
const inputTimeZone = useDefaultTimeZone(props.value || props.defaultValue || props.focusedValue || props.defaultFocusedValue);
|
|
22
|
+
const timeZone = props.timeZone || inputTimeZone;
|
|
23
|
+
const minValue = React.useMemo(() => (props.minValue ? props.minValue.timeZone(timeZone) : undefined), [timeZone, props.minValue]);
|
|
24
|
+
const maxValue = React.useMemo(() => (props.maxValue ? props.maxValue.timeZone(timeZone) : undefined), [timeZone, props.maxValue]);
|
|
18
25
|
const focusedValue = React.useMemo(() => {
|
|
19
26
|
if (!props.focusedValue) {
|
|
20
27
|
return props.focusedValue;
|
|
21
28
|
}
|
|
22
|
-
return constrainValue(props.focusedValue, minValue, maxValue);
|
|
23
|
-
}, [props.focusedValue, minValue, maxValue]);
|
|
29
|
+
return constrainValue(props.focusedValue.timeZone(timeZone), minValue, maxValue);
|
|
30
|
+
}, [props.focusedValue, minValue, maxValue, timeZone]);
|
|
24
31
|
const defaultFocusedValue = React.useMemo(() => {
|
|
25
|
-
|
|
32
|
+
var _a;
|
|
33
|
+
const defaultValue = ((_a = (props.defaultFocusedValue ? props.defaultFocusedValue : value)) === null || _a === void 0 ? void 0 : _a.timeZone(timeZone)) ||
|
|
26
34
|
createPlaceholderValue({ timeZone }).startOf(minMode);
|
|
27
35
|
return constrainValue(defaultValue, minValue, maxValue);
|
|
28
36
|
}, [maxValue, minValue, props.defaultFocusedValue, timeZone, value, minMode]);
|
|
29
|
-
const [focusedDateInner, setFocusedDate] = useControlledState(focusedValue, defaultFocusedValue,
|
|
30
|
-
|
|
37
|
+
const [focusedDateInner, setFocusedDate] = useControlledState(focusedValue, defaultFocusedValue, (date) => {
|
|
38
|
+
var _a;
|
|
39
|
+
(_a = props.onFocusUpdate) === null || _a === void 0 ? void 0 : _a.call(props, date.timeZone(inputTimeZone));
|
|
40
|
+
});
|
|
41
|
+
const focusedDate = (_c = focusedDateInner === null || focusedDateInner === void 0 ? void 0 : focusedDateInner.timeZone(timeZone)) !== null && _c !== void 0 ? _c : constrainValue(createPlaceholderValue({ timeZone }), minValue, maxValue);
|
|
31
42
|
if (isInvalid(focusedDate, minValue, maxValue)) {
|
|
32
43
|
// If the focused date was moved to an invalid value, it can't be focused, so constrain it.
|
|
33
44
|
setFocusedDate(constrainValue(focusedDate, minValue, maxValue));
|
|
@@ -42,16 +53,24 @@ export function useCalendarState(props) {
|
|
|
42
53
|
disabled,
|
|
43
54
|
readOnly,
|
|
44
55
|
value,
|
|
45
|
-
setValue
|
|
56
|
+
setValue(date) {
|
|
57
|
+
if (!disabled && !readOnly) {
|
|
58
|
+
let newValue = constrainValue(date, minValue, maxValue);
|
|
59
|
+
if (this.isCellUnavailable(newValue)) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (value) {
|
|
63
|
+
// If there is a date already selected, then we want to keep its time
|
|
64
|
+
newValue = mergeDateTime(newValue, value.timeZone(timeZone));
|
|
65
|
+
}
|
|
66
|
+
setValue(newValue.timeZone(inputTimeZone));
|
|
67
|
+
}
|
|
68
|
+
},
|
|
46
69
|
timeZone,
|
|
47
70
|
selectDate(date, force = false) {
|
|
48
71
|
if (!disabled) {
|
|
49
72
|
if (!readOnly && (force || this.mode === minMode)) {
|
|
50
|
-
|
|
51
|
-
if (this.isCellUnavailable(newValue)) {
|
|
52
|
-
return;
|
|
53
|
-
}
|
|
54
|
-
setValue(newValue);
|
|
73
|
+
this.setValue(date.startOf(minMode));
|
|
55
74
|
if (force && currentMode !== minMode) {
|
|
56
75
|
setMode(minMode);
|
|
57
76
|
}
|
|
@@ -127,15 +146,15 @@ export function useCalendarState(props) {
|
|
|
127
146
|
focusCell(getEndDate(focusedDate, this.mode));
|
|
128
147
|
},
|
|
129
148
|
zoomIn() {
|
|
130
|
-
const
|
|
131
|
-
if (
|
|
132
|
-
this.setMode(
|
|
149
|
+
const nextMode = availableModes[availableModes.indexOf(this.mode) - 1];
|
|
150
|
+
if (nextMode) {
|
|
151
|
+
this.setMode(nextMode);
|
|
133
152
|
}
|
|
134
153
|
},
|
|
135
154
|
zoomOut() {
|
|
136
|
-
const
|
|
137
|
-
if (
|
|
138
|
-
this.setMode(
|
|
155
|
+
const nextMode = availableModes[availableModes.indexOf(this.mode) + 1];
|
|
156
|
+
if (nextMode) {
|
|
157
|
+
this.setMode(nextMode);
|
|
139
158
|
}
|
|
140
159
|
},
|
|
141
160
|
selectFocusedDate() {
|
|
@@ -155,8 +174,8 @@ export function useCalendarState(props) {
|
|
|
155
174
|
return this.isInvalid(next);
|
|
156
175
|
},
|
|
157
176
|
isSelected(date) {
|
|
158
|
-
return
|
|
159
|
-
date.isSame(value
|
|
177
|
+
return Boolean(value &&
|
|
178
|
+
date.isSame(value.timeZone(timeZone), currentMode) &&
|
|
160
179
|
!this.isCellDisabled(date));
|
|
161
180
|
},
|
|
162
181
|
isCellUnavailable(date) {
|
|
@@ -176,6 +195,9 @@ export function useCalendarState(props) {
|
|
|
176
195
|
isWeekend(date) {
|
|
177
196
|
return this.mode === 'days' && [0, 6].includes(date.day());
|
|
178
197
|
},
|
|
198
|
+
isCurrent(date) {
|
|
199
|
+
return dateTime({ timeZone }).isSame(date, this.mode);
|
|
200
|
+
},
|
|
179
201
|
mode: currentMode,
|
|
180
202
|
setMode,
|
|
181
203
|
availableModes,
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { DateTime } from '@gravity-ui/date-utils';
|
|
2
|
+
import type { RangeValue } from '../../types';
|
|
3
|
+
import type { RangeCalendarState } from './types';
|
|
4
|
+
import type { CalendarStateOptions } from './useCalendarState';
|
|
5
|
+
export interface RangeCalendarStateOptions extends CalendarStateOptions<RangeValue<DateTime>> {
|
|
6
|
+
}
|
|
7
|
+
export type { RangeCalendarState } from './types';
|
|
8
|
+
export declare function useRangeCalendarState(props: RangeCalendarStateOptions): RangeCalendarState;
|
|
@@ -1,18 +1,31 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { useControlledState } from '
|
|
3
|
+
import { useControlledState } from '@gravity-ui/uikit';
|
|
4
|
+
import { mergeDateTime } from '../../utils/dates';
|
|
5
|
+
import { useDefaultTimeZone } from '../../utils/useDefaultTimeZone';
|
|
4
6
|
import { constrainValue } from '../utils';
|
|
5
7
|
import { useCalendarState } from './useCalendarState';
|
|
6
8
|
export function useRangeCalendarState(props) {
|
|
7
|
-
var _a
|
|
8
|
-
const { value: valueProp, defaultValue, onUpdate } = props, calendarProps = __rest(props, ["value", "defaultValue", "onUpdate"]);
|
|
9
|
+
var _a;
|
|
10
|
+
const { value: valueProp, defaultValue = null, onUpdate } = props, calendarProps = __rest(props, ["value", "defaultValue", "onUpdate"]);
|
|
9
11
|
const [value, setValue] = useControlledState(valueProp, defaultValue, onUpdate);
|
|
10
12
|
const [anchorDate, setAnchorDateState] = React.useState();
|
|
11
|
-
const
|
|
13
|
+
const inputTimeZone = useDefaultTimeZone((valueProp === null || valueProp === void 0 ? void 0 : valueProp.start) || (defaultValue === null || defaultValue === void 0 ? void 0 : defaultValue.start) || props.focusedValue || props.defaultFocusedValue);
|
|
14
|
+
const timeZone = props.timeZone || inputTimeZone;
|
|
15
|
+
const calendar = useCalendarState(Object.assign(Object.assign({}, calendarProps), { value: null, timeZone }));
|
|
12
16
|
const highlightedRange = anchorDate
|
|
13
17
|
? makeRange(anchorDate, calendar.focusedDate, calendar.mode)
|
|
14
|
-
: (
|
|
18
|
+
: (_a = (value &&
|
|
19
|
+
makeRange(value.start.timeZone(timeZone), value.end.timeZone(timeZone), calendar.mode))) !== null && _a !== void 0 ? _a : undefined;
|
|
15
20
|
const minMode = calendar.availableModes[0];
|
|
21
|
+
const handleSetValue = (v) => {
|
|
22
|
+
let { start, end } = v;
|
|
23
|
+
if (value) {
|
|
24
|
+
start = mergeDateTime(start, value.start.timeZone(timeZone));
|
|
25
|
+
end = mergeDateTime(end, value.end.timeZone(timeZone));
|
|
26
|
+
}
|
|
27
|
+
setValue({ start: start.timeZone(inputTimeZone), end: end.timeZone(inputTimeZone) });
|
|
28
|
+
};
|
|
16
29
|
const selectDate = (date, force = false) => {
|
|
17
30
|
if (props.disabled) {
|
|
18
31
|
return;
|
|
@@ -24,22 +37,20 @@ export function useRangeCalendarState(props) {
|
|
|
24
37
|
if (props.readOnly) {
|
|
25
38
|
return;
|
|
26
39
|
}
|
|
27
|
-
|
|
28
|
-
if (calendar.isCellUnavailable(
|
|
40
|
+
const newDate = constrainValue(date, calendar.minValue, calendar.maxValue);
|
|
41
|
+
if (calendar.isCellUnavailable(newDate)) {
|
|
29
42
|
return;
|
|
30
43
|
}
|
|
31
44
|
if (anchorDate) {
|
|
32
|
-
const range = makeRange(anchorDate,
|
|
33
|
-
|
|
45
|
+
const range = makeRange(anchorDate, newDate, calendar.mode);
|
|
46
|
+
handleSetValue(range);
|
|
34
47
|
setAnchorDateState(undefined);
|
|
35
48
|
}
|
|
36
49
|
else {
|
|
37
|
-
setAnchorDateState(
|
|
50
|
+
setAnchorDateState(newDate);
|
|
38
51
|
}
|
|
39
52
|
};
|
|
40
|
-
return Object.assign(Object.assign({}, calendar), { value,
|
|
41
|
-
setValue,
|
|
42
|
-
selectDate,
|
|
53
|
+
return Object.assign(Object.assign({}, calendar), { value, setValue: handleSetValue, selectDate,
|
|
43
54
|
anchorDate, setAnchorDate: setAnchorDateState, highlightedRange,
|
|
44
55
|
isSelected(date) {
|
|
45
56
|
if (!highlightedRange) {
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { DateFieldStateOptions } from './hooks/useDateFieldState';
|
|
1
|
+
import type { DateFieldProps } from './hooks/useDateFieldProps';
|
|
3
2
|
import './DateField.css';
|
|
4
|
-
export interface DateFieldProps extends DateFieldStateOptions, TextInputProps, TextInputExtendProps, DomProps, FocusableProps, KeyboardEvents, StyleProps, AccessibilityProps {
|
|
5
|
-
}
|
|
6
3
|
export declare function DateField({ className, ...props }: DateFieldProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __rest } from "tslib";
|
|
2
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import React from 'react';
|
|
4
4
|
import { TextInput, useFocusWithin } from '@gravity-ui/uikit';
|
|
5
5
|
import { block } from '../../utils/cn';
|
|
@@ -17,5 +17,7 @@ export function DateField(_a) {
|
|
|
17
17
|
setActive(isFocusWithin);
|
|
18
18
|
},
|
|
19
19
|
});
|
|
20
|
-
return (
|
|
20
|
+
return (_jsxs("div", Object.assign({ className: b(null, className), style: props.style }, focusWithinProps, { children: [_jsx(TextInput, Object.assign({}, inputProps, { value: state.isEmpty && !isActive && props.placeholder ? '' : inputProps.value })), _jsx("input", { type: "text", hidden: true, name: props.name, value: state.value ? state.value.toISOString() : '',
|
|
21
|
+
// Ignore React warning
|
|
22
|
+
onChange: () => { } })] })));
|
|
21
23
|
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { DateTime } from '@gravity-ui/date-utils';
|
|
2
|
+
import type { ValidationState } from '../../types';
|
|
3
|
+
import type { DateFieldSection } from '../types';
|
|
4
|
+
export type BaseDateFieldStateOptions<T = DateTime> = {
|
|
5
|
+
value: T | null;
|
|
6
|
+
displayValue: T;
|
|
7
|
+
placeholderValue?: DateTime;
|
|
8
|
+
timeZone: string;
|
|
9
|
+
validationState?: ValidationState;
|
|
10
|
+
editableSections: DateFieldSection[];
|
|
11
|
+
readOnly?: boolean;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
selectedSectionIndexes: {
|
|
14
|
+
startIndex: number;
|
|
15
|
+
endIndex: number;
|
|
16
|
+
} | null;
|
|
17
|
+
selectedSections: number | 'all';
|
|
18
|
+
isEmpty: boolean;
|
|
19
|
+
flushAllValidSections: () => void;
|
|
20
|
+
flushValidSection: (sectionIndex: number) => void;
|
|
21
|
+
setSelectedSections: (position: number | 'all') => void;
|
|
22
|
+
setValue: (value: T) => void;
|
|
23
|
+
setDate: (value: T | null) => void;
|
|
24
|
+
adjustSection: (sectionIndex: number, amount: number) => void;
|
|
25
|
+
setSection: (sectionIndex: number, amount: number) => void;
|
|
26
|
+
getSectionValue: (sectionIndex: number) => DateTime;
|
|
27
|
+
setSectionValue: (sectionIndex: number, currentValue: DateTime) => void;
|
|
28
|
+
createPlaceholder: () => T;
|
|
29
|
+
setValueFromString: (str: string) => boolean;
|
|
30
|
+
};
|
|
31
|
+
export type BaseDateFieldState<T = DateTime> = {
|
|
32
|
+
/** The current field value. */
|
|
33
|
+
value: T | null;
|
|
34
|
+
/** Is no part of value is filled. */
|
|
35
|
+
isEmpty: boolean;
|
|
36
|
+
/** The current used value. value or placeholderValue */
|
|
37
|
+
displayValue: T;
|
|
38
|
+
/** Sets the field's value. */
|
|
39
|
+
setValue: (value: T) => void;
|
|
40
|
+
/** Formatted value */
|
|
41
|
+
text: string;
|
|
42
|
+
/** Whether the field is read only. */
|
|
43
|
+
readOnly?: boolean;
|
|
44
|
+
/** Whether the field is disabled. */
|
|
45
|
+
disabled?: boolean;
|
|
46
|
+
/** A list of segments for the current value. */
|
|
47
|
+
sections: DateFieldSection[];
|
|
48
|
+
/** Whether the the format is containing date parts */
|
|
49
|
+
hasDate: boolean;
|
|
50
|
+
/** Whether the the format is containing time parts */
|
|
51
|
+
hasTime: boolean;
|
|
52
|
+
/** Selected sections */
|
|
53
|
+
selectedSectionIndexes: {
|
|
54
|
+
startIndex: number;
|
|
55
|
+
endIndex: number;
|
|
56
|
+
} | null;
|
|
57
|
+
/** The current validation state of the date field, based on the `validationState`, `minValue`, and `maxValue` props. */
|
|
58
|
+
validationState?: ValidationState;
|
|
59
|
+
/** Sets selection for segment in position. */
|
|
60
|
+
setSelectedSections: (position: number | 'all') => void;
|
|
61
|
+
/** Focuses segment in position */
|
|
62
|
+
focusSectionInPosition: (position: number) => void;
|
|
63
|
+
/** Focuses the next segment if present */
|
|
64
|
+
focusNextSection: () => void;
|
|
65
|
+
/** Focuses the previous segment if present */
|
|
66
|
+
focusPreviousSection: () => void;
|
|
67
|
+
/** Focuses the first segment */
|
|
68
|
+
focusFirstSection: () => void;
|
|
69
|
+
/** Focuses the last segment */
|
|
70
|
+
focusLastSection: () => void;
|
|
71
|
+
/** Increments the currently selected segment. Upon reaching the minimum or maximum value, the value wraps around to the opposite limit. */
|
|
72
|
+
increment: () => void;
|
|
73
|
+
/** Decrements the currently selected segment. Upon reaching the minimum or maximum value, the value wraps around to the opposite limit. */
|
|
74
|
+
decrement: () => void;
|
|
75
|
+
/**
|
|
76
|
+
* Increments the currently selected segment by a larger amount, rounding it to the nearest increment.
|
|
77
|
+
* The amount to increment by depends on the field, for example 15 minutes, 7 days, and 5 years.
|
|
78
|
+
* Upon reaching the minimum or maximum value, the value wraps around to the opposite limit.
|
|
79
|
+
*/
|
|
80
|
+
incrementPage: () => void;
|
|
81
|
+
/**
|
|
82
|
+
* Decrements the currently selected segment by a larger amount, rounding it to the nearest decrement.
|
|
83
|
+
* The amount to increment by depends on the field, for example 15 minutes, 7 days, and 5 years.
|
|
84
|
+
* Upon reaching the minimum or maximum value, the value wraps around to the opposite limit.
|
|
85
|
+
*/
|
|
86
|
+
decrementPage: () => void;
|
|
87
|
+
incrementToMax: () => void;
|
|
88
|
+
decrementToMin: () => void;
|
|
89
|
+
/** Clears the value of the currently selected segment, reverting it to the placeholder. */
|
|
90
|
+
clearSection: () => void;
|
|
91
|
+
/** Clears all segments, reverting them to the placeholder. */
|
|
92
|
+
clearAll: () => void;
|
|
93
|
+
/** Handles input key in the currently selected segment */
|
|
94
|
+
onInput: (key: string) => void;
|
|
95
|
+
setValueFromString: (str: string) => boolean;
|
|
96
|
+
};
|
|
97
|
+
export declare function useBaseDateFieldState<T = DateTime>(props: BaseDateFieldStateOptions<T>): BaseDateFieldState<T>;
|