Pigment: add a "system" mode to the dark mode switch #387
Labels
package: system
Specific to @mui/system
status: waiting for maintainer
These issues haven't been looked at yet by a maintainer
Milestone
Summary
With the current
colorSchemeSelector
API that is available to implement a dark mode switch in a pigment app, it is possible to choose themedia
option which relies on theprefers-color-scheme
media query, or chooseclass
ordata
which enables a manual toggle. But for a "system" option, we need both the media query selector and the class/data selector (since, if the system option is selected, we fall back to the media query). I've found a workaround to achieve this, but it feels a bit hacky, so it would be nice if there is an official documented way to do this.To be fair, the Pigment CSS docs also don't specify how to implement a "system" option to the dark mode switch, but they have a more flexible
getSelector
API which allows you to write something likewhich achieves the desired effect of both supporting a manual switch, and being able to fall back to the media query if the system option is chosen. So my workaround is to first create my theme with
createTheme
from material-ui, then pass that to theextendTheme
function from@pigment-css/vite-plugin
, where I can add thisgetSelector
function. I cannot just create my theme directly withextendTheme
because there is functionality in material-ui'screateTheme
that is missing fromextendTheme
. Please let me know if there is a better way to do it!Examples
No response
Motivation
Most dark mode switches have a "system" option, enabled by default, that falls back to the browser preference. It would be great to be able to do this in Pigment apps as well.
Search keywords: pigment, dark mode
The text was updated successfully, but these errors were encountered: