最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

reactjs - Force color scheme for a component independently from MantineProvider - Stack Overflow

programmeradmin1浏览0评论

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?

发布评论

评论列表(0)

  1. 暂无评论