Skip to content
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

Add dark editor style support #9683

Merged
merged 4 commits into from
Sep 10, 2018
Merged

Add dark editor style support #9683

merged 4 commits into from
Sep 10, 2018

Conversation

jasmussen
Copy link
Contributor

This fixes #6451.

This PR enables a new command to themers. They can now add add_theme_support( 'dark-theme' ); in order to ask the editing canvas to be friendly to dark themes.

What this does is add a body class to the editor, is-dark-theme, which enables already present color changes to the side UI and borders, that are friendly to dark themes.

To test, add a dark editor style, then enable support. For example, add this to your theme functions.php:

/**
 * Enqueue editor style in Gutenberg
 */

function navi_gutenberg_styles() {
	 wp_enqueue_style( 'navi-gutenberg', get_theme_file_uri( '/style-editor.css' ), false, '1.0', 'all' );
}
add_action( 'enqueue_block_editor_assets', 'navi_gutenberg_styles' );
add_theme_support( 'editor-styles' );
add_theme_support( 'dark-theme' );

In "style-editor.css", put the following:

/**
 * Editor style
 */

body.gutenberg-editor-page {
	background-color: #252526;
}

body.gutenberg-editor-page .editor-post-title__block,
body.gutenberg-editor-page .editor-post-title__input,
body.gutenberg-editor-page .editor-default-block-appender,
body.gutenberg-editor-page .editor-block-list__block {
	color: white;
}

Now test and see that the UI is usable.

Screenshots:

screen shot 2018-09-07 at 11 53 39

screen shot 2018-09-07 at 11 56 19

This fixes #6451.

This PR enables a new command to themers. They can now add `add_theme_support( 'dark-theme' );` in order to ask the editing canvas to be friendly to dark themes.

What this does is add a body class to the editor, `is-dark-theme`, which enables already present color changes to the side UI and borders, that are friendly to dark themes.
@jasmussen jasmussen added [Type] Enhancement A suggestion for improvement. [Type] Plugin Interoperability Incompatibilities between a specific plugin and the block editor. Close with workaround notes. labels Sep 7, 2018
@jasmussen jasmussen self-assigned this Sep 7, 2018
@jasmussen jasmussen requested review from youknowriad and a team September 7, 2018 09:58
@tofumatt
Copy link
Member

tofumatt commented Sep 7, 2018

😎

Copy link
Member

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

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

Makes sense to me; just a tweak in the documentation requested from me.

@@ -209,6 +209,13 @@ function mytheme_block_editor_styles() {
add_action( 'enqueue_block_editor_assets', 'mytheme_block_editor_styles' );
```

If your editor style relies on a dark background, you can add the following to invert the UI colors:
Copy link
Member

Choose a reason for hiding this comment

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

It's not really "Inverting the UI colours", it's more "tweaking the editor styles to accommodate a darker UI". It's not a 1:1 inversion.

Right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Correct, it's definitely not a 1:1 inversion. I will add a change, awesome.

Is https://github.com/WordPress/gutenberg/pull/9683/files#diff-26f7754641e020003bf92e16ac862f50R471 kosher, though? I mean it works solidly for me, just want to make sure, as I've never ever touched that file before.

Copy link
Member

Choose a reason for hiding this comment

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

Actually, come to think of it the docs should really include both add_theme_support( 'editor-styles' ); and add_theme_support( 'dark-theme' );, just for those who might be skimming the docs and not read above. I think that's fine…

The change itself makes sense to me, do you have a theme I can use to test it real quick? I don't have anything like that locally ^_^

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added the dark editor styles to https://github.com/jasmussen/navi, but I haven't pushed them so I sent the ones featuring copy pasta of the CSS above in a DM.

I'll make the docs change now.

@tofumatt tofumatt self-requested a review September 7, 2018 13:51
Copy link
Member

@tofumatt tofumatt left a comment

Choose a reason for hiding this comment

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

Tested locally with a dark theme sent to me by @jasmussen. Works though I find the light sidebar/topbar UI a bit odd:

screenshot 2018-09-07 23 17 21

But I think that's unrelated. 🚢

@karmatosed
Copy link
Member

I have to agree on the dark sidebar. I don't think we can tackle it but wow it really makes me want this to work throughout.

@karmatosed karmatosed self-requested a review September 8, 2018 18:16
Copy link
Member

@karmatosed karmatosed left a comment

Choose a reason for hiding this comment

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

🕳[ couldn't find dark emoji so imagine this is a blackhole ]. 👍

@jasmussen
Copy link
Contributor Author

Thanks for the reviews!

Important to note for passers by: this is not a dark theme for Gutenberg.

This PR enables UI to work on dark editor style backgrounds.

The difference here is that you can imagine any color background as defined by the WordPress theme in question. In this case, I picked a very dark gray at random.

@jasmussen jasmussen added this to the 3.9 milestone Sep 8, 2018
@jasmussen
Copy link
Contributor Author

🕳[ couldn't find dark emoji so imagine this is a blackhole ]. 👍

😂

@chrisvanpatten
Copy link
Contributor

Would it be worth renaming this "dark canvas" instead of "dark theme" to avoid confusion with the editor's own theme?

@tofumatt
Copy link
Member

tofumatt commented Sep 8, 2018

"Dark canvas" sounds cool.

At any rate, sounds like this is doing the right thing, but it's sort of weird that dark canvas doesn't at least have some saner defaults. I get no styling has been done to the sidebar, but if that's how it looks unstyled we could do better.

But that can totally be a later issue. This isn't a super-high priority 🚢

@jasmussen
Copy link
Contributor Author

Maybe actually "dark-editor-style"?

I understand the lightness of the UI, but I'm not sure the UI should be affected by the content. As in, if the UI it too bright when editing a post in a dark WordPress theme, should the WordPress theme affect the UI?

@tofumatt
Copy link
Member

tofumatt commented Sep 9, 2018

That works for me.

Generally I'm cool with the idea that theme content doesn't affect UI or with the idea that it can, but since this PR seems to allow the latter to a certain degree I say we just go for it and allow further UI adjustments. 🤷‍♂️

As mentioned though: can happen later, feel free to ship 😊

@jasmussen
Copy link
Contributor Author

I appreciate your reviews quite a bit. Thank you. Have a good Sunday.

Hopefully this will help prevent confusion.
@jasmussen jasmussen merged commit e90aad0 into master Sep 10, 2018
@jasmussen jasmussen deleted the try/dark-editor-styles branch September 10, 2018 12:32
@jasmussen jasmussen mentioned this pull request Sep 11, 2018
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Enhancement A suggestion for improvement. [Type] Plugin Interoperability Incompatibilities between a specific plugin and the block editor. Close with workaround notes.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Editor pop-up editing symbols need to be theme BG color neutral
4 participants