From 3401d458329b9eb7f96c7b21faafbba0d26d0ea7 Mon Sep 17 00:00:00 2001 From: Amit Raj Date: Sun, 7 Jul 2024 02:59:07 +0530 Subject: [PATCH 01/17] Adds background icon --- packages/icons/src/index.js | 1 + packages/icons/src/library/background.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 packages/icons/src/library/background.js diff --git a/packages/icons/src/index.js b/packages/icons/src/index.js index c5d5976dd2d5f..c334c2b7fac49 100644 --- a/packages/icons/src/index.js +++ b/packages/icons/src/index.js @@ -16,6 +16,7 @@ export { default as arrowUp } from './library/arrow-up'; export { default as atSymbol } from './library/at-symbol'; export { default as aspectRatio } from './library/aspect-ratio'; export { default as audio } from './library/audio'; +export { default as background } from './library/background'; export { default as backup } from './library/backup'; export { default as blockDefault } from './library/block-default'; export { default as blockMeta } from './library/block-meta'; diff --git a/packages/icons/src/library/background.js b/packages/icons/src/library/background.js new file mode 100644 index 0000000000000..3fcfed0618980 --- /dev/null +++ b/packages/icons/src/library/background.js @@ -0,0 +1,16 @@ +/** + * WordPress dependencies + */ +import { Path, SVG } from '@wordpress/primitives'; + +const background = ( + + + +); + +export default background; From 70fc60f42bd02e939d9931099fe1ca7b300d476b Mon Sep 17 00:00:00 2001 From: Amit Raj Date: Sun, 7 Jul 2024 02:59:46 +0530 Subject: [PATCH 02/17] Removes Background Panel from layout screen --- .../src/components/global-styles/screen-layout.js | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/packages/edit-site/src/components/global-styles/screen-layout.js b/packages/edit-site/src/components/global-styles/screen-layout.js index 1e68309fe0186..e7794985b7984 100644 --- a/packages/edit-site/src/components/global-styles/screen-layout.js +++ b/packages/edit-site/src/components/global-styles/screen-layout.js @@ -8,31 +8,20 @@ import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor'; * Internal dependencies */ import DimensionsPanel from './dimensions-panel'; -import BackgroundPanel from './background-panel'; import ScreenHeader from './header'; import { unlock } from '../../lock-unlock'; -const { - useHasBackgroundPanel, - useHasDimensionsPanel, - useGlobalSetting, - useSettingsForBlockElement, -} = unlock( blockEditorPrivateApis ); +const { useHasDimensionsPanel, useGlobalSetting, useSettingsForBlockElement } = + unlock( blockEditorPrivateApis ); function ScreenLayout() { const [ rawSettings ] = useGlobalSetting( '' ); const settings = useSettingsForBlockElement( rawSettings ); const hasDimensionsPanel = useHasDimensionsPanel( settings ); - /* - * Use the raw settings to determine if the background panel should be displayed, - * as the background panel is not dependent on the block element settings. - */ - const hasBackgroundPanel = useHasBackgroundPanel( rawSettings ); return ( <> { hasDimensionsPanel && } - { hasBackgroundPanel && } ); } From a5559020587a375ed629ee01e885e60c92c76237 Mon Sep 17 00:00:00 2001 From: Amit Raj Date: Sun, 7 Jul 2024 03:50:02 +0530 Subject: [PATCH 03/17] Improves organisation of site background image and color options in global styles --- .../global-styles/background-panel.js | 334 +++++++++++++++--- .../src/components/global-styles/style.scss | 29 +- .../src/components/global-styles/root-menu.js | 11 + .../global-styles/screen-background.js | 7 +- .../src/components/global-styles/ui.js | 4 + 5 files changed, 339 insertions(+), 46 deletions(-) diff --git a/packages/block-editor/src/components/global-styles/background-panel.js b/packages/block-editor/src/components/global-styles/background-panel.js index 18ecc26b002d0..0883977d99179 100644 --- a/packages/block-editor/src/components/global-styles/background-panel.js +++ b/packages/block-editor/src/components/global-styles/background-panel.js @@ -7,6 +7,7 @@ import clsx from 'clsx'; * WordPress dependencies */ import { + __experimentalUseNavigator as useNavigator, __experimentalToolsPanel as ToolsPanel, __experimentalToolsPanelItem as ToolsPanelItem, ToggleControl, @@ -14,7 +15,10 @@ import { __experimentalToggleGroupControlOption as ToggleGroupControlOption, __experimentalUnitControl as UnitControl, __experimentalVStack as VStack, + Button, + ColorIndicator, DropZone, + Flex, FlexItem, FocalPointPicker, MenuItem, @@ -22,8 +26,10 @@ import { __experimentalItemGroup as ItemGroup, __experimentalHStack as HStack, __experimentalTruncate as Truncate, + __experimentalZStack as ZStack, Dropdown, __experimentalDropdownContentWrapper as DropdownContentWrapper, + privateApis as componentsPrivateApis, } from '@wordpress/components'; import { __, _x, sprintf } from '@wordpress/i18n'; import { store as noticesStore } from '@wordpress/notices'; @@ -42,15 +48,19 @@ import { isBlobURL } from '@wordpress/blob'; /** * Internal dependencies */ -import { useToolsPanelDropdownMenuProps } from './utils'; +import { getValueFromVariable, useToolsPanelDropdownMenuProps } from './utils'; import { setImmutably } from '../../utils/object'; +import { useColorsPerOrigin, useGradientsPerOrigin } from './hooks'; +import ColorGradientControl from '../colors-gradients/control'; import MediaReplaceFlow from '../media-replace-flow'; import { store as blockEditorStore } from '../../store'; import { getResolvedThemeFilePath } from './theme-file-uri-utils'; +import { unlock } from '../../lock-unlock'; const IMAGE_BACKGROUND_TYPE = 'image'; const DEFAULT_CONTROLS = { backgroundImage: true, + background: true, }; const BACKGROUND_POPOVER_PROPS = { placement: 'left-start', @@ -644,6 +654,140 @@ function BackgroundToolsPanel( { ); } +const { Tabs } = unlock( componentsPrivateApis ); + +function ColorPanelTab( { + isGradient, + inheritedValue, + userValue, + setValue, + colorGradientControlSettings, +} ) { + return ( + + ); +} + +const LabeledColorIndicators = ( { indicators, label } ) => ( + + + { indicators.map( ( indicator, index ) => ( + + + + ) ) } + + + { label } + + +); + +function ColorPanelDropdown( { + label, + hasValue, + resetValue, + isShownByDefault, + indicators, + tabs, + colorGradientControlSettings, + panelId, +} ) { + const currentTab = tabs.find( ( tab ) => tab.userValue !== undefined ); + return ( + + { + const toggleProps = { + onClick: onToggle, + className: clsx( + 'block-editor-panel-color-gradient-settings__dropdown', + { 'is-open': isOpen } + ), + 'aria-expanded': isOpen, + 'aria-label': sprintf( + /* translators: %s is the type of color property, e.g., "background" */ + __( 'Color %s styles' ), + label + ), + }; + + return ( + + ); + } } + renderContent={ () => ( + +
+ { tabs.length > 1 && ( + + + { tabs.map( ( tab ) => ( + + { tab.label } + + ) ) } + + + { tabs.map( ( tab ) => { + const { key: tabKey, ...restTabProps } = + tab; + return ( + + + + ); + } ) } + + ) } +
+
+ ) } + /> +
+ ); +} + export default function BackgroundPanel( { as: Wrapper = BackgroundToolsPanel, value, @@ -653,13 +797,83 @@ export default function BackgroundPanel( { panelId, defaultControls = DEFAULT_CONTROLS, defaultValues = {}, - headerLabel = __( 'Background image' ), + headerLabel = __( 'Elements' ), themeFileURIs, } ) { + const navigator = useNavigator(); + const { path } = navigator.location; + + const colors = useColorsPerOrigin( settings ); + const gradients = useGradientsPerOrigin( settings ); + const areCustomSolidsEnabled = settings?.color?.custom; + const areCustomGradientsEnabled = settings?.color?.customGradient; + const hasSolidColors = colors.length > 0 || areCustomSolidsEnabled; + const hasGradientColors = gradients.length > 0 || areCustomGradientsEnabled; + const decodeValue = ( rawValue ) => + getValueFromVariable( { settings }, '', rawValue ); + const encodeColorValue = ( colorValue ) => { + const allColors = colors.flatMap( + ( { colors: originColors } ) => originColors + ); + const colorObject = allColors.find( + ( { color } ) => color === colorValue + ); + return colorObject + ? 'var:preset|color|' + colorObject.slug + : colorValue; + }; + const encodeGradientValue = ( gradientValue ) => { + const allGradients = gradients.flatMap( + ( { gradients: originGradients } ) => originGradients + ); + const gradientObject = allGradients.find( + ( { gradient } ) => gradient === gradientValue + ); + return gradientObject + ? 'var:preset|gradient|' + gradientObject.slug + : gradientValue; + }; + + // BackgroundColor + const showBackgroundPanel = useHasBackgroundPanel( settings ); + const backgroundColor = decodeValue( inheritedValue?.color?.background ); + const userBackgroundColor = decodeValue( value?.color?.background ); + const gradient = decodeValue( inheritedValue?.color?.gradient ); + const userGradient = decodeValue( value?.color?.gradient ); + const hasBackground = () => !! userBackgroundColor || !! userGradient; + const setBackgroundColor = ( newColor ) => { + const newValue = setImmutably( + value, + [ 'color', 'background' ], + encodeColorValue( newColor ) + ); + newValue.color.gradient = undefined; + onChange( newValue ); + }; + const setGradient = ( newGradient ) => { + const newValue = setImmutably( + value, + [ 'color', 'gradient' ], + encodeGradientValue( newGradient ) + ); + newValue.color.background = undefined; + onChange( newValue ); + }; + const resetBackgroundColor = () => { + const newValue = setImmutably( + value, + [ 'color', 'background' ], + undefined + ); + newValue.color.gradient = undefined; + onChange( newValue ); + }; + const resetAllFilter = useCallback( ( previousValue ) => { return { ...previousValue, background: {}, + color: undefined, }; }, [] ); @@ -697,44 +911,84 @@ export default function BackgroundPanel( { } ) } > - { shouldShowBackgroundImageControls ? ( - - - { - setIsDropDownOpen( false ); - resetBackground(); - } } - /> - - - - ) : ( - - ) } + <> + { shouldShowBackgroundImageControls ? ( + + + { + setIsDropDownOpen( false ); + resetBackground(); + } } + /> + + + + ) : ( + + ) } + { showBackgroundPanel && path === '/background' && ( + + ) } + { /* Dummy ToolsPanel items, so we can control what's in the dropdown popover */ } diff --git a/packages/block-editor/src/components/global-styles/style.scss b/packages/block-editor/src/components/global-styles/style.scss index f55e2da643704..0df85c021dac2 100644 --- a/packages/block-editor/src/components/global-styles/style.scss +++ b/packages/block-editor/src/components/global-styles/style.scss @@ -73,18 +73,39 @@ .block-editor-global-styles-background-panel__inspector-media-replace-container { - border: 1px solid $gray-300; - border-radius: 2px; // Full width. ToolsPanel lays out children in a grid. grid-column: 1 / -1; + & > div { + // Border styles. + border-left: 1px solid $gray-300; + border-right: 1px solid $gray-300; + border-bottom: 1px solid $gray-300; + + &:nth-child(1 of &) { + border-top-left-radius: $radius-block-ui; + border-top-right-radius: $radius-block-ui; + border-top: 1px solid $gray-300; + } + + // Identify the last visible instance as placeholder items will not have this class. + &:nth-last-child(1 of &) { + border-bottom-left-radius: $radius-block-ui; + border-bottom-right-radius: $radius-block-ui; + } + + > div, + > div > button { + border-radius: inherit; + } + } + &.is-open { background-color: $gray-100; } .block-editor-global-styles-background-panel__image-tools-panel-item { flex-grow: 1; - border: 0; .components-dropdown { display: block; } @@ -101,8 +122,6 @@ } .block-editor-global-styles-background-panel__image-tools-panel-item { - border: 1px solid $gray-300; - border-radius: 2px; // Full width. ToolsPanel lays out children in a grid. grid-column: 1 / -1; // Since there is no option to skip rendering the drag'n'drop icon in drop diff --git a/packages/edit-site/src/components/global-styles/root-menu.js b/packages/edit-site/src/components/global-styles/root-menu.js index 6db4621299f1e..bd013a6258a46 100644 --- a/packages/edit-site/src/components/global-styles/root-menu.js +++ b/packages/edit-site/src/components/global-styles/root-menu.js @@ -4,6 +4,7 @@ import { __experimentalItemGroup as ItemGroup } from '@wordpress/components'; import { typography, + background, color, layout, shadow as shadowIcon, @@ -33,6 +34,7 @@ function RootMenu() { const hasShadowPanel = true; // useHasShadowPanel( settings ); const hasDimensionsPanel = useHasDimensionsPanel( settings ); const hasLayoutPanel = hasDimensionsPanel; + const hasBackgroundPanel = true; // useHasBackgroundPanel( settings ); return ( <> @@ -73,6 +75,15 @@ function RootMenu() { { __( 'Layout' ) } ) } + { hasBackgroundPanel && ( + + { __( 'Background' ) } + + ) } ); diff --git a/packages/edit-site/src/components/global-styles/screen-background.js b/packages/edit-site/src/components/global-styles/screen-background.js index e6d338ffcbef1..35ae764e123e2 100644 --- a/packages/edit-site/src/components/global-styles/screen-background.js +++ b/packages/edit-site/src/components/global-styles/screen-background.js @@ -20,7 +20,12 @@ function ScreenBackground() { const hasBackgroundPanel = useHasBackgroundPanel( settings ); return ( <> - + { hasBackgroundPanel && } ); diff --git a/packages/edit-site/src/components/global-styles/ui.js b/packages/edit-site/src/components/global-styles/ui.js index 08cd20e9aac6a..c14d1daca5119 100644 --- a/packages/edit-site/src/components/global-styles/ui.js +++ b/packages/edit-site/src/components/global-styles/ui.js @@ -41,6 +41,7 @@ import ScreenStyleVariations from './screen-style-variations'; import StyleBook from '../style-book'; import ScreenCSS from './screen-css'; import ScreenRevisions from './screen-revisions'; +import ScreenBackground from './screen-background'; import { unlock } from '../../lock-unlock'; import { store as editSiteStore } from '../../store'; @@ -356,6 +357,9 @@ function GlobalStylesUI() { + + + { blocks.map( ( block ) => ( Date: Wed, 31 Jul 2024 18:35:51 +0530 Subject: [PATCH 04/17] Fix styling issue after merge conflict --- packages/block-editor/src/components/global-styles/style.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/block-editor/src/components/global-styles/style.scss b/packages/block-editor/src/components/global-styles/style.scss index 4403146d33292..9e18a78fe086f 100644 --- a/packages/block-editor/src/components/global-styles/style.scss +++ b/packages/block-editor/src/components/global-styles/style.scss @@ -86,6 +86,7 @@ border-top-left-radius: $radius-block-ui; border-top-right-radius: $radius-block-ui; border-top: 1px solid $gray-300; + border-bottom: 0; } // Identify the last visible instance as placeholder items will not have this class. From d6252d63424edabb28e6c528ca587619f498f89a Mon Sep 17 00:00:00 2001 From: Amit Raj Date: Wed, 31 Jul 2024 18:47:12 +0530 Subject: [PATCH 05/17] Resets border radius top and bottom for the first and last control --- packages/block-editor/src/components/global-styles/style.scss | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/block-editor/src/components/global-styles/style.scss b/packages/block-editor/src/components/global-styles/style.scss index 9e18a78fe086f..80329a53aa5e2 100644 --- a/packages/block-editor/src/components/global-styles/style.scss +++ b/packages/block-editor/src/components/global-styles/style.scss @@ -87,12 +87,16 @@ border-top-right-radius: $radius-block-ui; border-top: 1px solid $gray-300; border-bottom: 0; + border-bottom-left-radius: 0; + border-bottom-right-radius: 0; } // Identify the last visible instance as placeholder items will not have this class. &:nth-last-child(1 of &) { border-bottom-left-radius: $radius-block-ui; border-bottom-right-radius: $radius-block-ui; + border-top-left-radius: 0; + border-top-right-radius: 0; } > div, From 4a99ca155340392abaab36094e214c6d88f33535 Mon Sep 17 00:00:00 2001 From: Amit Raj Date: Thu, 1 Aug 2024 16:53:47 +0530 Subject: [PATCH 06/17] Refactor global styles to fix border focus issue for background panel --- .../src/components/global-styles/style.scss | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/packages/block-editor/src/components/global-styles/style.scss b/packages/block-editor/src/components/global-styles/style.scss index 80329a53aa5e2..b7f65c3c1572a 100644 --- a/packages/block-editor/src/components/global-styles/style.scss +++ b/packages/block-editor/src/components/global-styles/style.scss @@ -86,7 +86,6 @@ border-top-left-radius: $radius-block-ui; border-top-right-radius: $radius-block-ui; border-top: 1px solid $gray-300; - border-bottom: 0; border-bottom-left-radius: 0; border-bottom-right-radius: 0; } @@ -95,18 +94,37 @@ &:nth-last-child(1 of &) { border-bottom-left-radius: $radius-block-ui; border-bottom-right-radius: $radius-block-ui; + border-top: 0; border-top-left-radius: 0; border-top-right-radius: 0; } > div, - > div > button { + > div > div, + > div > button, + > div > div > button { border-radius: inherit; } } &.is-open { - background-color: $gray-100; + .block-editor-global-styles-background-panel__dropdown-toggle { + background-color: $gray-100; + } + } + + .block-editor-global-styles-background-panel__dropdown-toggle { + &:focus { + box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color, #3858e9); + outline: 3px solid transparent; + border-radius: inherit; + } + } + + .block-editor-panel-color-gradient-settings__dropdown { + &.is-open { + background-color: $gray-100; + } } .block-editor-global-styles-background-panel__image-tools-panel-item { @@ -155,10 +173,6 @@ &:hover { color: var(--wp-admin-theme-color); } - - &:focus { - box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color); - } } } From c4a17062492f7650276acf87e0adc0624bc9e1c4 Mon Sep 17 00:00:00 2001 From: Amit Raj Date: Thu, 1 Aug 2024 18:19:19 +0530 Subject: [PATCH 07/17] Adds upload icon for background image and change it's shape to rounded-rectangle --- .../components/global-styles/background-panel.js | 15 ++++++++++----- .../src/components/global-styles/style.scss | 9 ++++++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/packages/block-editor/src/components/global-styles/background-panel.js b/packages/block-editor/src/components/global-styles/background-panel.js index c8accd2fc7d0c..ffc23383b81bc 100644 --- a/packages/block-editor/src/components/global-styles/background-panel.js +++ b/packages/block-editor/src/components/global-styles/background-panel.js @@ -186,7 +186,7 @@ function InspectorImagePreviewItem( { as="span" className="block-editor-global-styles-background-panel__inspector-preview-inner" > - { imgUrl && ( + { imgUrl ? ( + ) : ( + + + ) }