Skip to content

There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.

feat: modify theme mode switch style

QiShaoXuan2b13a63848ff
diff --git a/packages/app/src/components/Header/icons.tsx b/packages/app/src/components/Header/icons.tsx
index 9e27fc7875..6f9d5ebee1 100644
--- a/packages/app/src/components/Header/icons.tsx
+++ b/packages/app/src/components/Header/icons.tsx
@@ -22,46 +22,6 @@ export const LogoIcon = ({ style = {}, ...props }: IconProps) => {
);
};
-export const MoonIcon = ({ style = {}, ...props }: IconProps) => {
- return (
- <svg
- xmlns="http://www.w3.org/2000/svg"
- viewBox="0 0 24 24"
- width="24"
- height="24"
- fill="currentColor"
- style={style}
- {...props}
- >
- <path
- fillRule="evenodd"
- d="M9.549 3.314a.775.775 0 0 1-.136-.855.801.801 0 0 1 .746-.46c3.287.078 6.352 2.081 7.577 5.292 1.608 4.215-.569 8.911-4.862 10.49a8.407 8.407 0 0 1-9.044-2.138.775.775 0 0 1-.137-.855.802.802 0 0 1 .747-.46c.832.02 1.684-.11 2.51-.414 3.465-1.275 5.222-5.066 3.924-8.469a6.6 6.6 0 0 0-1.325-2.13Z"
- clipRule="evenodd"
- />
- </svg>
- );
-};
-
-export const SunIcon = ({ style = {}, ...props }: IconProps) => {
- return (
- <svg
- xmlns="http://www.w3.org/2000/svg"
- viewBox="0 0 24 24"
- width="24"
- height="24"
- fill="currentColor"
- style={style}
- {...props}
- >
- <path
- fillRule="evenodd"
- d="M10.8 2.5a.8.8 0 0 0-1.6 0v.834a.8.8 0 1 0 1.6 0V2.5ZM5.15 4.018a.8.8 0 1 0-1.132 1.131l.678.679a.8.8 0 1 0 1.132-1.132l-.679-.678Zm10.832 1.131a.8.8 0 0 0-1.13-1.131l-.68.678a.8.8 0 1 0 1.132 1.132l.678-.679ZM10 5.867a4.133 4.133 0 1 0 0 8.267 4.133 4.133 0 0 0 0-8.267ZM2.5 9.2a.8.8 0 1 0 0 1.6h.834a.8.8 0 0 0 0-1.6H2.5Zm14.167 0a.8.8 0 1 0 0 1.6h.833a.8.8 0 0 0 0-1.6h-.833ZM5.827 15.31a.8.8 0 0 0-1.13-1.134l-.678.675a.8.8 0 0 0 1.129 1.134l.678-.675Zm9.476-1.134a.8.8 0 1 0-1.129 1.134l.679.675a.8.8 0 1 0 1.128-1.134l-.678-.675ZM10.8 16.667a.8.8 0 1 0-1.6 0v.833a.8.8 0 0 0 1.6 0v-.833Z"
- clipRule="evenodd"
- />
- </svg>
- );
-};
-
export const MoreIcon = ({ style = {}, ...props }: IconProps) => {
return (
<svg
diff --git a/packages/app/src/components/Header/index.tsx b/packages/app/src/components/Header/index.tsx
index b84ac0b4c6..4a982b4366 100644
--- a/packages/app/src/components/Header/index.tsx
+++ b/packages/app/src/components/Header/index.tsx
@@ -1,5 +1,5 @@
import React, { useEffect, useState } from 'react';
-import { LogoIcon, SunIcon, MoonIcon, MoreIcon, ExportIcon } from './icons';
+import { LogoIcon, MoreIcon, ExportIcon } from './icons';
import {
StyledHeader,
StyledTitle,
@@ -10,34 +10,10 @@ import {
IconButton,
} from './styles';
import { Popover } from '@/components/popover';
-import { useTheme } from '@/styles';
import { useEditor } from '@/components/editor-provider';
import EditorModeSwitch from '@/components/editor-mode-switch';
import { EdgelessIcon, PaperIcon } from '../editor-mode-switch/icons';
-
-const DarkModeSwitch = () => {
- const { changeMode, mode } = useTheme();
-
- return (
- <>
- {mode === 'dark' ? (
- <SunIcon
- style={{ cursor: 'pointer', color: '#9096A5' }}
- onClick={() => {
- changeMode('light');
- }}
- ></SunIcon>
- ) : (
- <MoonIcon
- style={{ cursor: 'pointer', color: '#9096A5' }}
- onClick={() => {
- changeMode('dark');
- }}
- ></MoonIcon>
- )}
- </>
- );
-};
+import ThemeModeSwitch from '@/components/theme-mode-switch';
const PopoverContent = () => {
const { editor, mode, setMode } = useEditor();
@@ -109,7 +85,7 @@ export const Header = () => {
</StyledTitle>
<StyledHeaderRightSide>
- <DarkModeSwitch />
+ <ThemeModeSwitch />
<Popover
popoverContent={<PopoverContent />}
style={{ marginLeft: '20px' }}
diff --git a/packages/app/src/components/editor-mode-switch/style.ts b/packages/app/src/components/editor-mode-switch/style.ts
index aea2af5738..f12dd45763 100644
--- a/packages/app/src/components/editor-mode-switch/style.ts
+++ b/packages/app/src/components/editor-mode-switch/style.ts
@@ -3,7 +3,7 @@ import { keyframes, styled } from '@/styles';
import spring, { toString } from 'css-spring';
import type { ItemStatus } from './type';
-const ANIMATE_DURATION = 300;
+const ANIMATE_DURATION = 400;
export const StyledAnimateRadioContainer = styled('div')<{ shrink: boolean }>(
({ shrink }) => {
diff --git a/packages/app/src/components/theme-mode-switch/icons.tsx b/packages/app/src/components/theme-mode-switch/icons.tsx
new file mode 100644
index 0000000000..43d9688d08
--- /dev/null
+++ b/packages/app/src/components/theme-mode-switch/icons.tsx
@@ -0,0 +1,44 @@
+import type { DOMAttributes, CSSProperties } from 'react';
+type IconProps = {
+ style?: CSSProperties;
+} & DOMAttributes<SVGElement>;
+
+export const MoonIcon = ({ style = {}, ...props }: IconProps) => {
+ return (
+ <svg
+ width="20"
+ height="20"
+ viewBox="0 0 20 20"
+ fill="currentColor"
+ xmlns="http://www.w3.org/2000/svg"
+ style={style}
+ {...props}
+ >
+ <path
+ fillRule="evenodd"
+ clipRule="evenodd"
+ d="M9.54893 3.31407C9.33328 3.08158 9.27962 2.74521 9.41255 2.45912C9.54547 2.17302 9.83936 1.99233 10.1595 1.99986C13.4456 2.07712 16.5114 4.08044 17.7359 7.29071C19.3437 11.5057 17.1672 16.2024 12.8744 17.781C9.60251 18.9843 6.04745 18.0285 3.82974 15.6428C3.61375 15.4104 3.55978 15.0739 3.69257 14.7876C3.82537 14.5014 4.11931 14.3205 4.43962 14.3279C5.27228 14.3474 6.12412 14.2171 6.94979 13.9135C10.415 12.6391 12.172 8.84782 10.8741 5.44537C10.5657 4.63692 10.1061 3.91474 9.54893 3.31407Z"
+ />
+ </svg>
+ );
+};
+
+export const SunIcon = ({ style = {}, ...props }: IconProps) => {
+ return (
+ <svg
+ width="20"
+ height="20"
+ viewBox="0 0 20 20"
+ xmlns="http://www.w3.org/2000/svg"
+ fill="currentColor"
+ style={style}
+ {...props}
+ >
+ <path
+ fillRule="evenodd"
+ clipRule="evenodd"
+ d="M10.8002 2.5002C10.8002 2.05837 10.442 1.7002 10.0002 1.7002C9.55837 1.7002 9.2002 2.05837 9.2002 2.5002V3.33353C9.2002 3.77536 9.55837 4.13353 10.0002 4.13353C10.442 4.13353 10.8002 3.77536 10.8002 3.33353V2.5002ZM5.14921 4.01784C4.83679 3.70542 4.33026 3.70542 4.01784 4.01784C3.70542 4.33026 3.70542 4.83679 4.01784 5.14921L4.69627 5.82764C5.00869 6.14006 5.51522 6.14006 5.82764 5.82764C6.14006 5.51522 6.14006 5.00869 5.82764 4.69627L5.14921 4.01784ZM15.9825 5.1492C16.2949 4.83678 16.2949 4.33025 15.9825 4.01783C15.6701 3.70542 15.1636 3.70543 14.8511 4.01785L14.1727 4.69628C13.8603 5.00871 13.8603 5.51524 14.1728 5.82765C14.4852 6.14007 14.9917 6.14006 15.3041 5.82763L15.9825 5.1492ZM10.0002 5.86686C7.71742 5.86686 5.86686 7.71742 5.86686 10.0002C5.86686 12.283 7.71742 14.1335 10.0002 14.1335C12.283 14.1335 14.1335 12.283 14.1335 10.0002C14.1335 7.71742 12.283 5.86686 10.0002 5.86686ZM2.5002 9.2002C2.05837 9.2002 1.7002 9.55837 1.7002 10.0002C1.7002 10.442 2.05837 10.8002 2.5002 10.8002H3.33353C3.77536 10.8002 4.13353 10.442 4.13353 10.0002C4.13353 9.55837 3.77536 9.2002 3.33353 9.2002H2.5002ZM16.6669 9.2002C16.225 9.2002 15.8669 9.55837 15.8669 10.0002C15.8669 10.442 16.225 10.8002 16.6669 10.8002H17.5002C17.942 10.8002 18.3002 10.442 18.3002 10.0002C18.3002 9.55837 17.942 9.2002 17.5002 9.2002H16.6669ZM5.82623 15.309C6.13943 14.9973 6.14069 14.4908 5.82906 14.1776C5.51742 13.8644 5.01089 13.8631 4.69769 14.1748L4.01926 14.8498C3.70606 15.1615 3.70479 15.668 4.01643 15.9812C4.32807 16.2944 4.8346 16.2956 5.1478 15.984L5.82623 15.309ZM15.3027 14.1748C14.9895 13.8631 14.483 13.8644 14.1713 14.1776C13.8597 14.4908 13.861 14.9973 14.1742 15.3089L14.8526 15.984C15.1658 16.2956 15.6723 16.2944 15.9839 15.9812C16.2956 15.668 16.2943 15.1615 15.9811 14.8498L15.3027 14.1748ZM10.8002 16.6669C10.8002 16.225 10.442 15.8669 10.0002 15.8669C9.55837 15.8669 9.2002 16.225 9.2002 16.6669V17.5002C9.2002 17.942 9.55837 18.3002 10.0002 18.3002C10.442 18.3002 10.8002 17.942 10.8002 17.5002V16.6669Z"
+ />
+ </svg>
+ );
+};
diff --git a/packages/app/src/components/theme-mode-switch/index.tsx b/packages/app/src/components/theme-mode-switch/index.tsx
new file mode 100644
index 0000000000..324a3cfdae
--- /dev/null
+++ b/packages/app/src/components/theme-mode-switch/index.tsx
@@ -0,0 +1,46 @@
+import { useState } from 'react';
+import { useTheme } from '@/styles';
+import { MoonIcon, SunIcon } from './icons';
+import { StyledThemeModeSwitch, StyledSwitchItem } from './style';
+
+export const ThemeModeSwitch = () => {
+ const { mode, changeMode } = useTheme();
+ const [isHover, setIsHover] = useState(false);
+ const [firstTrigger, setFirstTrigger] = useState(false);
+ return (
+ <StyledThemeModeSwitch
+ onMouseEnter={() => {
+ setIsHover(true);
+ if (!firstTrigger) {
+ setFirstTrigger(true);
+ }
+ }}
+ onMouseLeave={() => {
+ setIsHover(false);
+ }}
+ >
+ <StyledSwitchItem
+ active={mode === 'light'}
+ isHover={isHover}
+ firstTrigger={firstTrigger}
+ onClick={() => {
+ changeMode('light');
+ }}
+ >
+ <SunIcon />
+ </StyledSwitchItem>
+ <StyledSwitchItem
+ active={mode === 'dark'}
+ isHover={isHover}
+ firstTrigger={firstTrigger}
+ onClick={() => {
+ changeMode('dark');
+ }}
+ >
+ <MoonIcon />
+ </StyledSwitchItem>
+ </StyledThemeModeSwitch>
+ );
+};
+
+export default ThemeModeSwitch;
diff --git a/packages/app/src/components/theme-mode-switch/style.ts b/packages/app/src/components/theme-mode-switch/style.ts
new file mode 100644
index 0000000000..605fd304e2
--- /dev/null
+++ b/packages/app/src/components/theme-mode-switch/style.ts
@@ -0,0 +1,67 @@
+import { keyframes, styled } from '@/styles';
+import { CSSProperties } from 'react';
+// @ts-ignore
+import spring, { toString } from 'css-spring';
+
+const ANIMATE_DURATION = 400;
+
+export const StyledThemeModeSwitch = styled('div')({
+ width: '32px',
+ height: '32px',
+ borderRadius: '5px',
+ overflow: 'hidden',
+ backgroundColor: 'transparent',
+ position: 'relative',
+});
+export const StyledSwitchItem = styled('div')<{
+ active: boolean;
+ isHover: boolean;
+ firstTrigger: boolean;
+}>(({ active, isHover, firstTrigger, theme }) => {
+ const activeRaiseAnimate = keyframes`${toString(
+ spring({ top: '0' }, { top: '-100%' }, { preset: 'gentle' })
+ )}`;
+ const raiseAnimate = keyframes`${toString(
+ spring({ top: '100%' }, { top: '0' }, { preset: 'gentle' })
+ )}`;
+ const activeDeclineAnimate = keyframes`${toString(
+ spring({ top: '-100%' }, { top: '0' }, { preset: 'gentle' })
+ )}`;
+ const declineAnimate = keyframes`${toString(
+ spring({ top: '0' }, { top: '100%' }, { preset: 'gentle' })
+ )}`;
+ const activeStyle = active
+ ? {
+ color: theme.colors.disabled,
+ top: '0',
+ animation: firstTrigger
+ ? `${
+ isHover ? activeRaiseAnimate : activeDeclineAnimate
+ } ${ANIMATE_DURATION}ms forwards`
+ : 'unset',
+ animationDirection: isHover ? 'normal' : 'alternate',
+ }
+ : ({
+ top: '100%',
+ color: theme.colors.highlight,
+ backgroundColor: theme.colors.hoverBackground,
+ animation: firstTrigger
+ ? `${
+ isHover ? raiseAnimate : declineAnimate
+ } ${ANIMATE_DURATION}ms forwards`
+ : 'unset',
+ animationDirection: isHover ? 'normal' : 'alternate',
+ } as CSSProperties);
+
+ return {
+ width: '32px',
+ height: '32px',
+ display: 'flex',
+ position: 'absolute',
+ left: '0',
+ justifyContent: 'center',
+ alignItems: 'center',
+ cursor: 'pointer',
+ ...activeStyle,
+ };
+});
diff --git a/packages/app/src/pages/affine.tsx b/packages/app/src/pages/affine.tsx
index 73b35a6689..2d5bbe9b30 100644
--- a/packages/app/src/pages/affine.tsx
+++ b/packages/app/src/pages/affine.tsx
@@ -1,5 +1,23 @@
+import { styled } from '@/styles';
+import { ThemeModeSwitch } from '@/components/theme-mode-switch';
+
+export const StyledHeader = styled('div')({
+ height: '60px',
+ width: '100vw',
+ display: 'flex',
+ justifyContent: 'space-between',
+ alignItems: 'center',
+ position: 'relative',
+ padding: '0 22px',
+ borderBottom: '1px solid #e5e5e5',
+});
+
const Affine = () => {
- return <div>affine page</div>;
+ return (
+ <StyledHeader>
+ <ThemeModeSwitch></ThemeModeSwitch>
+ </StyledHeader>
+ );
};
export default Affine;
diff --git a/packages/app/src/styles/theme.ts b/packages/app/src/styles/theme.ts
index 5b00dd2583..464403c3c1 100644
--- a/packages/app/src/styles/theme.ts
+++ b/packages/app/src/styles/theme.ts
@@ -7,6 +7,7 @@ export const lightTheme: AffineTheme = {
highlight: '#7389FD',
disabled: '#9096A5',
background: '#fff',
+ hoverBackground: '#F1F3FF',
},
font: {
xs: '12px',
@@ -22,6 +23,7 @@ export const darkTheme: AffineTheme = {
highlight: '#7389FD',
disabled: '#9096A5',
background: '#3d3c3f',
+ hoverBackground: '#F1F3FF',
},
};
diff --git a/packages/app/src/styles/types.ts b/packages/app/src/styles/types.ts
index 7c042957c5..9eec4c335c 100644
--- a/packages/app/src/styles/types.ts
+++ b/packages/app/src/styles/types.ts
@@ -17,6 +17,7 @@ export interface AffineTheme {
highlight: string;
disabled: string;
background: string;
+ hoverBackground: string;
};
font: {
xs: string; // tiny