From 9ef492f5f8b6c837e0d7e357e5a17007a56bb0e5 Mon Sep 17 00:00:00 2001 From: Qi <474021214@qq.com> Date: Fri, 7 Jul 2023 19:59:38 +0800 Subject: [PATCH] feat: add font style setting (#3092) (cherry picked from commit b12412a3c136c2ff4822c88bf73f6b9d3687b461) --- apps/web/src/atoms/settings.ts | 11 +++++ .../general-setting/appearance/index.tsx | 47 +++++++++++++++++++ packages/component/package.json | 2 +- packages/i18n/src/resources/en.json | 4 +- yarn.lock | 10 ++-- 5 files changed, 67 insertions(+), 7 deletions(-) diff --git a/apps/web/src/atoms/settings.ts b/apps/web/src/atoms/settings.ts index 8253f88c3c..ca07ad5086 100644 --- a/apps/web/src/atoms/settings.ts +++ b/apps/web/src/atoms/settings.ts @@ -15,6 +15,7 @@ export type AppSetting = { clientBorder: boolean; fullWidthLayout: boolean; windowFrameStyle: 'frameless' | 'NativeTitleBar'; + fontStyle: 'Sans' | 'Serif' | 'Mono'; dateFormat: DateFormats; startWeekOnMonday: boolean; enableBlurBackground: boolean; @@ -37,10 +38,20 @@ export const dateFormatOptions: DateFormats[] = [ 'dd MMMM YYYY', ]; +export const fontStyleOptions: { + key: AppSetting['fontStyle']; + value: string; +}[] = [ + { key: 'Sans', value: 'var(--affine-font-sans-family)' }, + { key: 'Serif', value: 'var(--affine-font-serif-family)' }, + { key: 'Mono', value: 'var(--affine-font-mono-family)' }, +]; + export const AppSettingAtom = atomWithStorage('AFFiNE settings', { clientBorder: false, fullWidthLayout: false, windowFrameStyle: 'frameless', + fontStyle: 'Sans', dateFormat: dateFormatOptions[0], startWeekOnMonday: false, enableBlurBackground: true, diff --git a/apps/web/src/components/affine/setting-modal/general-setting/appearance/index.tsx b/apps/web/src/components/affine/setting-modal/general-setting/appearance/index.tsx index 5680f43490..acf00e88b6 100644 --- a/apps/web/src/components/affine/setting-modal/general-setting/appearance/index.tsx +++ b/apps/web/src/components/affine/setting-modal/general-setting/appearance/index.tsx @@ -8,6 +8,7 @@ import { useCallback } from 'react'; import { type AppSetting, + fontStyleOptions, useAppSetting, windowFrameStyleOptions, } from '../../../../../atoms/settings'; @@ -48,6 +49,46 @@ export const ThemeSettings = () => { ); }; +const FontFamilySettings = () => { + const [appSettings, setAppSettings] = useAppSetting(); + return ( + { + const value = fontStyleOptions.find(option => option.key === key) + ?.value; + + setAppSettings({ fontStyle: key }); + + document + .querySelector('html') + ?.style.setProperty('--affine-font-family', value || null); + }, + [setAppSettings] + )} + > + {fontStyleOptions.map(({ key, value }) => { + return ( + + {key} + + ); + })} + + ); +}; + export const AppearanceSettings = () => { const t = useAFFiNEI18N(); @@ -72,6 +113,12 @@ export const AppearanceSettings = () => { > + + +