From c78dbcf8f89072dc9c2fa8ba81e2cf5a80218cd7 Mon Sep 17 00:00:00 2001 From: Haishan Date: Sun, 13 Jun 2021 15:20:12 +0800 Subject: Support switch theme on backend config page --- src/components/shared/ThemeSwitcher.module.css | 28 ++++++++ src/components/shared/ThemeSwitcher.tsx | 97 ++++++++++++++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 src/components/shared/ThemeSwitcher.module.css create mode 100644 src/components/shared/ThemeSwitcher.tsx (limited to 'src/components/shared') diff --git a/src/components/shared/ThemeSwitcher.module.css b/src/components/shared/ThemeSwitcher.module.css new file mode 100644 index 0000000..919c86c --- /dev/null +++ b/src/components/shared/ThemeSwitcher.module.css @@ -0,0 +1,28 @@ +.iconWrapper { + --sz: 40px; + + width: var(--sz); + height: var(--sz); + display: flex; + justify-content: center; + align-items: center; + + outline: none; + padding: 5px; + color: var(--color-text); + border-radius: 100%; + border: 1px solid transparent; +} +.iconWrapper:hover { + opacity: 0.6; +} +.iconWrapper:focus { + border-color: var(--color-focus-blue); +} + +.themeSwitchContainer { + appearance: none; + user-select: none; + background: none; + cursor: pointer; +} diff --git a/src/components/shared/ThemeSwitcher.tsx b/src/components/shared/ThemeSwitcher.tsx new file mode 100644 index 0000000..fba5b0b --- /dev/null +++ b/src/components/shared/ThemeSwitcher.tsx @@ -0,0 +1,97 @@ +import Tooltip from '@reach/tooltip'; +import cx from 'clsx'; +import * as React from 'react'; +import { useTranslation } from 'react-i18next'; +import { connect } from 'src/components/StateProvider'; +import { framerMotionResouce } from 'src/misc/motion'; +import { getTheme, switchTheme } from 'src/store/app'; +import { State } from 'src/store/types'; + +import s from './ThemeSwitcher.module.css'; + +export function ThemeSwitcherImpl({ theme, dispatch }) { + const { t } = useTranslation(); + + const switchThemeHooked = React.useCallback(() => { + dispatch(switchTheme()); + }, [dispatch]); + + return ( + + + + ); +} + +function MoonA() { + const module = framerMotionResouce.read(); + const motion = module.motion; + return ( + + + + ); +} + +function Sun() { + 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