Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Global Styles: Improve organisation of site background color and image #63216

Open
wants to merge 21 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
3401d45
Adds background icon
amitraj2203 Jul 6, 2024
70fc60f
Removes Background Panel from layout screen
amitraj2203 Jul 6, 2024
a555902
Improves organisation of site background image and color options in g…
amitraj2203 Jul 6, 2024
c78e9f0
Merge branch 'trunk' of github.com:WordPress/gutenberg into feat/add-…
amitraj2203 Jul 31, 2024
5caa672
Fix styling issue after merge conflict
amitraj2203 Jul 31, 2024
d6252d6
Resets border radius top and bottom for the first and last control
amitraj2203 Jul 31, 2024
4a99ca1
Refactor global styles to fix border focus issue for background panel
amitraj2203 Aug 1, 2024
c4a1706
Adds upload icon for background image and change it's shape to rounde…
amitraj2203 Aug 1, 2024
635c62e
Change the border-radius to 2px and fix the missing border-top when t…
amitraj2203 Aug 2, 2024
7f4951d
Move background panel to the top
mtias Aug 3, 2024
f3fc268
Makes use of ColorIndicator component
amitraj2203 Aug 5, 2024
9f2d715
Used $radius-small instead of $radius-block-ui
amitraj2203 Aug 5, 2024
267a62b
Refactor SVG attributes to adhere to camel case convention
amitraj2203 Aug 5, 2024
dba7140
Wraps "Image" and "Color" items with ItemGroup
amitraj2203 Aug 7, 2024
f27779e
Merge branch 'trunk' of github.com:WordPress/gutenberg into feat/add-…
amitraj2203 Aug 17, 2024
f4e3a7d
feat: Use ItemGroup to wrap the Color and Image item
amitraj2203 Aug 17, 2024
f2cc826
Merge branch 'trunk' of github.com:WordPress/gutenberg into feat/add-…
amitraj2203 Aug 19, 2024
4f83540
Merge branch 'trunk' of github.com:WordPress/gutenberg into feat/add-…
amitraj2203 Aug 29, 2024
98833df
Removed blank lines
amitraj2203 Aug 29, 2024
7b8110a
chore: Update showColorControl prop in BackgroundPanel component
amitraj2203 Aug 31, 2024
9cd986c
chore: Update use of hasBackgroundPanel in RootMenu component
amitraj2203 Aug 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

55 changes: 33 additions & 22 deletions packages/block-editor/src/components/global-styles/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
.block-editor-global-styles__shadow-indicator {
color: $gray-800;
border: $gray-200 $border-width solid;
border-radius: $radius-block-ui;
border-radius: $radius-small;
cursor: pointer;
padding: 0;

Expand Down Expand Up @@ -83,13 +83,18 @@
}

.block-editor-global-styles-background-panel__image-tools-panel-item {
padding: 0;
flex-grow: 1;
border: 0;
.components-dropdown {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it was not introduced by this PR, but — as also mentioned about .components-button.components-* classnames re not meant to be used outside of the components package. We can use custom classnames instead.

Copy link
Contributor Author

@amitraj2203 amitraj2203 Aug 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I make the change in this PR only, or a separate PR would be good for it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy for it to be a separate, follow-up PR.

The main changes that would be needed:

  • understand why we need to set a 36px height on .components-dropdown. Ideally, we should use the default button height. If not, let's understand why, and at most use the renderToggle prop to pass differently sized button;
  • avoid overriding color and focus styles of .components-button, and only use the component props to tweak those aspects (mainly the variant prop)
  • passing a custom className to the components instances, and then using that custom classname in the styles file;

display: block;
}
}

.block-editor-global-styles-background-panel__color-tools-panel-item {
padding: 0;
}

.block-editor-global-styles-background-panel__inspector-preview-inner {
height: 100%;
}
Expand Down Expand Up @@ -130,7 +135,7 @@
}

&:focus {
box-shadow: inset 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color);
box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color);
}
}

Expand All @@ -146,6 +151,12 @@
}
}

.block-editor-global-styles-background-panel__color-tools-panel-item {
button {
padding: 0;
}
}

.block-editor-global-styles-background-panel__image-preview-content,
.block-editor-global-styles-background-panel__dropdown-toggle {
height: 100%;
Expand All @@ -157,6 +168,15 @@
cursor: pointer;
background: transparent;
border: none;

&.is-open {
background-color: $gray-100;
}

&:focus {
box-shadow: 0 0 0 var(--wp-admin-border-width-focus) var(--wp-admin-theme-color);
outline: none;
}
}

.block-editor-global-styles-background-panel__inspector-media-replace-title {
Expand All @@ -166,7 +186,6 @@

// Without this, the ellipsis can sometimes be partially hidden by the Button padding.
text-align: start;
text-align-last: center;
}

.block-editor-global-styles-background-panel__inspector-preview-inner {
Expand All @@ -179,25 +198,11 @@

.block-editor-global-styles-background-panel__inspector-image-indicator {
background-size: cover;
border-radius: $radius-round;
width: 20px;
height: 20px;
display: block;
position: relative;
}
border-radius: $radius-small;

.block-editor-global-styles-background-panel__inspector-image-indicator::after {
content: "";
position: absolute;
top: -1px;
left: -1px;
bottom: -1px;
right: -1px;
border-radius: $radius-round;
box-shadow: inset 0 0 0 $border-width rgba(0, 0, 0, 0.2);
// Show a thin outline in Windows high contrast mode, otherwise the button is invisible.
border: 1px solid transparent;
box-sizing: inherit;
&.has-image {
background-image: var(--image-url);
}
}

.block-editor-global-styles-background-panel__dropdown-content-wrapper {
Expand All @@ -207,7 +212,7 @@
.components-focal-point-picker-wrapper {
background-color: $gray-100;
width: 100%;
border-radius: $radius-block-ui;
border-radius: $radius-small;
border: $border-width solid $gray-300;
}

Expand All @@ -226,6 +231,12 @@
z-index: z-index(".block-editor-global-styles-background-panel__popover");
}

.block-editor-global-styles-background-panel__popover {
.block-editor-global-styles-background-panel__image-tools-panel-item {
padding: 0;
}
}

.block-editor-global-styles-background-panel__media-replace-popover {
.components-popover__content {
// width of block-editor-global-styles-background-panel__dropdown-content-wrapper minus padding.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export default function BackgroundPanel() {
onChange={ setStyle }
settings={ settings }
defaultValues={ BACKGROUND_DEFAULT_VALUES }
showColorControl
/>
);
}
12 changes: 12 additions & 0 deletions packages/edit-site/src/components/global-styles/root-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { __experimentalItemGroup as ItemGroup } from '@wordpress/components';
import {
typography,
background,
color,
layout,
shadow as shadowIcon,
Expand All @@ -23,6 +24,7 @@ const {
useHasColorPanel,
useGlobalSetting,
useSettingsForBlockElement,
useHasBackgroundPanel,
} = unlock( blockEditorPrivateApis );

function RootMenu() {
Expand All @@ -33,10 +35,20 @@ function RootMenu() {
const hasShadowPanel = true; // useHasShadowPanel( settings );
const hasDimensionsPanel = useHasDimensionsPanel( settings );
const hasLayoutPanel = hasDimensionsPanel;
const hasBackgroundPanel = useHasBackgroundPanel( settings );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The background panel doesn't show at all for me at the moment. I think we should be using rawSettings here, not the return value of useSettingsForBlockElement()

Suggested change
const hasBackgroundPanel = useHasBackgroundPanel( settings );
const hasBackgroundPanel = useHasBackgroundPanel( rawSettings );


return (
<>
<ItemGroup>
{ hasBackgroundPanel && (
<NavigationButtonAsItem
icon={ background }
path="/background"
aria-label={ __( 'Background styles' ) }
>
{ __( 'Background' ) }
</NavigationButtonAsItem>
) }
{ hasTypographyPanel && (
<NavigationButtonAsItem
icon={ typography }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { privateApis as blockEditorPrivateApis } from '@wordpress/block-editor';

/**
* Internal dependencies
*/
import BackgroundPanel from './background-panel';
import ScreenHeader from './header';
import { unlock } from '../../lock-unlock';

const { useHasBackgroundPanel, useGlobalSetting } = unlock(
blockEditorPrivateApis
);

function ScreenBackground() {
const [ settings ] = useGlobalSetting( '' );
const hasBackgroundPanel = useHasBackgroundPanel( settings );
return (
<>
<ScreenHeader
title={ __( 'Background' ) }
description={ __(
'Edit the site background image and color.'
) }
/>
{ hasBackgroundPanel && <BackgroundPanel /> }
</>
);
}

export default ScreenBackground;
15 changes: 2 additions & 13 deletions packages/edit-site/src/components/global-styles/screen-layout.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
<ScreenHeader title={ __( 'Layout' ) } />
{ hasDimensionsPanel && <DimensionsPanel /> }
{ hasBackgroundPanel && <BackgroundPanel /> }
</>
);
}
Expand Down
4 changes: 4 additions & 0 deletions packages/edit-site/src/components/global-styles/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,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';

Expand Down Expand Up @@ -371,6 +372,9 @@ function GlobalStylesUI() {
<GlobalStylesNavigationScreen path="/revisions">
<ScreenRevisions />
</GlobalStylesNavigationScreen>
<GlobalStylesNavigationScreen path="/background">
<ScreenBackground />
</GlobalStylesNavigationScreen>

{ blocks.map( ( block ) => (
<GlobalStylesNavigationScreen
Expand Down
1 change: 1 addition & 0 deletions packages/icons/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
16 changes: 16 additions & 0 deletions packages/icons/src/library/background.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* WordPress dependencies
*/
import { Path, SVG } from '@wordpress/primitives';

const background = (
<SVG width="24" height="24" fill="none" xmlns="http://www.w3.org/2000/svg">
<Path
fillRule="evenodd"
clipRule="evenodd"
d="M11.53 4.47a.75.75 0 1 0-1.06 1.06l8 8a.75.75 0 1 0 1.06-1.06l-8-8Zm5 1a.75.75 0 1 0-1.06 1.06l2 2a.75.75 0 1 0 1.06-1.06l-2-2Zm-11.06 10a.75.75 0 0 1 1.06 0l2 2a.75.75 0 1 1-1.06 1.06l-2-2a.75.75 0 0 1 0-1.06Zm.06-5a.75.75 0 0 0-1.06 1.06l8 8a.75.75 0 1 0 1.06-1.06l-8-8Zm-.06-3a.75.75 0 0 1 1.06 0l10 10a.75.75 0 1 1-1.06 1.06l-10-10a.75.75 0 0 1 0-1.06Zm3.06-2a.75.75 0 0 0-1.06 1.06l10 10a.75.75 0 1 0 1.06-1.06l-10-10Z"
/>
</SVG>
);

export default background;
Loading