@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,221 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { fn } from '@storybook/test';
|
|
5
|
+
import {
|
|
6
|
+
enUS,
|
|
7
|
+
fr,
|
|
8
|
+
es,
|
|
9
|
+
de,
|
|
10
|
+
it,
|
|
11
|
+
he,
|
|
12
|
+
ru,
|
|
13
|
+
ja,
|
|
14
|
+
ptBR,
|
|
15
|
+
nl,
|
|
16
|
+
ko,
|
|
17
|
+
tr,
|
|
18
|
+
id,
|
|
19
|
+
zhCN,
|
|
20
|
+
zhTW,
|
|
21
|
+
ar,
|
|
22
|
+
sv,
|
|
23
|
+
} from 'date-fns/locale';
|
|
24
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* WordPress dependencies
|
|
28
|
+
*/
|
|
29
|
+
import { useState, useEffect } from '@wordpress/element';
|
|
30
|
+
/**
|
|
31
|
+
* Internal dependencies
|
|
32
|
+
*/
|
|
33
|
+
import { DateCalendar, TZDate } from '..';
|
|
34
|
+
|
|
35
|
+
const meta: Meta< typeof DateCalendar > = {
|
|
36
|
+
title: 'Components/Selection & Input/Time & Date/DateCalendar',
|
|
37
|
+
component: DateCalendar,
|
|
38
|
+
argTypes: {
|
|
39
|
+
locale: {
|
|
40
|
+
options: [
|
|
41
|
+
'English (US)',
|
|
42
|
+
'French',
|
|
43
|
+
'Spanish',
|
|
44
|
+
'German',
|
|
45
|
+
'Italian',
|
|
46
|
+
'Hebrew',
|
|
47
|
+
'Russian',
|
|
48
|
+
'Japanese',
|
|
49
|
+
'Portuguese (Brazil)',
|
|
50
|
+
'Dutch',
|
|
51
|
+
'Korean',
|
|
52
|
+
'Turkish',
|
|
53
|
+
'Indonesian',
|
|
54
|
+
'Chinese (Simplified)',
|
|
55
|
+
'Chinese (Traditional)',
|
|
56
|
+
'Arabic',
|
|
57
|
+
'Swedish',
|
|
58
|
+
],
|
|
59
|
+
mapping: {
|
|
60
|
+
'English (US)': enUS,
|
|
61
|
+
French: fr,
|
|
62
|
+
Spanish: es,
|
|
63
|
+
German: de,
|
|
64
|
+
Italian: it,
|
|
65
|
+
Hebrew: he,
|
|
66
|
+
Russian: ru,
|
|
67
|
+
Japanese: ja,
|
|
68
|
+
'Portuguese (Brazil)': ptBR,
|
|
69
|
+
Dutch: nl,
|
|
70
|
+
Korean: ko,
|
|
71
|
+
Turkish: tr,
|
|
72
|
+
Indonesian: id,
|
|
73
|
+
'Chinese (Simplified)': zhCN,
|
|
74
|
+
'Chinese (Traditional)': zhTW,
|
|
75
|
+
Arabic: ar,
|
|
76
|
+
Swedish: sv,
|
|
77
|
+
},
|
|
78
|
+
control: 'select',
|
|
79
|
+
},
|
|
80
|
+
timeZone: {
|
|
81
|
+
options: [
|
|
82
|
+
'Pacific/Honolulu',
|
|
83
|
+
'America/New_York',
|
|
84
|
+
'Europe/London',
|
|
85
|
+
'Asia/Tokyo',
|
|
86
|
+
'Pacific/Auckland',
|
|
87
|
+
],
|
|
88
|
+
control: 'select',
|
|
89
|
+
},
|
|
90
|
+
labels: {
|
|
91
|
+
control: false,
|
|
92
|
+
},
|
|
93
|
+
defaultSelected: { control: 'date' },
|
|
94
|
+
selected: { control: 'date' },
|
|
95
|
+
onSelect: {
|
|
96
|
+
control: false,
|
|
97
|
+
},
|
|
98
|
+
defaultMonth: { control: 'date' },
|
|
99
|
+
month: { control: 'date' },
|
|
100
|
+
onMonthChange: {
|
|
101
|
+
control: false,
|
|
102
|
+
},
|
|
103
|
+
endMonth: { control: 'date' },
|
|
104
|
+
startMonth: { control: 'date' },
|
|
105
|
+
},
|
|
106
|
+
args: {
|
|
107
|
+
onMonthChange: fn(),
|
|
108
|
+
onSelect: fn(),
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
export default meta;
|
|
112
|
+
|
|
113
|
+
type Story = StoryObj< typeof DateCalendar >;
|
|
114
|
+
|
|
115
|
+
export const Default: Story = {};
|
|
116
|
+
|
|
117
|
+
export const DisabledDates: Story = {
|
|
118
|
+
args: {
|
|
119
|
+
disabled: [
|
|
120
|
+
// Disable tomorrow (single date)
|
|
121
|
+
new Date( new Date().setDate( new Date().getDate() + 1 ) ),
|
|
122
|
+
// Disable all dates after Feb 1st of next year
|
|
123
|
+
{ after: new Date( new Date().getFullYear() + 1, 1, 1 ) },
|
|
124
|
+
// Disable all dates before Dec 1st of last year
|
|
125
|
+
{ before: new Date( new Date().getFullYear() - 1, 11, 1 ) },
|
|
126
|
+
// Disable all dates between 12th and 14th of August of this year
|
|
127
|
+
{
|
|
128
|
+
after: new Date( new Date().getFullYear(), 7, 11 ),
|
|
129
|
+
before: new Date( new Date().getFullYear(), 7, 15 ),
|
|
130
|
+
},
|
|
131
|
+
// Disable all dates between 21st and 26th of October of this year
|
|
132
|
+
{
|
|
133
|
+
from: new Date( new Date().getFullYear(), 9, 21 ),
|
|
134
|
+
to: new Date( new Date().getFullYear(), 9, 26 ),
|
|
135
|
+
},
|
|
136
|
+
// Disable all Wednesdays
|
|
137
|
+
{ dayOfWeek: 3 },
|
|
138
|
+
// Disable all prime day numbers
|
|
139
|
+
function isPrimeDate( date: Date ) {
|
|
140
|
+
return [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 ].includes(
|
|
141
|
+
date.getDate()
|
|
142
|
+
);
|
|
143
|
+
},
|
|
144
|
+
],
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const nextMonth = new Date().getMonth() === 11 ? 0 : new Date().getMonth() + 1;
|
|
149
|
+
const nextMonthYear =
|
|
150
|
+
new Date().getMonth() === 11
|
|
151
|
+
? new Date().getFullYear() + 1
|
|
152
|
+
: new Date().getFullYear();
|
|
153
|
+
const firstDayOfNextMonth = new Date( nextMonthYear, nextMonth, 1 );
|
|
154
|
+
export const WithSelectedDateAndMonth: Story = {
|
|
155
|
+
args: {
|
|
156
|
+
defaultSelected: firstDayOfNextMonth,
|
|
157
|
+
defaultMonth: firstDayOfNextMonth,
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* When working with time zones, use the `TZDate` object exported by this package instead of the native `Date` object.
|
|
163
|
+
*/
|
|
164
|
+
export const WithTimeZone: Story = {
|
|
165
|
+
render: function DateCalendarWithTimeZone( args ) {
|
|
166
|
+
const [ selected, setSelected ] = useState< TZDate | null >( null );
|
|
167
|
+
|
|
168
|
+
useEffect( () => {
|
|
169
|
+
setSelected(
|
|
170
|
+
// Select one week from today every time the time zone changes.
|
|
171
|
+
new TZDate(
|
|
172
|
+
new Date().setDate( new Date().getDate() + 7 ),
|
|
173
|
+
args.timeZone
|
|
174
|
+
)
|
|
175
|
+
);
|
|
176
|
+
}, [ args.timeZone ] );
|
|
177
|
+
|
|
178
|
+
return (
|
|
179
|
+
<>
|
|
180
|
+
<DateCalendar
|
|
181
|
+
{ ...args }
|
|
182
|
+
selected={ selected }
|
|
183
|
+
onSelect={ ( selectedDate, ...rest ) => {
|
|
184
|
+
setSelected(
|
|
185
|
+
selectedDate
|
|
186
|
+
? new TZDate( selectedDate, args.timeZone )
|
|
187
|
+
: null
|
|
188
|
+
);
|
|
189
|
+
args.onSelect?.( selectedDate, ...rest );
|
|
190
|
+
} }
|
|
191
|
+
disabled={ [
|
|
192
|
+
{
|
|
193
|
+
// Disable any date before today
|
|
194
|
+
before: new TZDate( new Date(), args.timeZone ),
|
|
195
|
+
},
|
|
196
|
+
] }
|
|
197
|
+
/>
|
|
198
|
+
|
|
199
|
+
<p>
|
|
200
|
+
Calendar set to { args.timeZone ?? 'current' } timezone,
|
|
201
|
+
disabling selection for all dates before today, and starting
|
|
202
|
+
with a default date of 1 week from today.
|
|
203
|
+
</p>
|
|
204
|
+
</>
|
|
205
|
+
);
|
|
206
|
+
},
|
|
207
|
+
args: {
|
|
208
|
+
timeZone: 'Pacific/Auckland',
|
|
209
|
+
},
|
|
210
|
+
argTypes: {
|
|
211
|
+
selected: {
|
|
212
|
+
control: false,
|
|
213
|
+
},
|
|
214
|
+
defaultSelected: {
|
|
215
|
+
control: false,
|
|
216
|
+
},
|
|
217
|
+
disabled: {
|
|
218
|
+
control: false,
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
};
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { fn } from '@storybook/test';
|
|
5
|
+
import {
|
|
6
|
+
enUS,
|
|
7
|
+
fr,
|
|
8
|
+
es,
|
|
9
|
+
de,
|
|
10
|
+
it,
|
|
11
|
+
he,
|
|
12
|
+
ru,
|
|
13
|
+
ja,
|
|
14
|
+
ptBR,
|
|
15
|
+
nl,
|
|
16
|
+
ko,
|
|
17
|
+
tr,
|
|
18
|
+
id,
|
|
19
|
+
zhCN,
|
|
20
|
+
zhTW,
|
|
21
|
+
ar,
|
|
22
|
+
sv,
|
|
23
|
+
} from 'date-fns/locale';
|
|
24
|
+
import type { Meta, StoryObj } from '@storybook/react';
|
|
25
|
+
/**
|
|
26
|
+
* WordPress dependencies
|
|
27
|
+
*/
|
|
28
|
+
import { useState, useEffect } from '@wordpress/element';
|
|
29
|
+
/**
|
|
30
|
+
* Internal dependencies
|
|
31
|
+
*/
|
|
32
|
+
import { DateRangeCalendar, TZDate } from '..';
|
|
33
|
+
|
|
34
|
+
const meta: Meta< typeof DateRangeCalendar > = {
|
|
35
|
+
title: 'Components/Selection & Input/Time & Date/DateRangeCalendar',
|
|
36
|
+
component: DateRangeCalendar,
|
|
37
|
+
argTypes: {
|
|
38
|
+
locale: {
|
|
39
|
+
options: [
|
|
40
|
+
'English (US)',
|
|
41
|
+
'French',
|
|
42
|
+
'Spanish',
|
|
43
|
+
'German',
|
|
44
|
+
'Italian',
|
|
45
|
+
'Hebrew',
|
|
46
|
+
'Russian',
|
|
47
|
+
'Japanese',
|
|
48
|
+
'Portuguese (Brazil)',
|
|
49
|
+
'Dutch',
|
|
50
|
+
'Korean',
|
|
51
|
+
'Turkish',
|
|
52
|
+
'Indonesian',
|
|
53
|
+
'Chinese (Simplified)',
|
|
54
|
+
'Chinese (Traditional)',
|
|
55
|
+
'Arabic',
|
|
56
|
+
'Swedish',
|
|
57
|
+
],
|
|
58
|
+
mapping: {
|
|
59
|
+
'English (US)': enUS,
|
|
60
|
+
French: fr,
|
|
61
|
+
Spanish: es,
|
|
62
|
+
German: de,
|
|
63
|
+
Italian: it,
|
|
64
|
+
Hebrew: he,
|
|
65
|
+
Russian: ru,
|
|
66
|
+
Japanese: ja,
|
|
67
|
+
'Portuguese (Brazil)': ptBR,
|
|
68
|
+
Dutch: nl,
|
|
69
|
+
Korean: ko,
|
|
70
|
+
Turkish: tr,
|
|
71
|
+
Indonesian: id,
|
|
72
|
+
'Chinese (Simplified)': zhCN,
|
|
73
|
+
'Chinese (Traditional)': zhTW,
|
|
74
|
+
Arabic: ar,
|
|
75
|
+
Swedish: sv,
|
|
76
|
+
},
|
|
77
|
+
control: 'select',
|
|
78
|
+
},
|
|
79
|
+
timeZone: {
|
|
80
|
+
options: [
|
|
81
|
+
'Pacific/Honolulu',
|
|
82
|
+
'America/New_York',
|
|
83
|
+
'Europe/London',
|
|
84
|
+
'Asia/Tokyo',
|
|
85
|
+
'Pacific/Auckland',
|
|
86
|
+
],
|
|
87
|
+
control: 'select',
|
|
88
|
+
},
|
|
89
|
+
labels: {
|
|
90
|
+
control: false,
|
|
91
|
+
},
|
|
92
|
+
defaultSelected: { control: false },
|
|
93
|
+
selected: { control: false },
|
|
94
|
+
onSelect: {
|
|
95
|
+
control: false,
|
|
96
|
+
},
|
|
97
|
+
defaultMonth: { control: 'date' },
|
|
98
|
+
month: { control: 'date' },
|
|
99
|
+
onMonthChange: {
|
|
100
|
+
control: false,
|
|
101
|
+
},
|
|
102
|
+
endMonth: { control: 'date' },
|
|
103
|
+
startMonth: { control: 'date' },
|
|
104
|
+
},
|
|
105
|
+
args: {
|
|
106
|
+
onMonthChange: fn(),
|
|
107
|
+
onSelect: fn(),
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
export default meta;
|
|
111
|
+
|
|
112
|
+
type Story = StoryObj< typeof DateRangeCalendar >;
|
|
113
|
+
|
|
114
|
+
export const Default: Story = {};
|
|
115
|
+
|
|
116
|
+
export const DisabledDates: Story = {
|
|
117
|
+
args: {
|
|
118
|
+
disabled: [
|
|
119
|
+
// Disable tomorrow (single date)
|
|
120
|
+
new Date( new Date().setDate( new Date().getDate() + 1 ) ),
|
|
121
|
+
// Disable all dates after Feb 1st of next year
|
|
122
|
+
{ after: new Date( new Date().getFullYear() + 1, 1, 1 ) },
|
|
123
|
+
// Disable all dates before Dec 1st of last year
|
|
124
|
+
{ before: new Date( new Date().getFullYear() - 1, 11, 1 ) },
|
|
125
|
+
// Disable all dates between 12th and 14th of August of this year
|
|
126
|
+
{
|
|
127
|
+
after: new Date( new Date().getFullYear(), 7, 11 ),
|
|
128
|
+
before: new Date( new Date().getFullYear(), 7, 15 ),
|
|
129
|
+
},
|
|
130
|
+
// Disable all dates between 21st and 26th of October of this year
|
|
131
|
+
{
|
|
132
|
+
from: new Date( new Date().getFullYear(), 9, 21 ),
|
|
133
|
+
to: new Date( new Date().getFullYear(), 9, 26 ),
|
|
134
|
+
},
|
|
135
|
+
// Disable all Wednesdays
|
|
136
|
+
{ dayOfWeek: 3 },
|
|
137
|
+
// Disable all prime day numbers
|
|
138
|
+
function isPrimeDate( date: Date ) {
|
|
139
|
+
return [ 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31 ].includes(
|
|
140
|
+
date.getDate()
|
|
141
|
+
);
|
|
142
|
+
},
|
|
143
|
+
],
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
const nextMonth = new Date().getMonth() === 11 ? 0 : new Date().getMonth() + 1;
|
|
148
|
+
const nextMonthYear =
|
|
149
|
+
new Date().getMonth() === 11
|
|
150
|
+
? new Date().getFullYear() + 1
|
|
151
|
+
: new Date().getFullYear();
|
|
152
|
+
const firstDayOfNextMonth = new Date( nextMonthYear, nextMonth, 1 );
|
|
153
|
+
const fourthDayOfNextMonth = new Date( nextMonthYear, nextMonth, 4 );
|
|
154
|
+
export const WithSelectedRangeAndMonth: Story = {
|
|
155
|
+
args: {
|
|
156
|
+
defaultSelected: {
|
|
157
|
+
from: firstDayOfNextMonth,
|
|
158
|
+
to: fourthDayOfNextMonth,
|
|
159
|
+
},
|
|
160
|
+
defaultMonth: firstDayOfNextMonth,
|
|
161
|
+
},
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* When working with time zones, use the `TZDate` object exported by this package instead of the native `Date` object.
|
|
166
|
+
*/
|
|
167
|
+
export const WithTimeZone: Story = {
|
|
168
|
+
render: function DateCalendarWithTimeZone( args ) {
|
|
169
|
+
const [ range, setRange ] = useState< typeof args.selected | null >(
|
|
170
|
+
null
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
useEffect( () => {
|
|
174
|
+
setRange(
|
|
175
|
+
// Select from one week from today to two weeks from today
|
|
176
|
+
// every time the timezone changes.
|
|
177
|
+
{
|
|
178
|
+
from: new TZDate(
|
|
179
|
+
new Date().setDate( new Date().getDate() + 7 ),
|
|
180
|
+
args.timeZone
|
|
181
|
+
),
|
|
182
|
+
to: new TZDate(
|
|
183
|
+
new Date().setDate( new Date().getDate() + 14 ),
|
|
184
|
+
args.timeZone
|
|
185
|
+
),
|
|
186
|
+
}
|
|
187
|
+
);
|
|
188
|
+
}, [ args.timeZone ] );
|
|
189
|
+
|
|
190
|
+
return (
|
|
191
|
+
<>
|
|
192
|
+
<DateRangeCalendar
|
|
193
|
+
{ ...args }
|
|
194
|
+
selected={ range }
|
|
195
|
+
onSelect={ ( selectedDate, ...rest ) => {
|
|
196
|
+
setRange(
|
|
197
|
+
// Set controlled state to null if there's no selection
|
|
198
|
+
! selectedDate ||
|
|
199
|
+
( selectedDate.from === undefined &&
|
|
200
|
+
selectedDate.to === undefined )
|
|
201
|
+
? null
|
|
202
|
+
: selectedDate
|
|
203
|
+
);
|
|
204
|
+
args.onSelect?.( selectedDate, ...rest );
|
|
205
|
+
} }
|
|
206
|
+
disabled={ [
|
|
207
|
+
{
|
|
208
|
+
// Disable any date before today
|
|
209
|
+
before: new TZDate( new Date(), args.timeZone ),
|
|
210
|
+
},
|
|
211
|
+
] }
|
|
212
|
+
/>
|
|
213
|
+
<p>
|
|
214
|
+
Calendar set to { args.timeZone ?? 'current' } timezone,
|
|
215
|
+
disabling selection for all dates before today, and starting
|
|
216
|
+
with a default date range of 1 week from today to 2 weeks
|
|
217
|
+
from today.
|
|
218
|
+
</p>
|
|
219
|
+
</>
|
|
220
|
+
);
|
|
221
|
+
},
|
|
222
|
+
args: {
|
|
223
|
+
timeZone: 'Pacific/Auckland',
|
|
224
|
+
},
|
|
225
|
+
argTypes: {
|
|
226
|
+
disabled: {
|
|
227
|
+
control: false,
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
};
|