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

Use media query value when useColorSchemeMediaQuery is set to 'system' #1981

Merged

Conversation

draekien
Copy link
Contributor

@draekien draekien commented Oct 24, 2021

This PR is based on the changes proposed in #981 and fixes #787

This change adds a new option for useColorSchemeMediaQuery called 'system' which will
listen for changes to the prefers-color-scheme media query and update the color mode
accordingly.

This change also updates the documentation to include a short description for the 'system' option.

I decided to go with 'system' over 'live' as I've mostly encountered websites referring to the
user's preferred color scheme as the 'system' setting. Let me know if you would prefer 'live' instead.

Testing: 'system'
color-scheme-change

Testing: 'initial' | true
color-scheme-initial

julianbenegas and others added 8 commits June 4, 2020 21:02
And save to localStorage even if useColorScheme...: true,

to make the flash prevention script work.
… types

I felt that 'system' made a bit more sense here (over 'live') as we want to use the system color
mode preference
implemented julianbenegas changes in the new index tsx file for color-modes
@vercel
Copy link

vercel bot commented Oct 24, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/systemui/theme-ui/HJc47wRw1gg8YDBqzeMCbiFVcipX
✅ Preview: https://theme-ui-git-fork-draekien-fix-color-scheme-med-a8a7ca-systemui.vercel.app

…sting behaviour

We only want it to ignore the stored value when useColorSchemeMediaQuery is system
@lachlanjc
Copy link
Member

Wow, phenomenal work!! Haven't tested it out but looks great. Super appreciate the contribution.

@draekien
Copy link
Contributor Author

Wow, phenomenal work!! Haven't tested it out but looks great. Super appreciate the contribution.

Thanks! I'm loving the library so wanted to see if I could contribute. Keep up the great work!!

@hasparus
Copy link
Member

Great PR @draekien! Thank you for the contribution!

Co-authored-by: Piotr Monwid-Olechnowicz <hasparus@gmail.com>
Copy link
Member

@lachlanjc lachlanjc left a comment

Choose a reason for hiding this comment

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

Tried this locally & works exactly as I'd expect!

@hasparus hasparus merged commit 822f835 into system-ui:develop Oct 26, 2021
@draekien draekien deleted the fix/color-scheme-media-query-api-update branch October 27, 2021 00:00
@hasparus hasparus added the prerelease This change is available in a prerelease. label Oct 28, 2021
@hasparus
Copy link
Member

🚀 PR was released in v0.12.0 🚀

@hasparus hasparus added released This issue/pull request has been released. and removed prerelease This change is available in a prerelease. labels Oct 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
released This issue/pull request has been released.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use prefers-color-scheme preference over localStorage color mode
4 participants