@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,342 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { Locale } from 'date-fns';
|
|
5
|
+
import type * as React from 'react';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Represents the modifiers that match a specific day in the calendar.
|
|
9
|
+
* @example
|
|
10
|
+
* const modifiers: Modifiers = {
|
|
11
|
+
* today: false, // the day is not today
|
|
12
|
+
* selected: true, // the day is selected
|
|
13
|
+
* disabled: false, // the day is not disabled
|
|
14
|
+
* outside: false, // the day is not outside the month
|
|
15
|
+
* focused: false, // the day is not focused
|
|
16
|
+
*
|
|
17
|
+
* weekend: false // custom modifier example for matching a weekend
|
|
18
|
+
* booked: true // custom modifier example for matching a booked day
|
|
19
|
+
* available: false // custom modifier example for matching an available day
|
|
20
|
+
* };
|
|
21
|
+
*/
|
|
22
|
+
export type Modifiers = Record< string, boolean >;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A value or a function that matches a specific day.
|
|
26
|
+
* @example
|
|
27
|
+
* // will always match the day
|
|
28
|
+
* const booleanMatcher: Matcher = true;
|
|
29
|
+
*
|
|
30
|
+
* // will match the today's date
|
|
31
|
+
* const dateMatcher: Matcher = new Date();
|
|
32
|
+
*
|
|
33
|
+
* // will match the days in the array
|
|
34
|
+
* const arrayMatcher: Matcher = [
|
|
35
|
+
* new Date(2019, 1, 2),
|
|
36
|
+
* new Date(2019, 1, 4)
|
|
37
|
+
* ];
|
|
38
|
+
*
|
|
39
|
+
* // will match days after the 2nd of February 2019
|
|
40
|
+
* const afterMatcher: DateAfter = { after: new Date(2019, 1, 2) };
|
|
41
|
+
*
|
|
42
|
+
* // will match days before the 2nd of February 2019 }
|
|
43
|
+
* const beforeMatcher: DateBefore = { before: new Date(2019, 1, 2) };
|
|
44
|
+
*
|
|
45
|
+
* // will match Sundays
|
|
46
|
+
* const dayOfWeekMatcher: DayOfWeek = {
|
|
47
|
+
* dayOfWeek: 0
|
|
48
|
+
* };
|
|
49
|
+
*
|
|
50
|
+
* // will match the included days, except the two dates
|
|
51
|
+
* const intervalMatcher: DateInterval = {
|
|
52
|
+
* after: new Date(2019, 1, 2),
|
|
53
|
+
* before: new Date(2019, 1, 5)
|
|
54
|
+
* };
|
|
55
|
+
*
|
|
56
|
+
* // will match the included days, including the two dates
|
|
57
|
+
* const rangeMatcher: DateRange = {
|
|
58
|
+
* from: new Date(2019, 1, 2),
|
|
59
|
+
* to: new Date(2019, 1, 5)
|
|
60
|
+
* };
|
|
61
|
+
*
|
|
62
|
+
* // will match when the function return true
|
|
63
|
+
* const functionMatcher: Matcher = (day: Date) => {
|
|
64
|
+
* return day.getMonth() === 2; // match when month is March
|
|
65
|
+
* };
|
|
66
|
+
*/
|
|
67
|
+
type Matcher =
|
|
68
|
+
| boolean
|
|
69
|
+
| ( ( date: Date ) => boolean )
|
|
70
|
+
| Date
|
|
71
|
+
| Date[]
|
|
72
|
+
| DateRange
|
|
73
|
+
| DateBefore
|
|
74
|
+
| DateAfter
|
|
75
|
+
| DateInterval
|
|
76
|
+
| DayOfWeek;
|
|
77
|
+
/**
|
|
78
|
+
* Match a day falling after the specified date, with the date not included.
|
|
79
|
+
* @example
|
|
80
|
+
* // Match days after the 2nd of February 2019
|
|
81
|
+
* const matcher: DateAfter = { after: new Date(2019, 1, 2) };
|
|
82
|
+
*/
|
|
83
|
+
type DateAfter = {
|
|
84
|
+
after: Date;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Match a day falling before the specified date, with the date not included.
|
|
88
|
+
* @example
|
|
89
|
+
* // Match days before the 2nd of February 2019
|
|
90
|
+
* const matcher: DateBefore = { before: new Date(2019, 1, 2) };
|
|
91
|
+
*/
|
|
92
|
+
type DateBefore = {
|
|
93
|
+
before: Date;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* An interval of dates. Differently from `DateRange`, the range ends here
|
|
97
|
+
* are not included.
|
|
98
|
+
* @example
|
|
99
|
+
* // Match the days between the 2nd and the 5th of February 2019
|
|
100
|
+
* const matcher: DateInterval = {
|
|
101
|
+
* after: new Date(2019, 1, 2),
|
|
102
|
+
* before: new Date(2019, 1, 5)
|
|
103
|
+
* };
|
|
104
|
+
*/
|
|
105
|
+
type DateInterval = {
|
|
106
|
+
before: Date;
|
|
107
|
+
after: Date;
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* A range of dates. The range can be open. Differently from
|
|
111
|
+
* `DateInterval`, the range ends here are included.
|
|
112
|
+
* @example
|
|
113
|
+
* // Match the days between the 2nd and the 5th of February 2019
|
|
114
|
+
* const matcher: DateRange = {
|
|
115
|
+
* from: new Date(2019, 1, 2),
|
|
116
|
+
* to: new Date(2019, 1, 5)
|
|
117
|
+
* };
|
|
118
|
+
*/
|
|
119
|
+
export type DateRange = {
|
|
120
|
+
from: Date | undefined;
|
|
121
|
+
to?: Date | undefined;
|
|
122
|
+
};
|
|
123
|
+
/**
|
|
124
|
+
* Match dates being one of the specified days of the week (`0-6`, where `0` is
|
|
125
|
+
* Sunday).
|
|
126
|
+
* @example
|
|
127
|
+
* // Match Sundays
|
|
128
|
+
* const matcher: DayOfWeek = { dayOfWeek: 0 };
|
|
129
|
+
* // Match weekends
|
|
130
|
+
* const matcher: DayOfWeek = { dayOfWeek: [0, 6] };
|
|
131
|
+
*/
|
|
132
|
+
type DayOfWeek = {
|
|
133
|
+
dayOfWeek: number | number[];
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Shared handler type for `onSelect` callback when a selection mode is set.
|
|
138
|
+
* @example
|
|
139
|
+
* const handleSelect: OnSelectHandler<Date> = (
|
|
140
|
+
* selected,
|
|
141
|
+
* triggerDate,
|
|
142
|
+
* modifiers,
|
|
143
|
+
* e
|
|
144
|
+
* ) => {
|
|
145
|
+
* console.log( "Selected:", selected );
|
|
146
|
+
* console.log( "Triggered by:", triggerDate );
|
|
147
|
+
* };
|
|
148
|
+
* @template T - The type of the selected item.
|
|
149
|
+
* @callback OnSelectHandler
|
|
150
|
+
* @param {T} selected - The selected item after the event.
|
|
151
|
+
* @param {Date} triggerDate - The date when the event was triggered. This is
|
|
152
|
+
* typically the day clicked or interacted with.
|
|
153
|
+
* @param {Modifiers} modifiers - The modifiers associated with the event.
|
|
154
|
+
* @param {React.MouseEvent | React.KeyboardEvent} e - The event object.
|
|
155
|
+
*/
|
|
156
|
+
export type OnSelectHandler< T > = (
|
|
157
|
+
selected: T,
|
|
158
|
+
triggerDate: Date,
|
|
159
|
+
modifiers: Modifiers,
|
|
160
|
+
e: React.MouseEvent | React.KeyboardEvent
|
|
161
|
+
) => void;
|
|
162
|
+
|
|
163
|
+
export interface BaseProps
|
|
164
|
+
extends Omit<
|
|
165
|
+
React.HTMLAttributes< HTMLDivElement >,
|
|
166
|
+
'onSelect' | 'defaultValue'
|
|
167
|
+
> {
|
|
168
|
+
/**
|
|
169
|
+
* Whether the selection is required.
|
|
170
|
+
* When `true`, there always needs to be a date selected.
|
|
171
|
+
* @default false
|
|
172
|
+
*/
|
|
173
|
+
required?: boolean;
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* The initial month to show in the calendar view (uncontrolled).
|
|
177
|
+
* @default The current month
|
|
178
|
+
*/
|
|
179
|
+
defaultMonth?: Date;
|
|
180
|
+
/**
|
|
181
|
+
* The month displayed in the calendar view (controlled). Use together with
|
|
182
|
+
* `onMonthChange` to change the month programmatically.
|
|
183
|
+
*/
|
|
184
|
+
month?: Date;
|
|
185
|
+
/**
|
|
186
|
+
* The number of months displayed at once.
|
|
187
|
+
* @default 1
|
|
188
|
+
*/
|
|
189
|
+
numberOfMonths?: number;
|
|
190
|
+
/**
|
|
191
|
+
* The earliest month to start the month navigation.
|
|
192
|
+
*/
|
|
193
|
+
startMonth?: Date;
|
|
194
|
+
/**
|
|
195
|
+
* The latest month to end the month navigation.
|
|
196
|
+
*/
|
|
197
|
+
endMonth?: Date;
|
|
198
|
+
/**
|
|
199
|
+
* Focus the first selected day (if set) or today's date (if not disabled).
|
|
200
|
+
*
|
|
201
|
+
* Use this prop when you need to focus the calendar after a user action
|
|
202
|
+
* (e.g. opening the dialog with the calendar).
|
|
203
|
+
*/
|
|
204
|
+
autoFocus?: boolean;
|
|
205
|
+
/**
|
|
206
|
+
* Specify which days are disabled. Using `true` will disable all dates.
|
|
207
|
+
*/
|
|
208
|
+
disabled?: Matcher | Matcher[] | undefined;
|
|
209
|
+
/**
|
|
210
|
+
* Disable the navigation buttons.
|
|
211
|
+
*/
|
|
212
|
+
disableNavigation?: boolean;
|
|
213
|
+
/**
|
|
214
|
+
* Use custom labels, useful for translating the component.
|
|
215
|
+
*
|
|
216
|
+
* For a correct localized experience, consumers should make sure the locale
|
|
217
|
+
* used for the translated labels and `locale` prop are consistent.
|
|
218
|
+
*/
|
|
219
|
+
labels?: {
|
|
220
|
+
/**
|
|
221
|
+
* The label for the navigation toolbar.
|
|
222
|
+
* @default ""
|
|
223
|
+
*/
|
|
224
|
+
labelNav?: () => string;
|
|
225
|
+
/**
|
|
226
|
+
* The label for the month grid.
|
|
227
|
+
* @default "LLLL y" (e.g. "November 2022")
|
|
228
|
+
*/
|
|
229
|
+
labelGrid?: ( date: Date ) => string;
|
|
230
|
+
/**
|
|
231
|
+
* The label for the gridcell, when the calendar is not interactive.
|
|
232
|
+
* @default The formatted date.
|
|
233
|
+
*/
|
|
234
|
+
labelGridcell?: ( date: Date, modifiers?: Modifiers ) => string;
|
|
235
|
+
/**
|
|
236
|
+
* The label for the "next month" button.
|
|
237
|
+
* @default "Go to the Next Month"
|
|
238
|
+
*/
|
|
239
|
+
labelNext?: ( month: Date | undefined ) => string;
|
|
240
|
+
/**
|
|
241
|
+
* The label for the "previous month" button.
|
|
242
|
+
* @default "Go to the Previous Month"
|
|
243
|
+
*/
|
|
244
|
+
labelPrevious?: ( month: Date | undefined ) => string;
|
|
245
|
+
/**
|
|
246
|
+
* The label for the day button.
|
|
247
|
+
* @default The formatted date.
|
|
248
|
+
*/
|
|
249
|
+
labelDayButton?: ( date: Date, modifiers?: Modifiers ) => string;
|
|
250
|
+
/**
|
|
251
|
+
* The label for the weekday.
|
|
252
|
+
* @default ( date: Date ) => "Monday" | "Tuesday" | "Wednesday" | "Thursday" | "Friday" | "Saturday" | "Sunday"
|
|
253
|
+
*/
|
|
254
|
+
labelWeekday?: ( date: Date ) => string;
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
/**
|
|
258
|
+
* The locale object used to localize dates. Pass a locale from
|
|
259
|
+
* `@date-fns/locale` to localize the calendar.
|
|
260
|
+
*
|
|
261
|
+
* For a correct localized experience, consumers should make sure the locale
|
|
262
|
+
* used for the translated labels and `locale` prop are consistent.
|
|
263
|
+
* @see https://github.com/date-fns/date-fns/tree/main/src/locale for a list of the supported locales
|
|
264
|
+
* @default The `enUS` locale from `@date-fns/locale`
|
|
265
|
+
*/
|
|
266
|
+
locale?: Locale;
|
|
267
|
+
/**
|
|
268
|
+
* The index of the first day of the week (0 - Sunday). Overrides the locale's
|
|
269
|
+
* one.
|
|
270
|
+
* @default Based on the `locale` prop
|
|
271
|
+
*/
|
|
272
|
+
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6 | undefined;
|
|
273
|
+
/**
|
|
274
|
+
* Event fired when the user navigates between months.
|
|
275
|
+
*/
|
|
276
|
+
onMonthChange?: ( month: Date ) => void;
|
|
277
|
+
/**
|
|
278
|
+
* The time zone (IANA or UTC offset) to use in the calendar.
|
|
279
|
+
*
|
|
280
|
+
* See
|
|
281
|
+
* [Wikipedia](https://en.wikipedia.org/wiki/List_of_tz_database_time_zones)
|
|
282
|
+
* for the possible values.
|
|
283
|
+
*
|
|
284
|
+
* When working with time zones, use the `TZDate` object exported by this
|
|
285
|
+
* package instead of the native `Date` object.
|
|
286
|
+
* @example
|
|
287
|
+
* import { DateCalendar, TZDate } from "@wordpress/components";
|
|
288
|
+
*
|
|
289
|
+
* export function WithTimeZone() {
|
|
290
|
+
* const timeZone = "America/New_York";
|
|
291
|
+
* const [ selected, setSelected ] = useState< Date | undefined >(
|
|
292
|
+
* new TZDate( 2024, 12, 10, timeZone ) // Use `TZDate` instead of `Date`
|
|
293
|
+
* );
|
|
294
|
+
* return (
|
|
295
|
+
* <DateCalendar
|
|
296
|
+
* timeZone={ timeZone }
|
|
297
|
+
* selected={ selected }
|
|
298
|
+
* onSelect={ setSelected }
|
|
299
|
+
* />
|
|
300
|
+
* );
|
|
301
|
+
* }
|
|
302
|
+
*/
|
|
303
|
+
timeZone?: string;
|
|
304
|
+
/**
|
|
305
|
+
* The role attribute to add to the container element.
|
|
306
|
+
* @default 'application'
|
|
307
|
+
*/
|
|
308
|
+
role?: 'application' | 'dialog' | undefined;
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
interface SingleProps {
|
|
312
|
+
/** The selected date. */
|
|
313
|
+
selected?: Date | undefined | null;
|
|
314
|
+
/** Event handler when a day is selected. */
|
|
315
|
+
onSelect?: OnSelectHandler< Date | undefined >;
|
|
316
|
+
/** The default selected date (for uncontrolled usage). */
|
|
317
|
+
defaultSelected?: Date;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
interface RangeProps {
|
|
321
|
+
/**
|
|
322
|
+
* When `true`, the range will reset when including a disabled day.
|
|
323
|
+
*/
|
|
324
|
+
excludeDisabled?: boolean;
|
|
325
|
+
/**
|
|
326
|
+
* The minimum number of nights to include in the range.
|
|
327
|
+
*/
|
|
328
|
+
min?: number;
|
|
329
|
+
/**
|
|
330
|
+
* The maximum number of nights to include in the range.
|
|
331
|
+
*/
|
|
332
|
+
max?: number;
|
|
333
|
+
/** The selected range. */
|
|
334
|
+
selected?: DateRange | undefined | null;
|
|
335
|
+
/** Event handler when the selection changes. */
|
|
336
|
+
onSelect?: OnSelectHandler< DateRange | undefined >;
|
|
337
|
+
/** The default selected range (for uncontrolled usage). */
|
|
338
|
+
defaultSelected?: DateRange;
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export type DateCalendarProps = BaseProps & SingleProps;
|
|
342
|
+
export type DateRangeCalendarProps = BaseProps & RangeProps;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { Day } from './day-cell';
|
|
5
|
+
|
|
6
|
+
const CLASSNAMES = {
|
|
7
|
+
root: 'components-calendar',
|
|
8
|
+
day: 'components-calendar__day',
|
|
9
|
+
day_button: 'components-calendar__day-button',
|
|
10
|
+
caption_label: 'components-calendar__caption-label',
|
|
11
|
+
button_next: 'components-calendar__button-next',
|
|
12
|
+
button_previous: 'components-calendar__button-previous',
|
|
13
|
+
chevron: 'components-calendar__chevron',
|
|
14
|
+
nav: 'components-calendar__nav',
|
|
15
|
+
month_caption: 'components-calendar__month-caption',
|
|
16
|
+
months: 'components-calendar__months',
|
|
17
|
+
month_grid: 'components-calendar__month-grid',
|
|
18
|
+
weekday: 'components-calendar__weekday',
|
|
19
|
+
today: 'components-calendar__day--today',
|
|
20
|
+
selected: 'components-calendar__day--selected',
|
|
21
|
+
disabled: 'components-calendar__day--disabled',
|
|
22
|
+
hidden: 'components-calendar__day--hidden',
|
|
23
|
+
range_start: 'components-calendar__range-start',
|
|
24
|
+
range_end: 'components-calendar__range-end',
|
|
25
|
+
range_middle: 'components-calendar__range-middle',
|
|
26
|
+
weeks_before_enter: 'components-calendar__weeks-before-enter',
|
|
27
|
+
weeks_before_exit: 'components-calendar__weeks-before-exit',
|
|
28
|
+
weeks_after_enter: 'components-calendar__weeks-after-enter',
|
|
29
|
+
weeks_after_exit: 'components-calendar__weeks-after-exit',
|
|
30
|
+
caption_after_enter: 'components-calendar__caption-after-enter',
|
|
31
|
+
caption_after_exit: 'components-calendar__caption-after-exit',
|
|
32
|
+
caption_before_enter: 'components-calendar__caption-before-enter',
|
|
33
|
+
caption_before_exit: 'components-calendar__caption-before-exit',
|
|
34
|
+
};
|
|
35
|
+
export const MODIFIER_CLASSNAMES = {
|
|
36
|
+
preview: 'components-calendar__day--preview',
|
|
37
|
+
preview_start: 'components-calendar__day--preview-start',
|
|
38
|
+
preview_end: 'components-calendar__day--preview-end',
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const COMMON_PROPS = {
|
|
42
|
+
animate: true,
|
|
43
|
+
// Only show days in the current month
|
|
44
|
+
showOutsideDays: false,
|
|
45
|
+
// Hide week number column
|
|
46
|
+
showWeekNumber: false,
|
|
47
|
+
// Show weekdays row
|
|
48
|
+
hideWeekdays: false,
|
|
49
|
+
// Month and year caption are not interactive
|
|
50
|
+
captionLayout: 'label',
|
|
51
|
+
// Show a variable number of weeks depending on the month
|
|
52
|
+
fixedWeeks: false,
|
|
53
|
+
// Show navigation buttons
|
|
54
|
+
hideNavigation: false,
|
|
55
|
+
// Class names
|
|
56
|
+
classNames: CLASSNAMES,
|
|
57
|
+
// Default role
|
|
58
|
+
role: 'application',
|
|
59
|
+
components: {
|
|
60
|
+
Day,
|
|
61
|
+
},
|
|
62
|
+
} as const;
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { CalendarDay } from 'react-day-picker';
|
|
5
|
+
/**
|
|
6
|
+
* Internal dependencies
|
|
7
|
+
*/
|
|
8
|
+
import type { Modifiers } from '../types';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The dash array and offset are calculated by:
|
|
12
|
+
* - measuring the path length (eg 92,28384)
|
|
13
|
+
* - establishing how many segments should the path be split into (eg. 24)
|
|
14
|
+
* - dividing the path length by the number of segments (eg. 92,28384 / 24 = 3,84516)
|
|
15
|
+
* - playing with the dash offset to make sure the dashes look good on rounded corners
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Dashed rectangle. The dash array and offset are chosen to make sure dashes
|
|
20
|
+
* look good on rounded corners and have similar metrics to the other dash
|
|
21
|
+
* preview shapes.
|
|
22
|
+
*/
|
|
23
|
+
const PreviewDashStartAndEnd = () => {
|
|
24
|
+
return (
|
|
25
|
+
<svg
|
|
26
|
+
viewBox="0 0 32 32"
|
|
27
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
28
|
+
fill="none"
|
|
29
|
+
stroke="currentColor"
|
|
30
|
+
strokeDasharray="3.7677"
|
|
31
|
+
strokeDashoffset="3.2"
|
|
32
|
+
strokeWidth="1"
|
|
33
|
+
>
|
|
34
|
+
<path d="M29.5,0.5 h-27 a2,2 0 0 0 -2,2 v27 a2,2 0 0 0 2,2 h27 a2,2 0 0 0 2,-2 v-27 a2,2 0 0 0 -2,-2" />
|
|
35
|
+
</svg>
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Dashed top, left, and bottom sides, with rounded corners. The dash array and
|
|
41
|
+
* offset are chosen to make sure that multiple days in a row show a seamless
|
|
42
|
+
* dashed border, and the dashes look good on rounded corners.
|
|
43
|
+
*/
|
|
44
|
+
const PreviewDashStart = () => {
|
|
45
|
+
return (
|
|
46
|
+
<svg
|
|
47
|
+
viewBox="0 0 32 32"
|
|
48
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
49
|
+
fill="none"
|
|
50
|
+
stroke="currentColor"
|
|
51
|
+
strokeDasharray="3.84516"
|
|
52
|
+
strokeDashoffset="1.9226"
|
|
53
|
+
strokeWidth="1"
|
|
54
|
+
>
|
|
55
|
+
<path d="M32,0.5 h-29.5 a2,2 0 0 0 -2,2 v27 a2,2 0 0 0 2,2 h30" />
|
|
56
|
+
</svg>
|
|
57
|
+
);
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Dashed top and bottom sides. The dash array and offset are chosen
|
|
61
|
+
* to make sure that multiple days in a row show a seamless dashed border.
|
|
62
|
+
*/
|
|
63
|
+
const PreviewDashMiddle = () => {
|
|
64
|
+
return (
|
|
65
|
+
<svg
|
|
66
|
+
viewBox="0 0 32 32"
|
|
67
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
68
|
+
fill="none"
|
|
69
|
+
stroke="currentColor"
|
|
70
|
+
strokeDasharray="3.9 4"
|
|
71
|
+
strokeDashoffset="2"
|
|
72
|
+
strokeWidth="1"
|
|
73
|
+
>
|
|
74
|
+
<line x1="0" y1="0.5" x2="100" y2="0.5" />
|
|
75
|
+
<line x1="0" y1="31.5" x2="100" y2="31.5" />
|
|
76
|
+
</svg>
|
|
77
|
+
);
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Dashed top, right, and bottom sides, with rounded corners. The dash array and
|
|
81
|
+
* offset are chosen to make sure that multiple days in a row show a seamless
|
|
82
|
+
* dashed border, and the dashes look good on rounded corners.
|
|
83
|
+
*/
|
|
84
|
+
const PreviewDashEnd = () => {
|
|
85
|
+
return (
|
|
86
|
+
<svg
|
|
87
|
+
viewBox="0 0 32 32"
|
|
88
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
89
|
+
fill="none"
|
|
90
|
+
stroke="currentColor"
|
|
91
|
+
strokeDasharray="3.84516"
|
|
92
|
+
strokeDashoffset="1.9226"
|
|
93
|
+
strokeWidth="1"
|
|
94
|
+
>
|
|
95
|
+
<path d="M0,0.5 h29.5 a2,2 0 0 1 2,2 v27 a2,2 0 0 1 -2,2 h-29.5" />
|
|
96
|
+
</svg>
|
|
97
|
+
);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Render a grid cell for a specific day in the calendar.
|
|
102
|
+
*
|
|
103
|
+
* Handles interaction and focus for the day.
|
|
104
|
+
* @see https://daypicker.dev/guides/custom-components
|
|
105
|
+
*/
|
|
106
|
+
export function Day(
|
|
107
|
+
props: {
|
|
108
|
+
/** The day to render. */
|
|
109
|
+
day: CalendarDay;
|
|
110
|
+
/** The modifiers to apply to the day. */
|
|
111
|
+
modifiers: Modifiers;
|
|
112
|
+
} & React.HTMLAttributes< HTMLDivElement >
|
|
113
|
+
) {
|
|
114
|
+
const { day, modifiers, children, ...tdProps } = props;
|
|
115
|
+
|
|
116
|
+
let PreviewDash;
|
|
117
|
+
if ( modifiers.preview_start && modifiers.preview_end ) {
|
|
118
|
+
PreviewDash = PreviewDashStartAndEnd;
|
|
119
|
+
} else if ( modifiers.preview_start ) {
|
|
120
|
+
PreviewDash = PreviewDashStart;
|
|
121
|
+
} else if ( modifiers.preview_end ) {
|
|
122
|
+
PreviewDash = PreviewDashEnd;
|
|
123
|
+
} else if ( modifiers.preview ) {
|
|
124
|
+
PreviewDash = PreviewDashMiddle;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return (
|
|
128
|
+
<td { ...tdProps }>
|
|
129
|
+
{ PreviewDash && <PreviewDash /> }
|
|
130
|
+
{ children }
|
|
131
|
+
</td>
|
|
132
|
+
);
|
|
133
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __, sprintf } from '@wordpress/i18n';
|
|
5
|
+
import { useMemo } from '@wordpress/element';
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import type { Modifiers, BaseProps } from '../types';
|
|
10
|
+
|
|
11
|
+
function isLocaleRTL( localeCode: string ) {
|
|
12
|
+
const localeObj = new Intl.Locale( localeCode );
|
|
13
|
+
if ( 'getTextInfo' in localeObj ) {
|
|
14
|
+
// @ts-expect-error - getTextInfo is not typed yet
|
|
15
|
+
// see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/Locale/getTextInfo
|
|
16
|
+
return localeObj.getTextInfo().direction === 'rtl';
|
|
17
|
+
}
|
|
18
|
+
return [
|
|
19
|
+
'ar', // Arabic
|
|
20
|
+
'he', // Hebrew
|
|
21
|
+
'fa', // Persian (Farsi)
|
|
22
|
+
'ur', // Urdu
|
|
23
|
+
'ps', // Pashto
|
|
24
|
+
'syr', // Syriac
|
|
25
|
+
'dv', // Divehi
|
|
26
|
+
'ku', // Kurdish (Sorani)
|
|
27
|
+
'yi', // Yiddish
|
|
28
|
+
].includes( localeObj.language );
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Returns localization props for the calendar components.
|
|
33
|
+
*
|
|
34
|
+
* Notes:
|
|
35
|
+
* - the following props should be intended as defaults, and should
|
|
36
|
+
* be overridden by consumer props if listed as public props.
|
|
37
|
+
* - It is possible for the translated strings to use a different locale
|
|
38
|
+
* than the formatted dates and the computed `dir`. This is because the
|
|
39
|
+
* translation function doesn't expose the locale used for the translated
|
|
40
|
+
* strings, meaning that the dates are formatted using the `locale` prop.
|
|
41
|
+
* For a correct localized experience, consumers should make sure that
|
|
42
|
+
* translation context and `locale` prop are consistent.
|
|
43
|
+
* @param props
|
|
44
|
+
* @param props.locale
|
|
45
|
+
* @param props.timeZone
|
|
46
|
+
* @param props.mode
|
|
47
|
+
*/
|
|
48
|
+
export const useLocalizationProps = ( {
|
|
49
|
+
locale,
|
|
50
|
+
timeZone,
|
|
51
|
+
mode,
|
|
52
|
+
}: {
|
|
53
|
+
locale: NonNullable< BaseProps[ 'locale' ] >;
|
|
54
|
+
timeZone: BaseProps[ 'timeZone' ];
|
|
55
|
+
mode: 'single' | 'range';
|
|
56
|
+
} ) => {
|
|
57
|
+
return useMemo( () => {
|
|
58
|
+
// ie. April 2025
|
|
59
|
+
const monthNameFormatter = new Intl.DateTimeFormat( locale.code, {
|
|
60
|
+
year: 'numeric',
|
|
61
|
+
month: 'long',
|
|
62
|
+
timeZone,
|
|
63
|
+
} );
|
|
64
|
+
// ie. M, T, W, T, F, S, S
|
|
65
|
+
const weekdayNarrowFormatter = new Intl.DateTimeFormat( locale.code, {
|
|
66
|
+
weekday: 'narrow',
|
|
67
|
+
timeZone,
|
|
68
|
+
} );
|
|
69
|
+
// ie. Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday
|
|
70
|
+
const weekdayLongFormatter = new Intl.DateTimeFormat( locale.code, {
|
|
71
|
+
weekday: 'long',
|
|
72
|
+
timeZone,
|
|
73
|
+
} );
|
|
74
|
+
// ie. Monday, April 29, 2025
|
|
75
|
+
const fullDateFormatter = new Intl.DateTimeFormat( locale.code, {
|
|
76
|
+
weekday: 'long',
|
|
77
|
+
year: 'numeric',
|
|
78
|
+
month: 'long',
|
|
79
|
+
day: 'numeric',
|
|
80
|
+
timeZone,
|
|
81
|
+
} );
|
|
82
|
+
|
|
83
|
+
// Note: the following props should be intended as defaults, and should
|
|
84
|
+
// be overridden by consumer props if listed as public props.
|
|
85
|
+
return {
|
|
86
|
+
'aria-label':
|
|
87
|
+
mode === 'single'
|
|
88
|
+
? __( 'Date calendar' )
|
|
89
|
+
: __( 'Date range calendar' ),
|
|
90
|
+
labels: {
|
|
91
|
+
/**
|
|
92
|
+
* The label for the month grid.
|
|
93
|
+
* @param date
|
|
94
|
+
*/
|
|
95
|
+
labelGrid: ( date: Date ) => monthNameFormatter.format( date ),
|
|
96
|
+
/**
|
|
97
|
+
* The label for the gridcell, when the calendar is not interactive.
|
|
98
|
+
* @param date
|
|
99
|
+
* @param modifiers
|
|
100
|
+
*/
|
|
101
|
+
labelGridcell: (
|
|
102
|
+
date: Date,
|
|
103
|
+
/** The modifiers for the day. */
|
|
104
|
+
modifiers?: Modifiers
|
|
105
|
+
) => {
|
|
106
|
+
const formattedDate = fullDateFormatter.format( date );
|
|
107
|
+
let label = formattedDate;
|
|
108
|
+
if ( modifiers?.today ) {
|
|
109
|
+
label = sprintf(
|
|
110
|
+
// translators: %s is the full date (e.g. "Monday, April 29, 2025")
|
|
111
|
+
__( 'Today, %s' ),
|
|
112
|
+
formattedDate
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
return label;
|
|
116
|
+
},
|
|
117
|
+
/** The label for the "next month" button. */
|
|
118
|
+
labelNext: () => __( 'Go to the Next Month' ),
|
|
119
|
+
/** The label for the "previous month" button. */
|
|
120
|
+
labelPrevious: () => __( 'Go to the Previous Month' ),
|
|
121
|
+
/**
|
|
122
|
+
* The label for the day button.
|
|
123
|
+
* @param date
|
|
124
|
+
* @param modifiers
|
|
125
|
+
*/
|
|
126
|
+
labelDayButton: (
|
|
127
|
+
date: Date,
|
|
128
|
+
/** The modifiers for the day. */
|
|
129
|
+
modifiers?: Modifiers
|
|
130
|
+
) => {
|
|
131
|
+
const formattedDate = fullDateFormatter.format( date );
|
|
132
|
+
let label = formattedDate;
|
|
133
|
+
if ( modifiers?.today ) {
|
|
134
|
+
label = sprintf(
|
|
135
|
+
// translators: %s is the full date (e.g. "Monday, April 29, 2025")
|
|
136
|
+
__( 'Today, %s' ),
|
|
137
|
+
formattedDate
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
if ( modifiers?.selected ) {
|
|
141
|
+
label = sprintf(
|
|
142
|
+
// translators: %s is the full date (e.g. "Monday, April 29, 2025")
|
|
143
|
+
__( '%s, selected' ),
|
|
144
|
+
formattedDate
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
return label;
|
|
148
|
+
},
|
|
149
|
+
/**
|
|
150
|
+
* The label for the weekday.
|
|
151
|
+
* @param date
|
|
152
|
+
*/
|
|
153
|
+
labelWeekday: ( date: Date ) =>
|
|
154
|
+
weekdayLongFormatter.format( date ),
|
|
155
|
+
},
|
|
156
|
+
locale,
|
|
157
|
+
dir: isLocaleRTL( locale.code ) ? 'rtl' : 'ltr',
|
|
158
|
+
formatters: {
|
|
159
|
+
formatWeekdayName: ( date: Date ) => {
|
|
160
|
+
return weekdayNarrowFormatter.format( date );
|
|
161
|
+
},
|
|
162
|
+
formatCaption: ( date: Date ) => {
|
|
163
|
+
return monthNameFormatter.format( date );
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
timeZone,
|
|
167
|
+
} as const;
|
|
168
|
+
}, [ locale, timeZone, mode ] );
|
|
169
|
+
};
|