Skip to content
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

feat: Add dark mode #22

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 41 additions & 39 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,47 +59,49 @@ const App = () => {
const parentDir = getParentDirectory(openFilePathname)

return (
<Styled.root
css={{
maxWidth: '48em',
padding: 32,
marginLeft: 'auto',
marginRight: 'auto',
marginTop: '40px'
}}
>
<Styled.a
css={{
display: 'flex',
alignItems: 'center',
cursor: 'pointer',
marginBottom: '2px'
}}
onClick={() => {
handleFileListSelection(parentDir)
}}
>
<ArrowLeft />
<span sx={{ ml: 2 }}>Back</span>
</Styled.a>
<Styled.p
<Layout>
<Styled.root
css={{
display: 'flex',
alignItems: 'center',
marginBottom: '20px'
maxWidth: '48em',
padding: 32,
marginLeft: 'auto',
marginRight: 'auto',
marginTop: '40px'
}}
>
<FileText />
<span sx={{ ml: 2 }}>{openFilePathname}</span>
</Styled.p>
<Editor
initialValue={openFileContents}
onChange={({ value }) => {
write({ value })
}}
components={{}}
/>
</Styled.root>
<Styled.a
css={{
display: 'flex',
alignItems: 'center',
cursor: 'pointer',
marginBottom: '2px'
}}
onClick={() => {
handleFileListSelection(parentDir)
}}
>
<ArrowLeft />
<span sx={{ ml: 2 }}>Back</span>
</Styled.a>
<Styled.p
css={{
display: 'flex',
alignItems: 'center',
marginBottom: '20px'
}}
>
<FileText />
<span sx={{ ml: 2 }}>{openFilePathname}</span>
</Styled.p>
<Editor
initialValue={openFileContents}
onChange={({ value }) => {
write({ value })
}}
components={{}}
/>
</Styled.root>
</Layout>
)
} else {
return (
Expand All @@ -110,7 +112,7 @@ const App = () => {
padding: 32,
marginLeft: 'auto',
marginRight: 'auto',
marginTop: '40px'
// marginTop: 'auto'
}}
>
<Styled.ul>
Expand Down
7 changes: 5 additions & 2 deletions src/layout.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import React from 'react'
import { ThemeProvider } from 'theme-ui'
import { theme } from '@blocks/editor'
import { ThemeProvider, ColorMode } from 'theme-ui'
import ThemeSwitcher from './themeSwitcher';
import theme from './theme'

export default ({ children }) => (
<ThemeProvider theme={theme}>
<ThemeSwitcher />
<ColorMode />
{children}
</ThemeProvider>
)
16 changes: 16 additions & 0 deletions src/theme.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { theme } from '@blocks/editor'

export default {
...theme,
initialColorMode: 'light',
colors: {
...theme.colors,
background: '#fff',
modes: {
dark: {
...theme.colors.dark,
background: '#000',
}
}
}
}
19 changes: 19 additions & 0 deletions src/themeSwitcher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/** @jsx jsx */
import { jsx, useColorMode } from 'theme-ui'
import { Sun, Moon } from 'react-feather'

export default props => {
const [ mode, setMode ] = useColorMode()

return (
<a
{...props}
onClick={e => {
const next = mode === 'dark' ? 'light' : 'dark'
setMode(next)
}}
>
{mode == 'dark' ? <Sun /> : <Moon />}
</a>
)
}