[BBT-7] and [BBT-89] Convert CSS vars to work with hex value and create UI component for color #21
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
BBT-7 and BBT-89
BBT-7
I've taken what @balw had done in the now closed PR (#14) and adapted it to fit the current state of the plugin. It's wasn't needed to add the theme palette as a localised script so that part has been removed. Two helpers have been added
varToHex
andhexToVar
.varToHex
By passing through a css variable name (that's been set in the standardised
theme.json
theme palette) and the palette itself, the helper will find the corresponding hex value from the theme palette. If the string is already a hex it returns the hex back. If the css variable is not found the original value is returned.hexToVar
By passing through a hex value and the palette itself, the helper will find the corresponding css variable name from the theme palette. If the string is not a hex value it returns the string back. If value is not found in the theme palette the original value is returned.
BBT-89
I've added a
Color
component for the color attribute. This PR also renames anywhere colour (with a "u") is referenced as I think it's best to keep it consistent the code. This uses the WordPress componentColorPalette
which means a user can select any colour but also select a colour from the themes registered palette. If a colour is chosen from the palette the css variable is stored so that if the palette colour is changed it will be reflected here. If a custom colour is chosen the hex value is stored.Misc
In the preview I've changed the
core/heading
tolevel: 1
(h1) as that's what a post title would be. For the preview i've also added the classhas-global-padding
. This is present in the main block editor and adds left and right padding to the previews.Renamed the variable
color
tothemePalette
in theBorder
component, this reflects the same in theColor
component and better represents what the variable is.Changed the padding on
themer--blocks-item-component--styles
so that the style controls aren't indented and have a bit more space top and bottom. I just think it looks a bit tidier for now.Added some
themer--blocks-item-component
specific column styles so that we can put the style controls into columns. There is athemer--blocks-item-component--columns
class and then a.themer--blocks-item-component--columns-2
class to use when 2 columns are needed. I've added a container query to drop 2 columns to 1 at a certain container size.Change Log
varToHex
,hexToVar
andisHex
helpers.Colour/colour
toColor/color
for consistency.Color
component.themer--blocks-item-component
.Steps to test
theme.json
and example would be the following in{ "styles": { "blocks": {} } }
:theme.json
.theme.json
.Screenshots/Videos
Screenshot: UI
Video: Demo
http://bigbite.im/v/3w2DPH
Video: Showing correct value is saved
http://bigbite.im/v/Z7DAkh
Checklist: