Skip to content

Commit dfa22a5

Browse files
authored
Fix color palette when custom theme colors are present (#261)
* Use experimentalFeatures to work around Gutenberg issue 64857 * build block editor bundle
1 parent ceb2991 commit dfa22a5

3 files changed

Lines changed: 28 additions & 3 deletions

File tree

block-editor/build/index.asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('lodash', 'react', 'react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives', 'wp-rich-text'), 'version' => '5935c81d1996f7c0446b');
1+
<?php return array('dependencies' => array('lodash', 'react', 'react-jsx-runtime', 'wp-block-editor', 'wp-blocks', 'wp-components', 'wp-data', 'wp-element', 'wp-i18n', 'wp-primitives', 'wp-rich-text'), 'version' => '987f5e49022d05fb19a8');

block-editor/build/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

block-editor/src/iconModifier.js

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,29 @@ import { NO_CUSTOM_VALUE, SELECTED_CLASS, ANIMATIONS, DEFAULT_SIZE } from './con
1313
const STYLES_TAB_NAME = 'styling'
1414
const ANIMATIONS_TAB_NAME = 'animations'
1515

16+
function buildThemeColors(editorSettings) {
17+
// This is a workaround for this Gutenberg bug:
18+
// https://github.com/WordPress/gutenberg/issues/64857
19+
//
20+
// When the user has defined custom colors the Gutenberg editorSettings.colors array
21+
// contains only that custom color and not the full set of theme colors.
22+
// However, the full set of theme colors is available under the
23+
// editorSettings.__experimentalFeatures.
24+
//
25+
// If we detect that the colors array is shorter than the combined
26+
// experimental theme + custom colors arrays, we use the experimental arrays.
27+
const canonicalThemeColors = [...editorSettings.colors]
28+
const experimentalThemeColors = editorSettings?.__experimentalFeatures?.color?.palette?.theme || []
29+
const experimentalCustomColors = editorSettings?.__experimentalFeatures?.color?.palette?.custom || []
30+
const experimentalColors = [...experimentalThemeColors, ...experimentalCustomColors]
31+
32+
if (canonicalThemeColors.length >= experimentalColors.length) {
33+
return canonicalThemeColors
34+
} else {
35+
return experimentalColors
36+
}
37+
}
38+
1639
const SettingsTabPanel = ({ onSelect, onSizeChange, setColor, setAnimation, updateTransform, editorSettings, attributes }) => {
1740
const [customRotate, setCustomRotate] = useState(NO_CUSTOM_VALUE)
1841
const currentIconLayer = (attributes?.iconLayers || [])[0]
@@ -110,14 +133,16 @@ const SettingsTabPanel = ({ onSelect, onSizeChange, setColor, setAnimation, upda
110133
]}
111134
>
112135
{(tab) => {
136+
const themeColors = buildThemeColors(editorSettings)
137+
113138
if (STYLES_TAB_NAME == tab.name)
114139
return (
115140
<div className="fawp-icon-styling-tab-content-wrapper fawp-tab-content-wrapper">
116141
<div className="fawp-icon-styling-tab-content fawp-icon-styling-color fawp-tab-content">
117142
<div className="fawp-options-section-heading">{__('Color', 'font-awesome')}</div>
118143
<div>
119144
<Colors
120-
themeColors={editorSettings.colors}
145+
themeColors={themeColors}
121146
onChange={setColor}
122147
attributes={attributes}
123148
/>

0 commit comments

Comments
 (0)