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

Closed
wants to merge 21 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 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.

70 changes: 59 additions & 11 deletions packages/block-editor/src/components/global-styles/style.scss
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,67 @@


.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;

&:not(:only-child):nth-child(1 of &) {
border-top-left-radius: $radius-block-ui;
ciampo marked this conversation as resolved.
Show resolved Hide resolved
border-top-right-radius: $radius-block-ui;
border-top: 1px solid $gray-300;
border-bottom-left-radius: 0;
border-bottom-right-radius: 0;
}

// Identify the last visible instance as placeholder items will not have this class.
&:not(:only-child):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;
}

&:only-child {
border-top: 1px solid $gray-300;
border-radius: $radius-block-ui;
}

> div,
> div > div,
> div > button,
> div > div > button {
border-radius: inherit;
}
amitraj2203 marked this conversation as resolved.
Show resolved Hide resolved
}

&.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 {
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;
}
Expand Down Expand Up @@ -129,10 +178,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);
}
}
}

Expand All @@ -156,20 +201,23 @@

// 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 {
.block-editor-global-styles-background-panel__inspector-image-indicator-wrapper {
width: 20px;
height: 20px;
min-width: auto;

.component-color-indicator {
border-radius: $radius-small;
}
}
}

.block-editor-global-styles-background-panel__inspector-image-indicator {
background-size: cover;
border-radius: $radius-round;
border-radius: $radius-small;
width: 20px;
height: 20px;
display: block;
Expand All @@ -183,7 +231,7 @@
left: -1px;
bottom: -1px;
right: -1px;
border-radius: $radius-round;
border-radius: $radius-small;
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;
Expand Down
11 changes: 11 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 Down Expand Up @@ -33,6 +34,7 @@ function RootMenu() {
const hasShadowPanel = true; // useHasShadowPanel( settings );
const hasDimensionsPanel = useHasDimensionsPanel( settings );
const hasLayoutPanel = hasDimensionsPanel;
const hasBackgroundPanel = true; // useHasBackgroundPanel( settings );
amitraj2203 marked this conversation as resolved.
Show resolved Hide resolved

return (
<>
Expand Down Expand Up @@ -73,6 +75,15 @@ function RootMenu() {
{ __( 'Layout' ) }
</NavigationButtonAsItem>
) }
{ hasBackgroundPanel && (
ciampo marked this conversation as resolved.
Show resolved Hide resolved
<NavigationButtonAsItem
icon={ background }
path="/background"
aria-label={ __( 'Background styles' ) }
>
{ __( 'Background' ) }
</NavigationButtonAsItem>
) }
</ItemGroup>
</>
);
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
fill-rule="evenodd"
amitraj2203 marked this conversation as resolved.
Show resolved Hide resolved
clip-rule="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