Skip to content

Convert theme color slugs to CSS variables instead of resolving to hex#2743

Merged
vytisbulkevicius merged 25 commits intodevelopmentfrom
copilot/fix-color-slugs-in-otter-blocks
Apr 1, 2026
Merged

Convert theme color slugs to CSS variables instead of resolving to hex#2743
vytisbulkevicius merged 25 commits intodevelopmentfrom
copilot/fix-color-slugs-in-otter-blocks

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Feb 16, 2026

Otter blocks were not handling theme.json color slugs, causing them to revert to defaults. Core WordPress blocks convert slugs to CSS variable references that remain connected to theme settings.

Changes

Utility functions

  • Added getColorCSSVariable(slug) - converts "primary""var(--wp--preset--color--primary)"
  • Added useColorResolver() hook returning the converter
  • Added PHP equivalents: Base_CSS::get_color_css_variable() and resolve_color_value()

Block updates
Applied color resolution to 15 blocks: accordion, tabs, advanced-heading, button, section, posts, review, progress-bar, circle-counter, countdown, sharing-icons, popup, flip, font-awesome-icons, lottie

Unit tests
Added 13 tests covering slug conversion, passthrough of hex/rgb/hsl values, and edge cases

Technical approach

WordPress generates CSS variables from theme.json. By referencing these variables instead of storing resolved color values, blocks automatically reflect theme color changes without re-saving.

// Before: slug not converted
const inlineStyles = {
  '--title-color': attributes.titleColor  // "primary" → invalid
};

// After: slug → CSS variable
const resolveColor = useColorResolver();
const inlineStyles = {
  '--title-color': resolveColor(attributes.titleColor)  // "var(--wp--preset--color--primary)"
};

Hex/RGB/HSL values and existing CSS variables pass through unchanged (backward compatible).

Original prompt

This section details on the original issue you should resolve

<issue_title>Color slugs are not working in Otter Blocks</issue_title>
<issue_description>### Description

Currently if we reference in the color attributes a color slug from the theme.json Otter is not using that and is reverting to the defaults

Similar with the core blocks it should use the slug name when that is used as value.

Step-by-step reproduction instructions

  1. Pick a color slug form theme.json, let's say base
  2. Pick a core block, let's say button. You can use this snippet:
window.wp.data.dispatch('core/block-editor').insertBlocks(window.wp.blocks.createBlock(
        'core/paragraph',
         { textColor:"base", content:"Test"},
         []
       ))

You can see the paragraph color is used corectly.

  1. Pick a Otter block, lets say a heading. You can use this snippet:
window.wp.data.dispatch('core/block-editor').insertBlocks(window.wp.blocks.createBlock(
         'themeisle-blocks/advanced-heading',
          { headingColor:"base", content:"Test"},
          []
        ))

You can see that is not using the right color and is reverting to the default.

Screenshots, screen recording, code snippet or Help Scout ticket

No response

Environment info

No response

Is the issue you are reporting a regression

No</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] Fix color slugs not working in Otter Blocks Resolve color slugs from theme.json in Otter blocks Feb 16, 2026
Copilot AI requested a review from selul February 16, 2026 12:44
@selul
Copy link
Copy Markdown
Contributor

selul commented Feb 16, 2026

@copilot apply the fix to all blocks that uses attributes for colors.

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Feb 16, 2026

@copilot apply the fix to all blocks that uses attributes for colors.

Applied the color slug resolution fix to all 15 blocks with color attributes:

Commits:

  • ec91125: High-priority blocks (button, section, icons, posts, review, progress-bar)
  • b3417e8: Medium-priority blocks (circle-counter, countdown, sharing-icons, popup, flip)

Pattern applied:

  • JavaScript: useColorResolver() hook wraps all color attributes
  • PHP: Base_CSS::resolve_color_value() format function on all color properties

All blocks now properly resolve theme color slugs from theme.json while remaining backward compatible with hex/rgb/hsl values.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://storage.googleapis.com/chromium-browser-snapshots/Linux_x64/1045629/chrome-linux.zip
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node node install.js (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Resolve color slugs from theme.json in Otter blocks Resolve color slugs from theme.json in all Otter blocks Feb 16, 2026
@selul selul marked this pull request as ready for review February 16, 2026 13:21
@pirate-bot
Copy link
Copy Markdown
Contributor

pirate-bot commented Feb 16, 2026

Bundle Size Diff

Package Old Size New Size Diff
Animations 276.77 KB 276.77 KB 0 B (0.00%)
Blocks 1.55 MB 1.55 MB 826 B (0.05%)
CSS 105.9 KB 105.9 KB 0 B (0.00%)
Dashboard 204.08 KB 204.08 KB 0 B (0.00%)
Onboarding 165.94 KB 165.94 KB 0 B (0.00%)
Export Import 102.86 KB 102.86 KB 0 B (0.00%)
Pro 412.21 KB 412.55 KB 351 B (0.08%)

@pirate-bot
Copy link
Copy Markdown
Contributor

pirate-bot commented Feb 16, 2026

Plugin build for dda1c64 is ready 🛎️!

Copilot AI changed the title Resolve color slugs from theme.json in all Otter blocks Convert color slugs to CSS variables to preserve theme.json connection Feb 19, 2026
Copilot AI changed the title Convert color slugs to CSS variables to preserve theme.json connection Remove leftover color-slug-resolution.md documentation file Feb 19, 2026
@selul selul changed the base branch from master to development February 19, 2026 11:17
Copilot AI changed the title Remove leftover color-slug-resolution.md documentation file Fix JSDoc alignment error in color helper function Feb 19, 2026
Copilot AI changed the title Fix JSDoc alignment error in color helper function Fix useDarkBackground hook to resolve color slugs before lightness check Feb 19, 2026
Copilot AI changed the title Fix useDarkBackground hook to resolve color slugs before lightness check Fix type safety and environment compatibility in color resolution functions Feb 19, 2026
Copilot AI and others added 24 commits April 1, 2026 16:18
Co-authored-by: selul <3330746+selul@users.noreply.github.com>
Co-authored-by: selul <3330746+selul@users.noreply.github.com>
Co-authored-by: selul <3330746+selul@users.noreply.github.com>
Co-authored-by: selul <3330746+selul@users.noreply.github.com>
Co-authored-by: selul <3330746+selul@users.noreply.github.com>
…-icons, popup, and flip blocks

- circle-counter: Added useColorResolver hook and wrapped color attributes in edit.js and CircularProgressBar component; added color resolution in CSS for backgroundColor, progressColor, and titleColor
- countdown: Added color resolution in CSS for backgroundColor, borderColor, valueColor, labelColor, and separatorColor
- sharing-icons: Added color resolution in CSS for icon backgroundColor and textColor
- popup: Added useColorResolver hook and wrapped color attributes in edit.js; added color resolution in CSS for backgroundColor, closeColor, overlayColor, and borderColor
- flip: Added color resolution in CSS for borderColor, frontBackgroundColor, backBackgroundColor, titleColor, and descriptionColor

All changes follow the pattern of using useColorResolver() in edit.js and Base_CSS::resolve_color_value() in PHP CSS files to properly handle theme color slugs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
… icons, posts, review, progress-bar)

Co-authored-by: selul <3330746+selul@users.noreply.github.com>
Co-authored-by: selul <3330746+selul@users.noreply.github.com>
Co-authored-by: selul <3330746+selul@users.noreply.github.com>
Co-authored-by: selul <3330746+selul@users.noreply.github.com>
…functions

Co-authored-by: selul <3330746+selul@users.noreply.github.com>
Co-authored-by: selul <3330746+selul@users.noreply.github.com>
Co-authored-by: selul <3330746+selul@users.noreply.github.com>
Co-authored-by: selul <3330746+selul@users.noreply.github.com>
Co-authored-by: selul <3330746+selul@users.noreply.github.com>
Co-authored-by: selul <3330746+selul@users.noreply.github.com>
Co-authored-by: selul <3330746+selul@users.noreply.github.com>
Co-authored-by: selul <3330746+selul@users.noreply.github.com>
Co-authored-by: selul <3330746+selul@users.noreply.github.com>
Co-authored-by: selul <3330746+selul@users.noreply.github.com>
Co-authored-by: selul <3330746+selul@users.noreply.github.com>
Co-authored-by: selul <3330746+selul@users.noreply.github.com>
Co-authored-by: selul <3330746+selul@users.noreply.github.com>
Co-authored-by: selul <3330746+selul@users.noreply.github.com>
@girishpanchal30 girishpanchal30 force-pushed the copilot/fix-color-slugs-in-otter-blocks branch from 4ec805b to dda1c64 Compare April 1, 2026 10:49
@pirate-bot
Copy link
Copy Markdown
Contributor

E2E Tests

Playwright Test Status:

Performance Results serverResponse: {"q25":427.1,"q50":429.05,"q75":462.5,"cnt":10}, firstPaint: {"q25":363.9,"q50":420.75,"q75":450.7,"cnt":10}, domContentLoaded: {"q25":1582.7,"q50":1605.7,"q75":1645.7,"cnt":10}, loaded: {"q25":1583,"q50":1606.05,"q75":1646,"cnt":10}, firstContentfulPaint: {"q25":3347.5,"q50":3367.2,"q75":3450.1,"cnt":10}, firstBlock: {"q25":6860.9,"q50":7029.65,"q75":7180.2,"cnt":10}, type: {"q25":12.83,"q50":13.61,"q75":14,"cnt":10}, typeWithoutInspector: {"q25":11.9,"q50":12.29,"q75":12.83,"cnt":10}, typeWithTopToolbar: {"q25":15.79,"q50":16.82,"q75":18.64,"cnt":10}, typeContainer: {"q25":6.94,"q50":8.85,"q75":10.27,"cnt":10}, focus: {"q25":52.02,"q50":56.27,"q75":61.17,"cnt":10}, inserterOpen: {"q25":16.67,"q50":17.72,"q75":18.26,"cnt":10}, inserterSearch: {"q25":5.73,"q50":5.91,"q75":6.01,"cnt":10}, inserterHover: {"q25":2.41,"q50":2.51,"q75":2.85,"cnt":20}, loadPatterns: {"q25":1098.08,"q50":1116.54,"q75":1154.28,"cnt":10}, listViewOpen: {"q25":86.23,"q50":90.72,"q75":100.76,"cnt":10}

@vytisbulkevicius vytisbulkevicius merged commit eab70d3 into development Apr 1, 2026
10 of 11 checks passed
@vytisbulkevicius vytisbulkevicius deleted the copilot/fix-color-slugs-in-otter-blocks branch April 1, 2026 12:08
@pirate-bot
Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 3.1.8 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@pirate-bot pirate-bot added the released Indicate that an issue has been resolved and released in a particular version of the product. label Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Indicate that an issue has been resolved and released in a particular version of the product.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Color slugs are not working in Otter Blocks

5 participants