Skip to content

Commit e0117a7

Browse files
committed
feat: add dark mode
1 parent 31da992 commit e0117a7

File tree

5 files changed

+36
-52
lines changed

5 files changed

+36
-52
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import clsx from 'clsx';
2+
import { useTheme } from 'next-themes';
3+
import * as React from 'react';
4+
import { FiMoon, FiSun } from 'react-icons/fi';
5+
6+
import useLoaded from '@/hooks/useLoaded';
7+
8+
type ThemeButtonProps = React.ComponentPropsWithoutRef<'button'>;
9+
10+
export default function ThemeButton({ className, ...rest }: ThemeButtonProps) {
11+
const { theme, setTheme } = useTheme();
12+
const isLoaded = useLoaded();
13+
14+
return (
15+
<button
16+
className={clsx(className)}
17+
{...rest}
18+
onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}
19+
>
20+
{theme === 'light' && isLoaded ? <FiMoon /> : <FiSun />}
21+
</button>
22+
);
23+
}

src/components/layout/Footer.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import UnderlineLink from '@/components/links/UnderlineLink';
2+
13
export default function Footer() {
24
return (
35
<footer className='mt-16 text-right text-[#b3b3b3] dark:text-gray-200'>
4-
<section className='flex flex-col'>
6+
<section className='flex flex-col items-end'>
57
<div>
68
<a
79
href='https://creativecommons.org/licenses/by-nc-sa/4.0/'
@@ -17,12 +19,12 @@ export default function Footer() {
1719
className='pl-1'
1820
rel='noreferrer'
1921
>
20-
© Chocolate
22+
© Yang Chao Yi
2123
</a>
2224
</div>
23-
<a href='https://beian.miit.gov.cn/' rel='noreferrer' target='_blank'>
25+
<UnderlineLink href='https://beian.miit.gov.cn/'>
2426
湘ICP备20002952号
25-
</a>
27+
</UnderlineLink>
2628
</section>
2729
</footer>
2830
);

src/components/layout/Icon.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import { BsGithub } from 'react-icons/bs';
2-
import { FiSun } from 'react-icons/fi';
32
import { SiBilibili } from 'react-icons/si';
43

4+
import ThemeButton from '@/components/buttons/ThemeButton';
5+
56
const Logo = () => {
67
return (
78
<div className='flex cursor-pointer gap-[24px] text-[22px]'>
@@ -19,7 +20,7 @@ const Logo = () => {
1920
>
2021
<SiBilibili />
2122
</a>
22-
<FiSun />
23+
<ThemeButton />
2324
</div>
2425
);
2526
};

src/pages/_app.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { AppProps } from 'next/app';
22
import Router from 'next/router';
3+
import { ThemeProvider } from 'next-themes';
34
import nProgress from 'nprogress';
45
import { RecoilRoot } from 'recoil';
56

@@ -21,7 +22,9 @@ Router.events.on('routeChangeComplete', nProgress.done);
2122
function MyApp({ Component, pageProps }: AppProps) {
2223
return (
2324
<RecoilRoot>
24-
<Component {...pageProps} />
25+
<ThemeProvider attribute='class' enableSystem={false}>
26+
<Component {...pageProps} />
27+
</ThemeProvider>
2528
</RecoilRoot>
2629
);
2730
}

src/pages/index.tsx

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
import * as React from 'react';
2-
import { SiGithub, SiWechat } from 'react-icons/si';
32

4-
import { trackEvent } from '@/lib/analytics';
53
import clsxm from '@/lib/clsxm';
64
import useLoaded from '@/hooks/useLoaded';
75

86
import Layout from '@/components/layout/Layout';
97
import CustomLink from '@/components/links/CustomLink';
10-
import UnstyledLink from '@/components/links/UnstyledLink';
118
import Seo from '@/components/Seo';
12-
import Tooltip from '@/components/Tooltip';
139

1410
export default function HomePage() {
1511
const isLoaded = useLoaded();
@@ -55,47 +51,6 @@ export default function HomePage() {
5551
Learn more about me
5652
</CustomLink>
5753
</div>
58-
<div className='flex'>
59-
<Tooltip content={<p>Chocolate1999</p>}>
60-
<div
61-
data-fade='6'
62-
className='mt-8 flex flex-wrap gap-4 gap-y-2'
63-
>
64-
<UnstyledLink
65-
href='https://github.com/Chocolate1999'
66-
className={clsxm(
67-
'inline-flex items-center gap-1 text-base font-medium',
68-
'text-gray-600 hover:text-black dark:text-gray-400 dark:hover:text-white',
69-
'focus:outline-none focus-visible:ring focus-visible:ring-primary-300',
70-
'transition-colors'
71-
)}
72-
onClick={() => {
73-
trackEvent('Social Link: Github', 'link');
74-
}}
75-
>
76-
<SiGithub className='shrink-0' />
77-
</UnstyledLink>
78-
</div>
79-
</Tooltip>
80-
<Tooltip content={<p>小狮子前端</p>}>
81-
<div
82-
data-fade='6'
83-
className='mt-8 ml-4 flex flex-wrap gap-4 gap-y-2'
84-
>
85-
<UnstyledLink
86-
href='https://github.com/Chocolate1999'
87-
className={clsxm(
88-
'inline-flex items-center gap-1 text-base font-medium',
89-
'text-gray-600 hover:text-black dark:text-gray-400 dark:hover:text-white',
90-
'focus:outline-none focus-visible:ring focus-visible:ring-primary-300',
91-
'transition-colors'
92-
)}
93-
>
94-
<SiWechat className='shrink-0' />
95-
</UnstyledLink>
96-
</div>
97-
</Tooltip>
98-
</div>
9954
</div>
10055
</article>
10156
</div>

0 commit comments

Comments
 (0)