Skip to content

Commit 09d0a7f

Browse files
committed
SOFT-3870: resolve swatch display through @kadence/helpers KadenceColorOutput
The pop color controls painted their swatch tiles and the selected-value preview straight from the raw swatch value, so only a literal hex (or the hardcoded palette1..9 slugs) rendered. Delegate the final display resolution to `KadenceColorOutput`, which routes through the `kadence.helpers.colorValue` filter: a token reference resolves to its `var(--kb-token--<id>)`, a palette slug to its `var(--global-*)`, and a literal (hex/rgba/var) is returned unchanged (idempotent). This lets a consumer store a token-referencing value on a swatch and have it render correctly in the control, without this package knowing about any token vocabulary.
1 parent 8361f6c commit 09d0a7f

2 files changed

Lines changed: 10 additions & 4 deletions

File tree

src/inline-pop-color/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
* Import Icons
88
*/
99
import ColorPicker from '../color-picker';
10-
import { hexToRGBA } from '@kadence/helpers';
10+
import { hexToRGBA, KadenceColorOutput } from '@kadence/helpers';
1111
import { map } from 'lodash';
1212
import { useSetting } from '@wordpress/block-editor';
1313
import { useState, useMemo } from '@wordpress/element';
@@ -183,6 +183,9 @@ export default function InlinePopColorControl({
183183
break;
184184
}
185185
}
186+
// Delegate final resolution to @kadence/helpers: a swatch value that is a token reference or a
187+
// palette slug becomes a renderable CSS color, a literal (hex/rgba/var) is returned unchanged.
188+
previewColorString = KadenceColorOutput(previewColorString);
186189
const onChangeState = (tempColor, tempPalette) => {
187190
let newColor;
188191
let opacity = 100 === opacityUnit ? 100 : 1;
@@ -348,7 +351,7 @@ export default function InlinePopColorControl({
348351
{colors && (
349352
<div className="kadence-pop-color-palette-swatches">
350353
{map(colors, ({ color, slug, name }) => {
351-
const style = { color };
354+
const style = { color: KadenceColorOutput(color) };
352355
const palette = slug.replace('theme-', '');
353356
const isActive =
354357
palette === value || (!slug.startsWith('theme-palette') && value === color);

src/single-pop-color-control/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*/
99
import ColorPicker from '../color-picker';
1010
import ColorIcons from '../color-icons';
11-
import { hexToRGBA } from '@kadence/helpers';
11+
import { hexToRGBA, KadenceColorOutput } from '@kadence/helpers';
1212

1313
import { get, map } from 'lodash';
1414
import { useSetting } from '@wordpress/block-editor';
@@ -190,6 +190,9 @@ export default function SinglePopColorControl({
190190
break;
191191
}
192192
}
193+
// Delegate final resolution to @kadence/helpers: a swatch value that is a token reference or a
194+
// palette slug becomes a renderable CSS color, a literal (hex/rgba/var) is returned unchanged.
195+
previewColorString = KadenceColorOutput(previewColorString);
193196
const onChangeState = (tempColor, tempPalette) => {
194197
let newColor;
195198
let opacity = 100 === opacityUnit ? 100 : 1;
@@ -285,7 +288,7 @@ export default function SinglePopColorControl({
285288
{colors && (
286289
<div className="kadence-pop-color-palette-swatches">
287290
{map(colors, ({ color, slug, name }) => {
288-
const style = { color };
291+
const style = { color: KadenceColorOutput(color) };
289292
const palette = slug.replace('theme-', '');
290293
const isActive =
291294
palette === value || (!slug.startsWith('theme-palette') && value === color);

0 commit comments

Comments
 (0)