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.
We add a CSS transition to the body’s
color
style and listen totransitionstart
. (Trick found in https://github.com/bramus/style-observer.)This enables us to listen when the actual
color
starts transitioning, and update dark based on the computed value ofcolor-scheme
.Note that this works with any element within the body, so:
if we want to ensure that the user has not added their own
transition
definitions to the body, we could use another element — or even create one on purpose.we can listen to dark mode changes inside a page, say if someone has a block that needs to be in a mode that is toggled separately from the main page, maybe for demonstration purposes. I don't know if that is useful enough in practice, but it doesn't take more code to support this, and it's more consistent with
Generators.width(*element*)
. I've added such an example in the documentation—for testing purposes (I don't plan to ship this example in any case, but it could be documented in pangea as a side show).If we think the transition might break or not work in all cases, we could keep listening to the user preference (media).
Here is a standalone (user land) version:
closes #1339