@wordpress/components 28.1.0 → 28.3.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 +179 -120
- package/build/animation/index.js.map +1 -1
- package/build/autocomplete/autocompleter-ui.js +1 -0
- package/build/autocomplete/autocompleter-ui.js.map +1 -1
- package/build/autocomplete/index.js.map +1 -1
- package/build/base-control/index.js +14 -7
- package/build/base-control/index.js.map +1 -1
- package/build/border-box-control/border-box-control-visualizer/component.js +0 -4
- package/build/border-box-control/border-box-control-visualizer/component.js.map +1 -1
- package/build/button/index.js +5 -3
- package/build/button/index.js.map +1 -1
- package/build/button/types.js.map +1 -1
- package/build/combobox-control/index.js +4 -1
- package/build/combobox-control/index.js.map +1 -1
- package/build/composite/current/index.js.map +1 -1
- package/build/custom-select-control-v2/custom-select.js +58 -36
- package/build/custom-select-control-v2/custom-select.js.map +1 -1
- package/build/custom-select-control-v2/default-component/index.js +0 -1
- package/build/custom-select-control-v2/default-component/index.js.map +1 -1
- package/build/custom-select-control-v2/item.js +2 -0
- package/build/custom-select-control-v2/item.js.map +1 -1
- package/build/custom-select-control-v2/legacy-component/index.js +33 -15
- package/build/custom-select-control-v2/legacy-component/index.js.map +1 -1
- package/build/custom-select-control-v2/styles.js +92 -65
- package/build/custom-select-control-v2/styles.js.map +1 -1
- package/build/custom-select-control-v2/types.js.map +1 -1
- package/build/date-time/date-time/index.js +3 -1
- package/build/date-time/date-time/index.js.map +1 -1
- package/build/date-time/index.js +7 -0
- package/build/date-time/index.js.map +1 -1
- package/build/date-time/time/index.js +62 -145
- package/build/date-time/time/index.js.map +1 -1
- package/build/date-time/time-input/index.js +159 -0
- package/build/date-time/time-input/index.js.map +1 -0
- package/build/date-time/types.js.map +1 -1
- package/build/date-time/utils.js +64 -0
- package/build/date-time/utils.js.map +1 -1
- package/build/disclosure/index.js +0 -1
- package/build/disclosure/index.js.map +1 -1
- package/build/divider/component.js +0 -1
- package/build/divider/component.js.map +1 -1
- package/build/divider/types.js.map +1 -1
- package/build/drop-zone/index.js +16 -79
- package/build/drop-zone/index.js.map +1 -1
- package/build/dropdown-menu/index.js +1 -0
- package/build/dropdown-menu/index.js.map +1 -1
- package/build/dropdown-menu-v2/index.js +0 -1
- package/build/dropdown-menu-v2/index.js.map +1 -1
- package/build/dropdown-menu-v2/styles.js +15 -16
- package/build/dropdown-menu-v2/styles.js.map +1 -1
- package/build/dropdown-menu-v2/types.js.map +1 -1
- package/build/font-size-picker/font-size-picker-select.js +2 -2
- package/build/font-size-picker/font-size-picker-select.js.map +1 -1
- package/build/font-size-picker/index.js +1 -1
- package/build/font-size-picker/index.js.map +1 -1
- package/build/font-size-picker/utils.js +0 -4
- package/build/font-size-picker/utils.js.map +1 -1
- package/build/form-token-field/token.js +4 -1
- package/build/form-token-field/token.js.map +1 -1
- package/build/higher-order/with-spoken-messages/index.js +1 -2
- package/build/higher-order/with-spoken-messages/index.js.map +1 -1
- package/build/lock-unlock.js +1 -1
- package/build/lock-unlock.js.map +1 -1
- package/build/menu-items-choice/types.js.map +1 -1
- package/build/palette-edit/index.js +30 -38
- package/build/palette-edit/index.js.map +1 -1
- package/build/palette-edit/types.js.map +1 -1
- package/build/popover/index.js +0 -4
- package/build/popover/index.js.map +1 -1
- package/build/popover/utils.js +0 -1
- package/build/popover/utils.js.map +1 -1
- package/build/private-apis.js +2 -4
- package/build/private-apis.js.map +1 -1
- package/build/progress-bar/styles.js +19 -13
- package/build/progress-bar/styles.js.map +1 -1
- package/build/radio-group/context.js +0 -1
- package/build/radio-group/context.js.map +1 -1
- package/build/radio-group/index.js +0 -1
- package/build/radio-group/index.js.map +1 -1
- package/build/radio-group/radio.js +0 -1
- package/build/radio-group/radio.js.map +1 -1
- package/build/range-control/index.js +4 -1
- package/build/range-control/index.js.map +1 -1
- package/build/range-control/styles/range-control-styles.js +34 -28
- package/build/range-control/styles/range-control-styles.js.map +1 -1
- package/build/resizable-box/resize-tooltip/utils.js.map +1 -1
- package/build/select-control/index.js +1 -2
- package/build/select-control/index.js.map +1 -1
- package/build/select-control/styles/select-control-styles.js +13 -8
- package/build/select-control/styles/select-control-styles.js.map +1 -1
- package/build/tab-panel/index.js +0 -1
- package/build/tab-panel/index.js.map +1 -1
- package/build/tabs/index.js +0 -1
- package/build/tabs/index.js.map +1 -1
- package/build/tabs/styles.js +3 -5
- package/build/tabs/styles.js.map +1 -1
- package/build/tabs/tablist.js +148 -37
- package/build/tabs/tablist.js.map +1 -1
- package/build/tabs/types.js.map +1 -1
- package/build/toggle-group-control/toggle-group-control/as-radio-group.js +0 -2
- package/build/toggle-group-control/toggle-group-control/as-radio-group.js.map +1 -1
- package/build/toggle-group-control/toggle-group-control/component.js +0 -2
- package/build/toggle-group-control/toggle-group-control/component.js.map +1 -1
- package/build/toggle-group-control/toggle-group-control-option-base/component.js +0 -4
- package/build/toggle-group-control/toggle-group-control-option-base/component.js.map +1 -1
- package/build/toolbar/toolbar/toolbar-container.js +0 -1
- package/build/toolbar/toolbar/toolbar-container.js.map +1 -1
- package/build/toolbar/toolbar/types.js.map +1 -1
- package/build/toolbar/toolbar-button/index.js +27 -19
- package/build/toolbar/toolbar-button/index.js.map +1 -1
- package/build/toolbar/toolbar-button/types.js.map +1 -1
- package/build/toolbar/toolbar-context/index.js +0 -1
- package/build/toolbar/toolbar-context/index.js.map +1 -1
- package/build/toolbar/toolbar-item/index.js +1 -1
- package/build/toolbar/toolbar-item/index.js.map +1 -1
- package/build/tooltip/index.js +3 -2
- package/build/tooltip/index.js.map +1 -1
- package/build/tooltip/types.js.map +1 -1
- package/build/unit-control/index.js +3 -3
- package/build/unit-control/index.js.map +1 -1
- package/build/unit-control/styles/unit-control-styles.js +7 -7
- package/build/unit-control/styles/unit-control-styles.js.map +1 -1
- package/build/utils/hooks/use-update-effect.js +4 -1
- package/build/utils/hooks/use-update-effect.js.map +1 -1
- package/build-module/animation/index.js +0 -1
- package/build-module/animation/index.js.map +1 -1
- package/build-module/autocomplete/autocompleter-ui.js +1 -0
- package/build-module/autocomplete/autocompleter-ui.js.map +1 -1
- package/build-module/autocomplete/index.js.map +1 -1
- package/build-module/base-control/index.js +13 -6
- package/build-module/base-control/index.js.map +1 -1
- package/build-module/border-box-control/border-box-control-visualizer/component.js +0 -4
- package/build-module/border-box-control/border-box-control-visualizer/component.js.map +1 -1
- package/build-module/button/index.js +5 -3
- package/build-module/button/index.js.map +1 -1
- package/build-module/button/types.js.map +1 -1
- package/build-module/combobox-control/index.js +4 -1
- package/build-module/combobox-control/index.js.map +1 -1
- package/build-module/composite/current/index.js +0 -3
- package/build-module/composite/current/index.js.map +1 -1
- package/build-module/custom-select-control-v2/custom-select.js +59 -38
- package/build-module/custom-select-control-v2/custom-select.js.map +1 -1
- package/build-module/custom-select-control-v2/default-component/index.js +0 -1
- package/build-module/custom-select-control-v2/default-component/index.js.map +1 -1
- package/build-module/custom-select-control-v2/item.js +2 -0
- package/build-module/custom-select-control-v2/item.js.map +1 -1
- package/build-module/custom-select-control-v2/legacy-component/index.js +33 -16
- package/build-module/custom-select-control-v2/legacy-component/index.js.map +1 -1
- package/build-module/custom-select-control-v2/styles.js +90 -63
- package/build-module/custom-select-control-v2/styles.js.map +1 -1
- package/build-module/custom-select-control-v2/types.js.map +1 -1
- package/build-module/date-time/date-time/index.js +4 -1
- package/build-module/date-time/date-time/index.js.map +1 -1
- package/build-module/date-time/index.js +2 -1
- package/build-module/date-time/index.js.map +1 -1
- package/build-module/date-time/time/index.js +65 -149
- package/build-module/date-time/time/index.js.map +1 -1
- package/build-module/date-time/time-input/index.js +151 -0
- package/build-module/date-time/time-input/index.js.map +1 -0
- package/build-module/date-time/types.js.map +1 -1
- package/build-module/date-time/utils.js +61 -0
- package/build-module/date-time/utils.js.map +1 -1
- package/build-module/disclosure/index.js +0 -1
- package/build-module/disclosure/index.js.map +1 -1
- package/build-module/divider/component.js +0 -1
- package/build-module/divider/component.js.map +1 -1
- package/build-module/divider/types.js.map +1 -1
- package/build-module/drop-zone/index.js +17 -80
- package/build-module/drop-zone/index.js.map +1 -1
- package/build-module/dropdown-menu/index.js +1 -0
- package/build-module/dropdown-menu/index.js.map +1 -1
- package/build-module/dropdown-menu-v2/index.js +0 -1
- package/build-module/dropdown-menu-v2/index.js.map +1 -1
- package/build-module/dropdown-menu-v2/styles.js +14 -15
- package/build-module/dropdown-menu-v2/styles.js.map +1 -1
- package/build-module/dropdown-menu-v2/types.js.map +1 -1
- package/build-module/font-size-picker/font-size-picker-select.js +1 -1
- package/build-module/font-size-picker/font-size-picker-select.js.map +1 -1
- package/build-module/font-size-picker/index.js +1 -1
- package/build-module/font-size-picker/index.js.map +1 -1
- package/build-module/font-size-picker/utils.js +0 -4
- package/build-module/font-size-picker/utils.js.map +1 -1
- package/build-module/form-token-field/token.js +4 -1
- package/build-module/form-token-field/token.js.map +1 -1
- package/build-module/higher-order/with-spoken-messages/index.js +1 -2
- package/build-module/higher-order/with-spoken-messages/index.js.map +1 -1
- package/build-module/lock-unlock.js +1 -1
- package/build-module/lock-unlock.js.map +1 -1
- package/build-module/menu-items-choice/types.js.map +1 -1
- package/build-module/palette-edit/index.js +31 -39
- package/build-module/palette-edit/index.js.map +1 -1
- package/build-module/palette-edit/types.js.map +1 -1
- package/build-module/popover/index.js +0 -3
- package/build-module/popover/index.js.map +1 -1
- package/build-module/popover/utils.js +0 -1
- package/build-module/popover/utils.js.map +1 -1
- package/build-module/private-apis.js +2 -4
- package/build-module/private-apis.js.map +1 -1
- package/build-module/progress-bar/styles.js +21 -13
- package/build-module/progress-bar/styles.js.map +1 -1
- package/build-module/radio-group/context.js +0 -1
- package/build-module/radio-group/context.js.map +1 -1
- package/build-module/radio-group/index.js +0 -1
- package/build-module/radio-group/index.js.map +1 -1
- package/build-module/radio-group/radio.js +0 -1
- package/build-module/radio-group/radio.js.map +1 -1
- package/build-module/range-control/index.js +4 -1
- package/build-module/range-control/index.js.map +1 -1
- package/build-module/range-control/styles/range-control-styles.js +34 -28
- package/build-module/range-control/styles/range-control-styles.js.map +1 -1
- package/build-module/resizable-box/resize-tooltip/utils.js.map +1 -1
- package/build-module/select-control/index.js +2 -3
- package/build-module/select-control/index.js.map +1 -1
- package/build-module/select-control/styles/select-control-styles.js +12 -7
- package/build-module/select-control/styles/select-control-styles.js.map +1 -1
- package/build-module/tab-panel/index.js +0 -1
- package/build-module/tab-panel/index.js.map +1 -1
- package/build-module/tabs/index.js +0 -1
- package/build-module/tabs/index.js.map +1 -1
- package/build-module/tabs/styles.js +3 -4
- package/build-module/tabs/styles.js.map +1 -1
- package/build-module/tabs/tablist.js +149 -38
- package/build-module/tabs/tablist.js.map +1 -1
- package/build-module/tabs/types.js.map +1 -1
- package/build-module/toggle-group-control/toggle-group-control/as-radio-group.js +0 -1
- package/build-module/toggle-group-control/toggle-group-control/as-radio-group.js.map +1 -1
- package/build-module/toggle-group-control/toggle-group-control/component.js +0 -1
- package/build-module/toggle-group-control/toggle-group-control/component.js.map +1 -1
- package/build-module/toggle-group-control/toggle-group-control-option-base/component.js +0 -2
- package/build-module/toggle-group-control/toggle-group-control-option-base/component.js.map +1 -1
- package/build-module/toolbar/toolbar/toolbar-container.js +0 -1
- package/build-module/toolbar/toolbar/toolbar-container.js.map +1 -1
- package/build-module/toolbar/toolbar/types.js.map +1 -1
- package/build-module/toolbar/toolbar-button/index.js +27 -19
- package/build-module/toolbar/toolbar-button/index.js.map +1 -1
- package/build-module/toolbar/toolbar-button/types.js.map +1 -1
- package/build-module/toolbar/toolbar-context/index.js +0 -1
- package/build-module/toolbar/toolbar-context/index.js.map +1 -1
- package/build-module/toolbar/toolbar-item/index.js +1 -1
- package/build-module/toolbar/toolbar-item/index.js.map +1 -1
- package/build-module/tooltip/index.js +3 -2
- package/build-module/tooltip/index.js.map +1 -1
- package/build-module/tooltip/types.js.map +1 -1
- package/build-module/unit-control/index.js +3 -3
- package/build-module/unit-control/index.js.map +1 -1
- package/build-module/unit-control/styles/unit-control-styles.js +7 -7
- package/build-module/unit-control/styles/unit-control-styles.js.map +1 -1
- package/build-module/utils/hooks/use-update-effect.js +4 -1
- package/build-module/utils/hooks/use-update-effect.js.map +1 -1
- package/build-style/style-rtl.css +46 -6
- package/build-style/style.css +46 -6
- package/build-types/animation/index.d.ts.map +1 -1
- package/build-types/autocomplete/autocompleter-ui.d.ts.map +1 -1
- package/build-types/autocomplete/index.d.ts.map +1 -1
- package/build-types/base-control/index.d.ts +6 -20
- package/build-types/base-control/index.d.ts.map +1 -1
- package/build-types/base-control/stories/index.story.d.ts.map +1 -1
- package/build-types/border-box-control/border-box-control-visualizer/component.d.ts.map +1 -1
- package/build-types/button/deprecated.d.ts +4 -4
- package/build-types/button/index.d.ts.map +1 -1
- package/build-types/button/stories/e2e/index.story.d.ts.map +1 -1
- package/build-types/button/types.d.ts +27 -10
- package/build-types/button/types.d.ts.map +1 -1
- package/build-types/combobox-control/index.d.ts.map +1 -1
- package/build-types/composite/current/index.d.ts.map +1 -1
- package/build-types/custom-select-control/stories/index.story.d.ts +15 -0
- package/build-types/custom-select-control/stories/index.story.d.ts.map +1 -1
- package/build-types/custom-select-control-v2/custom-select.d.ts +2 -2
- package/build-types/custom-select-control-v2/custom-select.d.ts.map +1 -1
- package/build-types/custom-select-control-v2/default-component/index.d.ts.map +1 -1
- package/build-types/custom-select-control-v2/item.d.ts.map +1 -1
- package/build-types/custom-select-control-v2/legacy-component/index.d.ts.map +1 -1
- package/build-types/custom-select-control-v2/stories/default.story.d.ts +6 -3
- package/build-types/custom-select-control-v2/stories/default.story.d.ts.map +1 -1
- package/build-types/custom-select-control-v2/styles.d.ts +18 -22
- package/build-types/custom-select-control-v2/styles.d.ts.map +1 -1
- package/build-types/custom-select-control-v2/types.d.ts +13 -2
- package/build-types/custom-select-control-v2/types.d.ts.map +1 -1
- package/build-types/date-time/date-time/index.d.ts.map +1 -1
- package/build-types/date-time/index.d.ts +2 -1
- package/build-types/date-time/index.d.ts.map +1 -1
- package/build-types/date-time/stories/time-input.story.d.ts +12 -0
- package/build-types/date-time/stories/time-input.story.d.ts.map +1 -0
- package/build-types/date-time/time/index.d.ts +1 -1
- package/build-types/date-time/time/index.d.ts.map +1 -1
- package/build-types/date-time/time-input/index.d.ts +5 -0
- package/build-types/date-time/time-input/index.d.ts.map +1 -0
- package/build-types/date-time/time-input/test/index.d.ts +2 -0
- package/build-types/date-time/time-input/test/index.d.ts.map +1 -0
- package/build-types/date-time/types.d.ts +54 -0
- package/build-types/date-time/types.d.ts.map +1 -1
- package/build-types/date-time/utils.d.ts +40 -0
- package/build-types/date-time/utils.d.ts.map +1 -1
- package/build-types/disclosure/index.d.ts.map +1 -1
- package/build-types/divider/component.d.ts.map +1 -1
- package/build-types/divider/types.d.ts.map +1 -1
- package/build-types/drop-zone/index.d.ts +3 -0
- package/build-types/drop-zone/index.d.ts.map +1 -1
- package/build-types/dropdown-menu/index.d.ts.map +1 -1
- package/build-types/dropdown-menu-v2/index.d.ts.map +1 -1
- package/build-types/dropdown-menu-v2/styles.d.ts.map +1 -1
- package/build-types/dropdown-menu-v2/types.d.ts.map +1 -1
- package/build-types/font-size-picker/styles.d.ts +1 -1
- package/build-types/font-size-picker/utils.d.ts.map +1 -1
- package/build-types/form-token-field/token.d.ts.map +1 -1
- package/build-types/higher-order/with-spoken-messages/index.d.ts +1 -2
- package/build-types/higher-order/with-spoken-messages/index.d.ts.map +1 -1
- package/build-types/menu-items-choice/types.d.ts +1 -1
- package/build-types/menu-items-choice/types.d.ts.map +1 -1
- package/build-types/navigator/navigator-back-button/component.d.ts +1 -1
- package/build-types/navigator/navigator-back-button/hook.d.ts +1 -1
- package/build-types/navigator/navigator-button/component.d.ts +1 -1
- package/build-types/navigator/navigator-button/hook.d.ts +1 -1
- package/build-types/navigator/navigator-to-parent-button/component.d.ts +1 -1
- package/build-types/palette-edit/index.d.ts.map +1 -1
- package/build-types/palette-edit/types.d.ts +1 -3
- package/build-types/palette-edit/types.d.ts.map +1 -1
- package/build-types/popover/index.d.ts.map +1 -1
- package/build-types/popover/utils.d.ts.map +1 -1
- package/build-types/private-apis.d.ts.map +1 -1
- package/build-types/progress-bar/styles.d.ts.map +1 -1
- package/build-types/radio-group/context.d.ts.map +1 -1
- package/build-types/radio-group/index.d.ts.map +1 -1
- package/build-types/radio-group/radio.d.ts.map +1 -1
- package/build-types/range-control/index.d.ts.map +1 -1
- package/build-types/range-control/styles/range-control-styles.d.ts.map +1 -1
- package/build-types/resizable-box/resize-tooltip/utils.d.ts +2 -2
- package/build-types/resizable-box/resize-tooltip/utils.d.ts.map +1 -1
- package/build-types/select-control/index.d.ts.map +1 -1
- package/build-types/select-control/styles/select-control-styles.d.ts +5 -0
- package/build-types/select-control/styles/select-control-styles.d.ts.map +1 -1
- package/build-types/tab-panel/index.d.ts.map +1 -1
- package/build-types/tabs/index.d.ts.map +1 -1
- package/build-types/tabs/stories/index.story.d.ts.map +1 -1
- package/build-types/tabs/styles.d.ts.map +1 -1
- package/build-types/tabs/tablist.d.ts.map +1 -1
- package/build-types/tabs/types.d.ts.map +1 -1
- package/build-types/theme/stories/index.story.d.ts.map +1 -1
- package/build-types/toggle-group-control/toggle-group-control/as-radio-group.d.ts.map +1 -1
- package/build-types/toggle-group-control/toggle-group-control/component.d.ts.map +1 -1
- package/build-types/toggle-group-control/toggle-group-control-option-base/component.d.ts.map +1 -1
- package/build-types/toolbar/toolbar/toolbar-container.d.ts.map +1 -1
- package/build-types/toolbar/toolbar/types.d.ts +6 -0
- package/build-types/toolbar/toolbar/types.d.ts.map +1 -1
- package/build-types/toolbar/toolbar-button/index.d.ts +3 -96
- package/build-types/toolbar/toolbar-button/index.d.ts.map +1 -1
- package/build-types/toolbar/toolbar-button/types.d.ts +18 -0
- package/build-types/toolbar/toolbar-button/types.d.ts.map +1 -1
- package/build-types/toolbar/toolbar-context/index.d.ts.map +1 -1
- package/build-types/toolbar/toolbar-item/index.d.ts +1 -3
- package/build-types/toolbar/toolbar-item/index.d.ts.map +1 -1
- package/build-types/tooltip/index.d.ts.map +1 -1
- package/build-types/tooltip/types.d.ts +4 -0
- package/build-types/tooltip/types.d.ts.map +1 -1
- package/build-types/unit-control/index.d.ts.map +1 -1
- package/build-types/unit-control/styles/unit-control-styles.d.ts.map +1 -1
- package/build-types/utils/hooks/use-update-effect.d.ts +1 -1
- package/build-types/utils/hooks/use-update-effect.d.ts.map +1 -1
- package/package.json +19 -19
- package/src/animation/index.tsx +0 -1
- package/src/autocomplete/autocompleter-ui.tsx +1 -0
- package/src/autocomplete/index.tsx +0 -1
- package/src/base-control/index.tsx +16 -6
- package/src/base-control/stories/index.story.tsx +0 -1
- package/src/border-box-control/border-box-control-visualizer/component.tsx +0 -5
- package/src/button/README.md +13 -0
- package/src/button/index.tsx +6 -4
- package/src/button/stories/e2e/index.story.tsx +2 -1
- package/src/button/test/index.tsx +17 -2
- package/src/button/types.ts +27 -10
- package/src/combobox-control/index.tsx +2 -0
- package/src/composite/current/index.ts +0 -2
- package/src/custom-select-control/stories/index.story.tsx +32 -3
- package/src/custom-select-control/test/index.js +247 -28
- package/src/custom-select-control-v2/custom-select.tsx +58 -23
- package/src/custom-select-control-v2/default-component/index.tsx +0 -1
- package/src/custom-select-control-v2/item.tsx +5 -1
- package/src/custom-select-control-v2/legacy-component/index.tsx +45 -16
- package/src/custom-select-control-v2/legacy-component/test/index.tsx +261 -43
- package/src/custom-select-control-v2/styles.ts +156 -74
- package/src/custom-select-control-v2/test/index.tsx +35 -5
- package/src/custom-select-control-v2/types.ts +19 -6
- package/src/date-time/README.md +8 -0
- package/src/date-time/date-time/index.tsx +2 -1
- package/src/date-time/index.ts +2 -1
- package/src/date-time/stories/time-input.story.tsx +36 -0
- package/src/date-time/time/index.tsx +77 -194
- package/src/date-time/time/test/index.tsx +61 -0
- package/src/date-time/time-input/index.tsx +196 -0
- package/src/date-time/time-input/test/index.tsx +171 -0
- package/src/date-time/types.ts +63 -0
- package/src/date-time/utils.ts +69 -0
- package/src/dimension-control/test/__snapshots__/index.test.js.snap +116 -96
- package/src/disclosure/index.tsx +0 -1
- package/src/divider/component.tsx +0 -1
- package/src/divider/types.ts +0 -1
- package/src/drop-zone/index.tsx +17 -76
- package/src/drop-zone/style.scss +51 -16
- package/src/dropdown-menu/index.tsx +1 -0
- package/src/dropdown-menu-v2/index.tsx +0 -1
- package/src/dropdown-menu-v2/styles.ts +0 -1
- package/src/dropdown-menu-v2/types.ts +0 -1
- package/src/font-size-picker/font-size-picker-select.tsx +1 -1
- package/src/font-size-picker/index.tsx +1 -1
- package/src/font-size-picker/test/index.tsx +6 -6
- package/src/font-size-picker/utils.ts +0 -5
- package/src/form-token-field/token.tsx +2 -0
- package/src/higher-order/navigate-regions/style.scss +25 -13
- package/src/higher-order/with-spoken-messages/index.tsx +1 -2
- package/src/lock-unlock.js +1 -1
- package/src/menu-items-choice/types.ts +2 -1
- package/src/palette-edit/index.tsx +33 -45
- package/src/palette-edit/test/index.tsx +3 -4
- package/src/palette-edit/types.ts +1 -3
- package/src/popover/index.tsx +0 -2
- package/src/popover/utils.ts +0 -1
- package/src/private-apis.ts +2 -5
- package/src/progress-bar/styles.ts +18 -9
- package/src/radio-group/context.tsx +0 -1
- package/src/radio-group/index.tsx +0 -1
- package/src/radio-group/radio.tsx +0 -1
- package/src/range-control/index.tsx +2 -0
- package/src/range-control/styles/range-control-styles.ts +6 -2
- package/src/resizable-box/resize-tooltip/utils.ts +1 -1
- package/src/select-control/index.tsx +3 -4
- package/src/select-control/styles/select-control-styles.ts +17 -6
- package/src/tab-panel/index.tsx +0 -1
- package/src/tabs/index.tsx +0 -1
- package/src/tabs/stories/index.story.tsx +25 -18
- package/src/tabs/styles.ts +18 -14
- package/src/tabs/tablist.tsx +187 -43
- package/src/tabs/types.ts +0 -1
- package/src/theme/stories/index.story.tsx +2 -0
- package/src/toggle-group-control/toggle-group-control/as-radio-group.tsx +0 -1
- package/src/toggle-group-control/toggle-group-control/component.tsx +0 -2
- package/src/toggle-group-control/toggle-group-control-option-base/component.tsx +0 -2
- package/src/toolbar/toolbar/README.md +9 -0
- package/src/toolbar/toolbar/style.scss +7 -0
- package/src/toolbar/toolbar/toolbar-container.tsx +0 -1
- package/src/toolbar/toolbar/types.ts +6 -0
- package/src/toolbar/toolbar-button/index.tsx +30 -17
- package/src/toolbar/toolbar-button/types.ts +19 -0
- package/src/toolbar/toolbar-context/index.ts +0 -1
- package/src/toolbar/toolbar-item/index.tsx +1 -1
- package/src/tooltip/index.tsx +3 -2
- package/src/tooltip/test/index.tsx +18 -0
- package/src/tooltip/types.ts +4 -0
- package/src/unit-control/index.tsx +3 -2
- package/src/unit-control/styles/unit-control-styles.ts +10 -4
- package/src/utils/hooks/use-update-effect.js +8 -1
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["forwardRef","default","DatePicker","TimePicker","Wrapper","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","noop","UnforwardedDateTimePicker","currentDate","is12Hour","isInvalidDate","onMonthPreviewed","onChange","events","startOfWeek","ref","className","spacing","children","currentTime","DateTimePicker"],"sources":["@wordpress/components/src/date-time/date-time/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ForwardedRef } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { forwardRef } from '@wordpress/element';\
|
|
1
|
+
{"version":3,"names":["forwardRef","default","DatePicker","TimePicker","Wrapper","jsx","_jsx","Fragment","_Fragment","jsxs","_jsxs","noop","UnforwardedDateTimePicker","currentDate","is12Hour","dateOrder","isInvalidDate","onMonthPreviewed","onChange","events","startOfWeek","ref","className","spacing","children","currentTime","DateTimePicker"],"sources":["@wordpress/components/src/date-time/date-time/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ForwardedRef } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { forwardRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { default as DatePicker } from '../date';\nimport { default as TimePicker } from '../time';\nimport type { DateTimePickerProps } from '../types';\nimport { Wrapper } from './styles';\n\nexport { DatePicker, TimePicker };\n\nconst noop = () => {};\n\nfunction UnforwardedDateTimePicker(\n\t{\n\t\tcurrentDate,\n\t\tis12Hour,\n\t\tdateOrder,\n\t\tisInvalidDate,\n\t\tonMonthPreviewed = noop,\n\t\tonChange,\n\t\tevents,\n\t\tstartOfWeek,\n\t}: DateTimePickerProps,\n\tref: ForwardedRef< any >\n) {\n\treturn (\n\t\t<Wrapper ref={ ref } className=\"components-datetime\" spacing={ 4 }>\n\t\t\t<>\n\t\t\t\t<TimePicker\n\t\t\t\t\tcurrentTime={ currentDate }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\tis12Hour={ is12Hour }\n\t\t\t\t\tdateOrder={ dateOrder }\n\t\t\t\t/>\n\t\t\t\t<DatePicker\n\t\t\t\t\tcurrentDate={ currentDate }\n\t\t\t\t\tonChange={ onChange }\n\t\t\t\t\tisInvalidDate={ isInvalidDate }\n\t\t\t\t\tevents={ events }\n\t\t\t\t\tonMonthPreviewed={ onMonthPreviewed }\n\t\t\t\t\tstartOfWeek={ startOfWeek }\n\t\t\t\t/>\n\t\t\t</>\n\t\t</Wrapper>\n\t);\n}\n\n/**\n * DateTimePicker is a React component that renders a calendar and clock for\n * date and time selection. The calendar and clock components can be accessed\n * individually using the `DatePicker` and `TimePicker` components respectively.\n *\n * ```jsx\n * import { DateTimePicker } from '@wordpress/components';\n * import { useState } from '@wordpress/element';\n *\n * const MyDateTimePicker = () => {\n * const [ date, setDate ] = useState( new Date() );\n *\n * return (\n * <DateTimePicker\n * currentDate={ date }\n * onChange={ ( newDate ) => setDate( newDate ) }\n * is12Hour\n * />\n * );\n * };\n * ```\n */\nexport const DateTimePicker = forwardRef( UnforwardedDateTimePicker );\n\nexport default DateTimePicker;\n"],"mappings":"AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,SAASA,UAAU,QAAQ,oBAAoB;;AAE/C;AACA;AACA;AACA,SAASC,OAAO,IAAIC,UAAU,QAAQ,SAAS;AAC/C,SAASD,OAAO,IAAIE,UAAU,QA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default as TimePicker } from './time';
|
|
6
|
+
import { default as TimeInput } from './time-input';
|
|
6
7
|
import { default as DateTimePicker } from './date-time';
|
|
7
|
-
export { DatePicker, TimePicker };
|
|
8
|
+
export { DatePicker, TimePicker, TimeInput };
|
|
8
9
|
export default DateTimePicker;
|
|
9
10
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["default","DatePicker","TimePicker","DateTimePicker"],"sources":["@wordpress/components/src/date-time/index.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { default as DatePicker } from './date';\nimport { default as TimePicker } from './time';\nimport { default as DateTimePicker } from './date-time';\n\nexport { DatePicker, TimePicker };\nexport default DateTimePicker;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAO,IAAIC,UAAU,QAAQ,QAAQ;AAC9C,SAASD,OAAO,IAAIE,UAAU,QAAQ,QAAQ;AAC9C,SAASF,OAAO,IAAIG,cAAc,QAAQ,aAAa;AAEvD,
|
|
1
|
+
{"version":3,"names":["default","DatePicker","TimePicker","TimeInput","DateTimePicker"],"sources":["@wordpress/components/src/date-time/index.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { default as DatePicker } from './date';\nimport { default as TimePicker } from './time';\nimport { default as TimeInput } from './time-input';\nimport { default as DateTimePicker } from './date-time';\n\nexport { DatePicker, TimePicker, TimeInput };\nexport default DateTimePicker;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAO,IAAIC,UAAU,QAAQ,QAAQ;AAC9C,SAASD,OAAO,IAAIE,UAAU,QAAQ,QAAQ;AAC9C,SAASF,OAAO,IAAIG,SAAS,QAAQ,cAAc;AACnD,SAASH,OAAO,IAAII,cAAc,QAAQ,aAAa;AAEvD,SAASH,UAAU,EAAEC,UAAU,EAAEC,SAAS;AAC1C,eAAeC,cAAc","ignoreList":[]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* External dependencies
|
|
3
3
|
*/
|
|
4
|
-
import { startOfMinute, format, set,
|
|
4
|
+
import { startOfMinute, format, set, setMonth } from 'date-fns';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* WordPress dependencies
|
|
@@ -13,43 +13,17 @@ import { __ } from '@wordpress/i18n';
|
|
|
13
13
|
* Internal dependencies
|
|
14
14
|
*/
|
|
15
15
|
import BaseControl from '../../base-control';
|
|
16
|
-
import Button from '../../button';
|
|
17
|
-
import ButtonGroup from '../../button-group';
|
|
18
16
|
import SelectControl from '../../select-control';
|
|
19
17
|
import TimeZone from './timezone';
|
|
20
|
-
import { Wrapper, Fieldset,
|
|
18
|
+
import { Wrapper, Fieldset, MonthSelectWrapper, DayInput, YearInput } from './styles';
|
|
21
19
|
import { HStack } from '../../h-stack';
|
|
22
20
|
import { Spacer } from '../../spacer';
|
|
23
|
-
import {
|
|
24
|
-
import { inputToDate } from '../utils';
|
|
21
|
+
import { inputToDate, buildPadInputStateReducer, validateInputElementTarget } from '../utils';
|
|
25
22
|
import { TIMEZONELESS_FORMAT } from '../constants';
|
|
23
|
+
import { TimeInput } from '../time-input';
|
|
26
24
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
27
25
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
28
|
-
|
|
29
|
-
function from12hTo24h(hours, isPm) {
|
|
30
|
-
return isPm ? (hours % 12 + 12) % 24 : hours % 12;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Creates an InputControl reducer used to pad an input so that it is always a
|
|
35
|
-
* given width. For example, the hours and minutes inputs are padded to 2 so
|
|
36
|
-
* that '4' appears as '04'.
|
|
37
|
-
*
|
|
38
|
-
* @param pad How many digits the value should be.
|
|
39
|
-
*/
|
|
40
|
-
function buildPadInputStateReducer(pad) {
|
|
41
|
-
return (state, action) => {
|
|
42
|
-
const nextState = {
|
|
43
|
-
...state
|
|
44
|
-
};
|
|
45
|
-
if (action.type === COMMIT || action.type === PRESS_UP || action.type === PRESS_DOWN) {
|
|
46
|
-
if (nextState.value !== undefined) {
|
|
47
|
-
nextState.value = nextState.value.toString().padStart(pad, '0');
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return nextState;
|
|
51
|
-
};
|
|
52
|
-
}
|
|
26
|
+
const VALID_DATE_ORDERS = ['dmy', 'mdy', 'ymd'];
|
|
53
27
|
|
|
54
28
|
/**
|
|
55
29
|
* TimePicker is a React component that renders a clock for time selection.
|
|
@@ -74,7 +48,8 @@ function buildPadInputStateReducer(pad) {
|
|
|
74
48
|
export function TimePicker({
|
|
75
49
|
is12Hour,
|
|
76
50
|
currentTime,
|
|
77
|
-
onChange
|
|
51
|
+
onChange,
|
|
52
|
+
dateOrder: dateOrderProp
|
|
78
53
|
}) {
|
|
79
54
|
const [date, setDate] = useState(() =>
|
|
80
55
|
// Truncate the date at the minutes, see: #15495.
|
|
@@ -90,41 +65,25 @@ export function TimePicker({
|
|
|
90
65
|
month,
|
|
91
66
|
year,
|
|
92
67
|
minutes,
|
|
93
|
-
hours
|
|
94
|
-
am
|
|
68
|
+
hours
|
|
95
69
|
} = useMemo(() => ({
|
|
96
70
|
day: format(date, 'dd'),
|
|
97
71
|
month: format(date, 'MM'),
|
|
98
72
|
year: format(date, 'yyyy'),
|
|
99
73
|
minutes: format(date, 'mm'),
|
|
100
|
-
hours: format(date,
|
|
74
|
+
hours: format(date, 'HH'),
|
|
101
75
|
am: format(date, 'a')
|
|
102
|
-
}), [date
|
|
76
|
+
}), [date]);
|
|
103
77
|
const buildNumberControlChangeCallback = method => {
|
|
104
78
|
const callback = (value, {
|
|
105
79
|
event
|
|
106
80
|
}) => {
|
|
107
|
-
|
|
108
|
-
// `instanceof` checks need to get the instance definition from the
|
|
109
|
-
// corresponding window object — therefore, the following logic makes
|
|
110
|
-
// the component work correctly even when rendered inside an iframe.
|
|
111
|
-
const HTMLInputElementInstance = (_ownerDocument$defaul = event.target?.ownerDocument.defaultView?.HTMLInputElement) !== null && _ownerDocument$defaul !== void 0 ? _ownerDocument$defaul : HTMLInputElement;
|
|
112
|
-
if (!(event.target instanceof HTMLInputElementInstance)) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
if (!event.target.validity.valid) {
|
|
81
|
+
if (!validateInputElementTarget(event)) {
|
|
116
82
|
return;
|
|
117
83
|
}
|
|
118
84
|
|
|
119
85
|
// We can safely assume value is a number if target is valid.
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
// If the 12-hour format is being used and the 'PM' period is
|
|
123
|
-
// selected, then the incoming value (which ranges 1-12) should be
|
|
124
|
-
// increased by 12 to match the expected 24-hour format.
|
|
125
|
-
if (method === 'hours' && is12Hour) {
|
|
126
|
-
numberValue = from12hTo24h(numberValue, am === 'PM');
|
|
127
|
-
}
|
|
86
|
+
const numberValue = Number(value);
|
|
128
87
|
const newDate = set(date, {
|
|
129
88
|
[method]: numberValue
|
|
130
89
|
});
|
|
@@ -133,17 +92,17 @@ export function TimePicker({
|
|
|
133
92
|
};
|
|
134
93
|
return callback;
|
|
135
94
|
};
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
95
|
+
const onTimeInputChangeCallback = ({
|
|
96
|
+
hours: newHours,
|
|
97
|
+
minutes: newMinutes
|
|
98
|
+
}) => {
|
|
99
|
+
const newDate = set(date, {
|
|
100
|
+
hours: newHours,
|
|
101
|
+
minutes: newMinutes
|
|
102
|
+
});
|
|
103
|
+
setDate(newDate);
|
|
104
|
+
onChange?.(format(newDate, TIMEZONELESS_FORMAT));
|
|
105
|
+
};
|
|
147
106
|
const dayField = /*#__PURE__*/_jsx(DayInput, {
|
|
148
107
|
className: "components-datetime__time-field components-datetime__time-field-day" // Unused, for backwards compatibility.
|
|
149
108
|
,
|
|
@@ -160,7 +119,7 @@ export function TimePicker({
|
|
|
160
119
|
isDragEnabled: false,
|
|
161
120
|
isShiftStepEnabled: false,
|
|
162
121
|
onChange: buildNumberControlChangeCallback('date')
|
|
163
|
-
});
|
|
122
|
+
}, "day");
|
|
164
123
|
const monthField = /*#__PURE__*/_jsx(MonthSelectWrapper, {
|
|
165
124
|
children: /*#__PURE__*/_jsx(SelectControl, {
|
|
166
125
|
className: "components-datetime__time-field components-datetime__time-field-month" // Unused, for backwards compatibility.
|
|
@@ -213,6 +172,38 @@ export function TimePicker({
|
|
|
213
172
|
onChange?.(format(newDate, TIMEZONELESS_FORMAT));
|
|
214
173
|
}
|
|
215
174
|
})
|
|
175
|
+
}, "month");
|
|
176
|
+
const yearField = /*#__PURE__*/_jsx(YearInput, {
|
|
177
|
+
className: "components-datetime__time-field components-datetime__time-field-year" // Unused, for backwards compatibility.
|
|
178
|
+
,
|
|
179
|
+
label: __('Year'),
|
|
180
|
+
hideLabelFromVision: true,
|
|
181
|
+
__next40pxDefaultSize: true,
|
|
182
|
+
value: year,
|
|
183
|
+
step: 1,
|
|
184
|
+
min: 1,
|
|
185
|
+
max: 9999,
|
|
186
|
+
required: true,
|
|
187
|
+
spinControls: "none",
|
|
188
|
+
isPressEnterToChange: true,
|
|
189
|
+
isDragEnabled: false,
|
|
190
|
+
isShiftStepEnabled: false,
|
|
191
|
+
onChange: buildNumberControlChangeCallback('year'),
|
|
192
|
+
__unstableStateReducer: buildPadInputStateReducer(4)
|
|
193
|
+
}, "year");
|
|
194
|
+
const defaultDateOrder = is12Hour ? 'mdy' : 'dmy';
|
|
195
|
+
const dateOrder = dateOrderProp && VALID_DATE_ORDERS.includes(dateOrderProp) ? dateOrderProp : defaultDateOrder;
|
|
196
|
+
const fields = dateOrder.split('').map(field => {
|
|
197
|
+
switch (field) {
|
|
198
|
+
case 'd':
|
|
199
|
+
return dayField;
|
|
200
|
+
case 'm':
|
|
201
|
+
return monthField;
|
|
202
|
+
case 'y':
|
|
203
|
+
return yearField;
|
|
204
|
+
default:
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
216
207
|
});
|
|
217
208
|
return /*#__PURE__*/_jsxs(Wrapper, {
|
|
218
209
|
className: "components-datetime__time" // Unused, for backwards compatibility.
|
|
@@ -226,67 +217,13 @@ export function TimePicker({
|
|
|
226
217
|
}), /*#__PURE__*/_jsxs(HStack, {
|
|
227
218
|
className: "components-datetime__time-wrapper" // Unused, for backwards compatibility.
|
|
228
219
|
,
|
|
229
|
-
children: [/*#__PURE__*/
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
hideLabelFromVision: true,
|
|
237
|
-
__next40pxDefaultSize: true,
|
|
238
|
-
value: hours,
|
|
239
|
-
step: 1,
|
|
240
|
-
min: is12Hour ? 1 : 0,
|
|
241
|
-
max: is12Hour ? 12 : 23,
|
|
242
|
-
required: true,
|
|
243
|
-
spinControls: "none",
|
|
244
|
-
isPressEnterToChange: true,
|
|
245
|
-
isDragEnabled: false,
|
|
246
|
-
isShiftStepEnabled: false,
|
|
247
|
-
onChange: buildNumberControlChangeCallback('hours'),
|
|
248
|
-
__unstableStateReducer: buildPadInputStateReducer(2)
|
|
249
|
-
}), /*#__PURE__*/_jsx(TimeSeparator, {
|
|
250
|
-
className: "components-datetime__time-separator" // Unused, for backwards compatibility.
|
|
251
|
-
,
|
|
252
|
-
"aria-hidden": "true",
|
|
253
|
-
children: ":"
|
|
254
|
-
}), /*#__PURE__*/_jsx(MinutesInput, {
|
|
255
|
-
className: "components-datetime__time-field-minutes-input" // Unused, for backwards compatibility.
|
|
256
|
-
,
|
|
257
|
-
label: __('Minutes'),
|
|
258
|
-
hideLabelFromVision: true,
|
|
259
|
-
__next40pxDefaultSize: true,
|
|
260
|
-
value: minutes,
|
|
261
|
-
step: 1,
|
|
262
|
-
min: 0,
|
|
263
|
-
max: 59,
|
|
264
|
-
required: true,
|
|
265
|
-
spinControls: "none",
|
|
266
|
-
isPressEnterToChange: true,
|
|
267
|
-
isDragEnabled: false,
|
|
268
|
-
isShiftStepEnabled: false,
|
|
269
|
-
onChange: buildNumberControlChangeCallback('minutes'),
|
|
270
|
-
__unstableStateReducer: buildPadInputStateReducer(2)
|
|
271
|
-
})]
|
|
272
|
-
}), is12Hour && /*#__PURE__*/_jsxs(ButtonGroup, {
|
|
273
|
-
className: "components-datetime__time-field components-datetime__time-field-am-pm" // Unused, for backwards compatibility.
|
|
274
|
-
,
|
|
275
|
-
children: [/*#__PURE__*/_jsx(Button, {
|
|
276
|
-
className: "components-datetime__time-am-button" // Unused, for backwards compatibility.
|
|
277
|
-
,
|
|
278
|
-
variant: am === 'AM' ? 'primary' : 'secondary',
|
|
279
|
-
__next40pxDefaultSize: true,
|
|
280
|
-
onClick: buildAmPmChangeCallback('AM'),
|
|
281
|
-
children: __('AM')
|
|
282
|
-
}), /*#__PURE__*/_jsx(Button, {
|
|
283
|
-
className: "components-datetime__time-pm-button" // Unused, for backwards compatibility.
|
|
284
|
-
,
|
|
285
|
-
variant: am === 'PM' ? 'primary' : 'secondary',
|
|
286
|
-
__next40pxDefaultSize: true,
|
|
287
|
-
onClick: buildAmPmChangeCallback('PM'),
|
|
288
|
-
children: __('PM')
|
|
289
|
-
})]
|
|
220
|
+
children: [/*#__PURE__*/_jsx(TimeInput, {
|
|
221
|
+
value: {
|
|
222
|
+
hours: Number(hours),
|
|
223
|
+
minutes: Number(minutes)
|
|
224
|
+
},
|
|
225
|
+
is12Hour: is12Hour,
|
|
226
|
+
onChange: onTimeInputChangeCallback
|
|
290
227
|
}), /*#__PURE__*/_jsx(Spacer, {}), /*#__PURE__*/_jsx(TimeZone, {})]
|
|
291
228
|
})]
|
|
292
229
|
}), /*#__PURE__*/_jsxs(Fieldset, {
|
|
@@ -295,31 +232,10 @@ export function TimePicker({
|
|
|
295
232
|
className: "components-datetime__time-legend" // Unused, for backwards compatibility.
|
|
296
233
|
,
|
|
297
234
|
children: __('Date')
|
|
298
|
-
}), /*#__PURE__*/
|
|
235
|
+
}), /*#__PURE__*/_jsx(HStack, {
|
|
299
236
|
className: "components-datetime__time-wrapper" // Unused, for backwards compatibility.
|
|
300
237
|
,
|
|
301
|
-
children:
|
|
302
|
-
children: [monthField, dayField]
|
|
303
|
-
}) : /*#__PURE__*/_jsxs(_Fragment, {
|
|
304
|
-
children: [dayField, monthField]
|
|
305
|
-
}), /*#__PURE__*/_jsx(YearInput, {
|
|
306
|
-
className: "components-datetime__time-field components-datetime__time-field-year" // Unused, for backwards compatibility.
|
|
307
|
-
,
|
|
308
|
-
label: __('Year'),
|
|
309
|
-
hideLabelFromVision: true,
|
|
310
|
-
__next40pxDefaultSize: true,
|
|
311
|
-
value: year,
|
|
312
|
-
step: 1,
|
|
313
|
-
min: 1,
|
|
314
|
-
max: 9999,
|
|
315
|
-
required: true,
|
|
316
|
-
spinControls: "none",
|
|
317
|
-
isPressEnterToChange: true,
|
|
318
|
-
isDragEnabled: false,
|
|
319
|
-
isShiftStepEnabled: false,
|
|
320
|
-
onChange: buildNumberControlChangeCallback('year'),
|
|
321
|
-
__unstableStateReducer: buildPadInputStateReducer(4)
|
|
322
|
-
})]
|
|
238
|
+
children: fields
|
|
323
239
|
})]
|
|
324
240
|
})]
|
|
325
241
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["startOfMinute","format","set","setHours","setMonth","useState","useMemo","useEffect","__","BaseControl","Button","ButtonGroup","SelectControl","TimeZone","Wrapper","Fieldset","HoursInput","TimeSeparator","MinutesInput","MonthSelectWrapper","DayInput","YearInput","TimeWrapper","HStack","Spacer","COMMIT","PRESS_DOWN","PRESS_UP","inputToDate","TIMEZONELESS_FORMAT","jsx","_jsx","jsxs","_jsxs","Fragment","_Fragment","from12hTo24h","hours","isPm","buildPadInputStateReducer","pad","state","action","nextState","type","value","undefined","toString","padStart","TimePicker","is12Hour","currentTime","onChange","date","setDate","Date","day","month","year","minutes","am","buildNumberControlChangeCallback","method","callback","event","_ownerDocument$defaul","HTMLInputElementInstance","target","ownerDocument","defaultView","HTMLInputElement","validity","valid","numberValue","Number","newDate","buildAmPmChangeCallback","parsedHours","parseInt","dayField","className","label","hideLabelFromVision","__next40pxDefaultSize","step","min","max","required","spinControls","isPressEnterToChange","isDragEnabled","isShiftStepEnabled","monthField","children","__nextHasNoMarginBottom","options","VisualLabel","as","__unstableStateReducer","variant","onClick"],"sources":["@wordpress/components/src/date-time/time/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport { startOfMinute, format, set, setHours, setMonth } from 'date-fns';\n\n/**\n * WordPress dependencies\n */\nimport { useState, useMemo, useEffect } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport BaseControl from '../../base-control';\nimport Button from '../../button';\nimport ButtonGroup from '../../button-group';\nimport SelectControl from '../../select-control';\nimport TimeZone from './timezone';\nimport type { TimePickerProps } from '../types';\nimport {\n\tWrapper,\n\tFieldset,\n\tHoursInput,\n\tTimeSeparator,\n\tMinutesInput,\n\tMonthSelectWrapper,\n\tDayInput,\n\tYearInput,\n\tTimeWrapper,\n} from './styles';\nimport { HStack } from '../../h-stack';\nimport { Spacer } from '../../spacer';\nimport type { InputChangeCallback } from '../../input-control/types';\nimport type { InputState } from '../../input-control/reducer/state';\nimport type { InputAction } from '../../input-control/reducer/actions';\nimport {\n\tCOMMIT,\n\tPRESS_DOWN,\n\tPRESS_UP,\n} from '../../input-control/reducer/actions';\nimport { inputToDate } from '../utils';\nimport { TIMEZONELESS_FORMAT } from '../constants';\n\nfunction from12hTo24h( hours: number, isPm: boolean ) {\n\treturn isPm ? ( ( hours % 12 ) + 12 ) % 24 : hours % 12;\n}\n\n/**\n * Creates an InputControl reducer used to pad an input so that it is always a\n * given width. For example, the hours and minutes inputs are padded to 2 so\n * that '4' appears as '04'.\n *\n * @param pad How many digits the value should be.\n */\nfunction buildPadInputStateReducer( pad: number ) {\n\treturn ( state: InputState, action: InputAction ) => {\n\t\tconst nextState = { ...state };\n\t\tif (\n\t\t\taction.type === COMMIT ||\n\t\t\taction.type === PRESS_UP ||\n\t\t\taction.type === PRESS_DOWN\n\t\t) {\n\t\t\tif ( nextState.value !== undefined ) {\n\t\t\t\tnextState.value = nextState.value\n\t\t\t\t\t.toString()\n\t\t\t\t\t.padStart( pad, '0' );\n\t\t\t}\n\t\t}\n\t\treturn nextState;\n\t};\n}\n\n/**\n * TimePicker is a React component that renders a clock for time selection.\n *\n * ```jsx\n * import { TimePicker } from '@wordpress/components';\n * import { useState } from '@wordpress/element';\n *\n * const MyTimePicker = () => {\n * const [ time, setTime ] = useState( new Date() );\n *\n * return (\n * <TimePicker\n * currentTime={ date }\n * onChange={ ( newTime ) => setTime( newTime ) }\n * is12Hour\n * />\n * );\n * };\n * ```\n */\nexport function TimePicker( {\n\tis12Hour,\n\tcurrentTime,\n\tonChange,\n}: TimePickerProps ) {\n\tconst [ date, setDate ] = useState( () =>\n\t\t// Truncate the date at the minutes, see: #15495.\n\t\tcurrentTime ? startOfMinute( inputToDate( currentTime ) ) : new Date()\n\t);\n\n\t// Reset the state when currentTime changed.\n\t// TODO: useEffect() shouldn't be used like this, causes an unnecessary render\n\tuseEffect( () => {\n\t\tsetDate(\n\t\t\tcurrentTime\n\t\t\t\t? startOfMinute( inputToDate( currentTime ) )\n\t\t\t\t: new Date()\n\t\t);\n\t}, [ currentTime ] );\n\n\tconst { day, month, year, minutes, hours, am } = useMemo(\n\t\t() => ( {\n\t\t\tday: format( date, 'dd' ),\n\t\t\tmonth: format( date, 'MM' ),\n\t\t\tyear: format( date, 'yyyy' ),\n\t\t\tminutes: format( date, 'mm' ),\n\t\t\thours: format( date, is12Hour ? 'hh' : 'HH' ),\n\t\t\tam: format( date, 'a' ),\n\t\t} ),\n\t\t[ date, is12Hour ]\n\t);\n\n\tconst buildNumberControlChangeCallback = (\n\t\tmethod: 'hours' | 'minutes' | 'date' | 'year'\n\t) => {\n\t\tconst callback: InputChangeCallback = ( value, { event } ) => {\n\t\t\t// `instanceof` checks need to get the instance definition from the\n\t\t\t// corresponding window object — therefore, the following logic makes\n\t\t\t// the component work correctly even when rendered inside an iframe.\n\t\t\tconst HTMLInputElementInstance =\n\t\t\t\t( event.target as HTMLInputElement )?.ownerDocument.defaultView\n\t\t\t\t\t?.HTMLInputElement ?? HTMLInputElement;\n\n\t\t\tif ( ! ( event.target instanceof HTMLInputElementInstance ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( ! event.target.validity.valid ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// We can safely assume value is a number if target is valid.\n\t\t\tlet numberValue = Number( value );\n\n\t\t\t// If the 12-hour format is being used and the 'PM' period is\n\t\t\t// selected, then the incoming value (which ranges 1-12) should be\n\t\t\t// increased by 12 to match the expected 24-hour format.\n\t\t\tif ( method === 'hours' && is12Hour ) {\n\t\t\t\tnumberValue = from12hTo24h( numberValue, am === 'PM' );\n\t\t\t}\n\n\t\t\tconst newDate = set( date, { [ method ]: numberValue } );\n\t\t\tsetDate( newDate );\n\t\t\tonChange?.( format( newDate, TIMEZONELESS_FORMAT ) );\n\t\t};\n\t\treturn callback;\n\t};\n\n\tfunction buildAmPmChangeCallback( value: 'AM' | 'PM' ) {\n\t\treturn () => {\n\t\t\tif ( am === value ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst parsedHours = parseInt( hours, 10 );\n\n\t\t\tconst newDate = setHours(\n\t\t\t\tdate,\n\t\t\t\tfrom12hTo24h( parsedHours, value === 'PM' )\n\t\t\t);\n\t\t\tsetDate( newDate );\n\t\t\tonChange?.( format( newDate, TIMEZONELESS_FORMAT ) );\n\t\t};\n\t}\n\n\tconst dayField = (\n\t\t<DayInput\n\t\t\tclassName=\"components-datetime__time-field components-datetime__time-field-day\" // Unused, for backwards compatibility.\n\t\t\tlabel={ __( 'Day' ) }\n\t\t\thideLabelFromVision\n\t\t\t__next40pxDefaultSize\n\t\t\tvalue={ day }\n\t\t\tstep={ 1 }\n\t\t\tmin={ 1 }\n\t\t\tmax={ 31 }\n\t\t\trequired\n\t\t\tspinControls=\"none\"\n\t\t\tisPressEnterToChange\n\t\t\tisDragEnabled={ false }\n\t\t\tisShiftStepEnabled={ false }\n\t\t\tonChange={ buildNumberControlChangeCallback( 'date' ) }\n\t\t/>\n\t);\n\n\tconst monthField = (\n\t\t<MonthSelectWrapper>\n\t\t\t<SelectControl\n\t\t\t\tclassName=\"components-datetime__time-field components-datetime__time-field-month\" // Unused, for backwards compatibility.\n\t\t\t\tlabel={ __( 'Month' ) }\n\t\t\t\thideLabelFromVision\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\tvalue={ month }\n\t\t\t\toptions={ [\n\t\t\t\t\t{ value: '01', label: __( 'January' ) },\n\t\t\t\t\t{ value: '02', label: __( 'February' ) },\n\t\t\t\t\t{ value: '03', label: __( 'March' ) },\n\t\t\t\t\t{ value: '04', label: __( 'April' ) },\n\t\t\t\t\t{ value: '05', label: __( 'May' ) },\n\t\t\t\t\t{ value: '06', label: __( 'June' ) },\n\t\t\t\t\t{ value: '07', label: __( 'July' ) },\n\t\t\t\t\t{ value: '08', label: __( 'August' ) },\n\t\t\t\t\t{ value: '09', label: __( 'September' ) },\n\t\t\t\t\t{ value: '10', label: __( 'October' ) },\n\t\t\t\t\t{ value: '11', label: __( 'November' ) },\n\t\t\t\t\t{ value: '12', label: __( 'December' ) },\n\t\t\t\t] }\n\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\tconst newDate = setMonth( date, Number( value ) - 1 );\n\t\t\t\t\tsetDate( newDate );\n\t\t\t\t\tonChange?.( format( newDate, TIMEZONELESS_FORMAT ) );\n\t\t\t\t} }\n\t\t\t/>\n\t\t</MonthSelectWrapper>\n\t);\n\n\treturn (\n\t\t<Wrapper\n\t\t\tclassName=\"components-datetime__time\" // Unused, for backwards compatibility.\n\t\t>\n\t\t\t<Fieldset>\n\t\t\t\t<BaseControl.VisualLabel\n\t\t\t\t\tas=\"legend\"\n\t\t\t\t\tclassName=\"components-datetime__time-legend\" // Unused, for backwards compatibility.\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Time' ) }\n\t\t\t\t</BaseControl.VisualLabel>\n\t\t\t\t<HStack\n\t\t\t\t\tclassName=\"components-datetime__time-wrapper\" // Unused, for backwards compatibility.\n\t\t\t\t>\n\t\t\t\t\t<TimeWrapper\n\t\t\t\t\t\tclassName=\"components-datetime__time-field components-datetime__time-field-time\" // Unused, for backwards compatibility.\n\t\t\t\t\t>\n\t\t\t\t\t\t<HoursInput\n\t\t\t\t\t\t\tclassName=\"components-datetime__time-field-hours-input\" // Unused, for backwards compatibility.\n\t\t\t\t\t\t\tlabel={ __( 'Hours' ) }\n\t\t\t\t\t\t\thideLabelFromVision\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvalue={ hours }\n\t\t\t\t\t\t\tstep={ 1 }\n\t\t\t\t\t\t\tmin={ is12Hour ? 1 : 0 }\n\t\t\t\t\t\t\tmax={ is12Hour ? 12 : 23 }\n\t\t\t\t\t\t\trequired\n\t\t\t\t\t\t\tspinControls=\"none\"\n\t\t\t\t\t\t\tisPressEnterToChange\n\t\t\t\t\t\t\tisDragEnabled={ false }\n\t\t\t\t\t\t\tisShiftStepEnabled={ false }\n\t\t\t\t\t\t\tonChange={ buildNumberControlChangeCallback(\n\t\t\t\t\t\t\t\t'hours'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t__unstableStateReducer={ buildPadInputStateReducer(\n\t\t\t\t\t\t\t\t2\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t\t<TimeSeparator\n\t\t\t\t\t\t\tclassName=\"components-datetime__time-separator\" // Unused, for backwards compatibility.\n\t\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t:\n\t\t\t\t\t\t</TimeSeparator>\n\t\t\t\t\t\t<MinutesInput\n\t\t\t\t\t\t\tclassName=\"components-datetime__time-field-minutes-input\" // Unused, for backwards compatibility.\n\t\t\t\t\t\t\tlabel={ __( 'Minutes' ) }\n\t\t\t\t\t\t\thideLabelFromVision\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tvalue={ minutes }\n\t\t\t\t\t\t\tstep={ 1 }\n\t\t\t\t\t\t\tmin={ 0 }\n\t\t\t\t\t\t\tmax={ 59 }\n\t\t\t\t\t\t\trequired\n\t\t\t\t\t\t\tspinControls=\"none\"\n\t\t\t\t\t\t\tisPressEnterToChange\n\t\t\t\t\t\t\tisDragEnabled={ false }\n\t\t\t\t\t\t\tisShiftStepEnabled={ false }\n\t\t\t\t\t\t\tonChange={ buildNumberControlChangeCallback(\n\t\t\t\t\t\t\t\t'minutes'\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t\t__unstableStateReducer={ buildPadInputStateReducer(\n\t\t\t\t\t\t\t\t2\n\t\t\t\t\t\t\t) }\n\t\t\t\t\t\t/>\n\t\t\t\t\t</TimeWrapper>\n\t\t\t\t\t{ is12Hour && (\n\t\t\t\t\t\t<ButtonGroup\n\t\t\t\t\t\t\tclassName=\"components-datetime__time-field components-datetime__time-field-am-pm\" // Unused, for backwards compatibility.\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\tclassName=\"components-datetime__time-am-button\" // Unused, for backwards compatibility.\n\t\t\t\t\t\t\t\tvariant={\n\t\t\t\t\t\t\t\t\tam === 'AM' ? 'primary' : 'secondary'\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\tonClick={ buildAmPmChangeCallback( 'AM' ) }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'AM' ) }\n\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\t\tclassName=\"components-datetime__time-pm-button\" // Unused, for backwards compatibility.\n\t\t\t\t\t\t\t\tvariant={\n\t\t\t\t\t\t\t\t\tam === 'PM' ? 'primary' : 'secondary'\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\t\tonClick={ buildAmPmChangeCallback( 'PM' ) }\n\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t{ __( 'PM' ) }\n\t\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t</ButtonGroup>\n\t\t\t\t\t) }\n\t\t\t\t\t<Spacer />\n\t\t\t\t\t<TimeZone />\n\t\t\t\t</HStack>\n\t\t\t</Fieldset>\n\t\t\t<Fieldset>\n\t\t\t\t<BaseControl.VisualLabel\n\t\t\t\t\tas=\"legend\"\n\t\t\t\t\tclassName=\"components-datetime__time-legend\" // Unused, for backwards compatibility.\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Date' ) }\n\t\t\t\t</BaseControl.VisualLabel>\n\t\t\t\t<HStack\n\t\t\t\t\tclassName=\"components-datetime__time-wrapper\" // Unused, for backwards compatibility.\n\t\t\t\t>\n\t\t\t\t\t{ is12Hour ? (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t{ monthField }\n\t\t\t\t\t\t\t{ dayField }\n\t\t\t\t\t\t</>\n\t\t\t\t\t) : (\n\t\t\t\t\t\t<>\n\t\t\t\t\t\t\t{ dayField }\n\t\t\t\t\t\t\t{ monthField }\n\t\t\t\t\t\t</>\n\t\t\t\t\t) }\n\t\t\t\t\t<YearInput\n\t\t\t\t\t\tclassName=\"components-datetime__time-field components-datetime__time-field-year\" // Unused, for backwards compatibility.\n\t\t\t\t\t\tlabel={ __( 'Year' ) }\n\t\t\t\t\t\thideLabelFromVision\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvalue={ year }\n\t\t\t\t\t\tstep={ 1 }\n\t\t\t\t\t\tmin={ 1 }\n\t\t\t\t\t\tmax={ 9999 }\n\t\t\t\t\t\trequired\n\t\t\t\t\t\tspinControls=\"none\"\n\t\t\t\t\t\tisPressEnterToChange\n\t\t\t\t\t\tisDragEnabled={ false }\n\t\t\t\t\t\tisShiftStepEnabled={ false }\n\t\t\t\t\t\tonChange={ buildNumberControlChangeCallback( 'year' ) }\n\t\t\t\t\t\t__unstableStateReducer={ buildPadInputStateReducer(\n\t\t\t\t\t\t\t4\n\t\t\t\t\t\t) }\n\t\t\t\t\t/>\n\t\t\t\t</HStack>\n\t\t\t</Fieldset>\n\t\t</Wrapper>\n\t);\n}\n\nexport default TimePicker;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,aAAa,EAAEC,MAAM,EAAEC,GAAG,EAAEC,QAAQ,EAAEC,QAAQ,QAAQ,UAAU;;AAEzE;AACA;AACA;AACA,SAASC,QAAQ,EAAEC,OAAO,EAAEC,SAAS,QAAQ,oBAAoB;AACjE,SAASC,EAAE,QAAQ,iBAAiB;;AAEpC;AACA;AACA;AACA,OAAOC,WAAW,MAAM,oBAAoB;AAC5C,OAAOC,MAAM,MAAM,cAAc;AACjC,OAAOC,WAAW,MAAM,oBAAoB;AAC5C,OAAOC,aAAa,MAAM,sBAAsB;AAChD,OAAOC,QAAQ,MAAM,YAAY;AAEjC,SACCC,OAAO,EACPC,QAAQ,EACRC,UAAU,EACVC,aAAa,EACbC,YAAY,EACZC,kBAAkB,EAClBC,QAAQ,EACRC,SAAS,EACTC,WAAW,QACL,UAAU;AACjB,SAASC,MAAM,QAAQ,eAAe;AACtC,SAASC,MAAM,QAAQ,cAAc;AAIrC,SACCC,MAAM,EACNC,UAAU,EACVC,QAAQ,QACF,qCAAqC;AAC5C,SAASC,WAAW,QAAQ,UAAU;AACtC,SAASC,mBAAmB,QAAQ,cAAc;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAAA,SAAAC,IAAA,IAAAC,KAAA;AAAA,SAAAC,QAAA,IAAAC,SAAA;AAEnD,SAASC,YAAYA,CAAEC,KAAa,EAAEC,IAAa,EAAG;EACrD,OAAOA,IAAI,GAAG,CAAID,KAAK,GAAG,EAAE,G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CAAClB,QAAQ;MAAA8E,QAAA,gBACR9D,IAAA,CAACtB,WAAW,CAACuF,WAAW;QACvBC,EAAE,EAAC,QAAQ;QACXjB,SAAS,EAAC,kCAAkC,CAAC;QAAA;QAAAa,QAAA,EAE3CrF,EAAE,CAAE,MAAO;MAAC,CACU,CAAC,eAC1ByB,KAAA,CAACV,MAAM;QACNyD,SAAS,EAAC,mCAAmC,CAAC;QAAA;QAAAa,QAAA,GAE5C3C,QAAQ,gBACTjB,KAAA,CAAAE,SAAA;UAAA0D,QAAA,GACGD,UAAU,EACVb,QAAQ;QAAA,CACT,CAAC,gBAEH9C,KAAA,CAAAE,SAAA;UAAA0D,QAAA,GACGd,QAAQ,EACRa,UAAU;QAAA,CACX,CACF,eACD7D,IAAA,CAACV,SAAS;UACT2D,SAAS,EAAC,sEAAsE,CAAC;UAAA;UACjFC,KAAK,EAAGzE,EAAE,CAAE,MAAO,CAAG;UACtB0E,mBAAmB;UACnBC,qBAAqB;UACrBtC,KAAK,EAAGa,IAAM;UACd0B,IAAI,EAAG,CAAG;UACVC,GAAG,EAAG,CAAG;UACTC,GAAG,EAAG,IAAM;UACZC,QAAQ;UACRC,YAAY,EAAC,MAAM;UACnBC,oBAAoB;UACpBC,aAAa,EAAG,KAAO;UACvBC,kBAAkB,EAAG,KAAO;UAC5BvC,QAAQ,EAAGS,gCAAgC,CAAE,MAAO,CAAG;UACvDqC,sBAAsB,EAAG3D,yBAAyB,CACjD,CACD;QAAG,CACH,CAAC;MAAA,CACK,CAAC;IAAA,CACA,CAAC;EAAA,CACH,CAAC;AAEZ;AAEA,eAAeU,UAAU","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["startOfMinute","format","set","setMonth","useState","useMemo","useEffect","__","BaseControl","SelectControl","TimeZone","Wrapper","Fieldset","MonthSelectWrapper","DayInput","YearInput","HStack","Spacer","inputToDate","buildPadInputStateReducer","validateInputElementTarget","TIMEZONELESS_FORMAT","TimeInput","jsx","_jsx","jsxs","_jsxs","VALID_DATE_ORDERS","TimePicker","is12Hour","currentTime","onChange","dateOrder","dateOrderProp","date","setDate","Date","day","month","year","minutes","hours","am","buildNumberControlChangeCallback","method","callback","value","event","numberValue","Number","newDate","onTimeInputChangeCallback","newHours","newMinutes","dayField","className","label","hideLabelFromVision","__next40pxDefaultSize","step","min","max","required","spinControls","isPressEnterToChange","isDragEnabled","isShiftStepEnabled","monthField","children","__nextHasNoMarginBottom","options","yearField","__unstableStateReducer","defaultDateOrder","includes","fields","split","map","field","VisualLabel","as"],"sources":["@wordpress/components/src/date-time/time/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport { startOfMinute, format, set, setMonth } from 'date-fns';\n\n/**\n * WordPress dependencies\n */\nimport { useState, useMemo, useEffect } from '@wordpress/element';\nimport { __ } from '@wordpress/i18n';\n\n/**\n * Internal dependencies\n */\nimport BaseControl from '../../base-control';\nimport SelectControl from '../../select-control';\nimport TimeZone from './timezone';\nimport type { TimeInputValue, TimePickerProps } from '../types';\nimport {\n\tWrapper,\n\tFieldset,\n\tMonthSelectWrapper,\n\tDayInput,\n\tYearInput,\n} from './styles';\nimport { HStack } from '../../h-stack';\nimport { Spacer } from '../../spacer';\nimport type { InputChangeCallback } from '../../input-control/types';\nimport {\n\tinputToDate,\n\tbuildPadInputStateReducer,\n\tvalidateInputElementTarget,\n} from '../utils';\nimport { TIMEZONELESS_FORMAT } from '../constants';\nimport { TimeInput } from '../time-input';\n\nconst VALID_DATE_ORDERS = [ 'dmy', 'mdy', 'ymd' ];\n\n/**\n * TimePicker is a React component that renders a clock for time selection.\n *\n * ```jsx\n * import { TimePicker } from '@wordpress/components';\n * import { useState } from '@wordpress/element';\n *\n * const MyTimePicker = () => {\n * const [ time, setTime ] = useState( new Date() );\n *\n * return (\n * <TimePicker\n * currentTime={ date }\n * onChange={ ( newTime ) => setTime( newTime ) }\n * is12Hour\n * />\n * );\n * };\n * ```\n */\nexport function TimePicker( {\n\tis12Hour,\n\tcurrentTime,\n\tonChange,\n\tdateOrder: dateOrderProp,\n}: TimePickerProps ) {\n\tconst [ date, setDate ] = useState( () =>\n\t\t// Truncate the date at the minutes, see: #15495.\n\t\tcurrentTime ? startOfMinute( inputToDate( currentTime ) ) : new Date()\n\t);\n\n\t// Reset the state when currentTime changed.\n\t// TODO: useEffect() shouldn't be used like this, causes an unnecessary render\n\tuseEffect( () => {\n\t\tsetDate(\n\t\t\tcurrentTime\n\t\t\t\t? startOfMinute( inputToDate( currentTime ) )\n\t\t\t\t: new Date()\n\t\t);\n\t}, [ currentTime ] );\n\n\tconst { day, month, year, minutes, hours } = useMemo(\n\t\t() => ( {\n\t\t\tday: format( date, 'dd' ),\n\t\t\tmonth: format( date, 'MM' ),\n\t\t\tyear: format( date, 'yyyy' ),\n\t\t\tminutes: format( date, 'mm' ),\n\t\t\thours: format( date, 'HH' ),\n\t\t\tam: format( date, 'a' ),\n\t\t} ),\n\t\t[ date ]\n\t);\n\n\tconst buildNumberControlChangeCallback = ( method: 'date' | 'year' ) => {\n\t\tconst callback: InputChangeCallback = ( value, { event } ) => {\n\t\t\tif ( ! validateInputElementTarget( event ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// We can safely assume value is a number if target is valid.\n\t\t\tconst numberValue = Number( value );\n\n\t\t\tconst newDate = set( date, { [ method ]: numberValue } );\n\t\t\tsetDate( newDate );\n\t\t\tonChange?.( format( newDate, TIMEZONELESS_FORMAT ) );\n\t\t};\n\t\treturn callback;\n\t};\n\n\tconst onTimeInputChangeCallback = ( {\n\t\thours: newHours,\n\t\tminutes: newMinutes,\n\t}: TimeInputValue ) => {\n\t\tconst newDate = set( date, {\n\t\t\thours: newHours,\n\t\t\tminutes: newMinutes,\n\t\t} );\n\t\tsetDate( newDate );\n\t\tonChange?.( format( newDate, TIMEZONELESS_FORMAT ) );\n\t};\n\n\tconst dayField = (\n\t\t<DayInput\n\t\t\tkey=\"day\"\n\t\t\tclassName=\"components-datetime__time-field components-datetime__time-field-day\" // Unused, for backwards compatibility.\n\t\t\tlabel={ __( 'Day' ) }\n\t\t\thideLabelFromVision\n\t\t\t__next40pxDefaultSize\n\t\t\tvalue={ day }\n\t\t\tstep={ 1 }\n\t\t\tmin={ 1 }\n\t\t\tmax={ 31 }\n\t\t\trequired\n\t\t\tspinControls=\"none\"\n\t\t\tisPressEnterToChange\n\t\t\tisDragEnabled={ false }\n\t\t\tisShiftStepEnabled={ false }\n\t\t\tonChange={ buildNumberControlChangeCallback( 'date' ) }\n\t\t/>\n\t);\n\n\tconst monthField = (\n\t\t<MonthSelectWrapper key=\"month\">\n\t\t\t<SelectControl\n\t\t\t\tclassName=\"components-datetime__time-field components-datetime__time-field-month\" // Unused, for backwards compatibility.\n\t\t\t\tlabel={ __( 'Month' ) }\n\t\t\t\thideLabelFromVision\n\t\t\t\t__next40pxDefaultSize\n\t\t\t\t__nextHasNoMarginBottom\n\t\t\t\tvalue={ month }\n\t\t\t\toptions={ [\n\t\t\t\t\t{ value: '01', label: __( 'January' ) },\n\t\t\t\t\t{ value: '02', label: __( 'February' ) },\n\t\t\t\t\t{ value: '03', label: __( 'March' ) },\n\t\t\t\t\t{ value: '04', label: __( 'April' ) },\n\t\t\t\t\t{ value: '05', label: __( 'May' ) },\n\t\t\t\t\t{ value: '06', label: __( 'June' ) },\n\t\t\t\t\t{ value: '07', label: __( 'July' ) },\n\t\t\t\t\t{ value: '08', label: __( 'August' ) },\n\t\t\t\t\t{ value: '09', label: __( 'September' ) },\n\t\t\t\t\t{ value: '10', label: __( 'October' ) },\n\t\t\t\t\t{ value: '11', label: __( 'November' ) },\n\t\t\t\t\t{ value: '12', label: __( 'December' ) },\n\t\t\t\t] }\n\t\t\t\tonChange={ ( value ) => {\n\t\t\t\t\tconst newDate = setMonth( date, Number( value ) - 1 );\n\t\t\t\t\tsetDate( newDate );\n\t\t\t\t\tonChange?.( format( newDate, TIMEZONELESS_FORMAT ) );\n\t\t\t\t} }\n\t\t\t/>\n\t\t</MonthSelectWrapper>\n\t);\n\n\tconst yearField = (\n\t\t<YearInput\n\t\t\tkey=\"year\"\n\t\t\tclassName=\"components-datetime__time-field components-datetime__time-field-year\" // Unused, for backwards compatibility.\n\t\t\tlabel={ __( 'Year' ) }\n\t\t\thideLabelFromVision\n\t\t\t__next40pxDefaultSize\n\t\t\tvalue={ year }\n\t\t\tstep={ 1 }\n\t\t\tmin={ 1 }\n\t\t\tmax={ 9999 }\n\t\t\trequired\n\t\t\tspinControls=\"none\"\n\t\t\tisPressEnterToChange\n\t\t\tisDragEnabled={ false }\n\t\t\tisShiftStepEnabled={ false }\n\t\t\tonChange={ buildNumberControlChangeCallback( 'year' ) }\n\t\t\t__unstableStateReducer={ buildPadInputStateReducer( 4 ) }\n\t\t/>\n\t);\n\n\tconst defaultDateOrder = is12Hour ? 'mdy' : 'dmy';\n\tconst dateOrder =\n\t\tdateOrderProp && VALID_DATE_ORDERS.includes( dateOrderProp )\n\t\t\t? dateOrderProp\n\t\t\t: defaultDateOrder;\n\n\tconst fields = dateOrder.split( '' ).map( ( field ) => {\n\t\tswitch ( field ) {\n\t\t\tcase 'd':\n\t\t\t\treturn dayField;\n\t\t\tcase 'm':\n\t\t\t\treturn monthField;\n\t\t\tcase 'y':\n\t\t\t\treturn yearField;\n\t\t\tdefault:\n\t\t\t\treturn null;\n\t\t}\n\t} );\n\n\treturn (\n\t\t<Wrapper\n\t\t\tclassName=\"components-datetime__time\" // Unused, for backwards compatibility.\n\t\t>\n\t\t\t<Fieldset>\n\t\t\t\t<BaseControl.VisualLabel\n\t\t\t\t\tas=\"legend\"\n\t\t\t\t\tclassName=\"components-datetime__time-legend\" // Unused, for backwards compatibility.\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Time' ) }\n\t\t\t\t</BaseControl.VisualLabel>\n\t\t\t\t<HStack\n\t\t\t\t\tclassName=\"components-datetime__time-wrapper\" // Unused, for backwards compatibility.\n\t\t\t\t>\n\t\t\t\t\t<TimeInput\n\t\t\t\t\t\tvalue={ {\n\t\t\t\t\t\t\thours: Number( hours ),\n\t\t\t\t\t\t\tminutes: Number( minutes ),\n\t\t\t\t\t\t} }\n\t\t\t\t\t\tis12Hour={ is12Hour }\n\t\t\t\t\t\tonChange={ onTimeInputChangeCallback }\n\t\t\t\t\t/>\n\t\t\t\t\t<Spacer />\n\t\t\t\t\t<TimeZone />\n\t\t\t\t</HStack>\n\t\t\t</Fieldset>\n\t\t\t<Fieldset>\n\t\t\t\t<BaseControl.VisualLabel\n\t\t\t\t\tas=\"legend\"\n\t\t\t\t\tclassName=\"components-datetime__time-legend\" // Unused, for backwards compatibility.\n\t\t\t\t>\n\t\t\t\t\t{ __( 'Date' ) }\n\t\t\t\t</BaseControl.VisualLabel>\n\t\t\t\t<HStack\n\t\t\t\t\tclassName=\"components-datetime__time-wrapper\" // Unused, for backwards compatibility.\n\t\t\t\t>\n\t\t\t\t\t{ fields }\n\t\t\t\t</HStack>\n\t\t\t</Fieldset>\n\t\t</Wrapper>\n\t);\n}\n\nexport default TimePicker;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,aAAa,EAAEC,MAAM,EAAEC,GAAG,EAAEC,QAAQ,QAAQ,UAAU;;AAE/D;AACA;AACA;AACA,SAASC,QAAQ,EAAEC,OAAO,EAAEC,SAAS,QAAQ,oBAAoB;AACjE,SAASC,EAAE,QAAQ,iBAAiB;;AAEpC;AACA;AACA;AACA,OAAOC,WAAW,MAAM,oBAAoB;AAC5C,OAAOC,aAAa,MAAM,sBAAsB;AAChD,OAAOC,QAAQ,MAAM,YAAY;AAEjC,SACCC,OAAO,EACPC,QAAQ,EACRC,kBAAkB,EAClBC,QAAQ,EACRC,SAAS,QACH,UAAU;AACjB,SAASC,MAAM,QAAQ,eAAe;AACtC,SAASC,MAAM,QAAQ,cAAc;AAErC,SACCC,WAAW,EACXC,yBAAyB,EACzBC,0BAA0B,QACpB,UAAU;AACjB,SAASC,mBAAmB,QAAQ,cAAc;AAClD,SAASC,SAAS,QAAQ,eAAe;AAAC,SAAAC,GAAA,IAAA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
import clsx from 'clsx';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { __ } from '@wordpress/i18n';
|
|
10
|
+
import { Fragment } from '@wordpress/element';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Internal dependencies
|
|
14
|
+
*/
|
|
15
|
+
import { TimeWrapper, TimeSeparator, HoursInput, MinutesInput, Fieldset } from '../time/styles';
|
|
16
|
+
import { HStack } from '../../h-stack';
|
|
17
|
+
import Button from '../../button';
|
|
18
|
+
import ButtonGroup from '../../button-group';
|
|
19
|
+
import { from12hTo24h, from24hTo12h, buildPadInputStateReducer, validateInputElementTarget } from '../utils';
|
|
20
|
+
import { useControlledValue } from '../../utils';
|
|
21
|
+
import BaseControl from '../../base-control';
|
|
22
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
23
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
24
|
+
export function TimeInput({
|
|
25
|
+
value: valueProp,
|
|
26
|
+
defaultValue,
|
|
27
|
+
is12Hour,
|
|
28
|
+
label,
|
|
29
|
+
minutesProps,
|
|
30
|
+
onChange
|
|
31
|
+
}) {
|
|
32
|
+
const [value = {
|
|
33
|
+
hours: new Date().getHours(),
|
|
34
|
+
minutes: new Date().getMinutes()
|
|
35
|
+
}, setValue] = useControlledValue({
|
|
36
|
+
value: valueProp,
|
|
37
|
+
onChange,
|
|
38
|
+
defaultValue
|
|
39
|
+
});
|
|
40
|
+
const dayPeriod = parseDayPeriod(value.hours);
|
|
41
|
+
const hours12Format = from24hTo12h(value.hours);
|
|
42
|
+
const buildNumberControlChangeCallback = method => {
|
|
43
|
+
return (_value, {
|
|
44
|
+
event
|
|
45
|
+
}) => {
|
|
46
|
+
if (!validateInputElementTarget(event)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// We can safely assume value is a number if target is valid.
|
|
51
|
+
const numberValue = Number(_value);
|
|
52
|
+
setValue({
|
|
53
|
+
...value,
|
|
54
|
+
[method]: method === 'hours' && is12Hour ? from12hTo24h(numberValue, dayPeriod === 'PM') : numberValue
|
|
55
|
+
});
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
const buildAmPmChangeCallback = _value => {
|
|
59
|
+
return () => {
|
|
60
|
+
if (dayPeriod === _value) {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
setValue({
|
|
64
|
+
...value,
|
|
65
|
+
hours: from12hTo24h(hours12Format, _value === 'PM')
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
};
|
|
69
|
+
function parseDayPeriod(_hours) {
|
|
70
|
+
return _hours < 12 ? 'AM' : 'PM';
|
|
71
|
+
}
|
|
72
|
+
const Wrapper = label ? Fieldset : Fragment;
|
|
73
|
+
return /*#__PURE__*/_jsxs(Wrapper, {
|
|
74
|
+
children: [label && /*#__PURE__*/_jsx(BaseControl.VisualLabel, {
|
|
75
|
+
as: "legend",
|
|
76
|
+
children: label
|
|
77
|
+
}), /*#__PURE__*/_jsxs(HStack, {
|
|
78
|
+
alignment: "left",
|
|
79
|
+
expanded: false,
|
|
80
|
+
children: [/*#__PURE__*/_jsxs(TimeWrapper, {
|
|
81
|
+
className: "components-datetime__time-field components-datetime__time-field-time" // Unused, for backwards compatibility.
|
|
82
|
+
,
|
|
83
|
+
children: [/*#__PURE__*/_jsx(HoursInput, {
|
|
84
|
+
className: "components-datetime__time-field-hours-input" // Unused, for backwards compatibility.
|
|
85
|
+
,
|
|
86
|
+
label: __('Hours'),
|
|
87
|
+
hideLabelFromVision: true,
|
|
88
|
+
__next40pxDefaultSize: true,
|
|
89
|
+
value: String(is12Hour ? hours12Format : value.hours).padStart(2, '0'),
|
|
90
|
+
step: 1,
|
|
91
|
+
min: is12Hour ? 1 : 0,
|
|
92
|
+
max: is12Hour ? 12 : 23,
|
|
93
|
+
required: true,
|
|
94
|
+
spinControls: "none",
|
|
95
|
+
isPressEnterToChange: true,
|
|
96
|
+
isDragEnabled: false,
|
|
97
|
+
isShiftStepEnabled: false,
|
|
98
|
+
onChange: buildNumberControlChangeCallback('hours'),
|
|
99
|
+
__unstableStateReducer: buildPadInputStateReducer(2)
|
|
100
|
+
}), /*#__PURE__*/_jsx(TimeSeparator, {
|
|
101
|
+
className: "components-datetime__time-separator" // Unused, for backwards compatibility.
|
|
102
|
+
,
|
|
103
|
+
"aria-hidden": "true",
|
|
104
|
+
children: ":"
|
|
105
|
+
}), /*#__PURE__*/_jsx(MinutesInput, {
|
|
106
|
+
className: clsx('components-datetime__time-field-minutes-input',
|
|
107
|
+
// Unused, for backwards compatibility.
|
|
108
|
+
minutesProps?.className),
|
|
109
|
+
label: __('Minutes'),
|
|
110
|
+
hideLabelFromVision: true,
|
|
111
|
+
__next40pxDefaultSize: true,
|
|
112
|
+
value: String(value.minutes).padStart(2, '0'),
|
|
113
|
+
step: 1,
|
|
114
|
+
min: 0,
|
|
115
|
+
max: 59,
|
|
116
|
+
required: true,
|
|
117
|
+
spinControls: "none",
|
|
118
|
+
isPressEnterToChange: true,
|
|
119
|
+
isDragEnabled: false,
|
|
120
|
+
isShiftStepEnabled: false,
|
|
121
|
+
onChange: (...args) => {
|
|
122
|
+
buildNumberControlChangeCallback('minutes')(...args);
|
|
123
|
+
minutesProps?.onChange?.(...args);
|
|
124
|
+
},
|
|
125
|
+
__unstableStateReducer: buildPadInputStateReducer(2),
|
|
126
|
+
...minutesProps
|
|
127
|
+
})]
|
|
128
|
+
}), is12Hour && /*#__PURE__*/_jsxs(ButtonGroup, {
|
|
129
|
+
className: "components-datetime__time-field components-datetime__time-field-am-pm" // Unused, for backwards compatibility.
|
|
130
|
+
,
|
|
131
|
+
children: [/*#__PURE__*/_jsx(Button, {
|
|
132
|
+
className: "components-datetime__time-am-button" // Unused, for backwards compatibility.
|
|
133
|
+
,
|
|
134
|
+
variant: dayPeriod === 'AM' ? 'primary' : 'secondary',
|
|
135
|
+
__next40pxDefaultSize: true,
|
|
136
|
+
onClick: buildAmPmChangeCallback('AM'),
|
|
137
|
+
children: __('AM')
|
|
138
|
+
}), /*#__PURE__*/_jsx(Button, {
|
|
139
|
+
className: "components-datetime__time-pm-button" // Unused, for backwards compatibility.
|
|
140
|
+
,
|
|
141
|
+
variant: dayPeriod === 'PM' ? 'primary' : 'secondary',
|
|
142
|
+
__next40pxDefaultSize: true,
|
|
143
|
+
onClick: buildAmPmChangeCallback('PM'),
|
|
144
|
+
children: __('PM')
|
|
145
|
+
})]
|
|
146
|
+
})]
|
|
147
|
+
})]
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
export default TimeInput;
|
|
151
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["clsx","__","Fragment","TimeWrapper","TimeSeparator","HoursInput","MinutesInput","Fieldset","HStack","Button","ButtonGroup","from12hTo24h","from24hTo12h","buildPadInputStateReducer","validateInputElementTarget","useControlledValue","BaseControl","jsx","_jsx","jsxs","_jsxs","TimeInput","value","valueProp","defaultValue","is12Hour","label","minutesProps","onChange","hours","Date","getHours","minutes","getMinutes","setValue","dayPeriod","parseDayPeriod","hours12Format","buildNumberControlChangeCallback","method","_value","event","numberValue","Number","buildAmPmChangeCallback","_hours","Wrapper","children","VisualLabel","as","alignment","expanded","className","hideLabelFromVision","__next40pxDefaultSize","String","padStart","step","min","max","required","spinControls","isPressEnterToChange","isDragEnabled","isShiftStepEnabled","__unstableStateReducer","args","variant","onClick"],"sources":["@wordpress/components/src/date-time/time-input/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport clsx from 'clsx';\n\n/**\n * WordPress dependencies\n */\nimport { __ } from '@wordpress/i18n';\nimport { Fragment } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport {\n\tTimeWrapper,\n\tTimeSeparator,\n\tHoursInput,\n\tMinutesInput,\n\tFieldset,\n} from '../time/styles';\nimport { HStack } from '../../h-stack';\nimport Button from '../../button';\nimport ButtonGroup from '../../button-group';\nimport {\n\tfrom12hTo24h,\n\tfrom24hTo12h,\n\tbuildPadInputStateReducer,\n\tvalidateInputElementTarget,\n} from '../utils';\nimport type { TimeInputProps } from '../types';\nimport type { InputChangeCallback } from '../../input-control/types';\nimport { useControlledValue } from '../../utils';\nimport BaseControl from '../../base-control';\n\nexport function TimeInput( {\n\tvalue: valueProp,\n\tdefaultValue,\n\tis12Hour,\n\tlabel,\n\tminutesProps,\n\tonChange,\n}: TimeInputProps ) {\n\tconst [\n\t\tvalue = {\n\t\t\thours: new Date().getHours(),\n\t\t\tminutes: new Date().getMinutes(),\n\t\t},\n\t\tsetValue,\n\t] = useControlledValue( {\n\t\tvalue: valueProp,\n\t\tonChange,\n\t\tdefaultValue,\n\t} );\n\tconst dayPeriod = parseDayPeriod( value.hours );\n\tconst hours12Format = from24hTo12h( value.hours );\n\n\tconst buildNumberControlChangeCallback = (\n\t\tmethod: 'hours' | 'minutes'\n\t): InputChangeCallback => {\n\t\treturn ( _value, { event } ) => {\n\t\t\tif ( ! validateInputElementTarget( event ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// We can safely assume value is a number if target is valid.\n\t\t\tconst numberValue = Number( _value );\n\n\t\t\tsetValue( {\n\t\t\t\t...value,\n\t\t\t\t[ method ]:\n\t\t\t\t\tmethod === 'hours' && is12Hour\n\t\t\t\t\t\t? from12hTo24h( numberValue, dayPeriod === 'PM' )\n\t\t\t\t\t\t: numberValue,\n\t\t\t} );\n\t\t};\n\t};\n\n\tconst buildAmPmChangeCallback = ( _value: 'AM' | 'PM' ) => {\n\t\treturn () => {\n\t\t\tif ( dayPeriod === _value ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsetValue( {\n\t\t\t\t...value,\n\t\t\t\thours: from12hTo24h( hours12Format, _value === 'PM' ),\n\t\t\t} );\n\t\t};\n\t};\n\n\tfunction parseDayPeriod( _hours: number ) {\n\t\treturn _hours < 12 ? 'AM' : 'PM';\n\t}\n\n\tconst Wrapper = label ? Fieldset : Fragment;\n\n\treturn (\n\t\t<Wrapper>\n\t\t\t{ label && (\n\t\t\t\t<BaseControl.VisualLabel as=\"legend\">\n\t\t\t\t\t{ label }\n\t\t\t\t</BaseControl.VisualLabel>\n\t\t\t) }\n\n\t\t\t<HStack alignment=\"left\" expanded={ false }>\n\t\t\t\t<TimeWrapper\n\t\t\t\t\tclassName=\"components-datetime__time-field components-datetime__time-field-time\" // Unused, for backwards compatibility.\n\t\t\t\t>\n\t\t\t\t\t<HoursInput\n\t\t\t\t\t\tclassName=\"components-datetime__time-field-hours-input\" // Unused, for backwards compatibility.\n\t\t\t\t\t\tlabel={ __( 'Hours' ) }\n\t\t\t\t\t\thideLabelFromVision\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvalue={ String(\n\t\t\t\t\t\t\tis12Hour ? hours12Format : value.hours\n\t\t\t\t\t\t).padStart( 2, '0' ) }\n\t\t\t\t\t\tstep={ 1 }\n\t\t\t\t\t\tmin={ is12Hour ? 1 : 0 }\n\t\t\t\t\t\tmax={ is12Hour ? 12 : 23 }\n\t\t\t\t\t\trequired\n\t\t\t\t\t\tspinControls=\"none\"\n\t\t\t\t\t\tisPressEnterToChange\n\t\t\t\t\t\tisDragEnabled={ false }\n\t\t\t\t\t\tisShiftStepEnabled={ false }\n\t\t\t\t\t\tonChange={ buildNumberControlChangeCallback( 'hours' ) }\n\t\t\t\t\t\t__unstableStateReducer={ buildPadInputStateReducer(\n\t\t\t\t\t\t\t2\n\t\t\t\t\t\t) }\n\t\t\t\t\t/>\n\t\t\t\t\t<TimeSeparator\n\t\t\t\t\t\tclassName=\"components-datetime__time-separator\" // Unused, for backwards compatibility.\n\t\t\t\t\t\taria-hidden=\"true\"\n\t\t\t\t\t>\n\t\t\t\t\t\t:\n\t\t\t\t\t</TimeSeparator>\n\t\t\t\t\t<MinutesInput\n\t\t\t\t\t\tclassName={ clsx(\n\t\t\t\t\t\t\t'components-datetime__time-field-minutes-input', // Unused, for backwards compatibility.\n\t\t\t\t\t\t\tminutesProps?.className\n\t\t\t\t\t\t) }\n\t\t\t\t\t\tlabel={ __( 'Minutes' ) }\n\t\t\t\t\t\thideLabelFromVision\n\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\tvalue={ String( value.minutes ).padStart( 2, '0' ) }\n\t\t\t\t\t\tstep={ 1 }\n\t\t\t\t\t\tmin={ 0 }\n\t\t\t\t\t\tmax={ 59 }\n\t\t\t\t\t\trequired\n\t\t\t\t\t\tspinControls=\"none\"\n\t\t\t\t\t\tisPressEnterToChange\n\t\t\t\t\t\tisDragEnabled={ false }\n\t\t\t\t\t\tisShiftStepEnabled={ false }\n\t\t\t\t\t\tonChange={ ( ...args ) => {\n\t\t\t\t\t\t\tbuildNumberControlChangeCallback( 'minutes' )(\n\t\t\t\t\t\t\t\t...args\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tminutesProps?.onChange?.( ...args );\n\t\t\t\t\t\t} }\n\t\t\t\t\t\t__unstableStateReducer={ buildPadInputStateReducer(\n\t\t\t\t\t\t\t2\n\t\t\t\t\t\t) }\n\t\t\t\t\t\t{ ...minutesProps }\n\t\t\t\t\t/>\n\t\t\t\t</TimeWrapper>\n\t\t\t\t{ is12Hour && (\n\t\t\t\t\t<ButtonGroup\n\t\t\t\t\t\tclassName=\"components-datetime__time-field components-datetime__time-field-am-pm\" // Unused, for backwards compatibility.\n\t\t\t\t\t>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tclassName=\"components-datetime__time-am-button\" // Unused, for backwards compatibility.\n\t\t\t\t\t\t\tvariant={\n\t\t\t\t\t\t\t\tdayPeriod === 'AM' ? 'primary' : 'secondary'\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tonClick={ buildAmPmChangeCallback( 'AM' ) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'AM' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t\t<Button\n\t\t\t\t\t\t\tclassName=\"components-datetime__time-pm-button\" // Unused, for backwards compatibility.\n\t\t\t\t\t\t\tvariant={\n\t\t\t\t\t\t\t\tdayPeriod === 'PM' ? 'primary' : 'secondary'\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t__next40pxDefaultSize\n\t\t\t\t\t\t\tonClick={ buildAmPmChangeCallback( 'PM' ) }\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t{ __( 'PM' ) }\n\t\t\t\t\t\t</Button>\n\t\t\t\t\t</ButtonGroup>\n\t\t\t\t) }\n\t\t\t</HStack>\n\t\t</Wrapper>\n\t);\n}\nexport default TimeInput;\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,IAAI,MAAM,MAAM;;AAEvB;AACA;AACA;AACA,SAASC,EAAE,QAAQ,iBAAiB;AACpC,SAASC,QAAQ,QAAQ,oBAAoB;;AAE7C;AACA;AACA;AACA,SACCC,WAAW,EACXC,aAAa,EACbC,UAAU,EACVC,YAAY,EACZC,QAAQ,QACF,gBAAgB;AACvB,SAASC,MAAM,QAAQ,eAAe;AACtC,OAAOC,MAAM,MAAM,cAAc;AACjC,OAAOC,WAAW,MAAM,oBAAoB;AAC5C,SACCC,YAAY,EACZC,YAAY,EACZC,yBAAyB,EACzBC,0BAA0B,QACpB,UAAU;AAGjB,SAASC,kBAAkB,QAAQ,aAAa;AAChD,OAAOC,WAAW,MAAM,oBAAoB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAAA,SAAAC,IAAA,IAAAC,KAAA;AAE7C,OAAO,SAASC,SAASA,CAAE;EAC1BC,KAAK,EAAEC,SAAS;EAChBC,YAAY;EACZC,QAAQ;EACRC,KAAK;EACLC,YAAY;EACZC;AACe,CAAC,EAAG;EACnB,MAAM,CACLN,KAAK,GAAG;IACPO,KAAK,EAAE,IAAIC,IAAI,CAAC,CAAC,CAACC,QAAQ,CAAC,CAAC;IAC5BC,OAAO,EAAE,IAAIF,I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3,"names":[],"sources":["@wordpress/components/src/date-time/types.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"names":[],"sources":["@wordpress/components/src/date-time/types.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport type { MinutesInput } from './time/styles';\n\nexport type TimePickerProps = {\n\t/**\n\t * The initial current time the time picker should render.\n\t */\n\tcurrentTime?: Date | string | number | null;\n\n\t/**\n\t * Whether we use a 12-hour clock. With a 12-hour clock, an AM/PM widget is\n\t * displayed and the time format is assumed to be `MM-DD-YYYY` (as opposed\n\t * to the default format `DD-MM-YYYY`).\n\t */\n\tis12Hour?: boolean;\n\n\t/**\n\t * The order of day, month, and year. This prop overrides the time format\n\t * determined by `is12Hour` prop.\n\t *\n\t * @default 'dmy'\n\t */\n\tdateOrder?: 'dmy' | 'mdy' | 'ymd';\n\n\t/**\n\t * The function called when a new time has been selected. It is passed the\n\t * time as an argument.\n\t */\n\tonChange?: ( time: string ) => void;\n};\n\nexport type TimeInputValue = {\n\t/**\n\t * The hours value in 24-hour format.\n\t */\n\thours: number;\n\n\t/**\n\t * The minutes value.\n\t */\n\tminutes: number;\n};\n\nexport type TimeInputProps = {\n\t/**\n\t * Whether we use a 12-hour clock. With a 12-hour clock, an AM/PM widget is\n\t * displayed\n\t */\n\tis12Hour?: boolean;\n\n\t/**\n\t * The time input object with hours and minutes values.\n\t *\n\t * - hours: number (24-hour format)\n\t * - minutes: number\n\t */\n\tvalue?: TimeInputValue;\n\n\t/**\n\t * An optional default value for the control when used in uncontrolled mode.\n\t * If left `undefined`, the current time will be used.\n\t */\n\tdefaultValue?: TimeInputValue;\n\n\t/**\n\t * The props to pass down to the minutes input.\n\t */\n\tminutesProps?: React.ComponentProps< typeof MinutesInput >;\n\n\t/**\n\t * The label for the time input.\n\t */\n\tlabel?: string;\n\n\t/**\n\t * The function is called when a new time has been selected.\n\t * Passing hours and minutes as an object properties.\n\t */\n\tonChange?: ( time: TimeInputValue ) => void;\n};\n\nexport type DatePickerEvent = {\n\t/**\n\t * The date of the event.\n\t */\n\tdate: Date;\n};\n\nexport type DatePickerProps = {\n\t/**\n\t * The current date and time at initialization. Optionally pass in a `null`\n\t * value to specify no date is currently selected.\n\t */\n\tcurrentDate?: Date | string | number | null;\n\n\t/**\n\t * The function called when a new date has been selected. It is passed the\n\t * date as an argument.\n\t */\n\tonChange?: ( date: string ) => void;\n\n\t/**\n\t * A callback function which receives a Date object representing a day as an\n\t * argument, and should return a Boolean to signify if the day is valid or\n\t * not.\n\t */\n\tisInvalidDate?: ( date: Date ) => boolean;\n\n\t/**\n\t * A callback invoked when selecting the previous/next month in the date\n\t * picker. The callback receives the new month date in the ISO format as an\n\t * argument.\n\t */\n\tonMonthPreviewed?: ( date: string ) => void;\n\n\t/**\n\t * List of events to show in the date picker. Each event will appear as a\n\t * dot on the day of the event.\n\t */\n\tevents?: DatePickerEvent[];\n\n\t/**\n\t * The day that the week should start on. 0 for Sunday, 1 for Monday, etc.\n\t *\n\t * @default 0\n\t */\n\tstartOfWeek?: 0 | 1 | 2 | 3 | 4 | 5 | 6;\n};\n\nexport type DateTimePickerProps = Omit< DatePickerProps, 'onChange' > &\n\tOmit< TimePickerProps, 'currentTime' | 'onChange' > & {\n\t\t/**\n\t\t * The function called when a new date or time has been selected. It is\n\t\t * passed the date and time as an argument.\n\t\t */\n\t\tonChange?: ( date: string | null ) => void;\n\t};\n"],"mappings":"","ignoreList":[]}
|