-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Site Editor: Apply the user's admin color scheme #78397
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
Open
fushar
wants to merge
12
commits into
trunk
Choose a base branch
from
admin-bar-in-editor-color-4
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
25ae865
Site Editor: Apply the user's admin color scheme
fushar 2da1637
Move UserThemeProvider from wordpress/themes to wordpress/admin-ui
fushar 33d9c61
Update WPDS token usage to be better semantically
fushar 97ac084
Fix theming leaking outside site editor sidebar
fushar 61e2d6c
Only expose getAdminThemeColors()
fushar 600cb41
Fix theming condition on mobile sidebar
fushar 7aa1877
Update background so that white text stay white
fushar 8913f08
Refactor getAdminThemeColors()
fushar 74cacac
Explicitly add fresh's primary color
fushar 8e4d33d
Update fresh's background to match Modern's
fushar 3ca99df
Make getAdminThemeColors normal import
fushar f70d056
Update fresh, modern, light, midnight bg colors
fushar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| type AdminThemeColors = { | ||
| primary: string; | ||
| bg: string; | ||
| }; | ||
|
|
||
| const ADMIN_THEME_COLORS = new Map< string, AdminThemeColors >( [ | ||
| [ 'fresh', { primary: '#3858e9', bg: '#25292b' } ], | ||
| [ 'modern', { primary: '#3858e9', bg: '#222524' } ], | ||
| [ 'midnight', { primary: '#e14d43', bg: '#3d4042' } ], | ||
| [ 'coffee', { primary: '#46403c', bg: '#7c726c' } ], | ||
| [ 'ocean', { primary: '#627c83', bg: '#5f787f' } ], | ||
| [ 'blue', { primary: '#096484', bg: '#0e7da4' } ], | ||
| [ 'ectoplasm', { primary: '#523f6d', bg: '#8468ab' } ], | ||
| [ 'sunrise', { primary: '#dd823b', bg: '#cc4541' } ], | ||
| [ 'light', { primary: '#0085ba', bg: '#eaeeed' } ], | ||
| ] ); | ||
|
|
||
| /** | ||
| * Reads the active WordPress admin color scheme from the `admin-color-*` body | ||
| * class and returns its primary and background colors. Intended to seed a | ||
| * `ThemeProvider` (`color` prop) so the design system matches the user's chosen | ||
| * admin color scheme. | ||
| * | ||
| * @return The primary and background colors for the active admin color scheme. | ||
| */ | ||
| export function getAdminThemeColors(): AdminThemeColors | undefined { | ||
| const scheme = | ||
| document.body.className.match( /admin-color-([\w-]+)/ )?.[ 1 ] ?? | ||
| 'fresh'; | ||
|
|
||
| return ( | ||
| ADMIN_THEME_COLORS.get( scheme ) ?? ADMIN_THEME_COLORS.get( 'fresh' ) | ||
| ); | ||
| } |
15 changes: 15 additions & 0 deletions
15
packages/admin-ui/src/admin-theme-colors/test/index.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| /** | ||
| * Internal dependencies | ||
| */ | ||
| import { getAdminThemeColors } from '../index'; | ||
|
|
||
| describe( 'getAdminThemeColors', () => { | ||
| it( 'should return the colors for the admin theme from the body class', () => { | ||
| document.body.className = 'foo admin-color-coffee bar'; | ||
|
|
||
| expect( getAdminThemeColors() ).toEqual( { | ||
| primary: '#46403c', | ||
| bg: '#7c726c', | ||
| } ); | ||
| } ); | ||
| } ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| export { default as Breadcrumbs } from './breadcrumbs'; | ||
| export { default as NavigableRegion } from './navigable-region'; | ||
| export { default as Page } from './page'; | ||
| export { getAdminThemeColors } from './admin-theme-colors'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 0 additions & 35 deletions
35
packages/boot/src/components/user-theme-provider/index.tsx
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
packages/boot/src/components/user-theme-provider/test/index.test.ts
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 not sure that "WordPress app" concerns (such as named theme presets) should live in the
@wordpress/themepackage, which is supposed to be focused on app-agnostic features and tokens.Uh oh!
There was an error while loading. Please reload this page.
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.
Interesting, I thought because admin color scheme is a core WP feature, it could belong in that package.
OK, I moved the logic to
@wordpress/admin-uiinstead via f733f13. I think that's a better place. What do you think?Uh oh!
There was an error while loading. Please reload this page.
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.
admin-uifeels like a better fit given current constraints (dependency graph), although I don't know if it is the correct choice in general terms.@wordpress/themeis app-agnostic, and focuses on tokens + theming primitivesThere 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 would say
admin-uiis also not the best fit, since admin color schemes will be used in wider contexts (like post/page editors as well).If we consider the future of the
@wordpress/componentspackage as a more higher-level package of things with explicit WordPress coupling, maybe@wordpress/componentsis actually a better place 😄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.
Good idea; extracted
getAdminThemeColors()and removedUserThemeProvidervia 8180dde. Now we pass theme colors more explicitly.I think
admin-uiis good enough place for now. Post/Page Editors are by definition "admin" pages (wp-admin) as well 😄 unless I'm misunderstanding things.