Skip to content

Commit 2de5a4b

Browse files
committed
Added dark mode
1 parent 949f543 commit 2de5a4b

File tree

7 files changed

+74
-27
lines changed

7 files changed

+74
-27
lines changed

Diff for: components/Header.tsx

+4-6
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import { IoLogoGithub } from "react-icons/io5";
77

88
export function Header({
99
headerPadding,
10-
maxWidth,
10+
width,
1111
}: {
1212
headerPadding: string;
13-
maxWidth: string;
13+
width: string;
1414
}) {
1515
const router = useRouter();
1616
const [allTags, setallTags] = useState<string[]>([]);
@@ -34,15 +34,13 @@ export function Header({
3434

3535
return (
3636
<motion.header
37-
style={{ transition: "all ease .25s" }}
3837
className={`z-50 flex place-items-center justify-center fixed top-4 left-2 sm:left-[17px] xl:left-0 right-2 md:right-0`}
3938
>
4039
<motion.div
41-
style={{ transition: "all ease .25s" }}
42-
className={`flex flex-row ${maxWidth} justify-between items-center ${headerPadding} rounded-lg shadow bg-base-100 relative`}
40+
style={{ transition: "padding ease .25s, width ease .25s" }}
41+
className={`flex flex-row ${width} justify-between items-center ${headerPadding} rounded-lg shadow bg-base-100 relative`}
4342
>
4443
<motion.div
45-
style={{ transition: "all ease .25s" }}
4644
className={`absolute left-0 right-0 -bottom-12 bg-base-100 rounded-lg shadow p-1 flex items-center justify-end gap-1 ${
4745
showTags
4846
? "pointer-events-auto opacity-100 translate-y-0"

Diff for: components/ThemeWrapper.tsx

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React, { useEffect, useState } from "react";
2+
import Head from 'next/head'
3+
import { FaMoon, FaSun } from "react-icons/fa";
4+
import colors from "../tailwind.config";
5+
6+
export default function ThemeWrapper({ children }) {
7+
const [theme, settheme] = useState<"sivert_dark" | "sivert_light">(
8+
"sivert_dark"
9+
);
10+
useEffect(() => {
11+
const localTheme = localStorage.getItem("theme");
12+
if (theme) settheme(localTheme as typeof theme);
13+
}, []);
14+
15+
useEffect(() => {
16+
localStorage.setItem("theme", theme);
17+
}, [theme]);
18+
return (
19+
<>
20+
<Head>
21+
<meta
22+
name="theme-color"
23+
content={
24+
theme === "sivert_dark"
25+
? colors.daisyui.themes[0].sivert_dark["base-100"]
26+
: colors.daisyui.themes[0].sivert_light["base-100"]
27+
}
28+
/>
29+
</Head>
30+
<div data-theme={theme}
31+
className="overflow-y-scroll h-screen scroll-smooth bg-base-200 text-base-content transition-none">
32+
<button
33+
onClick={() =>
34+
settheme(theme === "sivert_dark" ? "sivert_light" : "sivert_dark")
35+
}
36+
className="btn btn-circle btn-ghost fixed bottom-8 right-8"
37+
>
38+
{theme === "sivert_dark" ? <FaMoon /> : <FaSun />}
39+
</button>
40+
{children}
41+
</div>
42+
</>
43+
);
44+
}

Diff for: pages/_app.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { Roboto, Noto_Color_Emoji, JetBrains_Mono } from "next/font/google";
99
import { useEffect, useState } from "react";
1010
import TimeAgo from "javascript-time-ago";
1111
import en from "javascript-time-ago/locale/en.json";
12+
import ThemeWrapper from "components/ThemeWrapper";
1213

1314
const roboto = Roboto({
1415
subsets: ["latin"],
@@ -40,7 +41,7 @@ export default function MyApp({ Component, pageProps, router }) {
4041
}, [pageProps.post]);
4142

4243
return (
43-
<>
44+
<ThemeWrapper>
4445
<Head>
4546
<link rel="icon" type="image/x-icon" href="/favicon.png" />
4647
<meta name="viewport" content="width=device-width, initial-scale=1" />
@@ -51,7 +52,7 @@ export default function MyApp({ Component, pageProps, router }) {
5152
</style>
5253
</Head>
5354

54-
<Header headerPadding={headerPadding} maxWidth={headerWidth} />
55+
<Header headerPadding={headerPadding} width={headerWidth} />
5556

5657
<style jsx global>{`
5758
html {
@@ -75,6 +76,6 @@ export default function MyApp({ Component, pageProps, router }) {
7576
key={`${pageProps.post?.url}_${router.route}_${router.query.slug}`}
7677
/>
7778
</AnimatePresence>
78-
</>
79+
</ThemeWrapper>
7980
);
8081
}

Diff for: pages/_document.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ export default function Document() {
44
return (
55
<Html
66
lang="en"
7-
className="bg-base-200 overflow-y-scroll h-screen scroll-smooth"
7+
className="bg-base-200"
8+
data-theme='sivert_dark'
89
>
910
<Head>
10-
<meta name="theme-color" content="#fff" />
1111
<link rel="icon" href="/favicon.ico" />
1212
</Head>
1313
<body>

Diff for: pages/posts/[slug].tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const PostLayout = ({ post }: { post: Post }) => {
4949
);
5050

5151
const ImageAuthor = () => {
52-
const style = "font-medium text-gray-400 text-sm";
52+
const style = "font-medium text-base-content opacity-75 text-sm";
5353
return (
5454
<p className={style}>
5555
Credit:{" "}

Diff for: styles/pretty-code.css

-8
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,6 @@ pre > code {
4949
@apply !text-purple-200 bg-purple-800/50 border-b-purple-600 font-bold;
5050
}
5151

52-
.prose :where(a):not(:where([class~="not-prose"] *)) {
53-
color: hsl(var(--n));
54-
}
55-
56-
.prose :where(a):not(:where([class~="not-prose"] *)):hover {
57-
background-color: hsl(var(--a));
58-
}
59-
6052
code {
6153
counter-reset: line;
6254
}

Diff for: tailwind.config.js

+19-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const linkHeadingStyles = {
88
},
99
};
1010

11-
1211
module.exports = {
1312
theme: {
1413
extend: {
@@ -32,14 +31,14 @@ module.exports = {
3231
},
3332
a: {
3433
textDecoration: 'none',
35-
borderBottom: `2px solid ${colors.cyan[800]}`,
36-
color: colors.cyan[400],
34+
borderBottom: `2px solid hsl(var(--p))`,
35+
color: `hsl(var(--p))`,
3736
transition:
3837
'color 0.2s ease, border-color 0.2s ease, background 0.2s ease',
3938
'&:hover': {
40-
color: `${colors.zinc[900]} !important`,
41-
borderBottomColor: `${colors.cyan[200]} !important`,
42-
background: colors.cyan[200],
39+
color: `hsl(var(--pc)) !important`,
40+
borderBottomColor: ` hsl(var(--p)) !important`,
41+
background: `hsl(var(--p))`,
4342
},
4443
},
4544
code: {
@@ -78,9 +77,11 @@ module.exports = {
7877
require("@tailwindcss/line-clamp"),
7978
],
8079
daisyui: {
80+
darkTheme: "dark",
81+
base: false,
8182
themes: [
8283
{
83-
mytheme: {
84+
sivert_light: {
8485
primary: "#570df8",
8586
secondary: "#f000b8",
8687
accent: "#1dcdbc",
@@ -91,6 +92,17 @@ module.exports = {
9192
warning: "#fbbd23",
9293
error: "#f87272",
9394
},
95+
sivert_dark: {
96+
primary: "#d0bcff",
97+
secondary: "#ccc2dc",
98+
accent: "#efb8c8",
99+
neutral: "#2b3440",
100+
"base-100": "#2b2930",
101+
info: "#3abff8",
102+
success: "#36d399",
103+
warning: "#fbbd23",
104+
error: "#f2b8b5",
105+
},
94106
},
95107
],
96108
},

0 commit comments

Comments
 (0)