Skip to content

Commit

Permalink
feat: fix dark mode toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
martapanc-resourcify committed Jul 5, 2023
1 parent ef5b359 commit 7cdfc01
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
7 changes: 4 additions & 3 deletions src/components/buttons/ModeToggleButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import clsx from 'clsx';
import { useTheme } from 'next-themes';
import * as React from 'react';
import { useEffect, useState } from 'react';
import { FiMoon, FiSun } from 'react-icons/fi';

type ThemeButtonProps = React.ComponentPropsWithoutRef<'button'>;
Expand All @@ -10,12 +11,12 @@ export default function ModeToggleButton({
...rest
}: ThemeButtonProps) {
const { theme, setTheme } = useTheme();
const [mounted, setMounted] = React.useState(false);
const [mounted, setMounted] = useState(false);

React.useEffect(() => setMounted(true), []);
useEffect(() => setMounted(true), []);

function toggleMode() {
return theme === 'dark' ? setTheme('light') : setTheme('dark');
return setTheme(theme === 'dark' ? 'light' : 'dark');
}

return (
Expand Down
4 changes: 2 additions & 2 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ export default function HomePage() {
<Seo templateTitle='Home' />

<main>
<section className='light:bg-white dark:bg-dark'>
<section className='dark:bg-dark bg-white'>
<div className='layout relative flex min-h-screen flex-col items-center justify-center py-12 text-center'>
<Vercel className='text-5xl' />
<h1 className='mt-4'>
Next.js + Tailwind CSS + TypeScript Starter
</h1>
<p className='light:text-gray-600 mt-2 text-sm dark:text-gray-100'>
<p className='mt-2 text-sm text-gray-600 dark:text-gray-100'>
A starter for Next.js, Tailwind CSS, and TypeScript with Absolute
Import, Seo, Link component, pre-configured with Husky{' '}
</p>
Expand Down
2 changes: 1 addition & 1 deletion src/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@
}

.burger-icon span {
/*@apply light:bg-black dark:bg-white;*/
@apply bg-black dark:bg-white;
display: block;
position: absolute;
height: 3px;
Expand Down
1 change: 1 addition & 0 deletions tailwind.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import defaultTheme from 'tailwindcss/defaultTheme';

export default {
content: ['./src/**/*.{js,jsx,ts,tsx}'],
darkMode: 'class',
theme: {
extend: {
fontFamily: {
Expand Down

0 comments on commit 7cdfc01

Please sign in to comment.