From 06428daa53029dca82d63cbf3364b3f74fce67d5 Mon Sep 17 00:00:00 2001 From: LASER-Yi Date: Sat, 11 Dec 2021 18:45:19 +0800 Subject: Add support of automatic switch color scheme --- src/components/shared/ThemeSwitcher.tsx | 81 ++++++++++++++++++++++++++------- 1 file changed, 65 insertions(+), 16 deletions(-) (limited to 'src/components/shared') diff --git a/src/components/shared/ThemeSwitcher.tsx b/src/components/shared/ThemeSwitcher.tsx index fba5b0b..90990b6 100644 --- a/src/components/shared/ThemeSwitcher.tsx +++ b/src/components/shared/ThemeSwitcher.tsx @@ -16,18 +16,38 @@ export function ThemeSwitcherImpl({ theme, dispatch }) { dispatch(switchTheme()); }, [dispatch]); + const nextThemeName = React.useMemo(() => { + switch (theme) { + case 'light': + return 'dark'; + case 'dark': + return 'auto'; + case 'auto': + return 'light'; + default: + console.assert(false, 'Unknown theme'); + return 'unknown'; + } + }, [theme]); + + const themeIcon = React.useMemo(() => { + switch (theme) { + case 'light': + return ; + case 'dark': + return ; + case 'auto': + return ; + default: + console.assert(false, 'Unknown theme'); + return ; + } + }, [theme]); + return ( - - ); @@ -75,11 +95,7 @@ function Sun() { strokeLinejoin="round" > - + @@ -93,5 +109,38 @@ function Sun() { ); } +function Auto() { + const module = framerMotionResouce.read(); + const motion = module.motion; + + return ( + + + + + + + + ); +} + const mapState = (s: State) => ({ theme: getTheme(s) }); export const ThemeSwitcher = connect(mapState)(ThemeSwitcherImpl); -- cgit v1.3.1