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.

Force a colour theme through ThemeProvider

See original GitHub issue

Is your feature request related to a problem? Please describe.

When using a theme from a package, in my case often @hackclub/theme, the packaged theme often has a light and dark mode. This is great when you want both light and dark mode, but sometimes you only want one of the two. As the config happens in the theme file, you have to use extend theme to remove a dark mode. Which can clutter the code base.

Describe the solution you’d like

I would like to be able to do:

<ThemeProvider theme={theme} forceColorMode="dark">

Describe alternatives you’ve considered

As mentioned above you can extended the theme, or use the react hook to set the colour mode. Neither is perfect. Another option would to export multiple themes from the package.

Additional context

View https://github.com/hackclub/theme/blob/main/packages/theme/src/index.ts

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
sampodercommented, Aug 18, 2021

Hey @hasparus! That’s a smart approach! Though, I’d still prefer a prop as it would simplify it more (and be a bit more understandable) but I’m going to switch over to using this for now, thanks so much!

This is what I ended up using to force a light mode:

<ThemeProvider
  theme={{
    ...theme,
    colors: { ...theme.colors, modes: {} }
  }}
>
1reaction
mryechkincommented, Aug 18, 2021

@hasparus +1 to that. IMO the approach above is simple, and is easy to understand what’s going on. No need to clutter the provider with additional props. This belongs in userland, as you said 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

A Dark Mode Toggle with React and ThemeProvider
This media feature is used to detect if the user has requested the page to use a light or dark color theme based...
Read more >
Dark Theme with Styled Components | by Gal Tadmor - Medium
Let's talk about dark theme (AKA dark mode). Dark-theming your app means adding an option to invert your app's colors. Whereas traditional apps ......
Read more >
Material-UI: How to Implement Dark Mode and Edit Theme ...
This article covers dark mode implementation and editing the default color scheme in Material-UI, a React component library that follows ...
Read more >
Allow creating built-in system functions with a default theme
When I have a theme with the property colors. ... like to have a default theme so my component users are not forced...
Read more >
Build a React theme switcher app with styled-components
In this tutorial, we demonstrate how to build a custom theme switcher for a Game of Thrones-themed React app using styled-components.
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