Skip to content

Commit f85c67b

Browse files
committed
feat: add light mode
1 parent 8b27102 commit f85c67b

File tree

8 files changed

+103
-26
lines changed

8 files changed

+103
-26
lines changed

src/App.tsx

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,23 @@
11
import * as React from 'react'
2-
import { Header } from './style/Header'
2+
import { useState } from 'react'
33
import { Footer } from './style/Footer'
44
import { Main, Info } from './style/Main'
5+
import { Theme, dark, light } from './style/theme'
56
import { GlobalStyle } from './style/Global'
67
import { Schedule } from './Schedule'
78
import { format } from 'date-fns'
9+
import { ThemeProvider } from 'styled-components'
810

911
import LockIcon from 'feather-icons/dist/icons/lock.svg'
1012
import UnLockIcon from 'feather-icons/dist/icons/unlock.svg'
13+
import LightModeIcon from 'feather-icons/dist/icons/sun.svg'
14+
import DarkModeIcon from 'feather-icons/dist/icons/moon.svg'
15+
import { Button } from './style/Form'
1116

1217
export const App = () => {
18+
const [theme, updateTheme] = useState<Theme>(
19+
window.localStorage.getItem('theme') === 'light' ? light : dark,
20+
)
1321
let cfg = {
1422
name: 'ExampleConf',
1523
day: format(new Date(), 'yyyy-MM-dd'),
@@ -40,9 +48,8 @@ export const App = () => {
4048
console.log(cfg)
4149
}
4250
return (
43-
<>
51+
<ThemeProvider theme={theme}>
4452
<GlobalStyle />
45-
<Header></Header>
4653
<Main>
4754
<Schedule
4855
sessions={cfg.sessions}
@@ -51,11 +58,35 @@ export const App = () => {
5158
conferenceDate={cfg.day}
5259
/>
5360
<Info>
54-
Click the <LockIcon /> icon to create your own schedule. When done,
55-
click the <UnLockIcon /> and share the updated URL.
61+
<p>
62+
Click the <LockIcon /> icon to create your own schedule. When done,
63+
click the <UnLockIcon /> and share the updated URL.
64+
</p>
65+
</Info>
66+
<Info>
67+
{theme === dark && (
68+
<Button
69+
onClick={() => {
70+
updateTheme(light)
71+
window.localStorage.setItem('theme', 'light')
72+
}}
73+
>
74+
<LightModeIcon /> switch to light mode
75+
</Button>
76+
)}
77+
{theme === light && (
78+
<Button
79+
onClick={() => {
80+
updateTheme(dark)
81+
window.localStorage.setItem('theme', 'dark')
82+
}}
83+
>
84+
<DarkModeIcon /> switch to dark mode
85+
</Button>
86+
)}
5687
</Info>
5788
</Main>
5889
<Footer />
59-
</>
90+
</ThemeProvider>
6091
)
6192
}

src/style/Footer.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ import GithubIcon from 'feather-icons/dist/icons/github.svg'
66

77
const StyledFooter = styled.footer`
88
padding: 1rem 2rem;
9+
opacity: 0.75;
910
@media (min-width: ${wideBreakpoint}) {
1011
padding: 4rem;
1112
}
1213
13-
color: #ffffffcc;
14+
color: ${(props) => props.theme.colors.text};
1415
a {
15-
color: #ffffffcc;
16+
color: ${(props) => props.theme.colors.text};
1617
}
1718
p {
1819
line-height: 1.5rem;

src/style/Form.tsx

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,34 @@ import styled from 'styled-components'
22

33
export const Button = styled.button`
44
background-color: transparent;
5-
color: #fff;
5+
color: ${(props) => props.theme.colors.text};
66
opacity: 0.75;
77
padding: 0;
88
border: 0;
9-
float: right;
9+
display: flex;
10+
align-items: center;
11+
svg {
12+
margin-right: 0.5rem;
13+
}
1014
`
1115

1216
export const DeleteButton = styled(Button)`
13-
color: #ff5235;
17+
color: ${(props) => props.theme.colors.delete};
1418
`
1519

1620
export const AddButton = styled(Button)`
17-
color: #0fa;
21+
color: ${(props) => props.theme.colors.add};
1822
&:disabled {
19-
color: #aaa;
23+
color: ${(props) => props.theme.colors.addDisabled};
2024
}
2125
`
2226

2327
export const Input = styled.input`
2428
background-color: transparent;
25-
border: 1px solid #fff;
29+
border: 1px solid ${(props) => props.theme.colors.text};
2630
padding: 0.25rem 0.5rem;
2731
height: 30px;
28-
color: #fff;
32+
color: ${(props) => props.theme.colors.text};
2933
`
3034

3135
export const DateInput = styled(Input)`

src/style/Global.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ import { createGlobalStyle } from 'styled-components'
22

33
export const GlobalStyle = createGlobalStyle`
44
body {
5-
background-color: black;
6-
color: white;
5+
background-color: ${(props) => props.theme.colors.background};
6+
color: ${(props) => props.theme.colors.text};
77
font-family: 'DM Mono', monospace;
88
}
99
`

src/style/Header.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/style/Main.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@ import styled from 'styled-components'
22

33
export const Main = styled.main``
44

5-
export const Info = styled.p`
5+
export const Info = styled.div`
66
text-align: center;
77
font-size: 14px;
88
margin: 1rem;
9+
display: flex;
10+
justify-content: center;
911
`

src/style/Table.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
import styled from 'styled-components'
22
import { wideBreakpoint } from './settings'
3+
import { Button } from './Form'
34

45
export const Table = styled.table`
56
border-collapse: collapse;
67
width: 100%;
78
height: 100%;
9+
${Button} {
10+
float: right;
11+
}
812
td,
913
th {
10-
border: 1px solid #7d7d7d;
14+
border: 1px solid ${(props) => props.theme.colors.borderColor};
1115
padding: 0.25rem;
1216
@media (min-width: ${wideBreakpoint}) {
1317
padding: 1rem;
@@ -48,7 +52,7 @@ export const Table = styled.table`
4852
white-space: nowrap;
4953
}
5054
td.hot {
51-
background-color: #ff5e007a;
55+
background-color: ${(props) => props.theme.colors.countdownWarning};
5256
}
5357
th {
5458
small {

src/style/theme.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import 'styled-components'
2+
3+
export type Theme = {
4+
colors: {
5+
background: string
6+
text: string
7+
delete: string
8+
add: string
9+
addDisabled: string
10+
countdownWarning: string
11+
borderColor: string
12+
}
13+
}
14+
15+
declare module 'styled-components' {
16+
export interface DefaultTheme extends Theme {}
17+
}
18+
19+
export const dark: Theme = {
20+
colors: {
21+
background: '#000',
22+
text: '#fff',
23+
delete: '#ff5235',
24+
add: '#0fa',
25+
addDisabled: '#aaa',
26+
countdownWarning: '#ff5e007a',
27+
borderColor: '#7d7d7d',
28+
},
29+
}
30+
31+
export const light: Theme = {
32+
colors: {
33+
background: '#fffbf6',
34+
text: '#000000cc',
35+
add: '#22a00d',
36+
addDisabled: '#aaa',
37+
delete: '#dc2000',
38+
countdownWarning: '#ff000052',
39+
borderColor: '#a7a7a7',
40+
},
41+
}

0 commit comments

Comments
 (0)