Skip to content

Commit

Permalink
fix(components): πŸŒ“ add default value for color mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ali4heydari committed Jul 17, 2021
1 parent 126e2a2 commit 6c538e7
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/components/Header/MainNav/ToggleMode.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ToggleMode as ToggleModeButtonBase } from "./styles";
import React from "react";
import React, { useMemo } from "react";
import { useDarkMode } from "../../../hooks";
import { Moon, Sun } from "styled-icons/fa-solid";

Expand All @@ -26,14 +26,17 @@ export const Icons = {
SunMoon: (props) => <SunSlashMoon {...props} width="1.2em" />,
};

const modes = {
light: [`Light Mode`, Icons.Sun, `dark`],
dark: [`Dark Mode`, Icons.Moon, `osPref`],
osPref: [`OS setting`, Icons.SunMoon, `light`],
};

export const ToggleMode = () => {
const [colorMode, setColorMode] = useDarkMode();
const [colorMode = "osPref", setColorMode] = useDarkMode();

const modes = useMemo(
() => ({
light: [`Light Mode`, Icons.Sun, `dark`],
dark: [`Dark Mode`, Icons.Moon, `osPref`],
osPref: [`OS setting`, Icons.SunMoon, `light`],
}),
[]
);

const [title, Icon, nextMode] = modes[colorMode];

Expand Down

0 comments on commit 6c538e7

Please sign in to comment.