Support 'system' theme #6418
Replies: 7 comments 2 replies
-
|
"system" isn't its own theme, it just means delegate the choice to the OS. You detect the user's OS-level preference via |
Beta Was this translation helpful? Give feedback.
-
|
I'd like to come up with the pseudo code for the 'system' theme. export default function RootLayout({ children }) {
const theme = getPrefersColorScheme()
return (
<html lang='en' className={theme} data-theme={theme}>
<body>{children}</body>
</html>
)
}Could you please help me to implement the magic function |
Beta Was this translation helpful? Give feedback.
-
|
I suggest that heroui supports 'system' value in export default function RootLayout({ children }) {
return (
<html lang='en' className='system' data-theme='system'>
<body>{children}</body>
</html>
)
}And internally, heroui could use the css magic for the 'system' theme: @media (prefers-color-scheme: dark) {
// do some magic here
}And then it would be very easy to implement theme switcher which just uses cookie. |
Beta Was this translation helpful? Give feedback.
-
|
It is very hard to implement 'system' theme value outside. Here is the answer from claude:
Suggest heroui provide 'system' theme value. |
Beta Was this translation helpful? Give feedback.
-
|
It does not support server side. And it uses tricky javascript to workaround SSR problem. And it does not support other theme systems https://semi.design/en-US/advanced/dark-mode#How%20to%20switch. With the support of 'system' value by heroui, I could use dozens of lines to replace next-theme. |
Beta Was this translation helpful? Give feedback.
-
|
It seems that supporting 'system' value only needs this code snippet: @media (prefers-color-scheme: dark) {
:root:not(.light):not([data-theme="light"]):not(.dark):not([data-theme="dark"]) {
/* Just inherit from .dark by reusing the same custom properties via a layer or @apply */
}
} |
Beta Was this translation helpful? Give feedback.
-
|
FYI. We will introduce |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
If we wanna set light/dark mode, we can do:
If we wanna set the theme to 'system', what should we do?
Beta Was this translation helpful? Give feedback.
All reactions