Skip to content

Color schemes: Use contextual palette values in the editor - #80809

Draft
MaggieCabrera wants to merge 2 commits into
codex/color-scheme-palette-uifrom
codex/color-scheme-contextual-pickers
Draft

Color schemes: Use contextual palette values in the editor#80809
MaggieCabrera wants to merge 2 commits into
codex/color-scheme-palette-uifrom
codex/color-scheme-contextual-pickers

Conversation

@MaggieCabrera

@MaggieCabrera MaggieCabrera commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

What?

Makes theme-defined color schemes contextual throughout the editor while keeping the base and alternative palettes independently editable in Global Styles.

This is stacked on #80805, #80746, and #80698.

Why?

A theme can define a base palette and a dark alternative. When a user's system prefers dark mode, the canvas uses the dark values, but editor color controls currently preview the base values. Named presets can also be resolved to fixed color values too early, preventing the browser from applying the active scheme.

The implementation uses the name colorScheme because it matches the CSS color-scheme property and prefers-color-scheme media feature.

How?

  • Normalizes alternative palettes against the base palette by slug so every valid scheme is complete and ordered consistently.
  • Uses the base value for any missing alternative entry without exposing inheritance details in the UI.
  • Ignores alternative entries whose slugs do not exist in the base palette.
  • Shows the active system scheme values in color, gradient, duotone, border, background, typography, and filter controls.
  • Keeps named selections as preset CSS custom-property references instead of resolving them to fixed hex or gradient values when color schemes are present.
  • Shows base and alternative palettes separately in Global Styles. Editing one stores that palette independently and does not change the other.
  • Updates previews as scheme values change.

Testing Instructions

Use either fixture from WordPress/community-themes#266 with the full PR stack.

  1. Set the operating system appearance to dark mode.
  2. Activate a theme with a base palette and a partial dark palette.
  3. Open a post and insert a Paragraph block.
  4. Open its background color control.
  5. Confirm every base palette color is present, dark overrides use their dark values, missing dark overrides use their base values, and unknown dark-only slugs are absent.
  6. Apply a named background color and confirm it uses the dark value on the canvas.
  7. Change the operating system appearance and confirm the preview updates without changing the stored block color slug.
  8. Open Appearance → Editor → Styles → Colors → Edit palette.
  9. Confirm both palettes contain the same named entries.
  10. Change a dark value and confirm the dark palette and active preview update while the base value remains unchanged. Repeat in the other direction.
  11. Save, reload, and confirm both values persist independently.
  12. Repeat the relevant checks for gradients and duotone.

Testing Instructions for Keyboard

Follow the steps above using Tab and Shift+Tab to move through the controls, Enter or Space to activate them, and the arrow keys where supported. Confirm both palette sections and their color controls remain reachable and labeled.

Screenshots or screencast

actual-color-scheme-palette-preview

Use of AI Tools

This PR was implemented and tested with assistance from OpenAI Codex. The author reviewed the resulting code and remains responsible for the contribution.

@github-actions

Copy link
Copy Markdown

Size Change: +1.02 kB (+0.01%)

Total Size: 7.76 MB

📦 View Changed
Filename Size Change
build/modules/lazy-editor/index.min.js 15.2 kB -7 B (-0.05%)
build/scripts/block-editor/index.min.js 429 kB +677 B (+0.16%)
build/scripts/block-library/index.min.js 356 kB +237 B (+0.07%)
build/scripts/components/index.min.js 272 kB -581 B (-0.21%)
build/scripts/edit-site/index.min.js 306 kB -13 B (0%)
build/scripts/editor/index.min.js 501 kB +636 B (+0.13%)
build/scripts/element/index.min.js 5.17 kB +3 B (+0.06%)
build/styles/block-editor/content-rtl.css 5.66 kB +1 B (+0.02%)
build/styles/block-editor/content.min.css 4.13 kB +1 B (+0.02%)
build/styles/edit-post/style-rtl.css 3.31 kB +16 B (+0.49%)
build/styles/edit-post/style-rtl.min.css 1.96 kB +8 B (+0.41%)
build/styles/edit-post/style.css 3.32 kB +17 B (+0.52%)
build/styles/edit-post/style.min.css 1.96 kB +9 B (+0.46%)
build/styles/edit-site/style-rtl.css 21.5 kB +2 B (+0.01%)
build/styles/edit-site/style-rtl.min.css 17.6 kB -1 B (-0.01%)
build/styles/edit-site/style.css 21.5 kB +1 B (0%)
build/styles/edit-site/style.min.css 17.6 kB -2 B (-0.01%)
build/styles/editor/style-rtl.css 31.1 kB +4 B (+0.01%)
build/styles/editor/style-rtl.min.css 26.5 kB +2 B (+0.01%)
build/styles/editor/style.css 31.2 kB +4 B (+0.01%)
build/styles/editor/style.min.css 26.5 kB +2 B (+0.01%)

compressed-size-action

@github-actions

Copy link
Copy Markdown

Flaky tests detected in d29f6ef.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/30390930036
📝 Reported issues:

@MaggieCabrera
MaggieCabrera requested a review from Copilot July 28, 2026 20:17
@github-actions

Copy link
Copy Markdown

Warning: Type of PR label mismatch

To merge this PR, it requires exactly 1 label indicating the type of PR. Other labels are optional and not being checked here.

  • Required label: Any label starting with [Type].
  • Labels found: [Package] Components, [Package] Block editor.

Read more about Type labels in Gutenberg. Don't worry if you don't have the required permissions to add labels; the PR reviewer should be able to help with the task.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR makes theme-defined light/dark color scheme preset values contextual throughout the editor (controls + previews), while keeping base and alternative palettes independently editable in Global Styles. It introduces shared normalization utilities for scheme presets, and updates editor style rendering to preserve preset CSS custom property references when schemes exist so the browser can apply the active scheme.

Changes:

  • Add flattenColorSchemePresets / normalizeColorSchemePresets utilities to @wordpress/global-styles-engine and reuse them from Global Styles UI.
  • Update Block Editor color/gradient/border/duotone-related hooks and Global Styles panels to use the active scheme’s preset values, and preserve preset CSS vars when schemes are present.
  • Add/adjust unit tests for preset normalization and for scheme-aware preset selection.

Reviewed changes

Copilot reviewed 28 out of 28 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
packages/global-styles-ui/tsconfig.json Excludes test files from the package TS project.
packages/global-styles-ui/src/test/color-scheme-palette.spec.ts Updates tests to cover scheme preset normalization behavior.
packages/global-styles-ui/src/test/color-palette-panel.spec.tsx Adds coverage ensuring alternative palettes are complete and unmatched slugs are omitted.
packages/global-styles-ui/src/scheme-preview-indicator.tsx Tightens scheme preset typing to BasePreset.
packages/global-styles-ui/src/gradients-palette-panel.tsx Uses normalized scheme gradients for Global Styles scheme panels.
packages/global-styles-ui/src/duotone-palette-panel.tsx Uses normalized scheme duotones for Global Styles scheme panels.
packages/global-styles-ui/src/color-scheme-palette.tsx Switches to re-exporting scheme helpers from @wordpress/global-styles-engine.
packages/global-styles-ui/src/color-palette-panel.tsx Uses normalized scheme colors for Global Styles scheme panels.
packages/global-styles-engine/src/utils/color-schemes.ts Introduces shared flatten/normalize helpers for scheme presets.
packages/global-styles-engine/src/index.ts Exposes scheme utilities/types via the package public API.
packages/components/src/palette-edit/stories/index.story.tsx Updates PaletteEdit story typing for palette variations.
packages/components/src/palette-edit/index.tsx Hardens PaletteEdit variation mapping when variation elements are absent.
packages/block-editor/src/utils/test/color-values.js Adds tests for new preset CSS var and scheme-aware style value helpers.
packages/block-editor/src/utils/color-values.ts Adds helpers to keep preset CSS var references when schemes exist.
packages/block-editor/src/hooks/utils.js Plumbs light/dark scheme settings into block settings.
packages/block-editor/src/hooks/use-color-props.js Uses active-scheme theme presets + preserves preset CSS vars for styles.
packages/block-editor/src/hooks/use-border-props.js Preserves preset CSS vars for named border colors when schemes exist.
packages/block-editor/src/hooks/duotone.js Uses active-scheme theme presets for duotone preset resolution.
packages/block-editor/src/hooks/color.js Preserves preset CSS vars for named text/background colors when schemes exist.
packages/block-editor/src/components/gradients/use-gradient.js Uses active-scheme theme gradients for gradient selection/update.
packages/block-editor/src/components/global-styles/hooks.js Makes Global Styles color/gradient origins scheme-aware + improves preset decoding.
packages/block-editor/src/components/global-styles/filters-panel.js Makes filter preset lists scheme-aware and decodes duotone preset vars.
packages/block-editor/src/components/global-styles/border-panel.js Decodes preset color vars using the active-scheme palette for UI display.
packages/block-editor/src/components/colors/with-colors.js Supplies active-scheme theme palette to wrapped components.
packages/block-editor/src/components/colors-gradients/use-multiple-origin-colors-and-gradients.js Uses scheme-aware theme colors/gradients and exposes hasColorSchemes.
packages/block-editor/src/components/colors-gradients/use-color-scheme-presets.js Adds hook to compute effective presets for the current OS scheme.
packages/block-editor/src/components/colors-gradients/test/use-color-scheme-presets.js Adds unit tests for scheme-aware preset selection/normalization.
packages/block-editor/src/components/color-palette/with-color-context.js Switches color context to active-scheme theme palette.

Comment on lines +85 to +88
const hasLightGradients =
lightScheme !== undefined && normalizedLightGradients.length > 0;
const hasDarkGradients =
darkScheme !== undefined && normalizedDarkGradients.length > 0;
Comment on lines +90 to +93
const hasLightColors =
lightScheme !== undefined && normalizedLightColors.length > 0;
const hasDarkColors =
darkScheme !== undefined && normalizedDarkColors.length > 0;
Comment on lines +113 to +116
const hasLightDuotones =
lightScheme !== undefined && normalizedLightDuotones.length > 0;
const hasDarkDuotones =
darkScheme !== undefined && normalizedDarkDuotones.length > 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

[Package] Block editor /packages/block-editor [Package] Components /packages/components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants