Skip to content

Commit

Permalink
fix: theme toggle button
Browse files Browse the repository at this point in the history
  • Loading branch information
martapanc committed Sep 20, 2023
1 parent a0d8db4 commit 7b19189
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 19 deletions.
16 changes: 11 additions & 5 deletions src/components/atoms/ThemeToggle/ThemeToggle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ import './themeToggle.css';

type Mode = 'dark' | 'light';

export default function ThemeToggle() {
export interface ThemeToggleProps {
includeLabels?: boolean;
}

export const ThemeToggle = ({ includeLabels }: ThemeToggleProps) => {
const { theme, setTheme } = useTheme();
const [mode, setMode] = useState<Mode>(theme as Mode);

Expand All @@ -27,8 +31,8 @@ export default function ThemeToggle() {
<div className=''>
<DarkModeToggle
mode={mode}
dark='Dark'
light='Light'
dark={includeLabels ? 'Dark' : ''}
light={includeLabels ? 'Light' : ''}
size='sm'
inactiveTrackColor='#e2e8f0'
inactiveTrackColorOnHover='#f8fafc'
Expand All @@ -44,9 +48,11 @@ export default function ThemeToggle() {
activeLabelColor='#0f172a'
activeLabelColorOnHover='#0f172a'
activeLabelColorOnActive='#0f172a'
ariaLabel='Toggle color scheme'
ariaLabel='Toggle Dark / Light Mode'
onChange={toggleTheme}
/>
</div>
);
}
};

export default ThemeToggle;
5 changes: 3 additions & 2 deletions src/components/atoms/ThemeToggle/themeToggle.css
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
[type='checkbox'] {
color: #334155;
border-width: 0 !important;
}

[type='checkbox']:checked {
background-image: none;
}

input::before {
/* input::before {
height: 19px !important;
}
input:checked::before {
left: 23px !important;
}
} */
2 changes: 1 addition & 1 deletion src/components/layout/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export default function Header() {
<div className='hidden md:flex md:flex-row'>
{i18nEnabled && <LanguageSwitcher languages={languageDefs} />}

<ThemeToggle />
<ThemeToggle includeLabels={true} />
</div>
</nav>

Expand Down
27 changes: 16 additions & 11 deletions src/components/molecules/MobileMenu/MobileMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { useTranslation } from 'react-i18next';

import languages from '@/data/languages.json';

import ModeToggleButton from '@/components/atoms/buttons/ModeToggleButton';
import { NavigationItem } from '@/components/atoms/NavigationItem';
import { ThemeToggle } from '@/components/atoms/ThemeToggle/ThemeToggle';
import { links } from '@/components/layout/Header';
import LanguageSwitcherMobile from '@/components/molecules/LanguageSwitcher/LanguageSwitcherMobile';

Expand All @@ -19,6 +19,8 @@ export interface MobileMenuProps {
export const MobileMenu = ({ isOpen }: MobileMenuProps) => {
const { t } = useTranslation();

const i18nEnabled = false;

const navigationVariants = {
hidden: { opacity: 0, x: -50 },
visible: (custom: number) => ({
Expand Down Expand Up @@ -62,17 +64,20 @@ export const MobileMenu = ({ isOpen }: MobileMenuProps) => {
animate='visible'
custom={0.5 + (links.length + 3) * 0.1}
>
<ModeToggleButton />
</motion.li>
<motion.li
className='flex justify-center'
variants={navigationVariants}
initial='hidden'
animate='visible'
custom={0.5 + (links.length + 4) * 0.1}
>
<LanguageSwitcherMobile languages={languages} />
<ThemeToggle includeLabels={false} />
</motion.li>

{i18nEnabled && (
<motion.li
className='flex justify-center'
variants={navigationVariants}
initial='hidden'
animate='visible'
custom={0.5 + (links.length + 4) * 0.1}
>
<LanguageSwitcherMobile languages={languages} />
</motion.li>
)}
</ul>
</FocusTrap>
</motion.div>
Expand Down

0 comments on commit 7b19189

Please sign in to comment.