@wordpress/components 29.12.0 → 30.0.0
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/CHANGELOG.md +23 -0
- package/build/autocomplete/index.js +4 -0
- package/build/autocomplete/index.js.map +1 -1
- package/build/box-control/input-control.js +2 -2
- package/build/box-control/input-control.js.map +1 -1
- package/build/calendar/date-calendar/index.js +69 -0
- package/build/calendar/date-calendar/index.js.map +1 -0
- package/build/calendar/date-range-calendar/index.js +172 -0
- package/build/calendar/date-range-calendar/index.js.map +1 -0
- package/build/calendar/index.js +27 -0
- package/build/calendar/index.js.map +1 -0
- package/build/calendar/types.js +6 -0
- package/build/calendar/types.js.map +1 -0
- package/build/calendar/utils/constants.js +68 -0
- package/build/calendar/utils/constants.js.map +1 -0
- package/build/calendar/utils/day-cell.js +137 -0
- package/build/calendar/utils/day-cell.js.map +1 -0
- package/build/calendar/utils/misc.js +10 -0
- package/build/calendar/utils/misc.js.map +1 -0
- package/build/calendar/utils/use-localization-props.js +162 -0
- package/build/calendar/utils/use-localization-props.js.map +1 -0
- package/build/custom-gradient-picker/gradient-bar/control-points.js +1 -1
- package/build/custom-gradient-picker/gradient-bar/control-points.js.map +1 -1
- package/build/custom-select-control-v2/custom-select.js +3 -3
- package/build/custom-select-control-v2/custom-select.js.map +1 -1
- package/build/date-time/date/index.js +1 -1
- package/build/date-time/date/index.js.map +1 -1
- package/build/form-token-field/index.js +11 -1
- package/build/form-token-field/index.js.map +1 -1
- package/build/form-token-field/token.js +1 -1
- package/build/form-token-field/token.js.map +1 -1
- package/build/icon/index.js +2 -0
- package/build/icon/index.js.map +1 -1
- package/build/mobile/bottom-sheet/cell.native.js +2 -2
- package/build/mobile/bottom-sheet/cell.native.js.map +1 -1
- package/build/mobile/link-picker/index.native.js +1 -1
- package/build/mobile/link-picker/index.native.js.map +1 -1
- package/build/navigation/menu/menu-title-search.js +1 -1
- package/build/navigation/menu/menu-title-search.js.map +1 -1
- package/build/palette-edit/index.js +4 -4
- package/build/palette-edit/index.js.map +1 -1
- package/build/private-apis.js +5 -1
- package/build/private-apis.js.map +1 -1
- package/build/select-control/index.js +1 -1
- package/build/select-control/index.js.map +1 -1
- package/build/toggle-group-control/toggle-group-control/as-button-group.js.map +1 -1
- package/build/utils/hooks/use-controlled-value.js +8 -4
- package/build/utils/hooks/use-controlled-value.js.map +1 -1
- package/build/validated-form-controls/components/checkbox-control.js +52 -0
- package/build/validated-form-controls/components/checkbox-control.js.map +1 -0
- package/build/validated-form-controls/components/combobox-control.js +64 -0
- package/build/validated-form-controls/components/combobox-control.js.map +1 -0
- package/build/validated-form-controls/components/custom-select-control.js +71 -0
- package/build/validated-form-controls/components/custom-select-control.js.map +1 -0
- package/build/validated-form-controls/components/index.js +138 -0
- package/build/validated-form-controls/components/index.js.map +1 -0
- package/build/validated-form-controls/components/input-control.js +50 -0
- package/build/validated-form-controls/components/input-control.js.map +1 -0
- package/build/validated-form-controls/components/number-control.js +53 -0
- package/build/validated-form-controls/components/number-control.js.map +1 -0
- package/build/validated-form-controls/components/radio-control.js +51 -0
- package/build/validated-form-controls/components/radio-control.js.map +1 -0
- package/build/validated-form-controls/components/range-control.js +51 -0
- package/build/validated-form-controls/components/range-control.js.map +1 -0
- package/build/validated-form-controls/components/select-control.js +53 -0
- package/build/validated-form-controls/components/select-control.js.map +1 -0
- package/build/validated-form-controls/components/text-control.js +51 -0
- package/build/validated-form-controls/components/text-control.js.map +1 -0
- package/build/validated-form-controls/components/textarea-control.js +50 -0
- package/build/validated-form-controls/components/textarea-control.js.map +1 -0
- package/build/validated-form-controls/components/toggle-control.js +60 -0
- package/build/validated-form-controls/components/toggle-control.js.map +1 -0
- package/build/validated-form-controls/components/toggle-group-control.js +69 -0
- package/build/validated-form-controls/components/toggle-group-control.js.map +1 -0
- package/build/validated-form-controls/components/types.js +6 -0
- package/build/validated-form-controls/components/types.js.map +1 -0
- package/build/validated-form-controls/control-with-error.js +137 -0
- package/build/validated-form-controls/control-with-error.js.map +1 -0
- package/build/validated-form-controls/index.js +28 -0
- package/build/validated-form-controls/index.js.map +1 -0
- package/build-module/autocomplete/index.js +4 -0
- package/build-module/autocomplete/index.js.map +1 -1
- package/build-module/box-control/input-control.js +2 -2
- package/build-module/box-control/input-control.js.map +1 -1
- package/build-module/calendar/date-calendar/index.js +59 -0
- package/build-module/calendar/date-calendar/index.js.map +1 -0
- package/build-module/calendar/date-range-calendar/index.js +161 -0
- package/build-module/calendar/date-range-calendar/index.js.map +1 -0
- package/build-module/calendar/index.js +4 -0
- package/build-module/calendar/index.js.map +1 -0
- package/build-module/calendar/types.js +2 -0
- package/build-module/calendar/types.js.map +1 -0
- package/build-module/calendar/utils/constants.js +61 -0
- package/build-module/calendar/utils/constants.js.map +1 -0
- package/build-module/calendar/utils/day-cell.js +131 -0
- package/build-module/calendar/utils/day-cell.js.map +1 -0
- package/build-module/calendar/utils/misc.js +4 -0
- package/build-module/calendar/utils/misc.js.map +1 -0
- package/build-module/calendar/utils/use-localization-props.js +154 -0
- package/build-module/calendar/utils/use-localization-props.js.map +1 -0
- package/build-module/custom-gradient-picker/gradient-bar/control-points.js +1 -1
- package/build-module/custom-gradient-picker/gradient-bar/control-points.js.map +1 -1
- package/build-module/custom-select-control-v2/custom-select.js +4 -4
- package/build-module/custom-select-control-v2/custom-select.js.map +1 -1
- package/build-module/date-time/date/index.js +1 -1
- package/build-module/date-time/date/index.js.map +1 -1
- package/build-module/form-token-field/index.js +11 -1
- package/build-module/form-token-field/index.js.map +1 -1
- package/build-module/form-token-field/token.js +1 -1
- package/build-module/form-token-field/token.js.map +1 -1
- package/build-module/icon/index.js +2 -0
- package/build-module/icon/index.js.map +1 -1
- package/build-module/mobile/bottom-sheet/cell.native.js +2 -2
- package/build-module/mobile/bottom-sheet/cell.native.js.map +1 -1
- package/build-module/mobile/link-picker/index.native.js +1 -1
- package/build-module/mobile/link-picker/index.native.js.map +1 -1
- package/build-module/navigation/menu/menu-title-search.js +1 -1
- package/build-module/navigation/menu/menu-title-search.js.map +1 -1
- package/build-module/palette-edit/index.js +4 -4
- package/build-module/palette-edit/index.js.map +1 -1
- package/build-module/private-apis.js +5 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/select-control/index.js +1 -1
- package/build-module/select-control/index.js.map +1 -1
- package/build-module/toggle-group-control/toggle-group-control/as-button-group.js.map +1 -1
- package/build-module/utils/hooks/use-controlled-value.js +9 -5
- package/build-module/utils/hooks/use-controlled-value.js.map +1 -1
- package/build-module/validated-form-controls/components/checkbox-control.js +44 -0
- package/build-module/validated-form-controls/components/checkbox-control.js.map +1 -0
- package/build-module/validated-form-controls/components/combobox-control.js +56 -0
- package/build-module/validated-form-controls/components/combobox-control.js.map +1 -0
- package/build-module/validated-form-controls/components/custom-select-control.js +63 -0
- package/build-module/validated-form-controls/components/custom-select-control.js.map +1 -0
- package/build-module/validated-form-controls/components/index.js +13 -0
- package/build-module/validated-form-controls/components/index.js.map +1 -0
- package/build-module/validated-form-controls/components/input-control.js +42 -0
- package/build-module/validated-form-controls/components/input-control.js.map +1 -0
- package/build-module/validated-form-controls/components/number-control.js +45 -0
- package/build-module/validated-form-controls/components/number-control.js.map +1 -0
- package/build-module/validated-form-controls/components/radio-control.js +43 -0
- package/build-module/validated-form-controls/components/radio-control.js.map +1 -0
- package/build-module/validated-form-controls/components/range-control.js +43 -0
- package/build-module/validated-form-controls/components/range-control.js.map +1 -0
- package/build-module/validated-form-controls/components/select-control.js +45 -0
- package/build-module/validated-form-controls/components/select-control.js.map +1 -0
- package/build-module/validated-form-controls/components/text-control.js +43 -0
- package/build-module/validated-form-controls/components/text-control.js.map +1 -0
- package/build-module/validated-form-controls/components/textarea-control.js +42 -0
- package/build-module/validated-form-controls/components/textarea-control.js.map +1 -0
- package/build-module/validated-form-controls/components/toggle-control.js +52 -0
- package/build-module/validated-form-controls/components/toggle-control.js.map +1 -0
- package/build-module/validated-form-controls/components/toggle-group-control.js +62 -0
- package/build-module/validated-form-controls/components/toggle-group-control.js.map +1 -0
- package/build-module/validated-form-controls/components/types.js +2 -0
- package/build-module/validated-form-controls/components/types.js.map +1 -0
- package/build-module/validated-form-controls/control-with-error.js +129 -0
- package/build-module/validated-form-controls/control-with-error.js.map +1 -0
- package/build-module/validated-form-controls/index.js +3 -0
- package/build-module/validated-form-controls/index.js.map +1 -0
- package/build-style/style-rtl.css +418 -22
- package/build-style/style.css +418 -22
- package/build-types/autocomplete/index.d.ts.map +1 -1
- package/build-types/box-control/input-control.d.ts.map +1 -1
- package/build-types/box-control/utils.d.ts +7 -7
- package/build-types/calendar/date-calendar/index.d.ts +11 -0
- package/build-types/calendar/date-calendar/index.d.ts.map +1 -0
- package/build-types/calendar/date-range-calendar/index.d.ts +14 -0
- package/build-types/calendar/date-range-calendar/index.d.ts.map +1 -0
- package/build-types/calendar/index.d.ts +4 -0
- package/build-types/calendar/index.d.ts.map +1 -0
- package/build-types/calendar/stories/date-calendar.story.d.ts +16 -0
- package/build-types/calendar/stories/date-calendar.story.d.ts.map +1 -0
- package/build-types/calendar/stories/date-range-calendar.story.d.ts +16 -0
- package/build-types/calendar/stories/date-range-calendar.story.d.ts.map +1 -0
- package/build-types/calendar/test/__utils__/index.d.ts +10 -0
- package/build-types/calendar/test/__utils__/index.d.ts.map +1 -0
- package/build-types/calendar/test/date-calendar.d.ts +2 -0
- package/build-types/calendar/test/date-calendar.d.ts.map +1 -0
- package/build-types/calendar/test/date-range-calendar.d.ts +2 -0
- package/build-types/calendar/test/date-range-calendar.d.ts.map +1 -0
- package/build-types/calendar/types.d.ts +317 -0
- package/build-types/calendar/types.d.ts.map +1 -0
- package/build-types/calendar/utils/constants.d.ts +52 -0
- package/build-types/calendar/utils/constants.d.ts.map +1 -0
- package/build-types/calendar/utils/day-cell.d.ts +21 -0
- package/build-types/calendar/utils/day-cell.d.ts.map +1 -0
- package/build-types/calendar/utils/misc.d.ts +2 -0
- package/build-types/calendar/utils/misc.d.ts.map +1 -0
- package/build-types/calendar/utils/use-localization-props.d.ts +64 -0
- package/build-types/calendar/utils/use-localization-props.d.ts.map +1 -0
- package/build-types/color-picker/styles.d.ts.map +1 -1
- package/build-types/custom-gradient-picker/constants.d.ts +6 -3
- package/build-types/custom-gradient-picker/constants.d.ts.map +1 -1
- package/build-types/custom-select-control-v2/custom-select.d.ts.map +1 -1
- package/build-types/dimension-control/sizes.d.ts +15 -3
- package/build-types/dimension-control/sizes.d.ts.map +1 -1
- package/build-types/font-size-picker/constants.d.ts +2 -2
- package/build-types/font-size-picker/constants.d.ts.map +1 -1
- package/build-types/form-token-field/index.d.ts.map +1 -1
- package/build-types/icon/index.d.ts.map +1 -1
- package/build-types/popover/overlay-middlewares.d.ts +6 -1
- package/build-types/popover/overlay-middlewares.d.ts.map +1 -1
- package/build-types/private-apis.d.ts.map +1 -1
- package/build-types/select-control/stories/index.story.d.ts.map +1 -1
- package/build-types/toggle-group-control/toggle-group-control/as-button-group.d.ts.map +1 -1
- package/build-types/utils/hooks/use-controlled-value.d.ts +2 -2
- package/build-types/utils/hooks/use-controlled-value.d.ts.map +1 -1
- package/build-types/validated-form-controls/components/checkbox-control.d.ts +9 -0
- package/build-types/validated-form-controls/components/checkbox-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/combobox-control.d.ts +21 -0
- package/build-types/validated-form-controls/components/combobox-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/custom-select-control.d.ts +4 -0
- package/build-types/validated-form-controls/components/custom-select-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/index.d.ts +13 -0
- package/build-types/validated-form-controls/components/index.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/input-control.d.ts +4 -0
- package/build-types/validated-form-controls/components/input-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/number-control.d.ts +17 -0
- package/build-types/validated-form-controls/components/number-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/radio-control.d.ts +11 -0
- package/build-types/validated-form-controls/components/radio-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/range-control.d.ts +36 -0
- package/build-types/validated-form-controls/components/range-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/select-control.d.ts +9 -0
- package/build-types/validated-form-controls/components/select-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/stories/checkbox-control.story.d.ts +12 -0
- package/build-types/validated-form-controls/components/stories/checkbox-control.story.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/stories/combobox-control.story.d.ts +12 -0
- package/build-types/validated-form-controls/components/stories/combobox-control.story.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/stories/custom-select-control.story.d.ts +12 -0
- package/build-types/validated-form-controls/components/stories/custom-select-control.story.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/stories/input-control.story.d.ts +18 -0
- package/build-types/validated-form-controls/components/stories/input-control.story.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/stories/number-control.story.d.ts +12 -0
- package/build-types/validated-form-controls/components/stories/number-control.story.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/stories/overview.story.d.ts +19 -0
- package/build-types/validated-form-controls/components/stories/overview.story.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/stories/radio-control.story.d.ts +12 -0
- package/build-types/validated-form-controls/components/stories/radio-control.story.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/stories/range-control.story.d.ts +9 -0
- package/build-types/validated-form-controls/components/stories/range-control.story.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/stories/select-control.story.d.ts +12 -0
- package/build-types/validated-form-controls/components/stories/select-control.story.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/stories/story-utils.d.ts +9 -0
- package/build-types/validated-form-controls/components/stories/story-utils.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/stories/text-control.story.d.ts +9 -0
- package/build-types/validated-form-controls/components/stories/text-control.story.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/stories/textarea-control.story.d.ts +9 -0
- package/build-types/validated-form-controls/components/stories/textarea-control.story.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/stories/toggle-control.story.d.ts +9 -0
- package/build-types/validated-form-controls/components/stories/toggle-control.story.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/stories/toggle-group-control.story.d.ts +9 -0
- package/build-types/validated-form-controls/components/stories/toggle-group-control.story.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/text-control.d.ts +8 -0
- package/build-types/validated-form-controls/components/text-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/textarea-control.d.ts +7 -0
- package/build-types/validated-form-controls/components/textarea-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/toggle-control.d.ts +7 -0
- package/build-types/validated-form-controls/components/toggle-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/toggle-group-control.d.ts +15 -0
- package/build-types/validated-form-controls/components/toggle-group-control.d.ts.map +1 -0
- package/build-types/validated-form-controls/components/types.d.ts +27 -0
- package/build-types/validated-form-controls/components/types.d.ts.map +1 -0
- package/build-types/validated-form-controls/control-with-error.d.ts +36 -0
- package/build-types/validated-form-controls/control-with-error.d.ts.map +1 -0
- package/build-types/validated-form-controls/index.d.ts +3 -0
- package/build-types/validated-form-controls/index.d.ts.map +1 -0
- package/package.json +21 -20
- package/src/autocomplete/index.tsx +4 -0
- package/src/box-control/input-control.tsx +14 -5
- package/src/calendar/date-calendar/README.md +261 -0
- package/src/calendar/date-calendar/index.tsx +69 -0
- package/src/calendar/date-range-calendar/README.md +298 -0
- package/src/calendar/date-range-calendar/index.tsx +215 -0
- package/src/calendar/index.tsx +3 -0
- package/src/calendar/stories/date-calendar.story.tsx +221 -0
- package/src/calendar/stories/date-range-calendar.story.tsx +230 -0
- package/src/calendar/style.scss +431 -0
- package/src/calendar/test/__utils__/index.ts +56 -0
- package/src/calendar/test/date-calendar.tsx +975 -0
- package/src/calendar/test/date-range-calendar.tsx +1701 -0
- package/src/calendar/types.ts +342 -0
- package/src/calendar/utils/constants.ts +62 -0
- package/src/calendar/utils/day-cell.tsx +133 -0
- package/src/calendar/utils/misc.ts +3 -0
- package/src/calendar/utils/use-localization-props.ts +169 -0
- package/src/custom-gradient-picker/gradient-bar/control-points.tsx +1 -1
- package/src/custom-select-control-v2/custom-select.tsx +6 -3
- package/src/date-time/date/index.tsx +1 -1
- package/src/dimension-control/test/__snapshots__/index.test.js.snap +8 -8
- package/src/form-token-field/index.tsx +12 -1
- package/src/form-token-field/token.tsx +1 -1
- package/src/icon/index.tsx +2 -0
- package/src/mobile/bottom-sheet/cell.native.js +2 -2
- package/src/mobile/link-picker/index.native.js +1 -1
- package/src/navigation/menu/menu-title-search.tsx +1 -1
- package/src/palette-edit/index.tsx +4 -4
- package/src/private-apis.ts +5 -0
- package/src/select-control/index.tsx +1 -1
- package/src/select-control/style.scss +0 -6
- package/src/style.scss +3 -2
- package/src/toggle-group-control/toggle-group-control/as-button-group.tsx +3 -1
- package/src/utils/hooks/use-controlled-value.ts +16 -8
- package/src/validated-form-controls/components/checkbox-control.tsx +64 -0
- package/src/validated-form-controls/components/combobox-control.tsx +77 -0
- package/src/validated-form-controls/components/custom-select-control.tsx +86 -0
- package/src/validated-form-controls/components/index.ts +12 -0
- package/src/validated-form-controls/components/input-control.tsx +59 -0
- package/src/validated-form-controls/components/number-control.tsx +61 -0
- package/src/validated-form-controls/components/radio-control.tsx +60 -0
- package/src/validated-form-controls/components/range-control.tsx +60 -0
- package/src/validated-form-controls/components/select-control.tsx +75 -0
- package/src/validated-form-controls/components/stories/checkbox-control.story.tsx +57 -0
- package/src/validated-form-controls/components/stories/combobox-control.story.tsx +64 -0
- package/src/validated-form-controls/components/stories/custom-select-control.story.tsx +64 -0
- package/src/validated-form-controls/components/stories/input-control.story.tsx +132 -0
- package/src/validated-form-controls/components/stories/number-control.story.tsx +62 -0
- package/src/validated-form-controls/components/stories/overview.mdx +52 -0
- package/src/validated-form-controls/components/stories/overview.story.tsx +100 -0
- package/src/validated-form-controls/components/stories/radio-control.story.tsx +64 -0
- package/src/validated-form-controls/components/stories/range-control.story.tsx +60 -0
- package/src/validated-form-controls/components/stories/select-control.story.tsx +60 -0
- package/src/validated-form-controls/components/stories/story-utils.tsx +46 -0
- package/src/validated-form-controls/components/stories/text-control.story.tsx +55 -0
- package/src/validated-form-controls/components/stories/textarea-control.story.tsx +52 -0
- package/src/validated-form-controls/components/stories/toggle-control.story.tsx +55 -0
- package/src/validated-form-controls/components/stories/toggle-group-control.story.tsx +66 -0
- package/src/validated-form-controls/components/text-control.tsx +60 -0
- package/src/validated-form-controls/components/textarea-control.tsx +59 -0
- package/src/validated-form-controls/components/toggle-control.tsx +69 -0
- package/src/validated-form-controls/components/toggle-group-control.tsx +82 -0
- package/src/validated-form-controls/components/types.ts +28 -0
- package/src/validated-form-controls/control-with-error.tsx +198 -0
- package/src/validated-form-controls/index.ts +2 -0
- package/src/validated-form-controls/style.scss +75 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/src/dimension-control/style.scss +0 -22
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
# `DateRangeCalendar`
|
|
2
|
+
|
|
3
|
+
🔒 This component is locked as a [private API](https://developer.wordpress.org/block-editor/reference-guides/packages/packages-private-apis/). We do not yet recommend using this outside of the Gutenberg project.
|
|
4
|
+
|
|
5
|
+
`DateRangeCalendar` is a React component that provides a customizable calendar interface for **date range** selection.
|
|
6
|
+
|
|
7
|
+
The component is built with accessibility in mind and follows ARIA best practices for calendar widgets. It provides keyboard navigation, screen reader support, and customizable labels for internationalization.
|
|
8
|
+
|
|
9
|
+
## Usage example
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import { DateRangeCalendar } from '@wordpress/components';
|
|
13
|
+
|
|
14
|
+
type DateRange = {
|
|
15
|
+
from: Date | undefined;
|
|
16
|
+
to?: Date | undefined;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
function MyComponent() {
|
|
20
|
+
const [ selected, setSelected ] = useState< DateRange >( {
|
|
21
|
+
from: new Date( date.getFullYear(), date.getMonth(), 1 ),
|
|
22
|
+
to: new Date(),
|
|
23
|
+
} );
|
|
24
|
+
|
|
25
|
+
return <DateRangeCalendar selected={ selected } onSelect={ setSelected } />;
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Props
|
|
30
|
+
|
|
31
|
+
These props are shared between both single date and date range calendar modes.
|
|
32
|
+
|
|
33
|
+
### `required`
|
|
34
|
+
|
|
35
|
+
- Type: `boolean`
|
|
36
|
+
- Required: No
|
|
37
|
+
- Default: `false`
|
|
38
|
+
|
|
39
|
+
Whether the selection is required. When `true`, there always needs to be a date selected.
|
|
40
|
+
|
|
41
|
+
### `selected`
|
|
42
|
+
|
|
43
|
+
- Type: `DateRange | undefined | null`
|
|
44
|
+
- Required: No
|
|
45
|
+
|
|
46
|
+
The selected date range. A `DateRange` object has the following shape:
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
{
|
|
50
|
+
from: Date | undefined;
|
|
51
|
+
to?: Date | undefined;
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### `onSelect`
|
|
56
|
+
|
|
57
|
+
- Type: `(selected: DateRange | undefined, triggerDate: Date, modifiers: Modifiers, e: React.MouseEvent | React.KeyboardEvent) => void`
|
|
58
|
+
- Required: No
|
|
59
|
+
|
|
60
|
+
Event handler when the selection changes. The `selected` parameter will contain the new date range.
|
|
61
|
+
|
|
62
|
+
### `defaultSelected`
|
|
63
|
+
|
|
64
|
+
- Type: `DateRange`
|
|
65
|
+
- Required: No
|
|
66
|
+
|
|
67
|
+
The default selected range (for uncontrolled usage).
|
|
68
|
+
|
|
69
|
+
### `excludeDisabled`
|
|
70
|
+
|
|
71
|
+
- Type: `boolean`
|
|
72
|
+
- Required: No
|
|
73
|
+
|
|
74
|
+
When `true`, the range will reset when including a disabled day. This is useful to prevent users from selecting ranges that include unavailable dates.
|
|
75
|
+
|
|
76
|
+
### `min`
|
|
77
|
+
|
|
78
|
+
- Type: `number`
|
|
79
|
+
- Required: No
|
|
80
|
+
|
|
81
|
+
The minimum number of days to include in the range. If a user tries to select a range shorter than this, the selection will be adjusted to meet the minimum requirement.
|
|
82
|
+
|
|
83
|
+
### `max`
|
|
84
|
+
|
|
85
|
+
- Type: `number`
|
|
86
|
+
- Required: No
|
|
87
|
+
|
|
88
|
+
The maximum number of days to include in the range. If a user tries to select a range longer than this, the selection will be adjusted to meet the maximum requirement.
|
|
89
|
+
|
|
90
|
+
### `defaultMonth`
|
|
91
|
+
|
|
92
|
+
- Type: `Date`
|
|
93
|
+
- Required: No
|
|
94
|
+
- Default: Current month
|
|
95
|
+
|
|
96
|
+
The initial month to show in the calendar view (uncontrolled).
|
|
97
|
+
|
|
98
|
+
### `month`
|
|
99
|
+
|
|
100
|
+
- Type: `Date`
|
|
101
|
+
- Required: No
|
|
102
|
+
|
|
103
|
+
The month displayed in the calendar view (controlled). Use together with `onMonthChange` to change the month programmatically.
|
|
104
|
+
|
|
105
|
+
### `numberOfMonths`
|
|
106
|
+
|
|
107
|
+
- Type: `number`
|
|
108
|
+
- Required: No
|
|
109
|
+
- Default: `1`
|
|
110
|
+
|
|
111
|
+
The number of months displayed at once.
|
|
112
|
+
|
|
113
|
+
### `startMonth`
|
|
114
|
+
|
|
115
|
+
- Type: `Date`
|
|
116
|
+
- Required: No
|
|
117
|
+
|
|
118
|
+
The earliest month to start the month navigation.
|
|
119
|
+
|
|
120
|
+
### `endMonth`
|
|
121
|
+
|
|
122
|
+
- Type: `Date`
|
|
123
|
+
- Required: No
|
|
124
|
+
|
|
125
|
+
The latest month to end the month navigation.
|
|
126
|
+
|
|
127
|
+
### `autoFocus`
|
|
128
|
+
|
|
129
|
+
- Type: `boolean`
|
|
130
|
+
- Required: No
|
|
131
|
+
|
|
132
|
+
Focus the first selected day (if set) or today's date (if not disabled). Use this prop when you need to focus the calendar after a user action (e.g. opening the dialog with the calendar).
|
|
133
|
+
|
|
134
|
+
### `disabled`
|
|
135
|
+
|
|
136
|
+
- Type: `Matcher | Matcher[] | undefined`
|
|
137
|
+
- Required: No
|
|
138
|
+
|
|
139
|
+
Specify which days are disabled. Using `true` will disable all dates. See the [Matcher Types](#matcher-types) section for more details.
|
|
140
|
+
|
|
141
|
+
### `disableNavigation`
|
|
142
|
+
|
|
143
|
+
- Type: `boolean`
|
|
144
|
+
- Required: No
|
|
145
|
+
|
|
146
|
+
Disable the navigation buttons.
|
|
147
|
+
|
|
148
|
+
### `labels`
|
|
149
|
+
|
|
150
|
+
- Type: `object`
|
|
151
|
+
- Required: No
|
|
152
|
+
|
|
153
|
+
Use custom labels for internationalization. All labels are optional and have sensible defaults:
|
|
154
|
+
|
|
155
|
+
```typescript
|
|
156
|
+
{
|
|
157
|
+
labelNav?: () => string; // Navigation toolbar label
|
|
158
|
+
labelGrid?: (date: Date) => string; // Month grid label (default: "LLLL y")
|
|
159
|
+
labelGridcell?: (date: Date, modifiers?: Modifiers) => string; // Grid cell label
|
|
160
|
+
labelNext?: (month: Date | undefined) => string; // Next month button label
|
|
161
|
+
labelPrevious?: (month: Date | undefined) => string; // Previous month button label
|
|
162
|
+
labelDayButton?: (date: Date, modifiers?: Modifiers) => string; // Day button label
|
|
163
|
+
labelWeekday?: (date: Date) => string; // Weekday label
|
|
164
|
+
}
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
**Important: For a correct localized experience, consumers should make sure the locale used for the translated labels and `locale` prop are consistent.**
|
|
168
|
+
|
|
169
|
+
### `locale`
|
|
170
|
+
|
|
171
|
+
- Type: `Locale`
|
|
172
|
+
- Required: No
|
|
173
|
+
- Default: `enUS` from `@date-fns/locale`
|
|
174
|
+
|
|
175
|
+
The locale object used to localize dates. Pass a locale from `@date-fns/locale` to localize the calendar.
|
|
176
|
+
|
|
177
|
+
**Important: For a correct localized experience, consumers should make sure the locale used for the translated labels and `locale` prop are consistent.**
|
|
178
|
+
|
|
179
|
+
### `weekStartsOn`
|
|
180
|
+
|
|
181
|
+
- Type: `0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined`
|
|
182
|
+
- Required: No
|
|
183
|
+
- Default: Based on the `locale` prop
|
|
184
|
+
|
|
185
|
+
The index of the first day of the week (0 - Sunday). Overrides the locale's setting.
|
|
186
|
+
|
|
187
|
+
### `onMonthChange`
|
|
188
|
+
|
|
189
|
+
- Type: `(month: Date) => void`
|
|
190
|
+
- Required: No
|
|
191
|
+
|
|
192
|
+
Event fired when the user navigates between months.
|
|
193
|
+
|
|
194
|
+
### `timeZone`
|
|
195
|
+
|
|
196
|
+
- Type: `string`
|
|
197
|
+
- Required: No
|
|
198
|
+
|
|
199
|
+
The time zone (IANA or UTC offset) to use in the calendar. See [Wikipedia](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones) for possible values.
|
|
200
|
+
|
|
201
|
+
When working with time zones, use the `TZDate` object exported by this package instead of the native `Date` object.
|
|
202
|
+
|
|
203
|
+
```tsx
|
|
204
|
+
import { DateRangeCalendar, TZDate } from '@wordpress/components';
|
|
205
|
+
|
|
206
|
+
export function WithTimeZone() {
|
|
207
|
+
const timeZone = 'America/New_York';
|
|
208
|
+
const [ selected, setSelected ] = useState< Date | undefined >( {
|
|
209
|
+
from: new TZDate( 2024, 12, 10, timeZone ), // Use `TZDate` instead of `Date`
|
|
210
|
+
to: new TZDate( 2024, 12, 8, timeZone ), // Use `TZDate` instead of `Date`
|
|
211
|
+
} );
|
|
212
|
+
return (
|
|
213
|
+
<DateRangeCalendar
|
|
214
|
+
timeZone={ timeZone }
|
|
215
|
+
selected={ selected }
|
|
216
|
+
onSelect={ setSelected }
|
|
217
|
+
/>
|
|
218
|
+
);
|
|
219
|
+
}
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### `role`
|
|
223
|
+
|
|
224
|
+
- Type: `'application' | 'dialog' | undefined`
|
|
225
|
+
- Required: No
|
|
226
|
+
- Default: `'application'`
|
|
227
|
+
|
|
228
|
+
The role attribute to add to the container element.
|
|
229
|
+
|
|
230
|
+
## Matcher Types
|
|
231
|
+
|
|
232
|
+
The calendar component uses a flexible matching system to determine which days should be disabled or have specific modifiers. Here are the available matcher types:
|
|
233
|
+
|
|
234
|
+
### Boolean Matcher
|
|
235
|
+
|
|
236
|
+
```typescript
|
|
237
|
+
const booleanMatcher: Matcher = true; // Will always match the day
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
### Date Matcher
|
|
241
|
+
|
|
242
|
+
```typescript
|
|
243
|
+
const dateMatcher: Matcher = new Date(); // Will match today's date
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
### Array Matcher
|
|
247
|
+
|
|
248
|
+
```typescript
|
|
249
|
+
const arrayMatcher: Matcher = [
|
|
250
|
+
new Date( 2019, 1, 2 ),
|
|
251
|
+
new Date( 2019, 1, 4 ),
|
|
252
|
+
]; // Will match the days in the array
|
|
253
|
+
```
|
|
254
|
+
|
|
255
|
+
### Date After Matcher
|
|
256
|
+
|
|
257
|
+
```typescript
|
|
258
|
+
const afterMatcher: DateAfter = { after: new Date( 2019, 1, 2 ) }; // Will match days after the 2nd of February 2019
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Date Before Matcher
|
|
262
|
+
|
|
263
|
+
```typescript
|
|
264
|
+
const beforeMatcher: DateBefore = { before: new Date( 2019, 1, 2 ) }; // Will match days before the 2nd of February 2019
|
|
265
|
+
```
|
|
266
|
+
|
|
267
|
+
### Date Interval Matcher
|
|
268
|
+
|
|
269
|
+
```typescript
|
|
270
|
+
const intervalMatcher: DateInterval = {
|
|
271
|
+
after: new Date( 2019, 1, 2 ),
|
|
272
|
+
before: new Date( 2019, 1, 5 ),
|
|
273
|
+
}; // Will match the days between the 2nd and the 5th of February 2019 (exclusive)
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### Date Range Matcher
|
|
277
|
+
|
|
278
|
+
```typescript
|
|
279
|
+
const rangeMatcher: DateRange = {
|
|
280
|
+
from: new Date( 2019, 1, 2 ),
|
|
281
|
+
to: new Date( 2019, 1, 5 ),
|
|
282
|
+
}; // Will match the days between the 2nd and the 5th of February 2019 (inclusive)
|
|
283
|
+
```
|
|
284
|
+
|
|
285
|
+
### Day of Week Matcher
|
|
286
|
+
|
|
287
|
+
```typescript
|
|
288
|
+
const dayOfWeekMatcher: DayOfWeek = { dayOfWeek: 0 }; // Will match Sundays
|
|
289
|
+
const weekendMatcher: DayOfWeek = { dayOfWeek: [ 0, 6 ] }; // Will match weekends
|
|
290
|
+
```
|
|
291
|
+
|
|
292
|
+
### Function Matcher
|
|
293
|
+
|
|
294
|
+
```typescript
|
|
295
|
+
const functionMatcher: Matcher = ( day: Date ) => {
|
|
296
|
+
return day.getMonth() === 2; // Will match when month is March
|
|
297
|
+
};
|
|
298
|
+
```
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { differenceInCalendarDays } from 'date-fns';
|
|
5
|
+
import { DayPicker, rangeContainsModifiers } from 'react-day-picker';
|
|
6
|
+
import { enUS } from 'react-day-picker/locale';
|
|
7
|
+
/**
|
|
8
|
+
* WordPress dependencies
|
|
9
|
+
*/
|
|
10
|
+
import { useMemo, useState, useCallback } from '@wordpress/element';
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
import { COMMON_PROPS, MODIFIER_CLASSNAMES } from '../utils/constants';
|
|
15
|
+
import { clampNumberOfMonths } from '../utils/misc';
|
|
16
|
+
import { useControlledValue } from '../../utils/hooks';
|
|
17
|
+
import { useLocalizationProps } from '../utils/use-localization-props';
|
|
18
|
+
import type {
|
|
19
|
+
DateRangeCalendarProps,
|
|
20
|
+
DateRange,
|
|
21
|
+
OnSelectHandler,
|
|
22
|
+
} from '../types';
|
|
23
|
+
|
|
24
|
+
export function usePreviewRange( {
|
|
25
|
+
selected,
|
|
26
|
+
hoveredDate,
|
|
27
|
+
excludeDisabled,
|
|
28
|
+
min,
|
|
29
|
+
max,
|
|
30
|
+
disabled,
|
|
31
|
+
}: Pick<
|
|
32
|
+
DateRangeCalendarProps,
|
|
33
|
+
'selected' | 'excludeDisabled' | 'min' | 'max' | 'disabled'
|
|
34
|
+
> & {
|
|
35
|
+
hoveredDate: Date | undefined;
|
|
36
|
+
} ) {
|
|
37
|
+
return useMemo( () => {
|
|
38
|
+
if ( ! hoveredDate || ! selected?.from ) {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let previewHighlight: DateRange | undefined;
|
|
43
|
+
let potentialNewRange: { from: Date; to: Date } | undefined;
|
|
44
|
+
|
|
45
|
+
// Hovering on a date before the start of the selected range
|
|
46
|
+
if ( hoveredDate < selected.from ) {
|
|
47
|
+
previewHighlight = {
|
|
48
|
+
from: hoveredDate,
|
|
49
|
+
to: selected.from,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
potentialNewRange = {
|
|
53
|
+
from: hoveredDate,
|
|
54
|
+
to: selected.to ?? selected.from,
|
|
55
|
+
};
|
|
56
|
+
} else if (
|
|
57
|
+
selected.to &&
|
|
58
|
+
hoveredDate > selected.from &&
|
|
59
|
+
hoveredDate < selected.to
|
|
60
|
+
) {
|
|
61
|
+
// Hovering on a date between the start and end of the selected range
|
|
62
|
+
previewHighlight = {
|
|
63
|
+
from: selected.from,
|
|
64
|
+
to: hoveredDate,
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
potentialNewRange = {
|
|
68
|
+
from: selected.from,
|
|
69
|
+
to: hoveredDate,
|
|
70
|
+
};
|
|
71
|
+
} else if ( hoveredDate > selected.from ) {
|
|
72
|
+
// Hovering on a date after the end of the selected range (either
|
|
73
|
+
// because it's greater than selected.to, or because it's not defined)
|
|
74
|
+
previewHighlight = {
|
|
75
|
+
from: selected.to ?? selected.from,
|
|
76
|
+
to: hoveredDate,
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
potentialNewRange = {
|
|
80
|
+
from: selected.from,
|
|
81
|
+
to: hoveredDate,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (
|
|
86
|
+
min !== undefined &&
|
|
87
|
+
min > 0 &&
|
|
88
|
+
potentialNewRange &&
|
|
89
|
+
differenceInCalendarDays(
|
|
90
|
+
potentialNewRange.to,
|
|
91
|
+
potentialNewRange.from
|
|
92
|
+
) < min
|
|
93
|
+
) {
|
|
94
|
+
previewHighlight = {
|
|
95
|
+
from: hoveredDate,
|
|
96
|
+
to: hoveredDate,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (
|
|
101
|
+
max !== undefined &&
|
|
102
|
+
max > 0 &&
|
|
103
|
+
potentialNewRange &&
|
|
104
|
+
differenceInCalendarDays(
|
|
105
|
+
potentialNewRange.to,
|
|
106
|
+
potentialNewRange.from
|
|
107
|
+
) > max
|
|
108
|
+
) {
|
|
109
|
+
previewHighlight = {
|
|
110
|
+
from: hoveredDate,
|
|
111
|
+
to: hoveredDate,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
if (
|
|
116
|
+
excludeDisabled &&
|
|
117
|
+
disabled &&
|
|
118
|
+
potentialNewRange &&
|
|
119
|
+
rangeContainsModifiers( potentialNewRange, disabled )
|
|
120
|
+
) {
|
|
121
|
+
previewHighlight = {
|
|
122
|
+
from: hoveredDate,
|
|
123
|
+
to: hoveredDate,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return previewHighlight;
|
|
128
|
+
}, [ selected, hoveredDate, excludeDisabled, min, max, disabled ] );
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* `DateRangeCalendar` is a React component that provides a customizable calendar
|
|
133
|
+
* interface for **date range** selection.
|
|
134
|
+
*
|
|
135
|
+
* The component is built with accessibility in mind and follows ARIA best
|
|
136
|
+
* practices for calendar widgets. It provides keyboard navigation, screen reader
|
|
137
|
+
* support, and customizable labels for internationalization.
|
|
138
|
+
*/
|
|
139
|
+
export const DateRangeCalendar = ( {
|
|
140
|
+
defaultSelected,
|
|
141
|
+
selected: selectedProp,
|
|
142
|
+
onSelect,
|
|
143
|
+
numberOfMonths = 1,
|
|
144
|
+
excludeDisabled,
|
|
145
|
+
min,
|
|
146
|
+
max,
|
|
147
|
+
disabled,
|
|
148
|
+
locale = enUS,
|
|
149
|
+
timeZone,
|
|
150
|
+
...props
|
|
151
|
+
}: DateRangeCalendarProps ) => {
|
|
152
|
+
const localizationProps = useLocalizationProps( {
|
|
153
|
+
locale,
|
|
154
|
+
timeZone,
|
|
155
|
+
mode: 'range',
|
|
156
|
+
} );
|
|
157
|
+
|
|
158
|
+
const onChange: OnSelectHandler< typeof selectedProp > = useCallback(
|
|
159
|
+
( selected, triggerDate, modifiers, e ) => {
|
|
160
|
+
// Convert internal `null` to `undefined` for the public event handler.
|
|
161
|
+
onSelect?.( selected ?? undefined, triggerDate, modifiers, e );
|
|
162
|
+
},
|
|
163
|
+
[ onSelect ]
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
const [ selected, setSelected ] = useControlledValue< typeof selectedProp >(
|
|
167
|
+
{
|
|
168
|
+
defaultValue: defaultSelected,
|
|
169
|
+
value: selectedProp,
|
|
170
|
+
onChange,
|
|
171
|
+
}
|
|
172
|
+
);
|
|
173
|
+
|
|
174
|
+
const [ hoveredDate, setHoveredDate ] = useState< Date | undefined >(
|
|
175
|
+
undefined
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
// Compute the preview range for hover effect
|
|
179
|
+
const previewRange = usePreviewRange( {
|
|
180
|
+
selected,
|
|
181
|
+
hoveredDate,
|
|
182
|
+
excludeDisabled,
|
|
183
|
+
min,
|
|
184
|
+
max,
|
|
185
|
+
disabled,
|
|
186
|
+
} );
|
|
187
|
+
|
|
188
|
+
const modifiers = useMemo( () => {
|
|
189
|
+
return {
|
|
190
|
+
preview: previewRange,
|
|
191
|
+
preview_start: previewRange?.from,
|
|
192
|
+
preview_end: previewRange?.to,
|
|
193
|
+
};
|
|
194
|
+
}, [ previewRange ] );
|
|
195
|
+
|
|
196
|
+
return (
|
|
197
|
+
<DayPicker
|
|
198
|
+
{ ...COMMON_PROPS }
|
|
199
|
+
{ ...localizationProps }
|
|
200
|
+
{ ...props }
|
|
201
|
+
mode="range"
|
|
202
|
+
numberOfMonths={ clampNumberOfMonths( numberOfMonths ) }
|
|
203
|
+
disabled={ disabled }
|
|
204
|
+
excludeDisabled={ excludeDisabled }
|
|
205
|
+
min={ min }
|
|
206
|
+
max={ max }
|
|
207
|
+
selected={ selected ?? undefined }
|
|
208
|
+
onSelect={ setSelected }
|
|
209
|
+
onDayMouseEnter={ ( date ) => setHoveredDate( date ) }
|
|
210
|
+
onDayMouseLeave={ () => setHoveredDate( undefined ) }
|
|
211
|
+
modifiers={ modifiers }
|
|
212
|
+
modifiersClassNames={ MODIFIER_CLASSNAMES }
|
|
213
|
+
/>
|
|
214
|
+
);
|
|
215
|
+
};
|