From 3af68c404710503e4edb0f160d48807c662a9c3f Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Tue, 23 Jan 2024 08:08:52 +0900 Subject: [PATCH 1/8] Components: Expand theming support in COLORS --- .../components/src/utils/colors-values.js | 55 +++++++++++++------ 1 file changed, 39 insertions(+), 16 deletions(-) diff --git a/packages/components/src/utils/colors-values.js b/packages/components/src/utils/colors-values.js index 1f2cdab672909..fb90a54e851b9 100644 --- a/packages/components/src/utils/colors-values.js +++ b/packages/components/src/utils/colors-values.js @@ -36,34 +36,57 @@ const ADMIN = { 'var(--wp-components-color-accent-darker-10, var(--wp-admin-theme-color-darker-10, #2145e6))', }; -const UI = { - background: white, - backgroundDisabled: GRAY[ 100 ], - border: GRAY[ 600 ], - borderHover: GRAY[ 700 ], - borderFocus: ADMIN.theme, - borderDisabled: GRAY[ 400 ], - textDisabled: GRAY[ 600 ], - textDark: white, - - // Matches @wordpress/base-styles - darkGrayPlaceholder: rgba( GRAY[ 900 ], 0.62 ), - lightGrayPlaceholder: rgba( white, 0.65 ), -}; - +// Should match packages/components/src/utils/theme-variables.scss const THEME = { accent: ADMIN.theme, accentDarker10: ADMIN.themeDark10, + background: `var(--wp-components-color-background, ${ white })`, + foreground: `var(--wp-components-color-foreground, ${ GRAY[ 900 ] })`, + gray: { + 900: `var(--wp-components-color-gray-900, ${ GRAY[ 900 ] })`, + 800: `var(--wp-components-color-gray-800, ${ GRAY[ 800 ] })`, + 700: `var(--wp-components-color-gray-700, ${ GRAY[ 700 ] })`, + 600: `var(--wp-components-color-gray-600, ${ GRAY[ 600 ] })`, + 400: `var(--wp-components-color-gray-400, ${ GRAY[ 400 ] })`, + 300: `var(--wp-components-color-gray-300, ${ GRAY[ 300 ] })`, + 200: `var(--wp-components-color-gray-200, ${ GRAY[ 200 ] })`, + 100: `var(--wp-components-color-gray-100, ${ GRAY[ 100 ] })`, + }, +}; + +const UI = { + background: THEME.background, + backgroundDisabled: THEME.gray[ 100 ], + border: THEME.gray[ 600 ], + borderHover: THEME.gray[ 700 ], + borderFocus: THEME.accent, + borderDisabled: THEME.gray[ 400 ], + textDisabled: THEME.gray[ 600 ], + textDark: white, // TODO: Make this Theme-ready + + // Matches @wordpress/base-styles + darkGrayPlaceholder: rgba( GRAY[ 900 ], 0.62 ), // TODO: Make this work with CSS vars + lightGrayPlaceholder: rgba( white, 0.65 ), // TODO: Make this work with CSS vars }; export const COLORS = Object.freeze( { /** * The main gray color object. + * + * @deprecated Use semantic aliases in `COLORS.ui` or theme-ready variables in `COLORS.theme.gray`. */ - gray: GRAY, + gray: GRAY, // TODO: Stop exporting this when everything is migrated to `theme` or `ui` white, alert: ALERT, + /** + * Theme-ready variables with fallbacks. + * + * Prefer semantic aliases in `COLORS.ui` when applicable. + */ theme: THEME, + /** + * Semantic aliases (prefer these over raw variables when applicable). + */ ui: UI, } ); From 10768424eccc6b3e976624bad60bb71787ae7eb5 Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Tue, 23 Jan 2024 08:15:15 +0900 Subject: [PATCH 2/8] Update changelog --- packages/components/CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/components/CHANGELOG.md b/packages/components/CHANGELOG.md index 92ce15dc425f6..c9b1286c996bf 100644 --- a/packages/components/CHANGELOG.md +++ b/packages/components/CHANGELOG.md @@ -18,6 +18,7 @@ ### Experimental - `BoxControl`: Update design ([#56665](https://github.com/WordPress/gutenberg/pull/56665)). +- Expand theming support in the `COLORS` variable object ([#58097](https://github.com/WordPress/gutenberg/pull/58097)). - `CustomSelect`: adjust `renderSelectedValue` to fix sizing ([#57865](https://github.com/WordPress/gutenberg/pull/57865)). ## 25.15.0 (2024-01-10) From 14733ddf7a3606af208d47d6702274e81ff4b425 Mon Sep 17 00:00:00 2001 From: Lena Morita Date: Tue, 23 Jan 2024 23:58:43 +0900 Subject: [PATCH 3/8] Update snapshots --- .../src/card/test/__snapshots__/index.tsx.snap | 6 +++--- .../test/__snapshots__/index.test.js.snap | 16 ++++++++-------- .../test/__snapshots__/index.tsx.snap | 16 ++++++++-------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/components/src/card/test/__snapshots__/index.tsx.snap b/packages/components/src/card/test/__snapshots__/index.tsx.snap index b86714d86636a..0b723732e3dba 100644 --- a/packages/components/src/card/test/__snapshots__/index.tsx.snap +++ b/packages/components/src/card/test/__snapshots__/index.tsx.snap @@ -26,7 +26,7 @@ Snapshot Diff:
@@ -43,7 +43,7 @@ Snapshot Diff: