-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a dark mode #10
Comments
@johno Would you want to use a hook for this? |
I'll need to do a bit of thinking on this, but perhaps we allow users to select a Theme UI theme (and we provide a couple defaults like light/dark/etc) and we store the selection in the config. If we go this approach we'd prolly use some sort of |
@johnletey The hook needs to be inside the |
@jxnblk The |
@johnletey right, so it looks like the |
That is correct |
@jxnblk So, still doesn't work when I have the following in import React from 'react'
import { ThemeProvider, ColorMode, useColorMode } from 'theme-ui'
import { theme } from '@blocks/editor'
import desktopTheme from './theme'
const [colorMode, setColorMode] = useColorMode()
export default ({ children }) => (
<ThemeProvider theme={theme && desktopTheme}>
<button
onClick={e => {
setColorMode(colorMode === 'light' ? 'dark' : 'light')
}}>
Toggle {colorMode === 'light' ? 'Dark' : 'Light'}
</button>
<ColorMode />
{children}
</ThemeProvider>
) and no other theme code in |
@johnletey the E.g. // header component
import React from 'react'
import { useColorMode } from 'theme-ui'
export default props => {
const [colorMode, setColorMode] = useColorMode()
return (
<header>
<button
onClick={e => {
setColorMode(colorMode === 'light' ? 'dark' : 'light')
}}>
Toggle {colorMode === 'light' ? 'Dark' : 'Light'}
</button>
</header>
)
} // layout component
const Layout = props =>
<ThemeProvider theme={theme}>
<Header />
{props.children}
</ThemeProvider> |
@jxnblk Thanks for the help ... but still not working ... here's the code:
import React from 'react'
import { ThemeProvider } from 'theme-ui'
import ThemeSwitcher from './themeSwitcher';
import theme from './theme'
export default ({ children }) => (
<ThemeProvider theme={theme}>
<ThemeSwitcher />
{children}
</ThemeProvider>
)
import React from 'react'
import { useColorMode, Styled } from 'theme-ui'
export default () => {
const [colorMode, setColorMode] = useColorMode()
return (
<Styled.root
css={{
maxWidth: '48em',
padding: 32,
marginLeft: 'auto',
marginRight: 'auto',
marginTop: '40px'
}}
>
<Styled.button
css={{
display: 'flex',
alignItems: 'center',
cursor: 'pointer'
}}
onClick={e => {
setColorMode(colorMode === 'light' ? 'dark' : 'light')
}}>
Toggle {colorMode === 'light' ? 'Dark' : 'Light'}
</Styled.button>
</Styled.root>
)
}
import { theme } from '@blocks/editor'
export default {
...theme,
initialColorMode: 'light',
useCustomProperties: true,
colors: {
background: '#fff',
modes: {
dark: {
background: '#000',
}
}
}
} |
Are you rendering the |
No I am not @jxnblk ... I never use the If I put it in import React from 'react'
import { ThemeProvider, ColorMode } from 'theme-ui'
import ThemeSwitcher from './themeSwitcher';
import theme from './theme'
export default ({ children }) => (
<ThemeProvider theme={theme}>
<ThemeSwitcher />
<ColorMode />
{children}
</ThemeProvider>
) the app still doesn't work |
Hmm, not sure then. Let me know when you push the branch up and I can try to take a look |
@jxnblk Just pushed my most recent edits to my feat/dark-mode branch ... you can also see #22 |
For anyone using this in the future at night, it would be nice to have a dark mode in the desktop app!
The text was updated successfully, but these errors were encountered: