-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Components: Expand theming support in COLORS #58097
Changes from all commits
3af68c4
1076842
14733dd
8b321ab
e602750
f0f2710
c9020bd
4353b34
88025c1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,6 @@ | ||
/** | ||
* Internal dependencies | ||
*/ | ||
import { rgba } from './colors'; | ||
|
||
const white = '#fff'; | ||
|
||
// Matches the grays in @wordpress/base-styles | ||
|
@@ -29,41 +27,65 @@ const ALERT = { | |
green: '#4ab866', | ||
}; | ||
|
||
// Matches the Modern admin scheme in @wordpress/base-styles | ||
const ADMIN = { | ||
theme: 'var(--wp-components-color-accent, var(--wp-admin-theme-color, #3858e9))', | ||
themeDark10: | ||
'var(--wp-components-color-accent-darker-10, var(--wp-admin-theme-color-darker-10, #2145e6))', | ||
// Should match packages/components/src/utils/theme-variables.scss | ||
const THEME = { | ||
accent: `var(--wp-components-color-accent, var(--wp-admin-theme-color, #3858e9))`, | ||
accentDarker10: `var(--wp-components-color-accent-darker-10, var(--wp-admin-theme-color-darker-10, #2145e6))`, | ||
accentDarker20: `var(--wp-components-color-accent-darker-20, var(--wp-admin-theme-color-darker-20, #183ad6))`, | ||
/** Used when placing text on the accent color. */ | ||
accentInverted: `var(--wp-components-color-accent-inverted, ${ white })`, | ||
|
||
background: `var(--wp-components-color-background, ${ white })`, | ||
|
||
foreground: `var(--wp-components-color-foreground, ${ GRAY[ 900 ] })`, | ||
/** Used when placing text on the foreground color. */ | ||
foregroundInverted: `var(--wp-components-color-foreground-inverted, ${ white })`, | ||
|
||
gray: { | ||
/** @deprecated Use `COLORS.theme.foreground` instead. */ | ||
900: `var(--wp-components-color-foreground, ${ 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: white, | ||
backgroundDisabled: GRAY[ 100 ], | ||
border: GRAY[ 600 ], | ||
borderHover: GRAY[ 700 ], | ||
borderFocus: ADMIN.theme, | ||
borderDisabled: GRAY[ 400 ], | ||
textDisabled: GRAY[ 600 ], | ||
textDark: white, | ||
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 ], | ||
|
||
// Matches @wordpress/base-styles | ||
darkGrayPlaceholder: rgba( GRAY[ 900 ], 0.62 ), | ||
lightGrayPlaceholder: rgba( white, 0.65 ), | ||
}; | ||
|
||
const THEME = { | ||
accent: ADMIN.theme, | ||
accentDarker10: ADMIN.themeDark10, | ||
darkGrayPlaceholder: `color-mix(in srgb, ${ THEME.foreground }, transparent 38%)`, | ||
lightGrayPlaceholder: `color-mix(in srgb, ${ THEME.background }, transparent 35%)`, | ||
}; | ||
|
||
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`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This deprecation marking should encourage devs to stop using this while we migrate the existing usages. |
||
*/ | ||
gray: GRAY, | ||
gray: GRAY, // TODO: Stop exporting this when everything is migrated to `theme` or `ui` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have a tracking issue for all the planned work that we intend to do around theming in the short term? Edit: yes, we do! It's #44116. We could probably tidy that issue up, knowing that in the long term the |
||
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, | ||
} ); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a
text
alias under UI ? Currently components would be forced to usetheme.foreground
instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm actually kind of reluctant to add a ton of semantic aliases for the pretty obvious ones like
foreground
,background
, andaccent
because it adds more overhead when reworking and renaming stuff. I do think the aliases for the grayscales are useful because nobody memorizes them and it's easy to introduce inconsistencies. Does that resonate?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My original reasoning behind proposing
text
was mostly so that folks can continue to use "semantic" color aliases to style their components, instead of mixing them with "raw" theme values. But if we're ok with folks using bothCOLORS.ui.*
andCOLORS.theme.*
, then we can keep things as-is and only adjust later / if needed, especially if the long term plan is to move theming functionality to a separate package.