@wordpress/block-editor 11.7.0 → 12.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/README.md +56 -57
- package/build/components/block-info-slot-fill/index.js +47 -0
- package/build/components/block-info-slot-fill/index.js.map +1 -0
- package/build/components/block-inspector/index.js +4 -2
- package/build/components/block-inspector/index.js.map +1 -1
- package/build/components/block-list/index.native.js +11 -21
- package/build/components/block-list/index.native.js.map +1 -1
- package/build/components/block-list/use-in-between-inserter.js +3 -1
- package/build/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build/components/block-popover/inbetween.js +2 -9
- package/build/components/block-popover/inbetween.js.map +1 -1
- package/build/components/block-settings-menu/block-settings-dropdown.js +1 -10
- package/build/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build/components/block-toolbar/index.js +2 -1
- package/build/components/block-toolbar/index.js.map +1 -1
- package/build/components/block-tools/block-contextual-toolbar.js +83 -9
- package/build/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build/components/block-tools/selected-block-popover.js +11 -28
- package/build/components/block-tools/selected-block-popover.js.map +1 -1
- package/build/components/caption/index.native.js +0 -1
- package/build/components/caption/index.native.js.map +1 -1
- package/build/components/date-format-picker/index.js +1 -1
- package/build/components/date-format-picker/index.js.map +1 -1
- package/build/components/editor-styles/index.js +4 -3
- package/build/components/editor-styles/index.js.map +1 -1
- package/build/components/font-sizes/fluid-utils.js +21 -14
- package/build/components/font-sizes/fluid-utils.js.map +1 -1
- package/build/components/global-styles/border-panel.js +15 -59
- package/build/components/global-styles/border-panel.js.map +1 -1
- package/build/components/global-styles/color-panel.js +12 -12
- package/build/components/global-styles/color-panel.js.map +1 -1
- package/build/components/global-styles/color-panel.native.js +174 -0
- package/build/components/global-styles/color-panel.native.js.map +1 -0
- package/build/components/global-styles/dimensions-panel.js +21 -20
- package/build/components/global-styles/dimensions-panel.js.map +1 -1
- package/build/components/global-styles/effects-panel.js +244 -0
- package/build/components/global-styles/effects-panel.js.map +1 -0
- package/build/components/global-styles/filters-panel.js +215 -0
- package/build/components/global-styles/filters-panel.js.map +1 -0
- package/build/components/global-styles/get-block-css-selector.js +1 -12
- package/build/components/global-styles/get-block-css-selector.js.map +1 -1
- package/build/components/global-styles/hooks.js +7 -0
- package/build/components/global-styles/hooks.js.map +1 -1
- package/build/components/global-styles/index.js +28 -0
- package/build/components/global-styles/index.js.map +1 -1
- package/build/components/global-styles/typography-panel.js +9 -9
- package/build/components/global-styles/typography-panel.js.map +1 -1
- package/build/components/global-styles/use-global-styles-output.js +100 -82
- package/build/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build/components/iframe/index.js +1 -1
- package/build/components/iframe/index.js.map +1 -1
- package/build/components/image-size-control/use-dimension-handler.js +5 -3
- package/build/components/image-size-control/use-dimension-handler.js.map +1 -1
- package/build/components/index.js +23 -0
- package/build/components/index.js.map +1 -1
- package/build/components/inserter/block-patterns-tab.js +4 -2
- package/build/components/inserter/block-patterns-tab.js.map +1 -1
- package/build/components/inserter/block-types-tab.js +12 -7
- package/build/components/inserter/block-types-tab.js.map +1 -1
- package/build/components/inserter/index.js +2 -1
- package/build/components/inserter/index.js.map +1 -1
- package/build/components/inspector-controls/groups.js +2 -0
- package/build/components/inspector-controls/groups.js.map +1 -1
- package/build/components/inspector-controls-tabs/styles-tab.js +2 -0
- package/build/components/inspector-controls-tabs/styles-tab.js.map +1 -1
- package/build/components/inspector-controls-tabs/utils.js +5 -3
- package/build/components/inspector-controls-tabs/utils.js.map +1 -1
- package/build/components/list-view/block-select-button.js +7 -2
- package/build/components/list-view/block-select-button.js.map +1 -1
- package/build/components/list-view/block.js +13 -21
- package/build/components/list-view/block.js.map +1 -1
- package/build/components/list-view/drop-indicator.js +37 -10
- package/build/components/list-view/drop-indicator.js.map +1 -1
- package/build/components/list-view/index.js +31 -7
- package/build/components/list-view/index.js.map +1 -1
- package/build/components/list-view/leaf.js +2 -1
- package/build/components/list-view/leaf.js.map +1 -1
- package/build/components/list-view/use-block-selection.js +1 -1
- package/build/components/list-view/use-block-selection.js.map +1 -1
- package/build/components/list-view/use-list-view-client-ids.js +7 -3
- package/build/components/list-view/use-list-view-client-ids.js.map +1 -1
- package/build/components/list-view/use-list-view-drop-zone.js +8 -2
- package/build/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build/components/media-replace-flow/index.js +5 -5
- package/build/components/media-replace-flow/index.js.map +1 -1
- package/build/components/navigable-toolbar/index.js +12 -4
- package/build/components/navigable-toolbar/index.js.map +1 -1
- package/build/components/off-canvas-editor/appender.js +2 -7
- package/build/components/off-canvas-editor/appender.js.map +1 -1
- package/build/components/off-canvas-editor/block-contents.js +6 -1
- package/build/components/off-canvas-editor/block-contents.js.map +1 -1
- package/build/components/off-canvas-editor/index.js +17 -14
- package/build/components/off-canvas-editor/index.js.map +1 -1
- package/build/components/resizable-box-popover/index.js +38 -0
- package/build/components/resizable-box-popover/index.js.map +1 -0
- package/build/components/rich-text/index.js +0 -1
- package/build/components/rich-text/index.js.map +1 -1
- package/build/components/rich-text/index.native.js +7 -11
- package/build/components/rich-text/index.native.js.map +1 -1
- package/build/components/spacing-sizes-control/spacing-input-control.js +8 -0
- package/build/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
- package/build/hooks/anchor.js +1 -1
- package/build/hooks/anchor.js.map +1 -1
- package/build/hooks/border.js +1 -1
- package/build/hooks/border.js.map +1 -1
- package/build/hooks/duotone.js +121 -70
- package/build/hooks/duotone.js.map +1 -1
- package/build/hooks/margin.js +27 -17
- package/build/hooks/margin.js.map +1 -1
- package/build/hooks/padding.js +19 -9
- package/build/hooks/padding.js.map +1 -1
- package/build/hooks/utils.js +22 -7
- package/build/hooks/utils.js.map +1 -1
- package/build/layouts/utils.js +3 -2
- package/build/layouts/utils.js.map +1 -1
- package/build/private-apis.js +13 -1
- package/build/private-apis.js.map +1 -1
- package/build/store/actions.js +8 -1
- package/build/store/actions.js.map +1 -1
- package/build/utils/object.js +6 -6
- package/build/utils/object.js.map +1 -1
- package/build/utils/transform-styles/index.js +2 -2
- package/build/utils/transform-styles/index.js.map +1 -1
- package/build/utils/use-should-contextual-toolbar-show.js +68 -0
- package/build/utils/use-should-contextual-toolbar-show.js.map +1 -0
- package/build-module/components/block-info-slot-fill/index.js +34 -0
- package/build-module/components/block-info-slot-fill/index.js.map +1 -0
- package/build-module/components/block-inspector/index.js +3 -2
- package/build-module/components/block-inspector/index.js.map +1 -1
- package/build-module/components/block-list/index.native.js +11 -19
- package/build-module/components/block-list/index.native.js.map +1 -1
- package/build-module/components/block-list/use-in-between-inserter.js +2 -1
- package/build-module/components/block-list/use-in-between-inserter.js.map +1 -1
- package/build-module/components/block-popover/inbetween.js +2 -9
- package/build-module/components/block-popover/inbetween.js.map +1 -1
- package/build-module/components/block-settings-menu/block-settings-dropdown.js +1 -9
- package/build-module/components/block-settings-menu/block-settings-dropdown.js.map +1 -1
- package/build-module/components/block-toolbar/index.js +2 -1
- package/build-module/components/block-toolbar/index.js.map +1 -1
- package/build-module/components/block-tools/block-contextual-toolbar.js +79 -9
- package/build-module/components/block-tools/block-contextual-toolbar.js.map +1 -1
- package/build-module/components/block-tools/selected-block-popover.js +10 -27
- package/build-module/components/block-tools/selected-block-popover.js.map +1 -1
- package/build-module/components/caption/index.native.js +0 -1
- package/build-module/components/caption/index.native.js.map +1 -1
- package/build-module/components/date-format-picker/index.js +1 -1
- package/build-module/components/date-format-picker/index.js.map +1 -1
- package/build-module/components/editor-styles/index.js +4 -3
- package/build-module/components/editor-styles/index.js.map +1 -1
- package/build-module/components/font-sizes/fluid-utils.js +21 -14
- package/build-module/components/font-sizes/fluid-utils.js.map +1 -1
- package/build-module/components/global-styles/border-panel.js +15 -59
- package/build-module/components/global-styles/border-panel.js.map +1 -1
- package/build-module/components/global-styles/color-panel.js +13 -13
- package/build-module/components/global-styles/color-panel.js.map +1 -1
- package/build-module/components/global-styles/color-panel.native.js +150 -0
- package/build-module/components/global-styles/color-panel.native.js.map +1 -0
- package/build-module/components/global-styles/dimensions-panel.js +22 -21
- package/build-module/components/global-styles/dimensions-panel.js.map +1 -1
- package/build-module/components/global-styles/effects-panel.js +228 -0
- package/build-module/components/global-styles/effects-panel.js.map +1 -0
- package/build-module/components/global-styles/filters-panel.js +201 -0
- package/build-module/components/global-styles/filters-panel.js.map +1 -0
- package/build-module/components/global-styles/get-block-css-selector.js +1 -12
- package/build-module/components/global-styles/get-block-css-selector.js.map +1 -1
- package/build-module/components/global-styles/hooks.js +7 -0
- package/build-module/components/global-styles/hooks.js.map +1 -1
- package/build-module/components/global-styles/index.js +2 -0
- package/build-module/components/global-styles/index.js.map +1 -1
- package/build-module/components/global-styles/typography-panel.js +10 -10
- package/build-module/components/global-styles/typography-panel.js.map +1 -1
- package/build-module/components/global-styles/use-global-styles-output.js +101 -83
- package/build-module/components/global-styles/use-global-styles-output.js.map +1 -1
- package/build-module/components/iframe/index.js +1 -1
- package/build-module/components/iframe/index.js.map +1 -1
- package/build-module/components/image-size-control/use-dimension-handler.js +5 -3
- package/build-module/components/image-size-control/use-dimension-handler.js.map +1 -1
- package/build-module/components/index.js +1 -0
- package/build-module/components/index.js.map +1 -1
- package/build-module/components/inserter/block-patterns-tab.js +5 -2
- package/build-module/components/inserter/block-patterns-tab.js.map +1 -1
- package/build-module/components/inserter/block-types-tab.js +12 -6
- package/build-module/components/inserter/block-types-tab.js.map +1 -1
- package/build-module/components/inserter/index.js +2 -1
- package/build-module/components/inserter/index.js.map +1 -1
- package/build-module/components/inspector-controls/groups.js +2 -0
- package/build-module/components/inspector-controls/groups.js.map +1 -1
- package/build-module/components/inspector-controls-tabs/styles-tab.js +2 -0
- package/build-module/components/inspector-controls-tabs/styles-tab.js.map +1 -1
- package/build-module/components/inspector-controls-tabs/utils.js +4 -3
- package/build-module/components/inspector-controls-tabs/utils.js.map +1 -1
- package/build-module/components/list-view/block-select-button.js +7 -2
- package/build-module/components/list-view/block-select-button.js.map +1 -1
- package/build-module/components/list-view/block.js +15 -22
- package/build-module/components/list-view/block.js.map +1 -1
- package/build-module/components/list-view/drop-indicator.js +36 -10
- package/build-module/components/list-view/drop-indicator.js.map +1 -1
- package/build-module/components/list-view/index.js +31 -8
- package/build-module/components/list-view/index.js.map +1 -1
- package/build-module/components/list-view/leaf.js +2 -1
- package/build-module/components/list-view/leaf.js.map +1 -1
- package/build-module/components/list-view/use-block-selection.js +1 -1
- package/build-module/components/list-view/use-block-selection.js.map +1 -1
- package/build-module/components/list-view/use-list-view-client-ids.js +7 -3
- package/build-module/components/list-view/use-list-view-client-ids.js.map +1 -1
- package/build-module/components/list-view/use-list-view-drop-zone.js +8 -4
- package/build-module/components/list-view/use-list-view-drop-zone.js.map +1 -1
- package/build-module/components/media-replace-flow/index.js +5 -5
- package/build-module/components/media-replace-flow/index.js.map +1 -1
- package/build-module/components/navigable-toolbar/index.js +12 -4
- package/build-module/components/navigable-toolbar/index.js.map +1 -1
- package/build-module/components/off-canvas-editor/appender.js +1 -5
- package/build-module/components/off-canvas-editor/appender.js.map +1 -1
- package/build-module/components/off-canvas-editor/block-contents.js +5 -1
- package/build-module/components/off-canvas-editor/block-contents.js.map +1 -1
- package/build-module/components/off-canvas-editor/index.js +17 -14
- package/build-module/components/off-canvas-editor/index.js.map +1 -1
- package/build-module/components/resizable-box-popover/index.js +26 -0
- package/build-module/components/resizable-box-popover/index.js.map +1 -0
- package/build-module/components/rich-text/index.js +0 -1
- package/build-module/components/rich-text/index.js.map +1 -1
- package/build-module/components/rich-text/index.native.js +7 -10
- package/build-module/components/rich-text/index.native.js.map +1 -1
- package/build-module/components/spacing-sizes-control/spacing-input-control.js +7 -0
- package/build-module/components/spacing-sizes-control/spacing-input-control.js.map +1 -1
- package/build-module/hooks/anchor.js +1 -1
- package/build-module/hooks/anchor.js.map +1 -1
- package/build-module/hooks/border.js +1 -1
- package/build-module/hooks/border.js.map +1 -1
- package/build-module/hooks/duotone.js +118 -71
- package/build-module/hooks/duotone.js.map +1 -1
- package/build-module/hooks/margin.js +29 -18
- package/build-module/hooks/margin.js.map +1 -1
- package/build-module/hooks/padding.js +21 -10
- package/build-module/hooks/padding.js.map +1 -1
- package/build-module/hooks/utils.js +24 -9
- package/build-module/hooks/utils.js.map +1 -1
- package/build-module/layouts/utils.js +3 -2
- package/build-module/layouts/utils.js.map +1 -1
- package/build-module/private-apis.js +9 -1
- package/build-module/private-apis.js.map +1 -1
- package/build-module/store/actions.js +8 -1
- package/build-module/store/actions.js.map +1 -1
- package/build-module/utils/object.js +5 -5
- package/build-module/utils/object.js.map +1 -1
- package/build-module/utils/transform-styles/index.js +2 -2
- package/build-module/utils/transform-styles/index.js.map +1 -1
- package/build-module/utils/use-should-contextual-toolbar-show.js +56 -0
- package/build-module/utils/use-should-contextual-toolbar-show.js.map +1 -0
- package/build-style/content-rtl.css +9 -6
- package/build-style/content.css +9 -6
- package/build-style/style-rtl.css +272 -54
- package/build-style/style.css +272 -54
- package/package.json +32 -32
- package/src/components/block-info-slot-fill/index.js +24 -0
- package/src/components/block-inspector/index.js +3 -0
- package/src/components/block-inspector/style.scss +6 -4
- package/src/components/block-list/content.scss +16 -15
- package/src/components/block-list/index.native.js +19 -38
- package/src/components/block-list/use-in-between-inserter.js +4 -1
- package/src/components/block-mobile-toolbar/test/block-actions-menu.native.js +9 -9
- package/src/components/block-mover/style.scss +10 -4
- package/src/components/block-mover/test/index.native.js +4 -4
- package/src/components/block-popover/inbetween.js +2 -13
- package/src/components/block-settings-menu/block-settings-dropdown.js +2 -12
- package/src/components/block-toolbar/index.js +4 -3
- package/src/components/block-toolbar/style.scss +56 -33
- package/src/components/block-tools/block-contextual-toolbar.js +94 -11
- package/src/components/block-tools/selected-block-popover.js +11 -44
- package/src/components/block-tools/style.scss +157 -3
- package/src/components/caption/index.native.js +0 -1
- package/src/components/date-format-picker/index.js +1 -1
- package/src/components/editor-styles/index.js +9 -5
- package/src/components/font-sizes/fluid-utils.js +31 -14
- package/src/components/font-sizes/test/fluid-utils.js +5 -16
- package/src/components/global-styles/README.md +129 -16
- package/src/components/global-styles/border-panel.js +13 -61
- package/src/components/global-styles/color-panel.js +13 -13
- package/src/components/global-styles/color-panel.native.js +207 -0
- package/src/components/global-styles/dimensions-panel.js +47 -20
- package/src/components/global-styles/effects-panel.js +228 -0
- package/src/components/global-styles/filters-panel.js +230 -0
- package/src/components/global-styles/get-block-css-selector.js +0 -11
- package/src/components/global-styles/hooks.js +10 -0
- package/src/components/global-styles/index.js +2 -0
- package/src/components/global-styles/style.scss +43 -0
- package/src/components/global-styles/test/typography-utils.js +63 -22
- package/src/components/global-styles/test/use-global-styles-output.js +130 -8
- package/src/components/global-styles/typography-panel.js +37 -11
- package/src/components/global-styles/use-global-styles-output.js +88 -72
- package/src/components/iframe/index.js +1 -1
- package/src/components/image-size-control/use-dimension-handler.js +4 -3
- package/src/components/index.js +5 -1
- package/src/components/inserter/block-patterns-tab.js +3 -1
- package/src/components/inserter/block-types-tab.js +9 -6
- package/src/components/inserter/index.js +1 -1
- package/src/components/inspector-controls/groups.js +2 -0
- package/src/components/inspector-controls-tabs/styles-tab.js +1 -0
- package/src/components/inspector-controls-tabs/utils.js +4 -3
- package/src/components/list-view/README.md +2 -0
- package/src/components/list-view/block-select-button.js +6 -1
- package/src/components/list-view/block.js +24 -31
- package/src/components/list-view/drop-indicator.js +67 -22
- package/src/components/list-view/index.js +26 -3
- package/src/components/list-view/leaf.js +1 -0
- package/src/components/list-view/style.scss +18 -4
- package/src/components/list-view/test/use-list-view-drop-zone.js +188 -0
- package/src/components/list-view/use-block-selection.js +1 -1
- package/src/components/list-view/use-list-view-client-ids.js +5 -3
- package/src/components/list-view/use-list-view-drop-zone.js +9 -3
- package/src/components/media-replace-flow/README.md +3 -2
- package/src/components/media-replace-flow/index.js +4 -5
- package/src/components/navigable-toolbar/index.js +12 -3
- package/src/components/off-canvas-editor/appender.js +1 -4
- package/src/components/off-canvas-editor/block-contents.js +4 -0
- package/src/components/off-canvas-editor/index.js +15 -11
- package/src/components/resizable-box-popover/index.js +27 -0
- package/src/components/rich-text/index.js +0 -1
- package/src/components/rich-text/index.native.js +2 -5
- package/src/components/spacing-sizes-control/spacing-input-control.js +10 -0
- package/src/components/spacing-sizes-control/style.scss +7 -7
- package/src/components/url-popover/test/__snapshots__/index.js.snap +3 -3
- package/src/hooks/anchor.js +1 -1
- package/src/hooks/border.js +1 -1
- package/src/hooks/duotone.js +162 -99
- package/src/hooks/margin.js +31 -26
- package/src/hooks/padding.js +24 -18
- package/src/hooks/test/anchor.js +113 -0
- package/src/hooks/test/color.js +0 -9
- package/src/hooks/test/use-typography-props.js +2 -2
- package/src/hooks/test/utils.js +20 -101
- package/src/hooks/utils.js +23 -6
- package/src/layouts/utils.js +2 -2
- package/src/private-apis.js +8 -0
- package/src/store/actions.js +8 -1
- package/src/style.scss +1 -0
- package/src/utils/object.js +5 -5
- package/src/utils/test/object.js +53 -15
- package/src/utils/transform-styles/index.js +2 -2
- package/src/utils/use-should-contextual-toolbar-show.js +75 -0
- package/tsconfig.json +1 -0
- package/build/components/rich-text/use-native-props.js +0 -11
- package/build/components/rich-text/use-native-props.js.map +0 -1
- package/build/components/rich-text/use-native-props.native.js +0 -24
- package/build/components/rich-text/use-native-props.native.js.map +0 -1
- package/build/hooks/color-panel.native.js +0 -77
- package/build/hooks/color-panel.native.js.map +0 -1
- package/build-module/components/rich-text/use-native-props.js +0 -4
- package/build-module/components/rich-text/use-native-props.js.map +0 -1
- package/build-module/components/rich-text/use-native-props.native.js +0 -15
- package/build-module/components/rich-text/use-native-props.native.js.map +0 -1
- package/build-module/hooks/color-panel.native.js +0 -62
- package/build-module/hooks/color-panel.native.js.map +0 -1
- package/src/components/rich-text/use-native-props.js +0 -3
- package/src/components/rich-text/use-native-props.native.js +0 -17
- package/src/hooks/color-panel.native.js +0 -63
|
@@ -14,9 +14,7 @@ import { useGlobalStylesReset } from '@wordpress/block-editor';
|
|
|
14
14
|
function MyComponent() {
|
|
15
15
|
const [ canReset, reset ] = useGlobalStylesReset();
|
|
16
16
|
|
|
17
|
-
return canReset
|
|
18
|
-
? <Button onClick={ () => reset() }>Reset</Button>
|
|
19
|
-
: null;
|
|
17
|
+
return canReset ? <Button onClick={ () => reset() }>Reset</Button> : null;
|
|
20
18
|
}
|
|
21
19
|
```
|
|
22
20
|
|
|
@@ -25,17 +23,25 @@ function MyComponent() {
|
|
|
25
23
|
A React hook used to retrieve the styles array and settings to provide for block editor instances based on the current global styles.
|
|
26
24
|
|
|
27
25
|
```js
|
|
28
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
useGlobalStylesOutput,
|
|
28
|
+
BlockEditorProvider,
|
|
29
|
+
BlockList,
|
|
30
|
+
} from '@wordpress/block-editor';
|
|
29
31
|
|
|
30
32
|
function MyComponent() {
|
|
31
33
|
const [ styles, settings ] = useGlobalStylesOutput();
|
|
32
34
|
|
|
33
|
-
return
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
return (
|
|
36
|
+
<BlockEditorProvider
|
|
37
|
+
settings={ {
|
|
38
|
+
styles,
|
|
39
|
+
__experimentalFeatures: settings,
|
|
40
|
+
} }
|
|
41
|
+
>
|
|
42
|
+
<BlockList />
|
|
43
|
+
</BlockEditorProvider>
|
|
44
|
+
);
|
|
39
45
|
}
|
|
40
46
|
```
|
|
41
47
|
|
|
@@ -48,12 +54,16 @@ import { useGlobalStyle } from '@wordpress/block-editor';
|
|
|
48
54
|
|
|
49
55
|
function MyComponent() {
|
|
50
56
|
// Text color for the site root.
|
|
51
|
-
const [ color, setColor ] = useGlobalStyle( 'color.text' );
|
|
57
|
+
const [ color, setColor ] = useGlobalStyle( 'color.text' );
|
|
52
58
|
|
|
53
59
|
// The user modified color for the core paragraph block.
|
|
54
|
-
const [ pColor, setPColor ] = useGlobalStyle(
|
|
60
|
+
const [ pColor, setPColor ] = useGlobalStyle(
|
|
61
|
+
'color.text',
|
|
62
|
+
'core/paragraph',
|
|
63
|
+
'user'
|
|
64
|
+
);
|
|
55
65
|
|
|
56
|
-
return
|
|
66
|
+
return 'Something';
|
|
57
67
|
}
|
|
58
68
|
```
|
|
59
69
|
|
|
@@ -66,12 +76,115 @@ import { useGlobalSetting } from '@wordpress/block-editor';
|
|
|
66
76
|
|
|
67
77
|
function MyComponent() {
|
|
68
78
|
// The theme color palette.
|
|
69
|
-
const [ colorPalette, setColorPalette ] = useGlobalSetting(
|
|
79
|
+
const [ colorPalette, setColorPalette ] = useGlobalSetting(
|
|
80
|
+
'color.palette.theme'
|
|
81
|
+
);
|
|
70
82
|
|
|
71
83
|
// The theme color palette for the paragraph block, ignoring user changes.
|
|
72
84
|
// If the palette is not defined for the paragraph block, the root one is returned.
|
|
73
|
-
const [ pColor, setPColor ] = useGlobalSetting(
|
|
85
|
+
const [ pColor, setPColor ] = useGlobalSetting(
|
|
86
|
+
'color.palette.theme',
|
|
87
|
+
'core/paragraph',
|
|
88
|
+
'base'
|
|
89
|
+
);
|
|
74
90
|
|
|
75
|
-
return
|
|
91
|
+
return 'Something';
|
|
76
92
|
}
|
|
77
93
|
```
|
|
94
|
+
|
|
95
|
+
## UI Components
|
|
96
|
+
|
|
97
|
+
The global styles folder also offers a set of reusable UI components. These components follow a strict set of guidelines:
|
|
98
|
+
|
|
99
|
+
- They are independent of any context or any store dependency. They only rely on the props passed to them.
|
|
100
|
+
- They receive a similar set of props:
|
|
101
|
+
|
|
102
|
+
- `value`: The value is a style object that maps closely the format used in `theme.json` and is also very close to the format of the `style` attributes for blocks. There are some differences with the block attributes due to the iteration process and the fact that we need to maintain compatibility with the existing blocks even if they predate the introduction of Global Styles and these UI components. An example value for a style object is:
|
|
103
|
+
|
|
104
|
+
```js
|
|
105
|
+
{
|
|
106
|
+
color: {
|
|
107
|
+
text: 'var:preset|color|blue',
|
|
108
|
+
background: '#FF0000',
|
|
109
|
+
},
|
|
110
|
+
typography: {
|
|
111
|
+
fontFamily: 'var:preset|font-family|base',
|
|
112
|
+
fontSize: '10px',
|
|
113
|
+
lineHeight: 1.5,
|
|
114
|
+
},
|
|
115
|
+
spacing: {
|
|
116
|
+
padding: 'var:preset|spacing|medium',
|
|
117
|
+
},
|
|
118
|
+
elements: {
|
|
119
|
+
link: {
|
|
120
|
+
color: {
|
|
121
|
+
text: 'var:preset|color|green',
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
}
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
- `onChange`: A callback that receives the new value and is called when the user changes the value of the UI component.
|
|
129
|
+
- `inheritedValue`: The inherited value is a style object that represents the combined value of the style inherited from the parent context in addition to the style applied to the current context. The format is the same as the `value` prop.
|
|
130
|
+
- `settings`: The settings are the theme.json settings. They are used to provide the UI components with the necessary information to render the UI. An example value for the settings is:
|
|
131
|
+
|
|
132
|
+
```js
|
|
133
|
+
{
|
|
134
|
+
color: {
|
|
135
|
+
palette: {
|
|
136
|
+
custom: [
|
|
137
|
+
{
|
|
138
|
+
slug: 'black',
|
|
139
|
+
color: '#000000',
|
|
140
|
+
},
|
|
141
|
+
{
|
|
142
|
+
slug: 'white',
|
|
143
|
+
color: '#FFFFFF',
|
|
144
|
+
},
|
|
145
|
+
{
|
|
146
|
+
slug: 'blue',
|
|
147
|
+
color: '#0000FF',
|
|
148
|
+
},
|
|
149
|
+
]
|
|
150
|
+
},
|
|
151
|
+
gradients: {
|
|
152
|
+
custom: [
|
|
153
|
+
{
|
|
154
|
+
slug: 'gradient-1',
|
|
155
|
+
gradient: 'linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)',
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
slug: 'gradient-2',
|
|
159
|
+
gradient: 'linear-gradient(135deg,rgba(6,147,227,1) 0%,rgb(155,81,224) 100%)',
|
|
160
|
+
},
|
|
161
|
+
]
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
typography: {
|
|
165
|
+
fontSizes: [
|
|
166
|
+
{
|
|
167
|
+
slug: 'small',
|
|
168
|
+
size: '12px',
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
slug: 'medium',
|
|
172
|
+
size: '16px',
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
slug: 'large',
|
|
176
|
+
size: '24px',
|
|
177
|
+
},
|
|
178
|
+
],
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
- `defaultControls`: The default controls are the controls that are used by default to render the UI. They are used to provide the UI components with the necessary information to render the UI. An example value for the default controls for the `ColorPanel` component is:
|
|
183
|
+
|
|
184
|
+
```js
|
|
185
|
+
{
|
|
186
|
+
background: true,
|
|
187
|
+
text: true,
|
|
188
|
+
link: true,
|
|
189
|
+
},
|
|
190
|
+
```
|
|
@@ -45,35 +45,6 @@ function useHasBorderWidthControl( settings ) {
|
|
|
45
45
|
return settings?.border?.width;
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
function applyFallbackStyle( border ) {
|
|
49
|
-
if ( ! border ) {
|
|
50
|
-
return border;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
if ( ! border.style && ( border.color || border.width ) ) {
|
|
54
|
-
return { ...border, style: 'solid' };
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return border;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function applyAllFallbackStyles( border ) {
|
|
61
|
-
if ( ! border ) {
|
|
62
|
-
return border;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
if ( hasSplitBorders( border ) ) {
|
|
66
|
-
return {
|
|
67
|
-
top: applyFallbackStyle( border.top ),
|
|
68
|
-
right: applyFallbackStyle( border.right ),
|
|
69
|
-
bottom: applyFallbackStyle( border.bottom ),
|
|
70
|
-
left: applyFallbackStyle( border.left ),
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
return applyFallbackStyle( border );
|
|
75
|
-
}
|
|
76
|
-
|
|
77
48
|
function BorderToolsPanel( {
|
|
78
49
|
resetAllFilter,
|
|
79
50
|
onChange,
|
|
@@ -186,39 +157,20 @@ export default function BorderPanel( {
|
|
|
186
157
|
const onBorderChange = ( newBorder ) => {
|
|
187
158
|
// Ensure we have a visible border style when a border width or
|
|
188
159
|
// color is being selected.
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
// As we can't conditionally generate styles based on if other
|
|
192
|
-
// style properties have been set we need to force split border
|
|
193
|
-
// definitions for user set border styles. Border radius is derived
|
|
194
|
-
// from the same property i.e. `border.radius` if it is a string
|
|
195
|
-
// that is used. The longhand border radii styles are only generated
|
|
196
|
-
// if that property is an object.
|
|
197
|
-
//
|
|
198
|
-
// For borders (color, style, and width) those are all properties on
|
|
199
|
-
// the `border` style property. This means if the theme.json defined
|
|
200
|
-
// split borders and the user condenses them into a flat border or
|
|
201
|
-
// vice-versa we'd get both sets of styles which would conflict.
|
|
202
|
-
const updatedBorder = ! hasSplitBorders( newBorderWithStyle )
|
|
203
|
-
? {
|
|
204
|
-
top: newBorderWithStyle,
|
|
205
|
-
right: newBorderWithStyle,
|
|
206
|
-
bottom: newBorderWithStyle,
|
|
207
|
-
left: newBorderWithStyle,
|
|
208
|
-
}
|
|
209
|
-
: {
|
|
210
|
-
color: null,
|
|
211
|
-
style: null,
|
|
212
|
-
width: null,
|
|
213
|
-
...newBorderWithStyle,
|
|
214
|
-
};
|
|
160
|
+
const updatedBorder = { ...newBorder };
|
|
215
161
|
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
162
|
+
if ( hasSplitBorders( updatedBorder ) ) {
|
|
163
|
+
[ 'top', 'right', 'bottom', 'left' ].forEach( ( side ) => {
|
|
164
|
+
if ( updatedBorder[ side ] ) {
|
|
165
|
+
updatedBorder[ side ] = {
|
|
166
|
+
...updatedBorder[ side ],
|
|
167
|
+
color: encodeColorValue( updatedBorder[ side ]?.color ),
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
} );
|
|
171
|
+
} else if ( updatedBorder ) {
|
|
172
|
+
updatedBorder.color = encodeColorValue( updatedBorder.color );
|
|
173
|
+
}
|
|
222
174
|
|
|
223
175
|
// As radius is maintained separately to color, style, and width
|
|
224
176
|
// maintain its value. Undefined values here will be cleaned when
|
|
@@ -28,7 +28,7 @@ import { __ } from '@wordpress/i18n';
|
|
|
28
28
|
import ColorGradientControl from '../colors-gradients/control';
|
|
29
29
|
import { useColorsPerOrigin, useGradientsPerOrigin } from './hooks';
|
|
30
30
|
import { getValueFromVariable } from './utils';
|
|
31
|
-
import {
|
|
31
|
+
import { setImmutably } from '../../utils/object';
|
|
32
32
|
|
|
33
33
|
export function useHasColorPanel( settings ) {
|
|
34
34
|
const hasTextPanel = useHasTextPanel( settings );
|
|
@@ -330,7 +330,7 @@ export default function ColorPanel( {
|
|
|
330
330
|
const hasTextColor = () => !! userTextColor;
|
|
331
331
|
const setTextColor = ( newColor ) => {
|
|
332
332
|
onChange(
|
|
333
|
-
|
|
333
|
+
setImmutably(
|
|
334
334
|
value,
|
|
335
335
|
[ 'color', 'text' ],
|
|
336
336
|
encodeColorValue( newColor )
|
|
@@ -347,7 +347,7 @@ export default function ColorPanel( {
|
|
|
347
347
|
const userGradient = decodeValue( value?.color?.gradient );
|
|
348
348
|
const hasBackground = () => !! userBackgroundColor || !! userGradient;
|
|
349
349
|
const setBackgroundColor = ( newColor ) => {
|
|
350
|
-
const newValue =
|
|
350
|
+
const newValue = setImmutably(
|
|
351
351
|
value,
|
|
352
352
|
[ 'color', 'background' ],
|
|
353
353
|
encodeColorValue( newColor )
|
|
@@ -356,7 +356,7 @@ export default function ColorPanel( {
|
|
|
356
356
|
onChange( newValue );
|
|
357
357
|
};
|
|
358
358
|
const setGradient = ( newGradient ) => {
|
|
359
|
-
const newValue =
|
|
359
|
+
const newValue = setImmutably(
|
|
360
360
|
value,
|
|
361
361
|
[ 'color', 'gradient' ],
|
|
362
362
|
encodeGradientValue( newGradient )
|
|
@@ -365,7 +365,7 @@ export default function ColorPanel( {
|
|
|
365
365
|
onChange( newValue );
|
|
366
366
|
};
|
|
367
367
|
const resetBackground = () => {
|
|
368
|
-
const newValue =
|
|
368
|
+
const newValue = setImmutably(
|
|
369
369
|
value,
|
|
370
370
|
[ 'color', 'background' ],
|
|
371
371
|
undefined
|
|
@@ -382,7 +382,7 @@ export default function ColorPanel( {
|
|
|
382
382
|
const userLinkColor = decodeValue( value?.elements?.link?.color?.text );
|
|
383
383
|
const setLinkColor = ( newColor ) => {
|
|
384
384
|
onChange(
|
|
385
|
-
|
|
385
|
+
setImmutably(
|
|
386
386
|
value,
|
|
387
387
|
[ 'elements', 'link', 'color', 'text' ],
|
|
388
388
|
encodeColorValue( newColor )
|
|
@@ -397,7 +397,7 @@ export default function ColorPanel( {
|
|
|
397
397
|
);
|
|
398
398
|
const setHoverLinkColor = ( newColor ) => {
|
|
399
399
|
onChange(
|
|
400
|
-
|
|
400
|
+
setImmutably(
|
|
401
401
|
value,
|
|
402
402
|
[ 'elements', 'link', ':hover', 'color', 'text' ],
|
|
403
403
|
encodeColorValue( newColor )
|
|
@@ -406,12 +406,12 @@ export default function ColorPanel( {
|
|
|
406
406
|
};
|
|
407
407
|
const hasLink = () => !! userLinkColor || !! userHoverLinkColor;
|
|
408
408
|
const resetLink = () => {
|
|
409
|
-
let newValue =
|
|
409
|
+
let newValue = setImmutably(
|
|
410
410
|
value,
|
|
411
411
|
[ 'elements', 'link', ':hover', 'color', 'text' ],
|
|
412
412
|
undefined
|
|
413
413
|
);
|
|
414
|
-
newValue =
|
|
414
|
+
newValue = setImmutably(
|
|
415
415
|
newValue,
|
|
416
416
|
[ 'elements', 'link', 'color', 'text' ],
|
|
417
417
|
undefined
|
|
@@ -591,7 +591,7 @@ export default function ColorPanel( {
|
|
|
591
591
|
elementGradientUserColor
|
|
592
592
|
);
|
|
593
593
|
const resetElement = () => {
|
|
594
|
-
const newValue =
|
|
594
|
+
const newValue = setImmutably(
|
|
595
595
|
value,
|
|
596
596
|
[ 'elements', name, 'color', 'background' ],
|
|
597
597
|
undefined
|
|
@@ -603,7 +603,7 @@ export default function ColorPanel( {
|
|
|
603
603
|
|
|
604
604
|
const setElementTextColor = ( newTextColor ) => {
|
|
605
605
|
onChange(
|
|
606
|
-
|
|
606
|
+
setImmutably(
|
|
607
607
|
value,
|
|
608
608
|
[ 'elements', name, 'color', 'text' ],
|
|
609
609
|
encodeColorValue( newTextColor )
|
|
@@ -611,7 +611,7 @@ export default function ColorPanel( {
|
|
|
611
611
|
);
|
|
612
612
|
};
|
|
613
613
|
const setElementBackgroundColor = ( newBackgroundColor ) => {
|
|
614
|
-
const newValue =
|
|
614
|
+
const newValue = setImmutably(
|
|
615
615
|
value,
|
|
616
616
|
[ 'elements', name, 'color', 'background' ],
|
|
617
617
|
encodeColorValue( newBackgroundColor )
|
|
@@ -620,7 +620,7 @@ export default function ColorPanel( {
|
|
|
620
620
|
onChange( newValue );
|
|
621
621
|
};
|
|
622
622
|
const setElementGradient = ( newGradient ) => {
|
|
623
|
-
const newValue =
|
|
623
|
+
const newValue = setImmutably(
|
|
624
624
|
value,
|
|
625
625
|
[ 'elements', name, 'color', 'gradient' ],
|
|
626
626
|
encodeGradientValue( newGradient )
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WordPress dependencies
|
|
3
|
+
*/
|
|
4
|
+
import { useSelect } from '@wordpress/data';
|
|
5
|
+
import { useEffect, useState, useMemo, useCallback } from '@wordpress/element';
|
|
6
|
+
import { __ } from '@wordpress/i18n';
|
|
7
|
+
import { useGlobalStyles } from '@wordpress/components';
|
|
8
|
+
import { store as blockEditorStore } from '@wordpress/block-editor';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Internal dependencies
|
|
12
|
+
*/
|
|
13
|
+
import PanelColorGradientSettings from '../colors-gradients/panel-color-gradient-settings';
|
|
14
|
+
import { useColorsPerOrigin, useGradientsPerOrigin } from './hooks';
|
|
15
|
+
import { getValueFromVariable } from './utils';
|
|
16
|
+
import { setImmutably } from '../../utils/object';
|
|
17
|
+
import ContrastChecker from '../contrast-checker';
|
|
18
|
+
import InspectorControls from '../inspector-controls';
|
|
19
|
+
import {
|
|
20
|
+
useHasColorPanel,
|
|
21
|
+
useHasTextPanel,
|
|
22
|
+
useHasBackgroundPanel,
|
|
23
|
+
} from './color-panel.js';
|
|
24
|
+
|
|
25
|
+
const ColorPanel = ( {
|
|
26
|
+
value,
|
|
27
|
+
inheritedValue = value,
|
|
28
|
+
onChange,
|
|
29
|
+
settings,
|
|
30
|
+
} ) => {
|
|
31
|
+
const colors = useColorsPerOrigin( settings );
|
|
32
|
+
const gradients = useGradientsPerOrigin( settings );
|
|
33
|
+
const globalStyles = useGlobalStyles();
|
|
34
|
+
|
|
35
|
+
const [ detectedBackgroundColor, setDetectedBackgroundColor ] = useState();
|
|
36
|
+
const [ detectedTextColor, setDetectedTextColor ] = useState();
|
|
37
|
+
|
|
38
|
+
const { baseGlobalStyles } = useSelect( ( select ) => {
|
|
39
|
+
const { getSettings } = select( blockEditorStore );
|
|
40
|
+
return {
|
|
41
|
+
baseGlobalStyles:
|
|
42
|
+
getSettings()?.__experimentalGlobalStylesBaseStyles?.color,
|
|
43
|
+
};
|
|
44
|
+
} );
|
|
45
|
+
|
|
46
|
+
const decodeValue = ( rawValue ) =>
|
|
47
|
+
getValueFromVariable( { settings }, '', rawValue );
|
|
48
|
+
const encodeColorValue = useCallback(
|
|
49
|
+
( colorValue ) => {
|
|
50
|
+
const allColors = colors.flatMap(
|
|
51
|
+
( { colors: originColors } ) => originColors
|
|
52
|
+
);
|
|
53
|
+
const colorObject = allColors.find(
|
|
54
|
+
( { color } ) => color === colorValue
|
|
55
|
+
);
|
|
56
|
+
return colorObject
|
|
57
|
+
? 'var:preset|color|' + colorObject.slug
|
|
58
|
+
: colorValue;
|
|
59
|
+
},
|
|
60
|
+
[ colors ]
|
|
61
|
+
);
|
|
62
|
+
const encodeGradientValue = useCallback(
|
|
63
|
+
( gradientValue ) => {
|
|
64
|
+
const allGradients = gradients.flatMap(
|
|
65
|
+
( { gradients: originGradients } ) => originGradients
|
|
66
|
+
);
|
|
67
|
+
const gradientObject = allGradients.find(
|
|
68
|
+
( { gradient } ) => gradient === gradientValue
|
|
69
|
+
);
|
|
70
|
+
return gradientObject
|
|
71
|
+
? 'var:preset|gradient|' + gradientObject.slug
|
|
72
|
+
: gradientValue;
|
|
73
|
+
},
|
|
74
|
+
[ gradients ]
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
// Text Color
|
|
78
|
+
const showTextPanel = useHasTextPanel( settings );
|
|
79
|
+
const textColor = decodeValue( inheritedValue?.color?.text );
|
|
80
|
+
const setTextColor = useCallback(
|
|
81
|
+
( newColor ) => {
|
|
82
|
+
onChange(
|
|
83
|
+
setImmutably(
|
|
84
|
+
value,
|
|
85
|
+
[ 'color', 'text' ],
|
|
86
|
+
encodeColorValue( newColor )
|
|
87
|
+
)
|
|
88
|
+
);
|
|
89
|
+
},
|
|
90
|
+
[ encodeColorValue, onChange, value ]
|
|
91
|
+
);
|
|
92
|
+
const resetTextColor = useCallback(
|
|
93
|
+
() => setTextColor( undefined ),
|
|
94
|
+
[ setTextColor ]
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
// BackgroundColor
|
|
98
|
+
const showBackgroundPanel = useHasBackgroundPanel( settings );
|
|
99
|
+
const backgroundColor = decodeValue( inheritedValue?.color?.background );
|
|
100
|
+
const gradient = decodeValue( inheritedValue?.color?.gradient );
|
|
101
|
+
const setBackgroundColor = useCallback(
|
|
102
|
+
( newColor ) => {
|
|
103
|
+
const newValue = setImmutably(
|
|
104
|
+
value,
|
|
105
|
+
[ 'color', 'background' ],
|
|
106
|
+
encodeColorValue( newColor )
|
|
107
|
+
);
|
|
108
|
+
newValue.color.gradient = undefined;
|
|
109
|
+
onChange( newValue );
|
|
110
|
+
},
|
|
111
|
+
[ encodeColorValue, onChange, value ]
|
|
112
|
+
);
|
|
113
|
+
const setGradient = useCallback(
|
|
114
|
+
( newGradient ) => {
|
|
115
|
+
const newValue = setImmutably(
|
|
116
|
+
value,
|
|
117
|
+
[ 'color', 'gradient' ],
|
|
118
|
+
encodeGradientValue( newGradient )
|
|
119
|
+
);
|
|
120
|
+
newValue.color.background = undefined;
|
|
121
|
+
onChange( newValue );
|
|
122
|
+
},
|
|
123
|
+
[ encodeGradientValue, onChange, value ]
|
|
124
|
+
);
|
|
125
|
+
const resetBackground = useCallback( () => {
|
|
126
|
+
const newValue = setImmutably(
|
|
127
|
+
value,
|
|
128
|
+
[ 'color', 'background' ],
|
|
129
|
+
undefined
|
|
130
|
+
);
|
|
131
|
+
newValue.color.gradient = undefined;
|
|
132
|
+
onChange( newValue );
|
|
133
|
+
}, [ onChange, value ] );
|
|
134
|
+
const currentGradients = settings?.color?.gradients;
|
|
135
|
+
const withoutGradientsSupport =
|
|
136
|
+
Array.isArray( currentGradients ) && currentGradients.length === 0;
|
|
137
|
+
|
|
138
|
+
const items = useMemo(
|
|
139
|
+
() =>
|
|
140
|
+
[
|
|
141
|
+
showTextPanel && {
|
|
142
|
+
label: __( 'Text' ),
|
|
143
|
+
colorValue: textColor,
|
|
144
|
+
onColorChange: setTextColor,
|
|
145
|
+
onColorCleared: resetTextColor,
|
|
146
|
+
},
|
|
147
|
+
showBackgroundPanel && {
|
|
148
|
+
label: __( 'Background' ),
|
|
149
|
+
colorValue: backgroundColor,
|
|
150
|
+
onColorChange: setBackgroundColor,
|
|
151
|
+
onColorCleared: resetBackground,
|
|
152
|
+
onGradientChange: ! withoutGradientsSupport
|
|
153
|
+
? setGradient
|
|
154
|
+
: undefined,
|
|
155
|
+
gradientValue: gradient,
|
|
156
|
+
},
|
|
157
|
+
].filter( Boolean ),
|
|
158
|
+
[
|
|
159
|
+
backgroundColor,
|
|
160
|
+
gradient,
|
|
161
|
+
resetBackground,
|
|
162
|
+
resetTextColor,
|
|
163
|
+
setBackgroundColor,
|
|
164
|
+
setGradient,
|
|
165
|
+
setTextColor,
|
|
166
|
+
showBackgroundPanel,
|
|
167
|
+
showTextPanel,
|
|
168
|
+
textColor,
|
|
169
|
+
withoutGradientsSupport,
|
|
170
|
+
]
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
useEffect( () => {
|
|
174
|
+
// The following logic is used to determine current text/background colors:
|
|
175
|
+
// 1. The globalStyles object is queried to determine whether a color has been
|
|
176
|
+
// set via a block's settings.
|
|
177
|
+
// 2. If a block-based theme is in use and no globalStyles exist, the theme's
|
|
178
|
+
// default/base colors are used.
|
|
179
|
+
// 3. If no globalStyles exist and a theme isn't block-based, there is no way
|
|
180
|
+
// to determine the default text/background color and the checker won't run.
|
|
181
|
+
const currentDetectedTextColor =
|
|
182
|
+
globalStyles?.color || baseGlobalStyles?.text;
|
|
183
|
+
const currentDetectedBackgroundColor =
|
|
184
|
+
globalStyles?.backgroundColor || baseGlobalStyles?.background;
|
|
185
|
+
|
|
186
|
+
setDetectedTextColor( currentDetectedTextColor );
|
|
187
|
+
setDetectedBackgroundColor( currentDetectedBackgroundColor );
|
|
188
|
+
}, [ globalStyles, baseGlobalStyles ] );
|
|
189
|
+
|
|
190
|
+
return (
|
|
191
|
+
<InspectorControls>
|
|
192
|
+
<PanelColorGradientSettings
|
|
193
|
+
title={ __( 'Color' ) }
|
|
194
|
+
initialOpen={ false }
|
|
195
|
+
settings={ items }
|
|
196
|
+
>
|
|
197
|
+
<ContrastChecker
|
|
198
|
+
backgroundColor={ detectedBackgroundColor }
|
|
199
|
+
textColor={ detectedTextColor }
|
|
200
|
+
/>
|
|
201
|
+
</PanelColorGradientSettings>
|
|
202
|
+
</InspectorControls>
|
|
203
|
+
);
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
export { useHasColorPanel };
|
|
207
|
+
export default ColorPanel;
|