Skip to content

Global Styles: Move Randomize colors button to Edit Palette panel #70128

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

Merged
merged 4 commits into from
May 21, 2025

Conversation

himanshupathak95
Copy link
Contributor

@himanshupathak95 himanshupathak95 commented May 15, 2025

What?

Closes #66169

This PR relocates the Randomize colors button from the main color palette overview to within the 'Edit Palette' panel in the Site Editor's Global Styles.

Why?

Introduced in #52315. Currently, the Randomize colors button is positioned outside the palette editing interface. These previews are limited to the first 5 colors, providing an incomplete view of the actual changes across the entire palette.

Moving the button inside the 'Edit Palette' panel allows users to see the randomization effect applied to the entire theme color palette displayed within that panel. This offers a clearer, more accurate, and more useful user experience for this feature.

Testing Instructions

  1. Set a theme like Twenty Twenty-Four.
  2. Navigate to the Site Editor (Appearance > Editor).
  3. In the Site sidebar, select "Styles > Colors".
  4. In the "Colors" panel, observe the "Palette" section.
  5. Confirm that the 'Randomize colors' button is no longer present directly under the 'Edit palette' button.
  6. Click the 'Edit palette' button.
  7. The "Edit Palette" panel will open. Confirm the 'Randomize colors' button is now visible within this panel.
  8. Click the 'Randomize colors' button.
  9. Observe that the theme colors randomization happens as intended.

Screenshots or screencast

Before After
image image

@himanshupathak95 himanshupathak95 marked this pull request as ready for review May 15, 2025 09:39
Copy link

github-actions bot commented May 15, 2025

The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: himanshupathak95 <abcd95@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: richtabor <richtabor@git.wordpress.org>
Co-authored-by: afercia <afercia@git.wordpress.org>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@himanshupathak95
Copy link
Contributor Author

Just found out that the Gradient panel is getting squashed in the Twenty Twenty-Five theme because of the newly occupied vertical space -

Screenshot 2025-05-15 at 15 11 34

I believe this can be taken out in a separate issue since this is happening even by adding custom colors ( basically anything that increases the vertical space occupation ).

Screen.Recording.2025-05-15.at.15.17.51.mov

The squash disappears after removing the height: 100% property from the edit-site-layout container -

Screenshot 2025-05-15 at 15 24 26

I'll wait for some more eyes on this.

@t-hamano t-hamano added [Type] Bug An existing feature does not function as intended [Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json labels May 16, 2025
Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

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

Thanks for the PR!

It almost looks good, but personally, it might be good to move the button up about 16px to make it more relevant to the palette:

Before After
image image

@himanshupathak95 himanshupathak95 requested a review from t-hamano May 19, 2025 10:25
@himanshupathak95
Copy link
Contributor Author

Hey @t-hamano, Thanks for the review. I have adjusted the button as suggested. Please let me know if it looks good to you whenever you have time.

@t-hamano
Copy link
Contributor

@himanshupathak95 Thanks for the update!

Sorry, my explanation was insufficient.

When defining styles, it's important to note the following:

  • Don't use selectors with the components- prefix as much as possible: the internal implementation of the component may change.
  • Don't use hard-coded values ​​for spacing. Use 8px-based $grid-unit-xx.

I think you can achieve this without using CSS using the following approach:

Details
diff --git a/packages/edit-site/src/components/global-styles/color-palette-panel.js b/packages/edit-site/src/components/global-styles/color-palette-panel.js
index 5aa45c7ca2..17750bf9d6 100644
--- a/packages/edit-site/src/components/global-styles/color-palette-panel.js
+++ b/packages/edit-site/src/components/global-styles/color-palette-panel.js
@@ -59,41 +59,43 @@ export default function ColorPalettePanel( { name } ) {
                        className="edit-site-global-styles-color-palette-panel"
                        spacing={ 8 }
                >
-                       { !! themeColors && !! themeColors.length && (
-                               <PaletteEdit
-                                       canReset={ themeColors !== baseThemeColors }
-                                       canOnlyChangeValues
-                                       colors={ themeColors }
-                                       onChange={ setThemeColors }
-                                       paletteLabel={ __( 'Theme' ) }
-                                       paletteLabelHeadingLevel={ 3 }
-                                       popoverProps={ popoverProps }
-                               />
-                       ) }
-                       { !! defaultColors &&
-                               !! defaultColors.length &&
-                               !! defaultPaletteEnabled && (
+                       <VStack spacing={ 4 }>
+                               { !! themeColors && !! themeColors.length && (
                                        <PaletteEdit
-                                               canReset={ defaultColors !== baseDefaultColors }
+                                               canReset={ themeColors !== baseThemeColors }
                                                canOnlyChangeValues
-                                               colors={ defaultColors }
-                                               onChange={ setDefaultColors }
-                                               paletteLabel={ __( 'Default' ) }
+                                               colors={ themeColors }
+                                               onChange={ setThemeColors }
+                                               paletteLabel={ __( 'Theme' ) }
                                                paletteLabelHeadingLevel={ 3 }
                                                popoverProps={ popoverProps }
+                                                       __next40pxDefaultSize
+                                                       variant="secondary"
+                                                       icon={ shuffle }
+                                                       onClick={ randomizeThemeColors }
+                                               >
+                                                       { __( 'Randomize colors' ) }
+                                               </Button>
+                                       ) }
+                       </VStack>
                        <PaletteEdit
                                colors={ customColors }
                                onChange={ setCustomColors }
diff --git a/packages/edit-site/src/components/global-styles/style.scss b/packages/edit-site/src/components/global-styles/style.scss
index ac98e6f2f7..bd6b0dec5d 100644
--- a/packages/edit-site/src/components/global-styles/style.scss
+++ b/packages/edit-site/src/components/global-styles/style.scss
@@ -259,10 +259,3 @@
                border-radius: $radius-small;
        }
 }
-
-.edit-site-global-styles-color-palette-panel {
-       // Reduce spacing between Color palette and Randomize colors button
-       .components-button.is-secondary.has-icon.has-text {
-               margin-top: -16px;
-       }
-}

In other words, all we need to do is wrap the color palette and the randomize button in a VStack component.

Copy link
Contributor

@t-hamano t-hamano left a comment

Choose a reason for hiding this comment

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

LGTM!

Just found out that the Gradient panel is getting squashed in the Twenty Twenty-Five theme because of the newly occupied vertical space -

Do you mind submitting a new issue regarding the problem above?

@himanshupathak95
Copy link
Contributor Author

Do you mind submitting a new issue regarding the problem above?

Thanks @t-hamano for the review. I will soon open an issue for that problem.

@t-hamano t-hamano closed this May 21, 2025
@t-hamano t-hamano reopened this May 21, 2025
@t-hamano t-hamano merged commit 9fc7182 into WordPress:trunk May 21, 2025
110 of 129 checks passed
@github-actions github-actions bot added this to the Gutenberg 20.9 milestone May 21, 2025
chriszarate pushed a commit to chriszarate/gutenberg that referenced this pull request Jul 1, 2025
…ordPress#70128)

* Global Styles: Move 'Randomize colors' button to Edit Palette panel

* Global Styles: Reduce spacing between Custom palette and Randomize colors button to `16px`

* Remove custom styles added

* Wrap the Theme colors palette and randomize colors button in VStack

Co-authored-by: himanshupathak95 <abcd95@git.wordpress.org>
Co-authored-by: t-hamano <wildworks@git.wordpress.org>
Co-authored-by: richtabor <richtabor@git.wordpress.org>
Co-authored-by: afercia <afercia@git.wordpress.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Focus] Accessibility (a11y) Changes that impact accessibility and need corresponding review (e.g. markup changes). Global Styles Anything related to the broader Global Styles efforts, including Styles Engine and theme.json [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Move the palette Randomize colors to the edit palette panel and remove the color previews from the edit palette button labeling
2 participants