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

Blockbase: Add support for custom palettes customization #4098

Merged
merged 23 commits into from
Jun 28, 2021

Conversation

MaggieCabrera
Copy link
Contributor

@MaggieCabrera MaggieCabrera commented Jun 25, 2021

Changes proposed in this Pull Request:

This is a WIP. The goal is to give the user optional palettes provided by the theme's designers. Right now I'm using the code from https://github.com/HardeepAsrani/o2 as a starting point but this is a list of what I hope this will be able to do:

  • Get the default palette from theme.json and have it as the default option and available for users to go back to (instead of resetting each color one by one, they can reset the whole palette)
  • Grab the rest of the palettes from theme.json too. They should probably be under custom and we can provide labels for them there. Later, when Gutenberg supports mulitple plaettes, we can reuse those custom variables and assign them where appropiate for FSE goodness.
  • This PR doesn't handle the functionality that allows for the actual color updates yet.

Screenshot 2021-06-25 at 13 16 08

@MaggieCabrera
Copy link
Contributor Author

@kjellr if you have any input on this UI, I would appreciate your 👀

@kjellr
Copy link
Contributor

kjellr commented Jun 25, 2021

Thanks! We talked about this on slack, but noting it here for posterity: Let's try to adjust the visual treatment of the palettes to be similar to the Featured palettes treatment on WordPress.com:

Screen Shot 2021-06-25 at 7 58 43 AM

@MaggieCabrera
Copy link
Contributor Author

Updated the styles of the palettes. I added a border color to mark the selected palette that the color annotations plugin does not have, since we are using radio buttons, I think it's important not to lose the checked value visual cue:

Screenshot 2021-06-25 at 14 29 40

@scruffian
Copy link
Member

I think this looks good to merge, but it would be good to have some more eyes on it.

@MaggieCabrera MaggieCabrera requested review from pbking and jffng June 25, 2021 16:21
@MaggieCabrera MaggieCabrera self-assigned this Jun 25, 2021
@MaggieCabrera MaggieCabrera requested a review from a team June 25, 2021 16:22
@MaggieCabrera MaggieCabrera marked this pull request as ready for review June 25, 2021 16:22
'colors' => $default_palette_setting,
);

$custom_palettes = $theme_json['settings']['custom']['colorPalettes'];
Copy link
Contributor

@pbking pbking Jun 25, 2021

Choose a reason for hiding this comment

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

I'm getting an error here w/ Quadrat due to there being no palette's currently defined in theme.json
Likely the Quadrat palette options weren't included in the change (yet).
But seems reasonable that a BB child might not ship with any customizations so probably a relevant use-case.

Notice: Undefined index: colorPalettes in /var/www/html/wp-content/themes/themes/blockbase/inc/wp-customize-color-palettes.php on line 33 Warning: Invalid argument supplied for foreach() in /var/www/html/wp-content/themes/themes/blockbase/inc/wp-customize-color-palettes.php on line 34

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, that fixed disappeared on a conflict, let me get it back

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should be fine now

Copy link
Contributor

Choose a reason for hiding this comment

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

Pushed this small change to only render these controls if there are alternatives to default to show. Also addressed that error that seemed to stick around despite the recent change.

@pbking
Copy link
Contributor

pbking commented Jun 25, 2021

I'm of the opinion that the alternative palettes should be BUTTONS instead of RADIO BUTTONS. The action feels more like "apply these colors to my color pickers" rather than "select these colors to use" and BUTTON rather than RADIO BUTTON seems to reflect that better.

Otherwise we will invite the situation where an option might be chosen and then customized. In this situation the RADIO BUTTON would need to be unselected (no option selected) otherwise that option couldn't be returned to without selecting something else and returning. If we do keep it as a RADIO BUTTON then I suggest another stylistic mechanism to signify that that option is selected (It's difficult to see.)

That's just an opinionated nit-pick. Otherwise this looks FANTASTIC and I would be happy to ship as-is and iterate.

Copy link
Contributor

@jffng jffng left a comment

Choose a reason for hiding this comment

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

Tested in all four themes and it is a thing of beauty 👏

I did run into an issue with Quadrat. Because of the way our merge / build step works for child theme, the colorPalettes from blockbase are added, which results in the following error after I build Quadrat's theme.json:

Screen Shot 2021-06-25 at 1 47 54 PM

If I provide a new palette with only the three colors per palette using the same palette slug (e.g. featured-1) and run build, I still get the above error because the merge appends the values to the colors. In this instance, I think what needs to happen is that the entire key colorPalettes object is replaced with the child-theme.json value, rather than the recursive merge.

@@ -116,6 +116,38 @@
"secondary": "var(--wp--preset--color--secondary)",
"selection": "var(--wp--preset--color--selection)"
},
"colorPalettes": {
"palette-1": {
"label": "Featured",
Copy link
Contributor

Choose a reason for hiding this comment

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

I think there is a mechanism now for labels for presets to get translated, but is there a way yet to mark that a custom variable needs to be translated?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think we do it like this. Since we haven't done this for any of the strings that we have (such as the template parts) I think this merits its own separate PR

@scruffian
Copy link
Member

I did run into an issue with Quadrat. Because of the way our merge / build step works for child theme, the colorPalettes from blockbase are added, which results in the following error after I build Quadrat's theme.json:

I wonder if this means we should switch to using an array...

@MaggieCabrera
Copy link
Contributor Author

I wonder if this means we should switch to using an array...

I think we kind of have to, it's what's consistent with what we've done for other variables like this

Copy link
Contributor Author

@MaggieCabrera MaggieCabrera left a comment

Choose a reason for hiding this comment

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

I tested Blockbase and selected one of the palettes, then I changed to Quadrat and the palette that was selected for Blockbase was showing up for the customizer too (while its colors showed up something else)

Screenshot 2021-06-28 at 11 49 34

@scruffian scruffian force-pushed the try/blockbase-customizer-alternative-palettes branch from c135fe6 to 28f033b Compare June 28, 2021 10:03
@scruffian
Copy link
Member

I tested Blockbase and selected one of the palettes, then I changed to Quadrat and the palette that was selected for Blockbase was showing up for the customizer too (while its colors showed up something else)

I think this is because the Global Styles settings weren't populating back into the customizer. I had to put back the settings file I removed because I couldn't find a way to set a dirty value.

@scruffian scruffian merged commit 9e49d27 into trunk Jun 28, 2021
@scruffian scruffian deleted the try/blockbase-customizer-alternative-palettes branch June 28, 2021 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants