Add 'auto' color scheme support #1048
Replies: 6 comments 6 replies
-
How this mode is supposed to work during ssr? |
Beta Was this translation helpful? Give feedback.
-
Ideally, sending both styles, and leaving CSS to do the media query: .mantine-1uxyx4n {
// light-mode style
}
@media (prefers-color-scheme: dark) {
.mantine-u1xyx4n {
//overriding dark-mode styles
}
} Effectively, the server would no longer have to worry about the user's preference. |
Beta Was this translation helpful? Give feedback.
-
That, may work, I'll give it a try. It's a huge feature though, so do not expect it any time soon. |
Beta Was this translation helpful? Give feedback.
-
I found a way to hack the first page's colour scheme, for anyone visiting this: import { MantineProvider } from "@mantine/core";
import { NotificationsProvider } from "@mantine/notifications";
import { useColorScheme, useMediaQuery } from "@mantine/hooks";
import Layout from "components/layout";
import { AppProps } from "next/app";
import Head from "next/head";
import { useEffect, useState } from "react";
import "styles/globals.css";
export default function MyApp({ Component, pageProps }: AppProps) {
// Big hack to make it work for now
let [dark, setDark] = useState(false);
const preferredColorScheme = useMediaQuery("(prefers-color-scheme: dark)");
useEffect(() => {
setDark(preferredColorScheme);
}, [preferredColorScheme]);
// Causes FART, but better than nothing :/
return (
<MantineProvider
theme={{ colorScheme: dark ? "dark" : "light" }}
>
<NotificationsProvider>
<Layout>
<Component {...pageProps} />
</Layout>
</NotificationsProvider>
</MantineProvider>
);
} As indicated in the comments, it causes FART, but since I'm using tailwind (with media queries) to do the background & text colour, it's not too harsh on users. |
Beta Was this translation helpful? Give feedback.
-
any update please? |
Beta Was this translation helpful? Give feedback.
-
Usage example, including component/hook API
I've noticed some of the limitations of the dark theme and SSR (including those on the docs page).
Currently, I'm using the
useColorScheme
provider, but that causes a mismatch between server and client, and means that the first page the user load into isn't themed correctly.I'm using tailwind for other styling, which has a convenient
mode= 'media'
setting, which I think would fit well with mantine.Possible implementation – describe how the feature can be implemented
Inspecting the elements shows that there's a change in classes between dark and light themes (e.g. on my inputs,
mantine-1uxyx4n
versusmantine-us7vc8
), which get swapped out programmatically.I'm thinking an option to have the dark class always attached, but with a media qeury.
As a user, having
would be neat.
Do you want to contribute this feature and create a pull request
No response
Beta Was this translation helpful? Give feedback.
All reactions