@wordpress/components 19.11.0 → 19.12.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 +36 -0
- package/README.md +1 -1
- package/build/alignment-matrix-control/index.js +5 -2
- package/build/alignment-matrix-control/index.js.map +1 -1
- package/build/autocomplete/autocompleter-ui.js +1 -1
- package/build/autocomplete/autocompleter-ui.js.map +1 -1
- package/build/autocomplete/autocompleter-ui.native.js +2 -2
- package/build/autocomplete/autocompleter-ui.native.js.map +1 -1
- package/build/autocomplete/index.js +12 -10
- package/build/autocomplete/index.js.map +1 -1
- package/build/border-box-control/border-box-control/hook.js +2 -2
- package/build/border-box-control/border-box-control/hook.js.map +1 -1
- package/build/border-box-control/border-box-control-split-controls/component.js +2 -0
- package/build/border-box-control/border-box-control-split-controls/component.js.map +1 -1
- package/build/border-box-control/border-box-control-split-controls/hook.js +13 -4
- package/build/border-box-control/border-box-control-split-controls/hook.js.map +1 -1
- package/build/border-box-control/border-box-control-visualizer/hook.js +6 -2
- package/build/border-box-control/border-box-control-visualizer/hook.js.map +1 -1
- package/build/border-box-control/styles.js +21 -11
- package/build/border-box-control/styles.js.map +1 -1
- package/build/border-control/border-control/hook.js +2 -2
- package/build/border-control/border-control/hook.js.map +1 -1
- package/build/color-palette/index.js +9 -2
- package/build/color-palette/index.js.map +1 -1
- package/build/color-palette/index.native.js +4 -1
- package/build/color-palette/index.native.js.map +1 -1
- package/build/color-picker/color-copy-button.js +87 -0
- package/build/color-picker/color-copy-button.js.map +1 -0
- package/build/color-picker/component.js +5 -15
- package/build/color-picker/component.js.map +1 -1
- package/build/color-picker/hex-input.js +18 -1
- package/build/color-picker/hex-input.js.map +1 -1
- package/build/color-picker/styles.js +11 -11
- package/build/color-picker/styles.js.map +1 -1
- package/build/custom-gradient-picker/utils.js +1 -1
- package/build/custom-gradient-picker/utils.js.map +1 -1
- package/build/date-time/{date.js → date/index.js} +51 -12
- package/build/date-time/date/index.js.map +1 -0
- package/build/date-time/date/styles.js +70 -0
- package/build/date-time/date/styles.js.map +1 -0
- package/build/date-time/{utils.js → date/utils.js} +0 -0
- package/build/date-time/date/utils.js.map +1 -0
- package/build/date-time/date-time/index.js +175 -0
- package/build/date-time/date-time/index.js.map +1 -0
- package/build/date-time/date-time/styles.js +32 -0
- package/build/date-time/date-time/styles.js.map +1 -0
- package/build/date-time/index.js +2 -109
- package/build/date-time/index.js.map +1 -1
- package/build/date-time/time/index.js +322 -0
- package/build/date-time/time/index.js.map +1 -0
- package/build/date-time/time/styles.js +139 -0
- package/build/date-time/time/styles.js.map +1 -0
- package/build/date-time/{timezone.js → time/timezone.js} +4 -2
- package/build/date-time/time/timezone.js.map +1 -0
- package/build/draggable/index.native.js +10 -5
- package/build/draggable/index.native.js.map +1 -1
- package/build/dropdown/index.js +4 -1
- package/build/dropdown/index.js.map +1 -1
- package/build/input-control/index.js +9 -4
- package/build/input-control/index.js.map +1 -1
- package/build/input-control/input-field.js +1 -26
- package/build/input-control/input-field.js.map +1 -1
- package/build/input-control/reducer/reducer.js +36 -24
- package/build/input-control/reducer/reducer.js.map +1 -1
- package/build/input-control/reducer/state.js +0 -1
- package/build/input-control/reducer/state.js.map +1 -1
- package/build/input-control/utils.js +45 -0
- package/build/input-control/utils.js.map +1 -1
- package/build/popover/index.js +40 -33
- package/build/popover/index.js.map +1 -1
- package/build/search-control/index.js +4 -6
- package/build/search-control/index.js.map +1 -1
- package/build/select-control/index.js +3 -1
- package/build/select-control/index.js.map +1 -1
- package/build/spacer/hook.js +11 -3
- package/build/spacer/hook.js.map +1 -1
- package/build/surface/component.js +7 -7
- package/build/surface/component.js.map +1 -1
- package/build/surface/hook.js +8 -11
- package/build/surface/hook.js.map +1 -1
- package/build/surface/index.js.map +1 -1
- package/build/surface/styles.js +8 -48
- package/build/surface/styles.js.map +1 -1
- package/build/textarea-control/index.js +40 -6
- package/build/textarea-control/index.js.map +1 -1
- package/build/textarea-control/styles/textarea-control-styles.js +3 -3
- package/build/textarea-control/styles/textarea-control-styles.js.map +1 -1
- package/build/textarea-control/types.js +6 -0
- package/build/textarea-control/types.js.map +1 -0
- package/build/utils/hooks/index.js +0 -8
- package/build/utils/hooks/index.js.map +1 -1
- package/build-module/alignment-matrix-control/index.js +5 -2
- package/build-module/alignment-matrix-control/index.js.map +1 -1
- package/build-module/autocomplete/autocompleter-ui.js +1 -1
- package/build-module/autocomplete/autocompleter-ui.js.map +1 -1
- package/build-module/autocomplete/autocompleter-ui.native.js +2 -2
- package/build-module/autocomplete/autocompleter-ui.native.js.map +1 -1
- package/build-module/autocomplete/index.js +13 -11
- package/build-module/autocomplete/index.js.map +1 -1
- package/build-module/border-box-control/border-box-control/hook.js +2 -2
- package/build-module/border-box-control/border-box-control/hook.js.map +1 -1
- package/build-module/border-box-control/border-box-control-split-controls/component.js +2 -0
- package/build-module/border-box-control/border-box-control-split-controls/component.js.map +1 -1
- package/build-module/border-box-control/border-box-control-split-controls/hook.js +11 -4
- package/build-module/border-box-control/border-box-control-split-controls/hook.js.map +1 -1
- package/build-module/border-box-control/border-box-control-visualizer/hook.js +4 -2
- package/build-module/border-box-control/border-box-control-visualizer/hook.js.map +1 -1
- package/build-module/border-box-control/styles.js +13 -8
- package/build-module/border-box-control/styles.js.map +1 -1
- package/build-module/border-control/border-control/hook.js +2 -2
- package/build-module/border-control/border-control/hook.js.map +1 -1
- package/build-module/color-palette/index.js +7 -5
- package/build-module/color-palette/index.js.map +1 -1
- package/build-module/color-palette/index.native.js +4 -1
- package/build-module/color-palette/index.native.js.map +1 -1
- package/build-module/color-picker/color-copy-button.js +73 -0
- package/build-module/color-picker/color-copy-button.js.map +1 -0
- package/build-module/color-picker/component.js +6 -15
- package/build-module/color-picker/component.js.map +1 -1
- package/build-module/color-picker/hex-input.js +18 -1
- package/build-module/color-picker/hex-input.js.map +1 -1
- package/build-module/color-picker/styles.js +9 -9
- package/build-module/color-picker/styles.js.map +1 -1
- package/build-module/custom-gradient-picker/utils.js +1 -1
- package/build-module/custom-gradient-picker/utils.js.map +1 -1
- package/build-module/date-time/{date.js → date/index.js} +46 -14
- package/build-module/date-time/date/index.js.map +1 -0
- package/build-module/date-time/date/styles.js +61 -0
- package/build-module/date-time/date/styles.js.map +1 -0
- package/build-module/date-time/{utils.js → date/utils.js} +0 -0
- package/build-module/date-time/date/utils.js.map +1 -0
- package/build-module/date-time/date-time/index.js +144 -0
- package/build-module/date-time/date-time/index.js.map +1 -0
- package/build-module/date-time/date-time/styles.js +22 -0
- package/build-module/date-time/date-time/styles.js.map +1 -0
- package/build-module/date-time/index.js +1 -105
- package/build-module/date-time/index.js.map +1 -1
- package/build-module/date-time/time/index.js +302 -0
- package/build-module/date-time/time/index.js.map +1 -0
- package/build-module/date-time/time/styles.js +118 -0
- package/build-module/date-time/time/styles.js.map +1 -0
- package/build-module/date-time/{timezone.js → time/timezone.js} +3 -2
- package/build-module/date-time/time/timezone.js.map +1 -0
- package/build-module/draggable/index.native.js +10 -5
- package/build-module/draggable/index.native.js.map +1 -1
- package/build-module/dropdown/index.js +4 -1
- package/build-module/dropdown/index.js.map +1 -1
- package/build-module/input-control/index.js +8 -4
- package/build-module/input-control/index.js.map +1 -1
- package/build-module/input-control/input-field.js +1 -25
- package/build-module/input-control/input-field.js.map +1 -1
- package/build-module/input-control/reducer/reducer.js +38 -26
- package/build-module/input-control/reducer/reducer.js.map +1 -1
- package/build-module/input-control/reducer/state.js +0 -1
- package/build-module/input-control/reducer/state.js.map +1 -1
- package/build-module/input-control/utils.js +48 -2
- package/build-module/input-control/utils.js.map +1 -1
- package/build-module/popover/index.js +40 -33
- package/build-module/popover/index.js.map +1 -1
- package/build-module/search-control/index.js +6 -7
- package/build-module/search-control/index.js.map +1 -1
- package/build-module/select-control/index.js +3 -1
- package/build-module/select-control/index.js.map +1 -1
- package/build-module/spacer/hook.js +10 -2
- package/build-module/spacer/hook.js.map +1 -1
- package/build-module/surface/component.js +7 -7
- package/build-module/surface/component.js.map +1 -1
- package/build-module/surface/hook.js +8 -11
- package/build-module/surface/hook.js.map +1 -1
- package/build-module/surface/index.js.map +1 -1
- package/build-module/surface/styles.js +8 -48
- package/build-module/surface/styles.js.map +1 -1
- package/build-module/textarea-control/index.js +36 -5
- package/build-module/textarea-control/index.js.map +1 -1
- package/build-module/textarea-control/styles/textarea-control-styles.js +3 -3
- package/build-module/textarea-control/styles/textarea-control-styles.js.map +1 -1
- package/build-module/textarea-control/types.js +2 -0
- package/build-module/textarea-control/types.js.map +1 -0
- package/build-module/utils/hooks/index.js +0 -1
- package/build-module/utils/hooks/index.js.map +1 -1
- package/build-style/style-rtl.css +13 -188
- package/build-style/style.css +13 -191
- package/build-types/border-box-control/border-box-control-split-controls/component.d.ts.map +1 -1
- package/build-types/border-box-control/border-box-control-split-controls/hook.d.ts +1 -0
- package/build-types/border-box-control/border-box-control-split-controls/hook.d.ts.map +1 -1
- package/build-types/border-box-control/border-box-control-visualizer/hook.d.ts.map +1 -1
- package/build-types/border-box-control/styles.d.ts +3 -2
- package/build-types/border-box-control/styles.d.ts.map +1 -1
- package/build-types/border-control/border-control/hook.d.ts.map +1 -1
- package/build-types/card/types.d.ts +1 -1
- package/build-types/card/types.d.ts.map +1 -1
- package/build-types/checkbox-control/test/index.d.ts +2 -0
- package/build-types/checkbox-control/test/index.d.ts.map +1 -0
- package/build-types/color-palette/index.d.ts +1 -0
- package/build-types/color-palette/index.d.ts.map +1 -1
- package/build-types/{date-time → color-palette}/test/utils.d.ts +0 -0
- package/build-types/color-palette/test/utils.d.ts.map +1 -0
- package/build-types/color-picker/color-copy-button.d.ts +4 -0
- package/build-types/color-picker/color-copy-button.d.ts.map +1 -0
- package/build-types/color-picker/component.d.ts.map +1 -1
- package/build-types/color-picker/hex-input.d.ts.map +1 -1
- package/build-types/color-picker/styles.d.ts +1 -1
- package/build-types/color-picker/styles.d.ts.map +1 -1
- package/build-types/color-picker/types.d.ts +8 -0
- package/build-types/color-picker/types.d.ts.map +1 -1
- package/build-types/date-time/{date.d.ts → date/index.d.ts} +3 -2
- package/build-types/date-time/date/index.d.ts.map +1 -0
- package/build-types/date-time/date/styles.d.ts +23 -0
- package/build-types/date-time/date/styles.d.ts.map +1 -0
- package/build-types/date-time/date/test/index.d.ts +2 -0
- package/build-types/date-time/date/test/index.d.ts.map +1 -0
- package/build-types/date-time/date/test/utils.d.ts +2 -0
- package/build-types/date-time/date/test/utils.d.ts.map +1 -0
- package/build-types/date-time/{utils.d.ts → date/utils.d.ts} +0 -0
- package/build-types/date-time/date/utils.d.ts.map +1 -0
- package/build-types/date-time/date-time/index.d.ts +33 -0
- package/build-types/date-time/date-time/index.d.ts.map +1 -0
- package/build-types/date-time/date-time/styles.d.ts +6 -0
- package/build-types/date-time/date-time/styles.d.ts.map +1 -0
- package/build-types/date-time/index.d.ts +2 -28
- package/build-types/date-time/index.d.ts.map +1 -1
- package/build-types/date-time/stories/{index.d.ts → date-time.d.ts} +2 -2
- package/build-types/date-time/stories/date-time.d.ts.map +1 -0
- package/build-types/date-time/{time.d.ts → time/index.d.ts} +2 -2
- package/build-types/date-time/time/index.d.ts.map +1 -0
- package/build-types/date-time/time/styles.d.ts +111 -0
- package/build-types/date-time/time/styles.d.ts.map +1 -0
- package/build-types/date-time/time/test/index.d.ts +2 -0
- package/build-types/date-time/time/test/index.d.ts.map +1 -0
- package/build-types/date-time/{timezone.d.ts → time/timezone.d.ts} +0 -0
- package/build-types/date-time/time/timezone.d.ts.map +1 -0
- package/build-types/date-time/types.d.ts +14 -15
- package/build-types/date-time/types.d.ts.map +1 -1
- package/build-types/dropdown/index.d.ts.map +1 -1
- package/build-types/input-control/index.d.ts.map +1 -1
- package/build-types/input-control/input-field.d.ts.map +1 -1
- package/build-types/input-control/reducer/reducer.d.ts +5 -3
- package/build-types/input-control/reducer/reducer.d.ts.map +1 -1
- package/build-types/input-control/reducer/state.d.ts +2 -2
- package/build-types/input-control/reducer/state.d.ts.map +1 -1
- package/build-types/input-control/utils.d.ts +17 -0
- package/build-types/input-control/utils.d.ts.map +1 -1
- package/build-types/popover/index.d.ts +1 -0
- package/build-types/popover/index.d.ts.map +1 -1
- package/build-types/select-control/index.d.ts.map +1 -1
- package/build-types/select-control/types.d.ts +1 -1
- package/build-types/select-control/types.d.ts.map +1 -1
- package/build-types/surface/component.d.ts +3 -2
- package/build-types/surface/component.d.ts.map +1 -1
- package/build-types/surface/hook.d.ts +4 -4
- package/build-types/surface/hook.d.ts.map +1 -1
- package/build-types/surface/index.d.ts +2 -2
- package/build-types/surface/index.d.ts.map +1 -1
- package/build-types/surface/stories/index.d.ts +12 -0
- package/build-types/surface/stories/index.d.ts.map +1 -0
- package/build-types/surface/styles.d.ts +10 -21
- package/build-types/surface/styles.d.ts.map +1 -1
- package/build-types/surface/test/index.d.ts +2 -0
- package/build-types/surface/test/index.d.ts.map +1 -0
- package/build-types/surface/types.d.ts +1 -1
- package/build-types/surface/types.d.ts.map +1 -1
- package/build-types/textarea-control/index.d.ts +29 -0
- package/build-types/textarea-control/index.d.ts.map +1 -0
- package/build-types/textarea-control/stories/index.d.ts +12 -0
- package/build-types/textarea-control/stories/index.d.ts.map +1 -0
- package/build-types/textarea-control/styles/textarea-control-styles.d.ts +6 -0
- package/build-types/textarea-control/styles/textarea-control-styles.d.ts.map +1 -0
- package/build-types/textarea-control/types.d.ts +26 -0
- package/build-types/textarea-control/types.d.ts.map +1 -0
- package/build-types/utils/hooks/index.d.ts +0 -1
- package/package.json +18 -18
- package/src/alignment-matrix-control/index.js +4 -2
- package/src/autocomplete/autocompleter-ui.js +1 -1
- package/src/autocomplete/autocompleter-ui.native.js +2 -2
- package/src/autocomplete/index.js +21 -9
- package/src/border-box-control/border-box-control/hook.ts +2 -2
- package/src/border-box-control/border-box-control-split-controls/component.tsx +2 -0
- package/src/border-box-control/border-box-control-split-controls/hook.ts +18 -4
- package/src/border-box-control/border-box-control-visualizer/hook.ts +5 -2
- package/src/border-box-control/styles.ts +6 -2
- package/src/border-control/border-control/hook.ts +8 -2
- package/src/box-control/test/index.js +120 -109
- package/src/card/types.ts +1 -1
- package/src/checkbox-control/test/__snapshots__/index.tsx.snap +42 -0
- package/src/checkbox-control/test/index.tsx +109 -0
- package/src/color-palette/index.js +11 -4
- package/src/color-palette/index.native.js +3 -0
- package/src/color-palette/stories/index.js +25 -1
- package/src/color-palette/test/utils.ts +24 -0
- package/src/color-picker/color-copy-button.tsx +76 -0
- package/src/color-picker/component.tsx +18 -38
- package/src/color-picker/hex-input.tsx +16 -0
- package/src/color-picker/styles.ts +5 -1
- package/src/color-picker/types.ts +9 -0
- package/src/custom-gradient-picker/utils.js +1 -1
- package/src/date-time/README.md +16 -0
- package/src/date-time/{datepicker.scss → date/datepicker.scss} +0 -0
- package/src/date-time/{date.tsx → date/index.tsx} +38 -15
- package/src/date-time/date/style.scss +75 -0
- package/src/date-time/date/styles.ts +55 -0
- package/src/date-time/{test/date.tsx → date/test/index.tsx} +1 -1
- package/src/date-time/{test → date/test}/utils.ts +0 -0
- package/src/date-time/{utils.ts → date/utils.ts} +0 -0
- package/src/date-time/date-time/index.tsx +217 -0
- package/src/date-time/date-time/styles.ts +8 -0
- package/src/date-time/index.ts +9 -0
- package/src/date-time/stories/{index.tsx → date-time.tsx} +1 -1
- package/src/date-time/style.scss +1 -262
- package/src/date-time/time/index.tsx +356 -0
- package/src/date-time/time/styles.ts +119 -0
- package/src/date-time/{test/time.tsx → time/test/index.tsx} +85 -38
- package/src/date-time/{timezone.tsx → time/timezone.tsx} +5 -2
- package/src/date-time/types.ts +16 -18
- package/src/draggable/index.native.js +14 -3
- package/src/draggable/test/index.native.js +130 -0
- package/src/dropdown/index.js +5 -1
- package/src/input-control/index.tsx +8 -2
- package/src/input-control/input-field.tsx +10 -30
- package/src/input-control/reducer/reducer.ts +40 -26
- package/src/input-control/reducer/state.ts +2 -3
- package/src/input-control/utils.ts +55 -1
- package/src/popover/index.js +42 -27
- package/src/query-controls/README.md +1 -1
- package/src/search-control/index.js +6 -7
- package/src/select-control/README.md +11 -0
- package/src/select-control/index.tsx +6 -1
- package/src/select-control/types.ts +1 -1
- package/src/slot-fill/README.md +1 -1
- package/src/spacer/hook.ts +13 -13
- package/src/surface/README.md +15 -15
- package/src/surface/{component.js → component.tsx} +13 -7
- package/src/surface/{hook.js → hook.ts} +13 -12
- package/src/surface/{index.js → index.ts} +0 -0
- package/src/surface/stories/index.tsx +40 -0
- package/src/surface/{styles.js → styles.ts} +15 -44
- package/src/surface/test/__snapshots__/{index.js.snap → index.tsx.snap} +0 -0
- package/src/surface/test/{index.js → index.tsx} +2 -1
- package/src/surface/types.ts +1 -1
- package/src/textarea-control/README.md +14 -20
- package/src/textarea-control/index.tsx +86 -0
- package/src/textarea-control/stories/index.tsx +58 -0
- package/src/textarea-control/styles/{textarea-control-styles.js → textarea-control-styles.ts} +0 -0
- package/src/textarea-control/types.ts +30 -0
- package/src/utils/hooks/index.js +0 -1
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/build/color-picker/color-display.js +0 -184
- package/build/color-picker/color-display.js.map +0 -1
- package/build/date-time/date.js.map +0 -1
- package/build/date-time/time.js +0 -289
- package/build/date-time/time.js.map +0 -1
- package/build/date-time/timezone.js.map +0 -1
- package/build/date-time/utils.js.map +0 -1
- package/build/utils/hooks/use-combined-ref.js +0 -32
- package/build/utils/hooks/use-combined-ref.js.map +0 -1
- package/build-module/color-picker/color-display.js +0 -170
- package/build-module/color-picker/color-display.js.map +0 -1
- package/build-module/date-time/date.js.map +0 -1
- package/build-module/date-time/time.js +0 -271
- package/build-module/date-time/time.js.map +0 -1
- package/build-module/date-time/timezone.js.map +0 -1
- package/build-module/date-time/utils.js.map +0 -1
- package/build-module/utils/hooks/use-combined-ref.js +0 -28
- package/build-module/utils/hooks/use-combined-ref.js.map +0 -1
- package/build-types/color-picker/color-display.d.ts +0 -14
- package/build-types/color-picker/color-display.d.ts.map +0 -1
- package/build-types/date-time/date.d.ts.map +0 -1
- package/build-types/date-time/stories/index.d.ts.map +0 -1
- package/build-types/date-time/test/date.d.ts +0 -2
- package/build-types/date-time/test/date.d.ts.map +0 -1
- package/build-types/date-time/test/time.d.ts +0 -2
- package/build-types/date-time/test/time.d.ts.map +0 -1
- package/build-types/date-time/test/utils.d.ts.map +0 -1
- package/build-types/date-time/time.d.ts.map +0 -1
- package/build-types/date-time/timezone.d.ts.map +0 -1
- package/build-types/date-time/utils.d.ts.map +0 -1
- package/build-types/utils/hooks/use-combined-ref.d.ts +0 -8
- package/build-types/utils/hooks/use-combined-ref.d.ts.map +0 -1
- package/src/color-picker/color-display.tsx +0 -169
- package/src/date-time/index.tsx +0 -196
- package/src/date-time/time.tsx +0 -321
- package/src/surface/stories/index.js +0 -46
- package/src/textarea-control/index.js +0 -45
- package/src/textarea-control/stories/index.js +0 -48
- package/src/utils/hooks/use-combined-ref.ts +0 -28
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import type { Colord } from 'colord';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* WordPress dependencies
|
|
8
|
-
*/
|
|
9
|
-
import { useCopyToClipboard } from '@wordpress/compose';
|
|
10
|
-
import { useState, useEffect, useRef } from '@wordpress/element';
|
|
11
|
-
import { __ } from '@wordpress/i18n';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Internal dependencies
|
|
15
|
-
*/
|
|
16
|
-
import { Text } from '../text';
|
|
17
|
-
import { Flex, FlexItem } from '../flex';
|
|
18
|
-
import { Tooltip } from '../ui/tooltip';
|
|
19
|
-
import type { ColorType } from './types';
|
|
20
|
-
import { space } from '../ui/utils/space';
|
|
21
|
-
import { COLORS } from '../utils/colors-values';
|
|
22
|
-
|
|
23
|
-
interface ColorDisplayProps {
|
|
24
|
-
color: Colord;
|
|
25
|
-
colorType: ColorType;
|
|
26
|
-
enableAlpha: boolean;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
interface DisplayProps {
|
|
30
|
-
color: Colord;
|
|
31
|
-
enableAlpha: boolean;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
type Values = [ number, string ][];
|
|
35
|
-
|
|
36
|
-
interface ValueDisplayProps {
|
|
37
|
-
values: Values;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const ValueDisplay = ( { values }: ValueDisplayProps ) => (
|
|
41
|
-
<>
|
|
42
|
-
{ values.map( ( [ value, abbreviation ] ) => {
|
|
43
|
-
return (
|
|
44
|
-
<FlexItem key={ abbreviation } isBlock display="flex">
|
|
45
|
-
<Text color={ COLORS.ui.theme }>{ abbreviation }</Text>
|
|
46
|
-
<Text>{ value }</Text>
|
|
47
|
-
</FlexItem>
|
|
48
|
-
);
|
|
49
|
-
} ) }
|
|
50
|
-
</>
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
const HslDisplay = ( { color, enableAlpha }: DisplayProps ) => {
|
|
54
|
-
const { h, s, l, a } = color.toHsl();
|
|
55
|
-
|
|
56
|
-
const values: Values = [
|
|
57
|
-
[ Math.floor( h ), 'H' ],
|
|
58
|
-
[ Math.round( s * 100 ), 'S' ],
|
|
59
|
-
[ Math.round( l * 100 ), 'L' ],
|
|
60
|
-
];
|
|
61
|
-
if ( enableAlpha ) {
|
|
62
|
-
values.push( [ Math.round( a * 100 ), 'A' ] );
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return <ValueDisplay values={ values } />;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
const RgbDisplay = ( { color, enableAlpha }: DisplayProps ) => {
|
|
69
|
-
const { r, g, b, a } = color.toRgb();
|
|
70
|
-
|
|
71
|
-
const values: Values = [
|
|
72
|
-
[ r, 'R' ],
|
|
73
|
-
[ g, 'G' ],
|
|
74
|
-
[ b, 'B' ],
|
|
75
|
-
];
|
|
76
|
-
|
|
77
|
-
if ( enableAlpha ) {
|
|
78
|
-
values.push( [ Math.round( a * 100 ), 'A' ] );
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
return <ValueDisplay values={ values } />;
|
|
82
|
-
};
|
|
83
|
-
|
|
84
|
-
const HexDisplay = ( { color }: DisplayProps ) => {
|
|
85
|
-
const colorWithoutHash = color.toHex().slice( 1 ).toUpperCase();
|
|
86
|
-
return (
|
|
87
|
-
<FlexItem>
|
|
88
|
-
<Text color={ COLORS.ui.theme }>#</Text>
|
|
89
|
-
<Text>{ colorWithoutHash }</Text>
|
|
90
|
-
</FlexItem>
|
|
91
|
-
);
|
|
92
|
-
};
|
|
93
|
-
|
|
94
|
-
const getComponent = ( colorType: ColorType ) => {
|
|
95
|
-
switch ( colorType ) {
|
|
96
|
-
case 'hsl':
|
|
97
|
-
return HslDisplay;
|
|
98
|
-
case 'rgb':
|
|
99
|
-
return RgbDisplay;
|
|
100
|
-
default:
|
|
101
|
-
case 'hex':
|
|
102
|
-
return HexDisplay;
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
export const ColorDisplay = ( {
|
|
107
|
-
color,
|
|
108
|
-
colorType,
|
|
109
|
-
enableAlpha,
|
|
110
|
-
}: ColorDisplayProps ) => {
|
|
111
|
-
const [ copiedColor, setCopiedColor ] = useState< string | null >( null );
|
|
112
|
-
const copyTimer = useRef< ReturnType< typeof setTimeout > | undefined >();
|
|
113
|
-
const props = { color, enableAlpha };
|
|
114
|
-
const Component = getComponent( colorType );
|
|
115
|
-
const copyRef = useCopyToClipboard< HTMLDivElement >(
|
|
116
|
-
() => {
|
|
117
|
-
switch ( colorType ) {
|
|
118
|
-
case 'hsl': {
|
|
119
|
-
return color.toHslString();
|
|
120
|
-
}
|
|
121
|
-
case 'rgb': {
|
|
122
|
-
return color.toRgbString();
|
|
123
|
-
}
|
|
124
|
-
default:
|
|
125
|
-
case 'hex': {
|
|
126
|
-
return color.toHex();
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
},
|
|
130
|
-
() => {
|
|
131
|
-
if ( copyTimer.current ) {
|
|
132
|
-
clearTimeout( copyTimer.current );
|
|
133
|
-
}
|
|
134
|
-
setCopiedColor( color.toHex() );
|
|
135
|
-
copyTimer.current = setTimeout( () => {
|
|
136
|
-
setCopiedColor( null );
|
|
137
|
-
copyTimer.current = undefined;
|
|
138
|
-
}, 3000 );
|
|
139
|
-
}
|
|
140
|
-
);
|
|
141
|
-
useEffect( () => {
|
|
142
|
-
// Clear copyTimer on component unmount.
|
|
143
|
-
return () => {
|
|
144
|
-
if ( copyTimer.current ) {
|
|
145
|
-
clearTimeout( copyTimer.current );
|
|
146
|
-
}
|
|
147
|
-
};
|
|
148
|
-
}, [] );
|
|
149
|
-
return (
|
|
150
|
-
<Tooltip
|
|
151
|
-
content={
|
|
152
|
-
<Text color="white">
|
|
153
|
-
{ copiedColor === color.toHex()
|
|
154
|
-
? __( 'Copied!' )
|
|
155
|
-
: __( 'Copy' ) }
|
|
156
|
-
</Text>
|
|
157
|
-
}
|
|
158
|
-
>
|
|
159
|
-
<Flex
|
|
160
|
-
justify="flex-start"
|
|
161
|
-
gap={ space( 1 ) }
|
|
162
|
-
ref={ copyRef }
|
|
163
|
-
style={ { height: 30 } }
|
|
164
|
-
>
|
|
165
|
-
<Component { ...props } />
|
|
166
|
-
</Flex>
|
|
167
|
-
</Tooltip>
|
|
168
|
-
);
|
|
169
|
-
};
|
package/src/date-time/index.tsx
DELETED
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
// Needed to initialise the default datepicker styles.
|
|
5
|
-
// See: https://github.com/airbnb/react-dates#initialize
|
|
6
|
-
import 'react-dates/initialize';
|
|
7
|
-
import { noop } from 'lodash';
|
|
8
|
-
import type { ForwardedRef } from 'react';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* WordPress dependencies
|
|
12
|
-
*/
|
|
13
|
-
import { useState, forwardRef } from '@wordpress/element';
|
|
14
|
-
import { __, _x } from '@wordpress/i18n';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Internal dependencies
|
|
18
|
-
*/
|
|
19
|
-
import Button from '../button';
|
|
20
|
-
import { default as DatePicker } from './date';
|
|
21
|
-
import { default as TimePicker } from './time';
|
|
22
|
-
import type { DateTimePickerProps } from './types';
|
|
23
|
-
|
|
24
|
-
export { DatePicker, TimePicker };
|
|
25
|
-
|
|
26
|
-
function UnforwardedDateTimePicker(
|
|
27
|
-
{
|
|
28
|
-
currentDate,
|
|
29
|
-
is12Hour,
|
|
30
|
-
isInvalidDate,
|
|
31
|
-
onMonthPreviewed = noop,
|
|
32
|
-
onChange,
|
|
33
|
-
events,
|
|
34
|
-
}: DateTimePickerProps,
|
|
35
|
-
ref: ForwardedRef< any >
|
|
36
|
-
) {
|
|
37
|
-
const [ calendarHelpIsVisible, setCalendarHelpIsVisible ] = useState(
|
|
38
|
-
false
|
|
39
|
-
);
|
|
40
|
-
|
|
41
|
-
function onClickDescriptionToggle() {
|
|
42
|
-
setCalendarHelpIsVisible( ! calendarHelpIsVisible );
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return (
|
|
46
|
-
<div ref={ ref } className="components-datetime">
|
|
47
|
-
{ ! calendarHelpIsVisible && (
|
|
48
|
-
<>
|
|
49
|
-
<TimePicker
|
|
50
|
-
currentTime={ currentDate }
|
|
51
|
-
onChange={ onChange }
|
|
52
|
-
is12Hour={ is12Hour }
|
|
53
|
-
/>
|
|
54
|
-
<DatePicker
|
|
55
|
-
currentDate={ currentDate }
|
|
56
|
-
onChange={ onChange }
|
|
57
|
-
isInvalidDate={ isInvalidDate }
|
|
58
|
-
events={ events }
|
|
59
|
-
onMonthPreviewed={ onMonthPreviewed }
|
|
60
|
-
/>
|
|
61
|
-
</>
|
|
62
|
-
) }
|
|
63
|
-
{ calendarHelpIsVisible && (
|
|
64
|
-
<>
|
|
65
|
-
<div className="components-datetime__calendar-help">
|
|
66
|
-
<h4>{ __( 'Click to Select' ) }</h4>
|
|
67
|
-
<ul>
|
|
68
|
-
<li>
|
|
69
|
-
{ __(
|
|
70
|
-
'Click the right or left arrows to select other months in the past or the future.'
|
|
71
|
-
) }
|
|
72
|
-
</li>
|
|
73
|
-
<li>
|
|
74
|
-
{ __( 'Click the desired day to select it.' ) }
|
|
75
|
-
</li>
|
|
76
|
-
</ul>
|
|
77
|
-
<h4>{ __( 'Navigating with a keyboard' ) }</h4>
|
|
78
|
-
<ul>
|
|
79
|
-
<li>
|
|
80
|
-
<abbr
|
|
81
|
-
aria-label={ _x(
|
|
82
|
-
'Enter',
|
|
83
|
-
'keyboard button'
|
|
84
|
-
) }
|
|
85
|
-
>
|
|
86
|
-
↵
|
|
87
|
-
</abbr>
|
|
88
|
-
{
|
|
89
|
-
' ' /* JSX removes whitespace, but a space is required for screen readers. */
|
|
90
|
-
}
|
|
91
|
-
<span>
|
|
92
|
-
{ __( 'Select the date in focus.' ) }
|
|
93
|
-
</span>
|
|
94
|
-
</li>
|
|
95
|
-
<li>
|
|
96
|
-
<abbr
|
|
97
|
-
aria-label={ __( 'Left and Right Arrows' ) }
|
|
98
|
-
>
|
|
99
|
-
←/→
|
|
100
|
-
</abbr>
|
|
101
|
-
{
|
|
102
|
-
' ' /* JSX removes whitespace, but a space is required for screen readers. */
|
|
103
|
-
}
|
|
104
|
-
{ __(
|
|
105
|
-
'Move backward (left) or forward (right) by one day.'
|
|
106
|
-
) }
|
|
107
|
-
</li>
|
|
108
|
-
<li>
|
|
109
|
-
<abbr aria-label={ __( 'Up and Down Arrows' ) }>
|
|
110
|
-
↑/↓
|
|
111
|
-
</abbr>
|
|
112
|
-
{
|
|
113
|
-
' ' /* JSX removes whitespace, but a space is required for screen readers. */
|
|
114
|
-
}
|
|
115
|
-
{ __(
|
|
116
|
-
'Move backward (up) or forward (down) by one week.'
|
|
117
|
-
) }
|
|
118
|
-
</li>
|
|
119
|
-
<li>
|
|
120
|
-
<abbr
|
|
121
|
-
aria-label={ __( 'Page Up and Page Down' ) }
|
|
122
|
-
>
|
|
123
|
-
{ __( 'PgUp/PgDn' ) }
|
|
124
|
-
</abbr>
|
|
125
|
-
{
|
|
126
|
-
' ' /* JSX removes whitespace, but a space is required for screen readers. */
|
|
127
|
-
}
|
|
128
|
-
{ __(
|
|
129
|
-
'Move backward (PgUp) or forward (PgDn) by one month.'
|
|
130
|
-
) }
|
|
131
|
-
</li>
|
|
132
|
-
<li>
|
|
133
|
-
<abbr aria-label={ __( 'Home and End' ) }>
|
|
134
|
-
{ /* Translators: Home/End reffer to the 'Home' and 'End' buttons on the keyboard.*/ }
|
|
135
|
-
{ __( 'Home/End' ) }
|
|
136
|
-
</abbr>
|
|
137
|
-
{
|
|
138
|
-
' ' /* JSX removes whitespace, but a space is required for screen readers. */
|
|
139
|
-
}
|
|
140
|
-
{ __(
|
|
141
|
-
'Go to the first (Home) or last (End) day of a week.'
|
|
142
|
-
) }
|
|
143
|
-
</li>
|
|
144
|
-
</ul>
|
|
145
|
-
</div>
|
|
146
|
-
</>
|
|
147
|
-
) }
|
|
148
|
-
<div className="components-datetime__buttons">
|
|
149
|
-
{ ! calendarHelpIsVisible && currentDate && (
|
|
150
|
-
<Button
|
|
151
|
-
className="components-datetime__date-reset-button"
|
|
152
|
-
variant="link"
|
|
153
|
-
onClick={ () => onChange?.( null ) }
|
|
154
|
-
>
|
|
155
|
-
{ __( 'Reset' ) }
|
|
156
|
-
</Button>
|
|
157
|
-
) }
|
|
158
|
-
<Button
|
|
159
|
-
className="components-datetime__date-help-toggle"
|
|
160
|
-
variant="link"
|
|
161
|
-
onClick={ onClickDescriptionToggle }
|
|
162
|
-
>
|
|
163
|
-
{ calendarHelpIsVisible
|
|
164
|
-
? __( 'Close' )
|
|
165
|
-
: __( 'Calendar Help' ) }
|
|
166
|
-
</Button>
|
|
167
|
-
</div>
|
|
168
|
-
</div>
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* DateTimePicker is a React component that renders a calendar and clock for
|
|
174
|
-
* date and time selection. The calendar and clock components can be accessed
|
|
175
|
-
* individually using the `DatePicker` and `TimePicker` components respectively.
|
|
176
|
-
*
|
|
177
|
-
* ```jsx
|
|
178
|
-
* import { DateTimePicker } from '@wordpress/components';
|
|
179
|
-
* import { useState } from '@wordpress/element';
|
|
180
|
-
*
|
|
181
|
-
* const MyDateTimePicker = () => {
|
|
182
|
-
* const [ date, setDate ] = useState( new Date() );
|
|
183
|
-
*
|
|
184
|
-
* return (
|
|
185
|
-
* <DateTimePicker
|
|
186
|
-
* currentDate={ date }
|
|
187
|
-
* onChange={ ( newDate ) => setDate( newDate ) }
|
|
188
|
-
* is12Hour
|
|
189
|
-
* />
|
|
190
|
-
* );
|
|
191
|
-
* };
|
|
192
|
-
* ```
|
|
193
|
-
*/
|
|
194
|
-
export const DateTimePicker = forwardRef( UnforwardedDateTimePicker );
|
|
195
|
-
|
|
196
|
-
export default DateTimePicker;
|
package/src/date-time/time.tsx
DELETED
|
@@ -1,321 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import classnames from 'classnames';
|
|
5
|
-
import { isInteger } from 'lodash';
|
|
6
|
-
import moment from 'moment';
|
|
7
|
-
import type { FocusEvent } from 'react';
|
|
8
|
-
import type { Moment } from 'moment';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* WordPress dependencies
|
|
12
|
-
*/
|
|
13
|
-
import {
|
|
14
|
-
createElement,
|
|
15
|
-
useState,
|
|
16
|
-
useMemo,
|
|
17
|
-
useEffect,
|
|
18
|
-
} from '@wordpress/element';
|
|
19
|
-
import { __ } from '@wordpress/i18n';
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Internal dependencies
|
|
23
|
-
*/
|
|
24
|
-
import Button from '../button';
|
|
25
|
-
import ButtonGroup from '../button-group';
|
|
26
|
-
import TimeZone from './timezone';
|
|
27
|
-
import type { WordPressComponentProps } from '../ui/context';
|
|
28
|
-
import type { UpdateOnBlurAsIntegerFieldProps, TimePickerProps } from './types';
|
|
29
|
-
|
|
30
|
-
const TIMEZONELESS_FORMAT = 'YYYY-MM-DDTHH:mm:ss';
|
|
31
|
-
|
|
32
|
-
function from12hTo24h( hours: number, isPm: boolean ) {
|
|
33
|
-
return isPm ? ( ( hours % 12 ) + 12 ) % 24 : hours % 12;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* A shared component to parse, validate, and handle remounting of the
|
|
38
|
-
* underlying form field element like <input> and <select>.
|
|
39
|
-
*/
|
|
40
|
-
function UpdateOnBlurAsIntegerField( {
|
|
41
|
-
as,
|
|
42
|
-
value,
|
|
43
|
-
onUpdate,
|
|
44
|
-
className,
|
|
45
|
-
...props
|
|
46
|
-
}: WordPressComponentProps< UpdateOnBlurAsIntegerFieldProps, 'input', true > ) {
|
|
47
|
-
function handleBlur( event: FocusEvent< HTMLInputElement > ) {
|
|
48
|
-
const { target } = event;
|
|
49
|
-
|
|
50
|
-
if ( String( value ) === target.value ) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const parsedValue = parseInt( target.value, 10 );
|
|
55
|
-
|
|
56
|
-
// Run basic number validation on the input.
|
|
57
|
-
if (
|
|
58
|
-
! isInteger( parsedValue ) ||
|
|
59
|
-
( typeof props.max !== 'undefined' && parsedValue > props.max ) ||
|
|
60
|
-
( typeof props.min !== 'undefined' && parsedValue < props.min )
|
|
61
|
-
) {
|
|
62
|
-
// If validation failed, reset the value to the previous valid value.
|
|
63
|
-
target.value = String( value );
|
|
64
|
-
} else {
|
|
65
|
-
// Otherwise, it's valid, call onUpdate.
|
|
66
|
-
onUpdate( parsedValue );
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return createElement( as || 'input', {
|
|
71
|
-
// Re-mount the input value to accept the latest value as the defaultValue.
|
|
72
|
-
key: value,
|
|
73
|
-
defaultValue: value,
|
|
74
|
-
onBlur: handleBlur,
|
|
75
|
-
className: classnames(
|
|
76
|
-
'components-datetime__time-field-integer-field',
|
|
77
|
-
className
|
|
78
|
-
),
|
|
79
|
-
...props,
|
|
80
|
-
} );
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/**
|
|
84
|
-
* TimePicker is a React component that renders a clock for time selection.
|
|
85
|
-
*
|
|
86
|
-
* ```jsx
|
|
87
|
-
* import { TimePicker } from '@wordpress/components';
|
|
88
|
-
* import { useState } from '@wordpress/element';
|
|
89
|
-
*
|
|
90
|
-
* const MyTimePicker = () => {
|
|
91
|
-
* const [ time, setTime ] = useState( new Date() );
|
|
92
|
-
*
|
|
93
|
-
* return (
|
|
94
|
-
* <TimePicker
|
|
95
|
-
* currentTime={ date }
|
|
96
|
-
* onChange={ ( newTime ) => setTime( newTime ) }
|
|
97
|
-
* is12Hour
|
|
98
|
-
* />
|
|
99
|
-
* );
|
|
100
|
-
* };
|
|
101
|
-
* ```
|
|
102
|
-
*/
|
|
103
|
-
export function TimePicker( {
|
|
104
|
-
is12Hour,
|
|
105
|
-
currentTime,
|
|
106
|
-
onChange,
|
|
107
|
-
}: TimePickerProps ) {
|
|
108
|
-
const [ date, setDate ] = useState( () =>
|
|
109
|
-
// Truncate the date at the minutes, see: #15495.
|
|
110
|
-
currentTime ? moment( currentTime ).startOf( 'minutes' ) : moment()
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
// Reset the state when currentTime changed.
|
|
114
|
-
useEffect( () => {
|
|
115
|
-
setDate(
|
|
116
|
-
currentTime ? moment( currentTime ).startOf( 'minutes' ) : moment()
|
|
117
|
-
);
|
|
118
|
-
}, [ currentTime ] );
|
|
119
|
-
|
|
120
|
-
const { day, month, year, minutes, hours, am } = useMemo(
|
|
121
|
-
() => ( {
|
|
122
|
-
day: date.format( 'DD' ),
|
|
123
|
-
month: date.format( 'MM' ),
|
|
124
|
-
year: date.format( 'YYYY' ),
|
|
125
|
-
minutes: date.format( 'mm' ),
|
|
126
|
-
hours: date.format( is12Hour ? 'hh' : 'HH' ),
|
|
127
|
-
am: Number( date.format( 'H' ) ) <= 11 ? 'AM' : 'PM',
|
|
128
|
-
} ),
|
|
129
|
-
[ date, is12Hour ]
|
|
130
|
-
);
|
|
131
|
-
|
|
132
|
-
/**
|
|
133
|
-
* Function that sets the date state and calls the onChange with a new date.
|
|
134
|
-
* The date is truncated at the minutes.
|
|
135
|
-
*
|
|
136
|
-
* @param {Moment} newDate The date object.
|
|
137
|
-
*/
|
|
138
|
-
function changeDate( newDate: Moment ) {
|
|
139
|
-
setDate( newDate );
|
|
140
|
-
onChange?.( newDate.format( TIMEZONELESS_FORMAT ) );
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function update( name: 'date' | 'month' | 'year' | 'hours' | 'minutes' ) {
|
|
144
|
-
return ( value: number ) => {
|
|
145
|
-
// If the 12-hour format is being used and the 'PM' period is selected, then
|
|
146
|
-
// the incoming value (which ranges 1-12) should be increased by 12 to match
|
|
147
|
-
// the expected 24-hour format.
|
|
148
|
-
let adjustedValue = value;
|
|
149
|
-
if ( name === 'hours' && is12Hour ) {
|
|
150
|
-
adjustedValue = from12hTo24h( value, am === 'PM' );
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
// Clone the date and call the specific setter function according to `name`.
|
|
154
|
-
const newDate = date.clone()[ name ]( adjustedValue );
|
|
155
|
-
changeDate( newDate );
|
|
156
|
-
};
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function updateAmPm( value: 'AM' | 'PM' ) {
|
|
160
|
-
return () => {
|
|
161
|
-
if ( am === value ) {
|
|
162
|
-
return;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
const parsedHours = parseInt( hours, 10 );
|
|
166
|
-
|
|
167
|
-
const newDate = date
|
|
168
|
-
.clone()
|
|
169
|
-
.hours( from12hTo24h( parsedHours, value === 'PM' ) );
|
|
170
|
-
|
|
171
|
-
changeDate( newDate );
|
|
172
|
-
};
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const dayFormat = (
|
|
176
|
-
<div className="components-datetime__time-field components-datetime__time-field-day">
|
|
177
|
-
<UpdateOnBlurAsIntegerField
|
|
178
|
-
aria-label={ __( 'Day' ) }
|
|
179
|
-
className="components-datetime__time-field-day-input"
|
|
180
|
-
type="number"
|
|
181
|
-
// The correct function to call in moment.js is "date" not "day".
|
|
182
|
-
name="date"
|
|
183
|
-
value={ day }
|
|
184
|
-
step={ 1 }
|
|
185
|
-
min={ 1 }
|
|
186
|
-
max={ 31 }
|
|
187
|
-
onUpdate={ update( 'date' ) }
|
|
188
|
-
/>
|
|
189
|
-
</div>
|
|
190
|
-
);
|
|
191
|
-
|
|
192
|
-
const monthFormat = (
|
|
193
|
-
<div className="components-datetime__time-field components-datetime__time-field-month">
|
|
194
|
-
<UpdateOnBlurAsIntegerField
|
|
195
|
-
as="select"
|
|
196
|
-
aria-label={ __( 'Month' ) }
|
|
197
|
-
className="components-datetime__time-field-month-select"
|
|
198
|
-
name="month"
|
|
199
|
-
value={ month }
|
|
200
|
-
// The value starts from 0, so we have to -1 when setting month.
|
|
201
|
-
onUpdate={ ( value ) => update( 'month' )( value - 1 ) }
|
|
202
|
-
>
|
|
203
|
-
<option value="01">{ __( 'January' ) }</option>
|
|
204
|
-
<option value="02">{ __( 'February' ) }</option>
|
|
205
|
-
<option value="03">{ __( 'March' ) }</option>
|
|
206
|
-
<option value="04">{ __( 'April' ) }</option>
|
|
207
|
-
<option value="05">{ __( 'May' ) }</option>
|
|
208
|
-
<option value="06">{ __( 'June' ) }</option>
|
|
209
|
-
<option value="07">{ __( 'July' ) }</option>
|
|
210
|
-
<option value="08">{ __( 'August' ) }</option>
|
|
211
|
-
<option value="09">{ __( 'September' ) }</option>
|
|
212
|
-
<option value="10">{ __( 'October' ) }</option>
|
|
213
|
-
<option value="11">{ __( 'November' ) }</option>
|
|
214
|
-
<option value="12">{ __( 'December' ) }</option>
|
|
215
|
-
</UpdateOnBlurAsIntegerField>
|
|
216
|
-
</div>
|
|
217
|
-
);
|
|
218
|
-
|
|
219
|
-
const dayMonthFormat = is12Hour ? (
|
|
220
|
-
<>
|
|
221
|
-
{ monthFormat }
|
|
222
|
-
{ dayFormat }
|
|
223
|
-
</>
|
|
224
|
-
) : (
|
|
225
|
-
<>
|
|
226
|
-
{ dayFormat }
|
|
227
|
-
{ monthFormat }
|
|
228
|
-
</>
|
|
229
|
-
);
|
|
230
|
-
|
|
231
|
-
return (
|
|
232
|
-
<div className={ classnames( 'components-datetime__time' ) }>
|
|
233
|
-
<fieldset>
|
|
234
|
-
<legend className="components-datetime__time-legend invisible">
|
|
235
|
-
{ __( 'Date' ) }
|
|
236
|
-
</legend>
|
|
237
|
-
<div className="components-datetime__time-wrapper">
|
|
238
|
-
{ dayMonthFormat }
|
|
239
|
-
|
|
240
|
-
<div className="components-datetime__time-field components-datetime__time-field-year">
|
|
241
|
-
<UpdateOnBlurAsIntegerField
|
|
242
|
-
aria-label={ __( 'Year' ) }
|
|
243
|
-
className="components-datetime__time-field-year-input"
|
|
244
|
-
type="number"
|
|
245
|
-
name="year"
|
|
246
|
-
step={ 1 }
|
|
247
|
-
min={ 0 }
|
|
248
|
-
max={ 9999 }
|
|
249
|
-
value={ year }
|
|
250
|
-
onUpdate={ update( 'year' ) }
|
|
251
|
-
/>
|
|
252
|
-
</div>
|
|
253
|
-
</div>
|
|
254
|
-
</fieldset>
|
|
255
|
-
|
|
256
|
-
<fieldset>
|
|
257
|
-
<legend className="components-datetime__time-legend invisible">
|
|
258
|
-
{ __( 'Time' ) }
|
|
259
|
-
</legend>
|
|
260
|
-
<div className="components-datetime__time-wrapper">
|
|
261
|
-
<div className="components-datetime__time-field components-datetime__time-field-time">
|
|
262
|
-
<UpdateOnBlurAsIntegerField
|
|
263
|
-
aria-label={ __( 'Hours' ) }
|
|
264
|
-
className="components-datetime__time-field-hours-input"
|
|
265
|
-
type="number"
|
|
266
|
-
name="hours"
|
|
267
|
-
step={ 1 }
|
|
268
|
-
min={ is12Hour ? 1 : 0 }
|
|
269
|
-
max={ is12Hour ? 12 : 23 }
|
|
270
|
-
value={ hours }
|
|
271
|
-
onUpdate={ update( 'hours' ) }
|
|
272
|
-
/>
|
|
273
|
-
<span
|
|
274
|
-
className="components-datetime__time-separator"
|
|
275
|
-
aria-hidden="true"
|
|
276
|
-
>
|
|
277
|
-
:
|
|
278
|
-
</span>
|
|
279
|
-
<UpdateOnBlurAsIntegerField
|
|
280
|
-
aria-label={ __( 'Minutes' ) }
|
|
281
|
-
className="components-datetime__time-field-minutes-input"
|
|
282
|
-
type="number"
|
|
283
|
-
name="minutes"
|
|
284
|
-
step={ 1 }
|
|
285
|
-
min={ 0 }
|
|
286
|
-
max={ 59 }
|
|
287
|
-
value={ minutes }
|
|
288
|
-
onUpdate={ update( 'minutes' ) }
|
|
289
|
-
/>
|
|
290
|
-
</div>
|
|
291
|
-
{ is12Hour && (
|
|
292
|
-
<ButtonGroup className="components-datetime__time-field components-datetime__time-field-am-pm">
|
|
293
|
-
<Button
|
|
294
|
-
variant={
|
|
295
|
-
am === 'AM' ? 'primary' : 'secondary'
|
|
296
|
-
}
|
|
297
|
-
onClick={ updateAmPm( 'AM' ) }
|
|
298
|
-
className="components-datetime__time-am-button"
|
|
299
|
-
>
|
|
300
|
-
{ __( 'AM' ) }
|
|
301
|
-
</Button>
|
|
302
|
-
<Button
|
|
303
|
-
variant={
|
|
304
|
-
am === 'PM' ? 'primary' : 'secondary'
|
|
305
|
-
}
|
|
306
|
-
onClick={ updateAmPm( 'PM' ) }
|
|
307
|
-
className="components-datetime__time-pm-button"
|
|
308
|
-
>
|
|
309
|
-
{ __( 'PM' ) }
|
|
310
|
-
</Button>
|
|
311
|
-
</ButtonGroup>
|
|
312
|
-
) }
|
|
313
|
-
|
|
314
|
-
<TimeZone />
|
|
315
|
-
</div>
|
|
316
|
-
</fieldset>
|
|
317
|
-
</div>
|
|
318
|
-
);
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
export default TimePicker;
|