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

New Block: Dark Mode Toggle #42828

Open
bhubbard opened this issue Jul 30, 2022 · 24 comments
Open

New Block: Dark Mode Toggle #42828

bhubbard opened this issue Jul 30, 2022 · 24 comments
Labels
[Type] Enhancement A suggestion for improvement.

Comments

@bhubbard
Copy link

What problem does this address?

A simple block to let site visitors toggle between dark mode and light mode.

@ramonjd ramonjd added [Type] Enhancement A suggestion for improvement. [Status] Needs More Info Follow-up required in order to be actionable. labels Jul 31, 2022
@ramonjd
Copy link
Member

ramonjd commented Jul 31, 2022

This could be useful, but might also be tricky to deliver in the plugin because it would be very difficult to guarantee that it would work for all themes.

How would you see it working, especially in terms of styles?

@bhubbard
Copy link
Author

bhubbard commented Aug 8, 2022

@ramonjd I could see the default being the toggle, if there are multiple styles available then I could see a possible setting to allow it to be a dropdown that lets the user choose the style.

@scruffian
Copy link
Contributor

I think we'd need to add some tools for themes to be able to define "light" and "dark" colors.

@bhubbard
Copy link
Author

I think we'd need to add some tools for themes to be able to define "light" and "dark" colors.

@scruffian I agree, maybe this needs to be supported in theme.json for styles?

@github-actions
Copy link

github-actions bot commented Sep 7, 2022

Help us move this issue forward. This issue is being marked stale since it has no activity after 15 days of requesting more information. Please add info requested so we can help move the issue forward. Note: The triage policy is to close stale issues that need more info and no response after 2 weeks.

@github-actions github-actions bot added the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Sep 7, 2022
@bhubbard
Copy link
Author

bhubbard commented Sep 7, 2022

Any suggestions on how to move this forward?

@ramonjd
Copy link
Member

ramonjd commented Sep 7, 2022

Isn't this already possible with global style variations?

See: https://fullsiteediting.com/lessons/global-style-variations/

Given that light/dark modes will be very theme-specific, it makes sense that a theme could have 2 x global style variations to cater.

@bhubbard
Copy link
Author

bhubbard commented Sep 7, 2022

Isn't this already possible with global style variations?

See: https://fullsiteediting.com/lessons/global-style-variations/

Given that light/dark modes will be very theme-specific, it makes sense that a theme could have 2 x global style variations to cater.

A theme can have many styles. The original request is to have a dark mode/light mode toggle button block, such as this one for example: https://www.w3schools.com/howto/howto_js_toggle_dark_mode.asp

This light mode/dark mode toggle is becoming more common across websites today. As a website visitor if my browser/os is set to dark mode, they may still wish to see the website in light mode. At the moment I don't think theme.json has a way to set a "style" as dark mode or light mode specific, nor does it support "prefer-color-scheme".

Further Reading:

Prefers Color Scheme

@github-actions github-actions bot removed the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Sep 8, 2022
@github-actions
Copy link

Help us move this issue forward. This issue is being marked stale since it has no activity after 15 days of requesting more information. Please add info requested so we can help move the issue forward. Note: The triage policy is to close stale issues that need more info and no response after 2 weeks.

@github-actions github-actions bot added the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Sep 24, 2022
@Lewiscowles1986
Copy link
Contributor

Just a note that mainstream browsers have JS and CSS support for detecting the user preference on dark-mode.

It's nothing but sparkling laziness to use a physical toggle if the default is not to respect the standards-based API's.

I'm also not 100% sold that it matters if the editing experience needs to be in lock-step with the display presentation theme. There is a preview button if someone needs to see what content looks like on their frontend as a visitor would see it.

I Created Automattic/blocks-everywhere#27 for Gutenberg outside of WordPress. Which presently describes a hack, which "works for me". This hack is predicated on the visual editor not being a WYSIWYG website editor; which honestly neither TinyMCE or Gutenberg are capable of achieving despite a lot of sunk effort and painful engineering to that end.

@github-actions github-actions bot removed the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Oct 23, 2022
@github-actions
Copy link

github-actions bot commented Nov 8, 2022

Help us move this issue forward. This issue is being marked stale since it has no activity after 15 days of requesting more information. Please add info requested so we can help move the issue forward. Note: The triage policy is to close stale issues that need more info and no response after 2 weeks.

@github-actions github-actions bot added the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Nov 8, 2022
@Lewiscowles1986
Copy link
Contributor

Not sure who this bot is helping, but the progress on the linked issue I believe is that it was closed (marked as completed despite not being completed)
Automattic/blocks-everywhere#27 (comment)
It's really simple; mark as want help, not priority and leave open as its honest about the shortcomings of the platform / tooling. All these bots producing sparkling nonsense does not help end-users.

@Lewiscowles1986
Copy link
Contributor

This issue for example does not need any more information. The only labels applied that make sense are [Type] Enhancement.

I'd argue that from labels, the following seemed like they might apply

@github-actions github-actions bot removed the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Nov 9, 2022
@github-actions
Copy link

Help us move this issue forward. This issue is being marked stale since it has no activity after 15 days of requesting more information. Please add info requested so we can help move the issue forward. Note: The triage policy is to close stale issues that need more info and no response after 2 weeks.

@github-actions github-actions bot added the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Nov 25, 2022
@bhubbard
Copy link
Author

bhubbard commented Nov 25, 2022

Maybe we can move this forward by adding support for "prefers-color-scheme" to the styles JSON?

prefers-color-scheme: dark
prefers-color-scheme: light

@github-actions github-actions bot removed the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Nov 26, 2022
@Lewiscowles1986
Copy link
Contributor

Thanks @bhubbard

So one limitation of a solely CSS based approach (although that is better than what we have now); is that it does not let a user set an override (for session or otherwise).

I did use the prefers-color-scheme, by-proxy, but because the software I'd integrated Gutenberg with had system theme independence, I also used some JS Automattic/blocks-everywhere#27

I Think not locking down to solely CSS is an ideal world, and I'm open to any world where I'm not writing custom CSS hacks 👍

@github-actions
Copy link

Help us move this issue forward. This issue is being marked stale since it has no activity after 15 days of requesting more information. Please add info requested so we can help move the issue forward. Note: The triage policy is to close stale issues that need more info and no response after 2 weeks.

@github-actions github-actions bot added the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Dec 12, 2022
@Lewiscowles1986
Copy link
Contributor

I'd like to move that bot forward... into the bin. While I understand the need to keep issues fresh and assess interest, it comes across as disinterest.

For me it was purely aesthetic, but there are always benefits to supporting multi-palette UI if the cost can be controlled.

@github-actions github-actions bot removed the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Dec 13, 2022
@github-actions
Copy link

Help us move this issue forward. This issue is being marked stale since it has no activity after 15 days of requesting more information. Please add info requested so we can help move the issue forward. Note: The triage policy is to close stale issues that need more info and no response after 2 weeks.

@github-actions github-actions bot added the [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. label Dec 28, 2022
@ndiego ndiego removed [Status] Needs More Info Follow-up required in order to be actionable. [Status] Stale Gives the original author opportunity to update before closing. Can be reopened as needed. labels May 30, 2023
@bhubbard
Copy link
Author

bhubbard commented Jun 7, 2024

@richtabor made a block for this: https://rich.blog/dark-mode-toggle-block/

@Lewiscowles1986
Copy link
Contributor

So is this asking for a block for websites to add a toggle, or for Gutenberg itself to support dark-mode?

All my posts were for the latter, not the former.

@bhubbard
Copy link
Author

@Lewiscowles1986 So the original request is for a new toggle block. Browsing a lot of templates, I do see a lot of sites doing a drop-down that has light, dark, and system (default) as the options. And I feel this is probably best, as it defaults to system, but site visitors can then choose to see light and dark when they wish.

Example:
fb5a636f-f605-4ca3-b224-8a07c63d9912

Based on the comments, I do see some work that may need to be completed first, such as let developers define "prefers-color-scheme" for color palette's set within the theme.json file. It might also make sense to have this as a site option stored in the wp_options table, with default being system, but allowing site owners to override the default for the site globally.

@Lewiscowles1986
Copy link
Contributor

@bhubbard are wp_options user-specific?
I thought it was not https://codex.wordpress.org/Database_Description#Table:_wp_options

To add complexity, I'm not 100% certain, that a user wanting dark-mode, would wish to do so for all of their devices.

@bhubbard
Copy link
Author

@Lewiscowles1986 wp_options is not user-specific. But I was thinking its more for site owners to choose the default for their site, if they choose to not have it be "system". The idea being a user can always use this toggle or drop-down to then change on the front-end of the site.

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.
Projects
None yet
Development

No branches or pull requests

5 participants