question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Store color mode value in theme

See original GitHub issue

Currently 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:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:7 (6 by maintainers)

github_iconTop GitHub Comments

5reactions
arnaudjnncommented, Jul 10, 2020

Is it possible to use color mode like in theme-ui:

colors: {
    ...chakraTheme.colors,
    accent1: '#FAFAFA',
    accent2: '#EAEAEA',
    accent3: '#999',
    accent4: '#888',
    modes: {
      dark: {
        accent1: '#111',
        accent2: '#333',
        accent3: '#999',
        accent4: '#FAFAFA',
      },
    },
  },
4reactions
segunadebayocommented, Jul 15, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found