forked from AngleProtocol/merkl-lite
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add: themes and theme switcher in dev mode (#4)
* add: theme selector when in dev mode * add: theme switcher in dev mode * fix: protocol empty tag * fix: lint error
- Loading branch information
Showing
3 changed files
with
49 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,31 @@ | ||
import { Button, Icon, Select, useTheme } from "dappkit"; | ||
import config from "merkl.config"; | ||
import { Button, Icon, useTheme } from "packages/dappkit/src"; | ||
import { useMemo } from "react"; | ||
|
||
export default function SwitchMode() { | ||
const { mode, toggleMode } = useTheme(); | ||
const { mode, toggleMode, themes, theme, setTheme } = useTheme(); | ||
const canSwitchModes = useMemo(() => !(!config.modes || config.modes?.length === 1), []); | ||
|
||
const themeOptions = useMemo(() => { | ||
return Object.keys(themes).reduce( | ||
(obj, name) => | ||
Object.assign(obj, { | ||
[name]: name, | ||
}), | ||
{}, | ||
); | ||
}, [themes]); | ||
|
||
return ( | ||
canSwitchModes && ( | ||
<Button look="base" onClick={toggleMode}> | ||
<Icon remix={mode === "dark" ? "RiMoonClearLine" : "RiSunLine"} /> | ||
</Button> | ||
) | ||
<> | ||
{process.env.NODE_ENV !== "production" && Object.keys(themeOptions)?.length > 1 && ( | ||
<Select state={[theme, setTheme]} options={themeOptions} /> | ||
)} | ||
{canSwitchModes && ( | ||
<Button look="base" onClick={toggleMode}> | ||
<Icon remix={mode === "dark" ? "RiMoonClearLine" : "RiSunLine"} /> | ||
</Button> | ||
)} | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters