admin 管理员组

文章数量: 1086019

Mantine has robust theming capabilities, including color schemes. Nevertheless, I have not been able to figure out how to force a particular color scheme for a section of the page (a component and its children, for instance) independently from the rest of the page.

MantineProvider "must be rendered at the root of your application and should be used only once", so I can't wrap a component with another MantineProvider deep down into the layout and use forceColorScheme only from that point in the tree onwards. Even if it was possible to use multiple MantineProviders, since the library uses CSS variables in :root to define the default values and :root[data-mantine-color-scheme="dark"] and :root[data-mantine-color-scheme="light"] to override them, the color scheme is not localized but set for the whole document.

If the variables were defined in classes (i.e. mantine-light and mantine-dark) instead using :root, that would be easy. I would just have to apply one of the classes to the component to override locally, but that's not the case.

The case in hand is that I want the header (and everything in it) to always use the dark color scheme no matter if the whole page is using light, dark or auto. I don't want to override all CSS variables manually in the header, though. Any ideas?

本文标签: reactjsForce color scheme for a component independently from MantineProviderStack Overflow