Store color mode value in theme
See original GitHub issueCurrently we store the color mode value in a react context
This approach has a few problems that limit the extensibility with other packages
- when other packages use another color mode context the state is duplicated in multiple places
- if other UI packages want to know the current color mode they must have a peer dependency on
@chakra-ui/color-mode
- if there are multiple installs of
chakra-ui
the color mode context is duplicated and color mode will stop working
We could instead use the emotion ThemeContext
to store the color mode value, this way chakra-ui
color mode can easily be used by other UI packages without having to depend on chakra-ui
Obviously there would be no change on the current API as we can just change the useColorMode
and useColorModeValue
functions to get the value from theme instead of context
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Color Modes - Theme UI
Use the useColorMode hook in your application to change the color mode. This value will be stored in localStorage and used whenever the...
Read more >Colors and styling | Visualize and present data - Mode Support
Under Features, select Colors & Themes. To modify a custom color palette, locate it in the list and click on it. Make any...
Read more >Color Mode - Chakra UI
useColorModeValue is a React hook used to change any value or style based on the color mode. It takes 2 arguments: the value...
Read more >Theme settings - Shopify Help Center
You can use theme settings to make changes to your online store's typography, colors, social media links, and checkout settings. You can use...
Read more >How to store theme color preferences using the Local Storage ...
we store the themeSwitch key (and set it to 'dark') if the dark mode is selected or remove it if the user goes...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Is it possible to use color mode like in
theme-ui
:I see where this is going @remorses. I think it makes sense to store the value in the theme and allow the user to provide their mechanism to control the color mode, we can use localStorage by default.