@wordpress/components 23.2.0 → 23.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 +35 -1
- package/CONTRIBUTING.md +1 -1
- package/build/alignment-matrix-control/utils.js +2 -2
- package/build/alignment-matrix-control/utils.js.map +1 -1
- package/build/autocomplete/autocompleter-ui.js +1 -3
- package/build/autocomplete/autocompleter-ui.js.map +1 -1
- package/build/border-box-control/border-box-control-linked-button/component.js.map +1 -1
- package/build/border-box-control/border-box-control-linked-button/hook.js.map +1 -1
- package/build/border-control/border-control-dropdown/component.js +8 -4
- package/build/border-control/border-control-dropdown/component.js.map +1 -1
- package/build/button/deprecated.js +8 -6
- package/build/button/deprecated.js.map +1 -1
- package/build/button/index.js +52 -23
- package/build/button/index.js.map +1 -1
- package/build/button/types.js +6 -0
- package/build/button/types.js.map +1 -0
- package/build/color-list-picker/index.js.map +1 -1
- package/build/color-list-picker/types.js +6 -0
- package/build/color-list-picker/types.js.map +1 -0
- package/build/color-palette/index.js +9 -61
- package/build/color-palette/index.js.map +1 -1
- package/build/color-palette/index.native.js +24 -9
- package/build/color-palette/index.native.js.map +1 -1
- package/build/color-palette/utils.js +103 -0
- package/build/color-palette/utils.js.map +1 -0
- package/build/custom-gradient-picker/gradient-bar/utils.js +1 -1
- package/build/custom-gradient-picker/gradient-bar/utils.js.map +1 -1
- package/build/date-time/date/index.js.map +1 -1
- package/build/dropdown/index.js +20 -8
- package/build/dropdown/index.js.map +1 -1
- package/build/form-token-field/token.js +1 -1
- package/build/form-token-field/token.js.map +1 -1
- package/build/gradient-picker/index.js +9 -1
- package/build/gradient-picker/index.js.map +1 -1
- package/build/h-stack/component.js +0 -1
- package/build/h-stack/component.js.map +1 -1
- package/build/input-control/input-field.js +4 -2
- package/build/input-control/input-field.js.map +1 -1
- package/build/keyboard-shortcuts/index.js +44 -16
- package/build/keyboard-shortcuts/index.js.map +1 -1
- package/build/keyboard-shortcuts/types.js +6 -0
- package/build/keyboard-shortcuts/types.js.map +1 -0
- package/build/modal/index.js +1 -1
- package/build/modal/index.js.map +1 -1
- package/build/notice/index.js +16 -18
- package/build/notice/index.js.map +1 -1
- package/build/notice/list.js +23 -8
- package/build/notice/list.js.map +1 -1
- package/build/notice/types.js +6 -0
- package/build/notice/types.js.map +1 -0
- package/build/number-control/index.js +1 -1
- package/build/number-control/index.js.map +1 -1
- package/build/query-controls/author-select.js +7 -3
- package/build/query-controls/author-select.js.map +1 -1
- package/build/query-controls/category-select.js +7 -3
- package/build/query-controls/category-select.js.map +1 -1
- package/build/query-controls/index.js +68 -20
- package/build/query-controls/index.js.map +1 -1
- package/build/query-controls/terms.js +4 -3
- package/build/query-controls/terms.js.map +1 -1
- package/build/query-controls/types.js +6 -0
- package/build/query-controls/types.js.map +1 -0
- package/build/slot-fill/bubbles-virtually/fill.js +1 -0
- package/build/slot-fill/bubbles-virtually/fill.js.map +1 -1
- package/build/slot-fill/slot.js +1 -0
- package/build/slot-fill/slot.js.map +1 -1
- package/build/slot-fill/use-slot.js +1 -11
- package/build/slot-fill/use-slot.js.map +1 -1
- package/build/snackbar/index.js.map +1 -1
- package/build/snackbar/list.js.map +1 -1
- package/build/tab-panel/index.js +36 -8
- package/build/tab-panel/index.js.map +1 -1
- package/build/tree-grid/index.js +1 -1
- package/build/tree-grid/index.js.map +1 -1
- package/build/tree-select/index.js +2 -6
- package/build/tree-select/index.js.map +1 -1
- package/build-module/alignment-matrix-control/utils.js +2 -2
- package/build-module/alignment-matrix-control/utils.js.map +1 -1
- package/build-module/autocomplete/autocompleter-ui.js +1 -2
- package/build-module/autocomplete/autocompleter-ui.js.map +1 -1
- package/build-module/border-box-control/border-box-control-linked-button/component.js.map +1 -1
- package/build-module/border-box-control/border-box-control-linked-button/hook.js.map +1 -1
- package/build-module/border-control/border-control-dropdown/component.js +7 -4
- package/build-module/border-control/border-control-dropdown/component.js.map +1 -1
- package/build-module/button/deprecated.js +8 -5
- package/build-module/button/deprecated.js.map +1 -1
- package/build-module/button/index.js +51 -22
- package/build-module/button/index.js.map +1 -1
- package/build-module/button/types.js +2 -0
- package/build-module/button/types.js.map +1 -0
- package/build-module/color-list-picker/index.js.map +1 -1
- package/build-module/color-list-picker/types.js +2 -0
- package/build-module/color-list-picker/types.js.map +1 -0
- package/build-module/color-palette/index.js +7 -54
- package/build-module/color-palette/index.js.map +1 -1
- package/build-module/color-palette/index.native.js +24 -8
- package/build-module/color-palette/index.native.js.map +1 -1
- package/build-module/color-palette/utils.js +79 -0
- package/build-module/color-palette/utils.js.map +1 -0
- package/build-module/custom-gradient-picker/gradient-bar/utils.js +1 -1
- package/build-module/custom-gradient-picker/gradient-bar/utils.js.map +1 -1
- package/build-module/date-time/date/index.js +1 -1
- package/build-module/date-time/date/index.js.map +1 -1
- package/build-module/dropdown/index.js +19 -8
- package/build-module/dropdown/index.js.map +1 -1
- package/build-module/form-token-field/token.js +1 -1
- package/build-module/form-token-field/token.js.map +1 -1
- package/build-module/gradient-picker/index.js +9 -2
- package/build-module/gradient-picker/index.js.map +1 -1
- package/build-module/h-stack/component.js +0 -1
- package/build-module/h-stack/component.js.map +1 -1
- package/build-module/input-control/input-field.js +4 -2
- package/build-module/input-control/input-field.js.map +1 -1
- package/build-module/keyboard-shortcuts/index.js +48 -16
- package/build-module/keyboard-shortcuts/index.js.map +1 -1
- package/build-module/keyboard-shortcuts/types.js +2 -0
- package/build-module/keyboard-shortcuts/types.js.map +1 -0
- package/build-module/modal/index.js +1 -1
- package/build-module/modal/index.js.map +1 -1
- package/build-module/notice/index.js +14 -15
- package/build-module/notice/index.js.map +1 -1
- package/build-module/notice/list.js +23 -8
- package/build-module/notice/list.js.map +1 -1
- package/build-module/notice/types.js +2 -0
- package/build-module/notice/types.js.map +1 -0
- package/build-module/number-control/index.js +1 -1
- package/build-module/number-control/index.js.map +1 -1
- package/build-module/query-controls/author-select.js +7 -3
- package/build-module/query-controls/author-select.js.map +1 -1
- package/build-module/query-controls/category-select.js +8 -4
- package/build-module/query-controls/category-select.js.map +1 -1
- package/build-module/query-controls/index.js +64 -20
- package/build-module/query-controls/index.js.map +1 -1
- package/build-module/query-controls/terms.js +8 -4
- package/build-module/query-controls/terms.js.map +1 -1
- package/build-module/query-controls/types.js +2 -0
- package/build-module/query-controls/types.js.map +1 -0
- package/build-module/slot-fill/bubbles-virtually/fill.js +1 -0
- package/build-module/slot-fill/bubbles-virtually/fill.js.map +1 -1
- package/build-module/slot-fill/slot.js +1 -0
- package/build-module/slot-fill/slot.js.map +1 -1
- package/build-module/slot-fill/use-slot.js +2 -12
- package/build-module/slot-fill/use-slot.js.map +1 -1
- package/build-module/snackbar/index.js.map +1 -1
- package/build-module/snackbar/list.js.map +1 -1
- package/build-module/tab-panel/index.js +36 -8
- package/build-module/tab-panel/index.js.map +1 -1
- package/build-module/tree-grid/index.js +1 -1
- package/build-module/tree-grid/index.js.map +1 -1
- package/build-module/tree-select/index.js +2 -6
- package/build-module/tree-select/index.js.map +1 -1
- package/build-style/style-rtl.css +5 -0
- package/build-style/style.css +5 -0
- package/build-types/border-box-control/border-box-control/hook.d.ts +1 -1
- package/build-types/border-box-control/border-box-control-linked-button/component.d.ts +1 -1
- package/build-types/border-box-control/border-box-control-linked-button/hook.d.ts +171 -160
- package/build-types/border-box-control/border-box-control-linked-button/hook.d.ts.map +1 -1
- package/build-types/border-box-control/border-box-control-split-controls/hook.d.ts +1 -1
- package/build-types/border-control/border-control/hook.d.ts +1 -1
- package/build-types/border-control/border-control-dropdown/component.d.ts.map +1 -1
- package/build-types/border-control/border-control-dropdown/hook.d.ts +1 -1
- package/build-types/button/deprecated.d.ts +143 -7
- package/build-types/button/deprecated.d.ts.map +1 -1
- package/build-types/button/index.d.ts +20 -3
- package/build-types/button/index.d.ts.map +1 -1
- package/build-types/button/stories/index.d.ts +20 -0
- package/build-types/button/stories/index.d.ts.map +1 -0
- package/build-types/button/test/index.d.ts +2 -0
- package/build-types/button/test/index.d.ts.map +1 -0
- package/build-types/button/types.d.ts +134 -0
- package/build-types/button/types.d.ts.map +1 -0
- package/build-types/color-list-picker/index.d.ts +5 -0
- package/build-types/color-list-picker/index.d.ts.map +1 -0
- package/build-types/color-list-picker/types.d.ts +42 -0
- package/build-types/color-list-picker/types.d.ts.map +1 -0
- package/build-types/color-palette/index.d.ts +2 -4
- package/build-types/color-palette/index.d.ts.map +1 -1
- package/build-types/color-palette/stories/index.d.ts +2 -2
- package/build-types/color-palette/styles.d.ts +1 -1
- package/build-types/color-palette/types.d.ts +1 -1
- package/build-types/color-palette/types.d.ts.map +1 -1
- package/build-types/color-palette/utils.d.ts +14 -0
- package/build-types/color-palette/utils.d.ts.map +1 -0
- package/build-types/color-picker/styles.d.ts +2 -2
- package/build-types/date-time/date/index.d.ts.map +1 -1
- package/build-types/date-time/date/styles.d.ts +3 -3
- package/build-types/dropdown/index.d.ts +4 -4
- package/build-types/dropdown/index.d.ts.map +1 -1
- package/build-types/dropdown/stories/index.d.ts.map +1 -1
- package/build-types/dropdown/types.d.ts +9 -10
- package/build-types/dropdown/types.d.ts.map +1 -1
- package/build-types/font-size-picker/styles.d.ts +2 -2
- package/build-types/h-stack/component.d.ts +0 -1
- package/build-types/h-stack/component.d.ts.map +1 -1
- package/build-types/input-control/input-field.d.ts.map +1 -1
- package/build-types/keyboard-shortcuts/index.d.ts +38 -0
- package/build-types/keyboard-shortcuts/index.d.ts.map +1 -0
- package/build-types/keyboard-shortcuts/stories/index.d.ts +12 -0
- package/build-types/keyboard-shortcuts/stories/index.d.ts.map +1 -0
- package/build-types/keyboard-shortcuts/test/index.d.ts +2 -0
- package/build-types/keyboard-shortcuts/test/index.d.ts.map +1 -0
- package/build-types/keyboard-shortcuts/types.d.ts +48 -0
- package/build-types/keyboard-shortcuts/types.d.ts.map +1 -0
- package/build-types/modal/index.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 +2 -2
- package/build-types/navigator/navigator-button/component.d.ts +1 -1
- package/build-types/navigator/navigator-button/hook.d.ts +2 -2
- package/build-types/notice/index.d.ts +16 -0
- package/build-types/notice/index.d.ts.map +1 -0
- package/build-types/notice/list.d.ts +32 -0
- package/build-types/notice/list.d.ts.map +1 -0
- package/build-types/notice/stories/index.d.ts +17 -0
- package/build-types/notice/stories/index.d.ts.map +1 -0
- package/build-types/notice/test/index.d.ts +2 -0
- package/build-types/notice/test/index.d.ts.map +1 -0
- package/build-types/notice/test/list.d.ts +2 -0
- package/build-types/notice/test/list.d.ts.map +1 -0
- package/build-types/notice/types.d.ts +128 -0
- package/build-types/notice/types.d.ts.map +1 -0
- package/build-types/number-control/styles/number-control-styles.d.ts +2 -2
- package/build-types/number-control/styles/number-control-styles.d.ts.map +1 -1
- package/build-types/placeholder/stories/index.d.ts.map +1 -1
- package/build-types/query-controls/author-select.d.ts +4 -0
- package/build-types/query-controls/author-select.d.ts.map +1 -0
- package/build-types/query-controls/category-select.d.ts +4 -0
- package/build-types/query-controls/category-select.d.ts.map +1 -0
- package/build-types/query-controls/index.d.ts +30 -0
- package/build-types/query-controls/index.d.ts.map +1 -0
- package/build-types/query-controls/stories/index.d.ts +13 -0
- package/build-types/query-controls/stories/index.d.ts.map +1 -0
- package/build-types/query-controls/terms.d.ts +13 -0
- package/build-types/query-controls/terms.d.ts.map +1 -0
- package/build-types/query-controls/test/terms.d.ts +2 -0
- package/build-types/query-controls/test/terms.d.ts.map +1 -0
- package/build-types/query-controls/types.d.ts +131 -0
- package/build-types/query-controls/types.d.ts.map +1 -0
- package/build-types/range-control/index.d.ts +1 -1
- package/build-types/slot-fill/bubbles-virtually/fill.d.ts.map +1 -1
- package/build-types/slot-fill/use-slot.d.ts.map +1 -1
- package/build-types/snackbar/index.d.ts +9 -2
- package/build-types/snackbar/index.d.ts.map +1 -1
- package/build-types/snackbar/list.d.ts.map +1 -1
- package/build-types/snackbar/types.d.ts +15 -88
- package/build-types/snackbar/types.d.ts.map +1 -1
- package/build-types/tab-panel/index.d.ts.map +1 -1
- package/build-types/tab-panel/types.d.ts +1 -1
- package/build-types/tab-panel/types.d.ts.map +1 -1
- package/build-types/toggle-group-control/stories/index.d.ts.map +1 -1
- package/build-types/tree-select/index.d.ts.map +1 -1
- package/build-types/ui/form-group/form-group.d.ts +2 -2
- package/package.json +18 -17
- package/src/alignment-matrix-control/utils.tsx +2 -2
- package/src/autocomplete/autocompleter-ui.js +1 -2
- package/src/autocomplete/test/index.js +1 -5
- package/src/border-box-control/border-box-control-linked-button/component.tsx +1 -1
- package/src/border-box-control/border-box-control-linked-button/hook.ts +1 -1
- package/src/border-control/border-control-dropdown/component.tsx +9 -8
- package/src/box-control/test/index.js +11 -35
- package/src/button/README.md +49 -55
- package/src/button/{deprecated.js → deprecated.tsx} +19 -4
- package/src/button/{index.js → index.tsx} +95 -34
- package/src/button/stories/index.tsx +106 -0
- package/src/button/style.scss +3 -2
- package/src/button/test/{index.js → index.tsx} +30 -7
- package/src/button/types.ts +138 -0
- package/src/checkbox-control/test/index.tsx +1 -5
- package/src/color-list-picker/{index.js → index.tsx} +3 -2
- package/src/color-list-picker/types.ts +46 -0
- package/src/color-palette/README.md +1 -1
- package/src/color-palette/index.native.js +11 -4
- package/src/color-palette/index.tsx +11 -67
- package/src/color-palette/test/index.tsx +4 -14
- package/src/color-palette/test/utils.ts +1 -1
- package/src/color-palette/types.ts +1 -1
- package/src/color-palette/utils.ts +98 -0
- package/src/color-picker/test/index.js +6 -15
- package/src/combobox-control/test/index.js +1 -6
- package/src/confirm-dialog/test/index.js +9 -29
- package/src/custom-gradient-picker/gradient-bar/utils.js +1 -1
- package/src/date-time/date/index.tsx +2 -1
- package/src/date-time/date/test/index.tsx +2 -8
- package/src/date-time/time/test/index.tsx +9 -29
- package/src/dimension-control/test/index.test.js +2 -8
- package/src/disabled/test/index.tsx +1 -5
- package/src/draggable/test/index.native.js +4 -4
- package/src/dropdown/README.md +1 -8
- package/src/dropdown/index.tsx +17 -6
- package/src/dropdown/stories/index.tsx +3 -3
- package/src/dropdown/test/index.tsx +2 -8
- package/src/dropdown/types.ts +9 -10
- package/src/dropdown-menu/README.md +1 -1
- package/src/dropdown-menu/stories/index.js +96 -27
- package/src/dropdown-menu/test/index.js +2 -8
- package/src/external-link/test/index.tsx +1 -6
- package/src/focal-point-picker/test/index.js +3 -11
- package/src/font-size-picker/test/index.tsx +14 -44
- package/src/form-file-upload/test/index.tsx +2 -17
- package/src/form-toggle/test/index.tsx +1 -5
- package/src/form-token-field/test/index.tsx +80 -163
- package/src/form-token-field/token.tsx +1 -1
- package/src/gradient-picker/index.js +15 -4
- package/src/guide/test/index.js +5 -17
- package/src/h-stack/component.tsx +0 -1
- package/src/higher-order/with-filters/test/index.js +24 -24
- package/src/higher-order/with-focus-outside/test/index.js +11 -25
- package/src/higher-order/with-focus-return/test/index.js +1 -5
- package/src/input-control/input-field.tsx +3 -1
- package/src/input-control/test/index.js +1 -6
- package/src/isolated-event-container/test/index.js +2 -8
- package/src/keyboard-shortcuts/README.md +1 -1
- package/src/keyboard-shortcuts/index.tsx +93 -0
- package/src/keyboard-shortcuts/stories/index.tsx +60 -0
- package/src/keyboard-shortcuts/test/{index.js → index.tsx} +16 -6
- package/src/keyboard-shortcuts/types.ts +51 -0
- package/src/modal/index.tsx +1 -2
- package/src/navigable-container/test/navigable-menu.js +5 -17
- package/src/navigable-container/test/tababble-container.js +3 -11
- package/src/navigation/test/index.js +3 -11
- package/src/navigator/test/index.tsx +6 -20
- package/src/notice/README.md +89 -42
- package/src/notice/{index.js → index.tsx} +28 -20
- package/src/notice/list.tsx +72 -0
- package/src/notice/stories/index.tsx +119 -0
- package/src/notice/test/__snapshots__/{index.js.snap → index.tsx.snap} +0 -0
- package/src/notice/test/{index.js → index.tsx} +7 -4
- package/src/notice/test/{list.js → list.tsx} +0 -0
- package/src/notice/types.ts +136 -0
- package/src/number-control/index.tsx +1 -1
- package/src/number-control/test/index.tsx +28 -86
- package/src/panel/test/body.js +2 -8
- package/src/placeholder/stories/index.tsx +1 -0
- package/src/query-controls/README.md +56 -56
- package/src/query-controls/author-select.tsx +37 -0
- package/src/query-controls/category-select.tsx +46 -0
- package/src/query-controls/index.tsx +192 -0
- package/src/query-controls/stories/index.tsx +205 -0
- package/src/query-controls/terms.ts +57 -0
- package/src/query-controls/test/{terms.js → terms.ts} +36 -20
- package/src/query-controls/types.ts +150 -0
- package/src/select-control/test/select-control.tsx +1 -6
- package/src/slot-fill/bubbles-virtually/fill.js +1 -0
- package/src/slot-fill/slot.js +1 -1
- package/src/slot-fill/use-slot.js +6 -16
- package/src/snackbar/index.tsx +6 -5
- package/src/snackbar/list.tsx +4 -2
- package/src/snackbar/types.ts +18 -92
- package/src/tab-panel/index.tsx +38 -16
- package/src/tab-panel/style.scss +8 -0
- package/src/tab-panel/test/index.tsx +35 -7
- package/src/tab-panel/types.ts +1 -1
- package/src/theme/test/index.tsx +4 -4
- package/src/toggle-group-control/stories/index.tsx +1 -0
- package/src/toggle-group-control/test/index.tsx +7 -23
- package/src/toolbar/stories/index.js +75 -72
- package/src/tools-panel/stories/index.js +3 -0
- package/src/tools-panel/test/index.js +1 -1
- package/src/tree-grid/index.js +1 -1
- package/src/tree-select/index.tsx +3 -6
- package/src/ui/context/test/context-connect.tsx +2 -0
- package/src/ui/context/test/wordpress-component.tsx +2 -0
- package/src/unit-control/test/index.tsx +21 -74
- package/src/utils/hooks/test/use-latest-ref.js +15 -18
- package/tsconfig.json +1 -4
- package/tsconfig.tsbuildinfo +1 -1
- package/build-types/radio-context/index.d.ts +0 -6
- package/build-types/radio-context/index.d.ts.map +0 -1
- package/src/button/stories/index.js +0 -179
- package/src/keyboard-shortcuts/index.js +0 -56
- package/src/notice/list.js +0 -48
- package/src/notice/stories/index.js +0 -46
- package/src/query-controls/author-select.js +0 -23
- package/src/query-controls/category-select.js +0 -31
- package/src/query-controls/index.js +0 -122
- package/src/query-controls/terms.js +0 -40
- package/src/toolbar/stories/toolbar-button.js +0 -32
- package/src/toolbar/stories/toolbar-group.js +0 -33
|
@@ -28,10 +28,10 @@ const QUERY_DEFAULTS = {
|
|
|
28
28
|
},
|
|
29
29
|
],
|
|
30
30
|
maxItems: 20,
|
|
31
|
-
minItems: 1,
|
|
31
|
+
minItems: 1,
|
|
32
32
|
numberOfItems: 10,
|
|
33
33
|
order: 'asc',
|
|
34
|
-
orderBy: 'title',
|
|
34
|
+
orderBy: 'title',
|
|
35
35
|
};
|
|
36
36
|
|
|
37
37
|
const MyQueryControls = () => {
|
|
@@ -66,24 +66,35 @@ The `QueryControls` component now supports multiple category selection, to repla
|
|
|
66
66
|
const QUERY_DEFAULTS = {
|
|
67
67
|
orderBy: 'title',
|
|
68
68
|
order: 'asc',
|
|
69
|
-
selectedCategories: [
|
|
70
|
-
categories: [
|
|
69
|
+
selectedCategories: [
|
|
71
70
|
{
|
|
72
71
|
id: 1,
|
|
73
|
-
|
|
72
|
+
value: 'Category 1',
|
|
74
73
|
parent: 0,
|
|
75
74
|
},
|
|
76
75
|
{
|
|
76
|
+
id: 2,
|
|
77
|
+
value: 'Category 1b',
|
|
78
|
+
parent: 1,
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
categories: {
|
|
82
|
+
'Category 1': {
|
|
83
|
+
id: 1,
|
|
84
|
+
name: 'Category 1',
|
|
85
|
+
parent: 0,
|
|
86
|
+
},
|
|
87
|
+
'Category 1b': {
|
|
77
88
|
id: 2,
|
|
78
89
|
name: 'Category 1b',
|
|
79
90
|
parent: 1,
|
|
80
91
|
},
|
|
81
|
-
{
|
|
92
|
+
'Category 2': {
|
|
82
93
|
id: 3,
|
|
83
94
|
name: 'Category 2',
|
|
84
95
|
parent: 0,
|
|
85
96
|
},
|
|
86
|
-
|
|
97
|
+
},
|
|
87
98
|
numberOfItems: 10,
|
|
88
99
|
};
|
|
89
100
|
|
|
@@ -111,132 +122,121 @@ const MyQueryControls = () => {
|
|
|
111
122
|
};
|
|
112
123
|
```
|
|
113
124
|
|
|
114
|
-
The format of the categories list also needs to be updated to match
|
|
125
|
+
The format of the categories list also needs to be updated to match the expected type for the category suggestions.
|
|
115
126
|
|
|
116
127
|
### Props
|
|
117
128
|
|
|
118
|
-
#### authorList
|
|
129
|
+
#### `authorList`: `Author[]`
|
|
119
130
|
|
|
120
|
-
An array of
|
|
131
|
+
An array of the authors to select from.
|
|
121
132
|
|
|
122
|
-
- Type: `Array`
|
|
123
133
|
- Required: No
|
|
124
134
|
- Platform: Web
|
|
125
135
|
|
|
126
|
-
####
|
|
136
|
+
#### `categoriesList`: `Category[]`
|
|
127
137
|
|
|
128
|
-
|
|
138
|
+
An array of categories. When passed in conjunction with the `onCategoryChange` prop, it causes the component to render UI that allows selecting one category at a time.
|
|
129
139
|
|
|
130
|
-
- Type: `Number`
|
|
131
140
|
- Required: No
|
|
132
141
|
- Platform: Web
|
|
133
142
|
|
|
134
|
-
####
|
|
143
|
+
#### `categorySuggestions`: `Record< Category[ 'name' ], Category >`
|
|
135
144
|
|
|
136
|
-
An
|
|
145
|
+
An object of categories with the category name as the key. When passed in conjunction with the `onCategoryChange` prop, it causes the component to render UI that enables multiple selection.
|
|
137
146
|
|
|
138
|
-
- Type: `Array`
|
|
139
147
|
- Required: No
|
|
140
148
|
- Platform: Web
|
|
141
149
|
|
|
142
|
-
####
|
|
150
|
+
#### `maxItems`: `number`
|
|
143
151
|
|
|
144
|
-
|
|
152
|
+
The maximum number of items.
|
|
145
153
|
|
|
146
|
-
- Type: `Array`
|
|
147
154
|
- Required: No
|
|
155
|
+
- Default: 100
|
|
148
156
|
- Platform: Web
|
|
149
157
|
|
|
150
|
-
####
|
|
158
|
+
#### `minItems`: `number`
|
|
159
|
+
|
|
160
|
+
The minimum number of items.
|
|
151
161
|
|
|
152
|
-
- Type: `Number`
|
|
153
162
|
- Required: No
|
|
154
|
-
- Default:
|
|
163
|
+
- Default: 1
|
|
155
164
|
- Platform: Web
|
|
156
165
|
|
|
157
|
-
####
|
|
166
|
+
#### `numberOfItems`: `number`
|
|
167
|
+
|
|
168
|
+
The selected number of items to retrieve via the query.
|
|
158
169
|
|
|
159
|
-
- Type: `Number`
|
|
160
170
|
- Required: No
|
|
161
|
-
- Default: 1
|
|
162
171
|
- Platform: Web
|
|
163
172
|
|
|
164
|
-
####
|
|
173
|
+
#### `onAuthorChange`: `( newAuthor: string ) => void`
|
|
165
174
|
|
|
166
|
-
|
|
175
|
+
A function that receives the new author value. If not specified, the author controls are not rendered.
|
|
167
176
|
|
|
168
|
-
- Type: `Number`
|
|
169
177
|
- Required: No
|
|
170
178
|
- Platform: Web
|
|
171
179
|
|
|
172
|
-
####
|
|
180
|
+
#### `onCategoryChange`: `( newCategory: string ) => void | FormTokenFieldProps[ 'onChange' ]`
|
|
173
181
|
|
|
174
|
-
A function that receives the new
|
|
182
|
+
A function that receives the new category value. If not specified, the category controls are not rendered.
|
|
183
|
+
The function's signature changes depending on whether multiple category selection is enabled or not.
|
|
175
184
|
|
|
176
|
-
- Type: `Function`
|
|
177
185
|
- Required: No
|
|
178
186
|
- Platform: Web
|
|
179
187
|
|
|
180
|
-
####
|
|
188
|
+
#### `onNumberOfItemsChange`: `( newNumber?: number ) => void`
|
|
181
189
|
|
|
182
|
-
A function that receives the new
|
|
190
|
+
A function that receives the new number of items. If not specified, then the number of items range control is not rendered.
|
|
183
191
|
|
|
184
|
-
- Type: `Function`
|
|
185
192
|
- Required: No
|
|
186
193
|
- Platform: Web
|
|
187
194
|
|
|
188
|
-
####
|
|
195
|
+
#### `onOrderChange`: `( newOrder: 'asc' | 'desc' ) => void`
|
|
189
196
|
|
|
190
|
-
A function that receives the new
|
|
197
|
+
A function that receives the new order value. If this prop or the `onOrderByChange` prop are not specified, then the order controls are not rendered.
|
|
191
198
|
|
|
192
|
-
- Type: `Function`
|
|
193
199
|
- Required: No
|
|
194
200
|
- Platform: Web
|
|
195
201
|
|
|
196
|
-
####
|
|
202
|
+
#### `onOrderByChange`: `( newOrderBy: 'date' | 'title' ) => void`
|
|
197
203
|
|
|
198
|
-
A function that receives the new
|
|
204
|
+
A function that receives the new orderby value. If this prop or the `onOrderChange` prop are not specified, then the order controls are not rendered.
|
|
199
205
|
|
|
200
|
-
- Type: `Function`
|
|
201
206
|
- Required: No
|
|
202
207
|
- Platform: Web
|
|
203
208
|
|
|
204
|
-
####
|
|
209
|
+
#### `order`: `'asc' | 'desc'`
|
|
205
210
|
|
|
206
|
-
|
|
211
|
+
The order in which to retrieve posts.
|
|
207
212
|
|
|
208
|
-
- Type: `Function`
|
|
209
213
|
- Required: No
|
|
210
214
|
- Platform: Web
|
|
211
215
|
|
|
212
|
-
####
|
|
216
|
+
#### `orderBy`: `'date' | 'title'`
|
|
213
217
|
|
|
214
|
-
The
|
|
218
|
+
The meta key by which to order posts.
|
|
215
219
|
|
|
216
|
-
- Type: `String`
|
|
217
220
|
- Required: No
|
|
218
221
|
- Platform: Web
|
|
219
222
|
|
|
220
|
-
####
|
|
223
|
+
#### `selectedAuthorId`: `number`
|
|
221
224
|
|
|
222
|
-
The
|
|
225
|
+
The selected author ID.
|
|
223
226
|
|
|
224
|
-
- Type: `String`
|
|
225
227
|
- Required: No
|
|
226
228
|
- Platform: Web
|
|
227
229
|
|
|
228
|
-
#### selectedCategories
|
|
230
|
+
#### `selectedCategories`: `Category[]`
|
|
229
231
|
|
|
230
|
-
The selected categories for the `categorySuggestions
|
|
232
|
+
The selected categories for the `categorySuggestions` prop.
|
|
231
233
|
|
|
232
|
-
- Type: `Array`
|
|
233
234
|
- Required: No
|
|
234
235
|
- Platform: Web
|
|
235
236
|
|
|
236
|
-
#### selectedCategoryId
|
|
237
|
+
#### `selectedCategoryId`: `number`
|
|
237
238
|
|
|
238
|
-
The selected category for the `categoriesList
|
|
239
|
+
The selected category for the `categoriesList` prop.
|
|
239
240
|
|
|
240
|
-
- Type: `Number`
|
|
241
241
|
- Required: No
|
|
242
242
|
- Platform: Web
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { buildTermsTree } from './terms';
|
|
5
|
+
import TreeSelect from '../tree-select';
|
|
6
|
+
import type { TreeSelectProps } from '../tree-select/types';
|
|
7
|
+
import type { AuthorSelectProps } from './types';
|
|
8
|
+
|
|
9
|
+
export default function AuthorSelect( {
|
|
10
|
+
label,
|
|
11
|
+
noOptionLabel,
|
|
12
|
+
authorList,
|
|
13
|
+
selectedAuthorId,
|
|
14
|
+
onChange: onChangeProp,
|
|
15
|
+
}: AuthorSelectProps ) {
|
|
16
|
+
if ( ! authorList ) return null;
|
|
17
|
+
const termsTree = buildTermsTree( authorList );
|
|
18
|
+
return (
|
|
19
|
+
<TreeSelect
|
|
20
|
+
{ ...{
|
|
21
|
+
label,
|
|
22
|
+
noOptionLabel,
|
|
23
|
+
// Since the `multiple` attribute is not passed to `TreeSelect`, it is
|
|
24
|
+
// safe to assume that the argument of `onChange` cannot be `string[]`.
|
|
25
|
+
// The correct solution would be to type `SelectControl` better, so that
|
|
26
|
+
// the type of `value` and `onChange` vary depending on `multiple`.
|
|
27
|
+
onChange: onChangeProp as TreeSelectProps[ 'onChange' ],
|
|
28
|
+
} }
|
|
29
|
+
tree={ termsTree }
|
|
30
|
+
selectedId={
|
|
31
|
+
selectedAuthorId !== undefined
|
|
32
|
+
? String( selectedAuthorId )
|
|
33
|
+
: undefined
|
|
34
|
+
}
|
|
35
|
+
/>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { buildTermsTree } from './terms';
|
|
5
|
+
import TreeSelect from '../tree-select';
|
|
6
|
+
import type { TreeSelectProps } from '../tree-select/types';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* WordPress dependencies
|
|
10
|
+
*/
|
|
11
|
+
import { useMemo } from '@wordpress/element';
|
|
12
|
+
import type { CategorySelectProps } from './types';
|
|
13
|
+
|
|
14
|
+
export default function CategorySelect( {
|
|
15
|
+
label,
|
|
16
|
+
noOptionLabel,
|
|
17
|
+
categoriesList,
|
|
18
|
+
selectedCategoryId,
|
|
19
|
+
onChange: onChangeProp,
|
|
20
|
+
...props
|
|
21
|
+
}: CategorySelectProps ) {
|
|
22
|
+
const termsTree = useMemo( () => {
|
|
23
|
+
return buildTermsTree( categoriesList );
|
|
24
|
+
}, [ categoriesList ] );
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<TreeSelect
|
|
28
|
+
{ ...{
|
|
29
|
+
label,
|
|
30
|
+
noOptionLabel,
|
|
31
|
+
// Since the `multiple` attribute is not passed to `TreeSelect`, it is
|
|
32
|
+
// safe to assume that the argument of `onChange` cannot be `string[]`.
|
|
33
|
+
// The correct solution would be to type `SelectControl` better, so that
|
|
34
|
+
// the type of `value` and `onChange` vary depending on `multiple`.
|
|
35
|
+
onChange: onChangeProp as TreeSelectProps[ 'onChange' ],
|
|
36
|
+
} }
|
|
37
|
+
tree={ termsTree }
|
|
38
|
+
selectedId={
|
|
39
|
+
selectedCategoryId !== undefined
|
|
40
|
+
? String( selectedCategoryId )
|
|
41
|
+
: undefined
|
|
42
|
+
}
|
|
43
|
+
{ ...props }
|
|
44
|
+
/>
|
|
45
|
+
);
|
|
46
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { __ } from '@wordpress/i18n';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Internal dependencies
|
|
8
|
+
*/
|
|
9
|
+
import AuthorSelect from './author-select';
|
|
10
|
+
import CategorySelect from './category-select';
|
|
11
|
+
import FormTokenField from '../form-token-field';
|
|
12
|
+
import RangeControl from '../range-control';
|
|
13
|
+
import SelectControl from '../select-control';
|
|
14
|
+
import type {
|
|
15
|
+
QueryControlsProps,
|
|
16
|
+
QueryControlsWithMultipleCategorySelectionProps,
|
|
17
|
+
QueryControlsWithSingleCategorySelectionProps,
|
|
18
|
+
} from './types';
|
|
19
|
+
|
|
20
|
+
const DEFAULT_MIN_ITEMS = 1;
|
|
21
|
+
const DEFAULT_MAX_ITEMS = 100;
|
|
22
|
+
const MAX_CATEGORIES_SUGGESTIONS = 20;
|
|
23
|
+
|
|
24
|
+
function isSingleCategorySelection(
|
|
25
|
+
props: QueryControlsProps
|
|
26
|
+
): props is QueryControlsWithSingleCategorySelectionProps {
|
|
27
|
+
return 'categoriesList' in props;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function isMultipleCategorySelection(
|
|
31
|
+
props: QueryControlsProps
|
|
32
|
+
): props is QueryControlsWithMultipleCategorySelectionProps {
|
|
33
|
+
return 'categorySuggestions' in props;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Controls to query for posts.
|
|
38
|
+
*
|
|
39
|
+
* ```jsx
|
|
40
|
+
* const MyQueryControls = () => (
|
|
41
|
+
* <QueryControls
|
|
42
|
+
* { ...{ maxItems, minItems, numberOfItems, order, orderBy } }
|
|
43
|
+
* onOrderByChange={ ( newOrderBy ) => {
|
|
44
|
+
* updateQuery( { orderBy: newOrderBy } )
|
|
45
|
+
* }
|
|
46
|
+
* onOrderChange={ ( newOrder ) => {
|
|
47
|
+
* updateQuery( { order: newOrder } )
|
|
48
|
+
* }
|
|
49
|
+
* categoriesList={ categories }
|
|
50
|
+
* selectedCategoryId={ category }
|
|
51
|
+
* onCategoryChange={ ( newCategory ) => {
|
|
52
|
+
* updateQuery( { category: newCategory } )
|
|
53
|
+
* }
|
|
54
|
+
* onNumberOfItemsChange={ ( newNumberOfItems ) => {
|
|
55
|
+
* updateQuery( { numberOfItems: newNumberOfItems } )
|
|
56
|
+
* } }
|
|
57
|
+
* />
|
|
58
|
+
* );
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export function QueryControls( {
|
|
62
|
+
authorList,
|
|
63
|
+
selectedAuthorId,
|
|
64
|
+
numberOfItems,
|
|
65
|
+
order,
|
|
66
|
+
orderBy,
|
|
67
|
+
maxItems = DEFAULT_MAX_ITEMS,
|
|
68
|
+
minItems = DEFAULT_MIN_ITEMS,
|
|
69
|
+
onAuthorChange,
|
|
70
|
+
onNumberOfItemsChange,
|
|
71
|
+
onOrderChange,
|
|
72
|
+
onOrderByChange,
|
|
73
|
+
// Props for single OR multiple category selection are not destructured here,
|
|
74
|
+
// but instead are destructured inline where necessary.
|
|
75
|
+
...props
|
|
76
|
+
}: QueryControlsProps ) {
|
|
77
|
+
return (
|
|
78
|
+
<>
|
|
79
|
+
{ [
|
|
80
|
+
onOrderChange && onOrderByChange && (
|
|
81
|
+
<SelectControl
|
|
82
|
+
__nextHasNoMarginBottom
|
|
83
|
+
key="query-controls-order-select"
|
|
84
|
+
label={ __( 'Order by' ) }
|
|
85
|
+
value={ `${ orderBy }/${ order }` }
|
|
86
|
+
options={ [
|
|
87
|
+
{
|
|
88
|
+
label: __( 'Newest to oldest' ),
|
|
89
|
+
value: 'date/desc',
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
label: __( 'Oldest to newest' ),
|
|
93
|
+
value: 'date/asc',
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
/* translators: label for ordering posts by title in ascending order */
|
|
97
|
+
label: __( 'A → Z' ),
|
|
98
|
+
value: 'title/asc',
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
/* translators: label for ordering posts by title in descending order */
|
|
102
|
+
label: __( 'Z → A' ),
|
|
103
|
+
value: 'title/desc',
|
|
104
|
+
},
|
|
105
|
+
] }
|
|
106
|
+
onChange={ ( value ) => {
|
|
107
|
+
if ( typeof value !== 'string' ) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const [ newOrderBy, newOrder ] = value.split( '/' );
|
|
112
|
+
if ( newOrder !== order ) {
|
|
113
|
+
onOrderChange(
|
|
114
|
+
newOrder as NonNullable<
|
|
115
|
+
QueryControlsProps[ 'order' ]
|
|
116
|
+
>
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
if ( newOrderBy !== orderBy ) {
|
|
120
|
+
onOrderByChange(
|
|
121
|
+
newOrderBy as NonNullable<
|
|
122
|
+
QueryControlsProps[ 'orderBy' ]
|
|
123
|
+
>
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
} }
|
|
127
|
+
/>
|
|
128
|
+
),
|
|
129
|
+
isSingleCategorySelection( props ) &&
|
|
130
|
+
props.categoriesList &&
|
|
131
|
+
props.onCategoryChange && (
|
|
132
|
+
<CategorySelect
|
|
133
|
+
key="query-controls-category-select"
|
|
134
|
+
categoriesList={ props.categoriesList }
|
|
135
|
+
label={ __( 'Category' ) }
|
|
136
|
+
noOptionLabel={ __( 'All' ) }
|
|
137
|
+
selectedCategoryId={ props.selectedCategoryId }
|
|
138
|
+
onChange={ props.onCategoryChange }
|
|
139
|
+
/>
|
|
140
|
+
),
|
|
141
|
+
isMultipleCategorySelection( props ) &&
|
|
142
|
+
props.categorySuggestions &&
|
|
143
|
+
props.onCategoryChange && (
|
|
144
|
+
<FormTokenField
|
|
145
|
+
key="query-controls-categories-select"
|
|
146
|
+
label={ __( 'Categories' ) }
|
|
147
|
+
value={
|
|
148
|
+
props.selectedCategories &&
|
|
149
|
+
props.selectedCategories.map( ( item ) => ( {
|
|
150
|
+
id: item.id,
|
|
151
|
+
// Keeping the fallback to `item.value` for legacy reasons,
|
|
152
|
+
// even if items of `selectedCategories` should not have a
|
|
153
|
+
// `value` property.
|
|
154
|
+
// @ts-expect-error
|
|
155
|
+
value: item.name || item.value,
|
|
156
|
+
} ) )
|
|
157
|
+
}
|
|
158
|
+
suggestions={ Object.keys(
|
|
159
|
+
props.categorySuggestions
|
|
160
|
+
) }
|
|
161
|
+
onChange={ props.onCategoryChange }
|
|
162
|
+
maxSuggestions={ MAX_CATEGORIES_SUGGESTIONS }
|
|
163
|
+
/>
|
|
164
|
+
),
|
|
165
|
+
onAuthorChange && (
|
|
166
|
+
<AuthorSelect
|
|
167
|
+
key="query-controls-author-select"
|
|
168
|
+
authorList={ authorList }
|
|
169
|
+
label={ __( 'Author' ) }
|
|
170
|
+
noOptionLabel={ __( 'All' ) }
|
|
171
|
+
selectedAuthorId={ selectedAuthorId }
|
|
172
|
+
onChange={ onAuthorChange }
|
|
173
|
+
/>
|
|
174
|
+
),
|
|
175
|
+
onNumberOfItemsChange && (
|
|
176
|
+
<RangeControl
|
|
177
|
+
__nextHasNoMarginBottom
|
|
178
|
+
key="query-controls-range-control"
|
|
179
|
+
label={ __( 'Number of items' ) }
|
|
180
|
+
value={ numberOfItems }
|
|
181
|
+
onChange={ onNumberOfItemsChange }
|
|
182
|
+
min={ minItems }
|
|
183
|
+
max={ maxItems }
|
|
184
|
+
required
|
|
185
|
+
/>
|
|
186
|
+
),
|
|
187
|
+
] }
|
|
188
|
+
</>
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export default QueryControls;
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External dependencies
|
|
3
|
+
*/
|
|
4
|
+
import type { ComponentMeta, ComponentStory } from '@storybook/react';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* WordPress dependencies
|
|
8
|
+
*/
|
|
9
|
+
import { useState } from '@wordpress/element';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Internal dependencies
|
|
13
|
+
*/
|
|
14
|
+
import QueryControls from '..';
|
|
15
|
+
import type {
|
|
16
|
+
Category,
|
|
17
|
+
QueryControlsWithSingleCategorySelectionProps,
|
|
18
|
+
QueryControlsWithMultipleCategorySelectionProps,
|
|
19
|
+
} from '../types';
|
|
20
|
+
|
|
21
|
+
const meta: ComponentMeta< typeof QueryControls > = {
|
|
22
|
+
title: 'Components/QueryControls',
|
|
23
|
+
component: QueryControls,
|
|
24
|
+
argTypes: {
|
|
25
|
+
numberOfItems: { control: { type: null } },
|
|
26
|
+
order: { control: { type: null } },
|
|
27
|
+
orderBy: { control: { type: null } },
|
|
28
|
+
selectedAuthorId: { control: { type: null } },
|
|
29
|
+
selectedCategories: { control: { type: null } },
|
|
30
|
+
selectedCategoryId: { control: { type: null } },
|
|
31
|
+
},
|
|
32
|
+
parameters: {
|
|
33
|
+
actions: { argTypesRegex: '^on.*' },
|
|
34
|
+
controls: { expanded: true },
|
|
35
|
+
docs: { source: { state: 'open' } },
|
|
36
|
+
},
|
|
37
|
+
};
|
|
38
|
+
export default meta;
|
|
39
|
+
|
|
40
|
+
export const Default: ComponentStory< typeof QueryControls > = ( args ) => {
|
|
41
|
+
const {
|
|
42
|
+
onAuthorChange,
|
|
43
|
+
onCategoryChange,
|
|
44
|
+
onNumberOfItemsChange,
|
|
45
|
+
onOrderByChange,
|
|
46
|
+
onOrderChange,
|
|
47
|
+
...props
|
|
48
|
+
} = args as QueryControlsWithMultipleCategorySelectionProps;
|
|
49
|
+
const [ ownNumberOfItems, setOwnNumberOfItems ] = useState(
|
|
50
|
+
props.numberOfItems
|
|
51
|
+
);
|
|
52
|
+
const [ ownOrder, setOwnOrder ] = useState( props.order );
|
|
53
|
+
const [ ownOrderBy, setOwnOrderBy ] = useState( props.orderBy );
|
|
54
|
+
const [ ownSelectedAuthorId, setOwnSelectedAuthorId ] = useState(
|
|
55
|
+
props.selectedAuthorId
|
|
56
|
+
);
|
|
57
|
+
const [ ownSelectedCategories, setOwnSelectedCategories ] = useState(
|
|
58
|
+
props.selectedCategories
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
const handleCategoryChange: QueryControlsWithMultipleCategorySelectionProps[ 'onCategoryChange' ] =
|
|
62
|
+
( tokens ) => {
|
|
63
|
+
onCategoryChange?.( tokens );
|
|
64
|
+
|
|
65
|
+
const hasNoSuggestion = tokens.some(
|
|
66
|
+
( token ) =>
|
|
67
|
+
typeof token === 'string' &&
|
|
68
|
+
! props.categorySuggestions?.[ token ]
|
|
69
|
+
);
|
|
70
|
+
if ( hasNoSuggestion ) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
const allCategories = tokens
|
|
74
|
+
.map( ( token ) => {
|
|
75
|
+
return typeof token === 'string'
|
|
76
|
+
? props.categorySuggestions?.[ token ]
|
|
77
|
+
: token;
|
|
78
|
+
} )
|
|
79
|
+
.filter( Boolean ) as Array< Required< Category > >;
|
|
80
|
+
|
|
81
|
+
setOwnSelectedCategories( allCategories );
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<QueryControls
|
|
86
|
+
{ ...props }
|
|
87
|
+
numberOfItems={ ownNumberOfItems }
|
|
88
|
+
onCategoryChange={ handleCategoryChange }
|
|
89
|
+
onOrderByChange={ ( newOrderBy ) => {
|
|
90
|
+
onOrderByChange?.( newOrderBy );
|
|
91
|
+
setOwnOrderBy( newOrderBy );
|
|
92
|
+
} }
|
|
93
|
+
onOrderChange={ ( newOrder ) => {
|
|
94
|
+
onOrderChange?.( newOrder );
|
|
95
|
+
setOwnOrder( newOrder );
|
|
96
|
+
} }
|
|
97
|
+
order={ ownOrder }
|
|
98
|
+
orderBy={ ownOrderBy }
|
|
99
|
+
onNumberOfItemsChange={ ( newNumber ) => {
|
|
100
|
+
onNumberOfItemsChange?.( newNumber );
|
|
101
|
+
setOwnNumberOfItems( newNumber );
|
|
102
|
+
} }
|
|
103
|
+
onAuthorChange={ ( newAuthor ) => {
|
|
104
|
+
onAuthorChange?.( newAuthor );
|
|
105
|
+
setOwnSelectedAuthorId( Number( newAuthor ) );
|
|
106
|
+
} }
|
|
107
|
+
selectedAuthorId={ ownSelectedAuthorId }
|
|
108
|
+
selectedCategories={ ownSelectedCategories }
|
|
109
|
+
/>
|
|
110
|
+
);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
Default.args = {
|
|
114
|
+
authorList: [
|
|
115
|
+
{
|
|
116
|
+
id: 1,
|
|
117
|
+
name: 'admin',
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
id: 2,
|
|
121
|
+
name: 'editor',
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
categorySuggestions: {
|
|
125
|
+
TypeScript: {
|
|
126
|
+
id: 11,
|
|
127
|
+
name: 'TypeScript',
|
|
128
|
+
parent: 0,
|
|
129
|
+
},
|
|
130
|
+
JavaScript: {
|
|
131
|
+
id: 12,
|
|
132
|
+
name: 'JavaScript',
|
|
133
|
+
parent: 0,
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
selectedCategories: [
|
|
137
|
+
{
|
|
138
|
+
id: 11,
|
|
139
|
+
name: 'JavaScript',
|
|
140
|
+
parent: 0,
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
numberOfItems: 5,
|
|
144
|
+
order: 'desc',
|
|
145
|
+
orderBy: 'date',
|
|
146
|
+
selectedAuthorId: 1,
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
const SingleCategoryTemplate: ComponentStory< typeof QueryControls > = (
|
|
150
|
+
args
|
|
151
|
+
) => {
|
|
152
|
+
const {
|
|
153
|
+
onAuthorChange,
|
|
154
|
+
onCategoryChange,
|
|
155
|
+
onNumberOfItemsChange,
|
|
156
|
+
onOrderByChange,
|
|
157
|
+
onOrderChange,
|
|
158
|
+
...props
|
|
159
|
+
} = args as QueryControlsWithSingleCategorySelectionProps;
|
|
160
|
+
const [ ownOrder, setOwnOrder ] = useState( props.order );
|
|
161
|
+
const [ ownOrderBy, setOwnOrderBy ] = useState( props.orderBy );
|
|
162
|
+
const [ ownSelectedCategoryId, setSelectedCategoryId ] = useState(
|
|
163
|
+
props.selectedCategoryId
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
const handleCategoryChange: QueryControlsWithSingleCategorySelectionProps[ 'onCategoryChange' ] =
|
|
167
|
+
( newCategory ) => {
|
|
168
|
+
onCategoryChange?.( newCategory );
|
|
169
|
+
setSelectedCategoryId( Number( newCategory ) );
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
return (
|
|
173
|
+
<QueryControls
|
|
174
|
+
{ ...props }
|
|
175
|
+
onCategoryChange={ handleCategoryChange }
|
|
176
|
+
onOrderByChange={ ( newOrderBy ) => {
|
|
177
|
+
setOwnOrderBy( newOrderBy );
|
|
178
|
+
} }
|
|
179
|
+
onOrderChange={ ( newOrder ) => {
|
|
180
|
+
onOrderChange?.( newOrder );
|
|
181
|
+
setOwnOrder( newOrder );
|
|
182
|
+
} }
|
|
183
|
+
order={ ownOrder }
|
|
184
|
+
orderBy={ ownOrderBy }
|
|
185
|
+
selectedCategoryId={ ownSelectedCategoryId }
|
|
186
|
+
/>
|
|
187
|
+
);
|
|
188
|
+
};
|
|
189
|
+
export const SelectSingleCategory: ComponentStory< typeof QueryControls > =
|
|
190
|
+
SingleCategoryTemplate.bind( {} );
|
|
191
|
+
SelectSingleCategory.args = {
|
|
192
|
+
categoriesList: [
|
|
193
|
+
{
|
|
194
|
+
id: 11,
|
|
195
|
+
name: 'TypeScript',
|
|
196
|
+
parent: 0,
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
id: 12,
|
|
200
|
+
name: 'JavaScript',
|
|
201
|
+
parent: 0,
|
|
202
|
+
},
|
|
203
|
+
],
|
|
204
|
+
selectedCategoryId: 11,
|
|
205
|
+
};
|