Skip to content

Commit e0fd589

Browse files
committed
🌟 toggle theme active with styled-components
1 parent 81e5f9f commit e0fd589

File tree

8 files changed

+6272
-840
lines changed

8 files changed

+6272
-840
lines changed

package-lock.json

Lines changed: 5079 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@
2424
"@types/mongodb": "^4.0.7",
2525
"@types/node": "^18.11.15",
2626
"@types/react": "^18.0.26",
27+
"@types/styled-components": "^5.1.26",
2728
"axios": "^1.2.1",
2829
"react-icons": "^4.7.1",
2930
"sass": "^1.56.2",
31+
"styled-components": "^5.3.6",
3032
"typescript": "^4.9.4"
3133
}
3234
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// icons
2+
import { BiMoon, BiSun } from "react-icons/bi"
3+
4+
function ToggleTheme({ theme, onClick }) {
5+
return (
6+
<button
7+
onClick={() => onClick()}
8+
style={{
9+
width: '30px',
10+
height: '30px',
11+
color: '#000',
12+
background: '#fff4',
13+
borderRadius: "60%",
14+
position: "fixed",
15+
zIndex: 100,
16+
border: 'none',
17+
cursor: "pointer",
18+
margin: '9px'
19+
}}>
20+
{theme == 'dark' ? <BiSun /> : <BiMoon />}
21+
</button>
22+
)
23+
}
24+
25+
export default ToggleTheme

src/pages/_app.tsx

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,28 @@
11
// styles
2+
import { useEffect, useState } from 'react'
3+
import ToggleTheme from '../components/toggleTheme/ToggleTheme'
24
import '../styles/globals.scss'
5+
import StyleDark from "../styles/themes/dark"
6+
import StyleLight from "../styles/themes/light"
37

48
function App({ Component, pageProps }) {
9+
const [theme, setTheme] = useState('dark')
10+
11+
function onClickToggle() {
12+
if (theme == 'dark') {
13+
setTheme('light')
14+
15+
} else {
16+
setTheme('dark')
17+
}
18+
}
519

620
return (
7-
<Component {...pageProps} />
21+
<>
22+
{theme == 'dark' ? <StyleLight/> : <StyleDark/>}
23+
<ToggleTheme onClick={onClickToggle} theme={theme} />
24+
<Component {...pageProps} />
25+
</>
826
)
927
}
1028

src/styles/globals.scss

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
margin: 0;
55
padding: 0;
66
box-sizing: border-box;
7+
transition: 0.1s;
78
}
89

910
body {
@@ -20,17 +21,15 @@ body {
2021
overflow-x: hidden;
2122

2223
background-color: var(--primaryColor);
23-
2424
}
2525

26-
2726
:root {
2827
--menuWidth: 50px;
2928
}
3029

31-
// @import "themes/light.scss";
32-
@import "themes/dark.scss";
33-
3430
.active {
3531
color: #ff9f19;
36-
}
32+
}
33+
34+
// @import 'themes/dark.scss';
35+
// @import 'themes/light.scss';

src/styles/themes/dark.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { createGlobalStyle } from "styled-components";
2+
3+
export default createGlobalStyle`
4+
:root{
5+
--primaryColor: #ff9f19;
6+
--secondaryColor: #1f1f1e;
7+
8+
--primaryColorPastelDark25opacity: #715e438a;
9+
10+
--primaryColorPastelDark: #7b6240;
11+
--primaryColorPastelLight: #c4a67d;
12+
13+
--primaryColorPastel: #f8b557;
14+
15+
16+
--primaryColorVivid: #ff9500;
17+
18+
--labelColor: #8e8e8e;
19+
--h1Color: #f3f3f3;
20+
--h2Color: #8e8d8d;
21+
}
22+
`;

src/styles/themes/light.tsx

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { createGlobalStyle } from "styled-components";
2+
3+
export default createGlobalStyle`
4+
:root{
5+
--primaryColor: #f4a73a;
6+
--secondaryColor: #ffffff;
7+
8+
--primaryColorPastelDark25opacity: #e19c3b8a;
9+
10+
--primaryColorPastelDark: #877762;
11+
--primaryColorPastelLight: #c4a67d;
12+
13+
--primaryColorPastel: #f8b557;
14+
15+
16+
--primaryColorVivid: #ff9500;
17+
18+
--labelColor: #8e8e8e;
19+
--h1Color: #202020;
20+
--h2Color: #555555;
21+
`;

0 commit comments

Comments
 (0)