@@ -41,51 +41,67 @@ import { Virtuoso } from 'react-virtuoso';
4141import { DropdownMenu } from './menu' ;
4242import * as styles from './style.css' ;
4343
44+ const getLabel = ( fontKey : FontFamily , t : ReturnType < typeof useI18n > ) => {
45+ switch ( fontKey ) {
46+ case 'Sans' :
47+ return t [ 'com.affine.appearanceSettings.fontStyle.sans' ] ( ) ;
48+ case 'Serif' :
49+ return t [ 'com.affine.appearanceSettings.fontStyle.serif' ] ( ) ;
50+ case 'Mono' :
51+ return t [ `com.affine.appearanceSettings.fontStyle.mono` ] ( ) ;
52+ case 'Custom' :
53+ return t [ 'com.affine.settings.editorSettings.edgeless.custom' ] ( ) ;
54+ default :
55+ return '' ;
56+ }
57+ } ;
58+
59+ export const getBaseFontStyleOptions = (
60+ t : ReturnType < typeof useI18n >
61+ ) : Array < Omit < RadioItem , 'value' > & { value : FontFamily } > => {
62+ return fontStyleOptions
63+ . map ( ( { key, value } ) => {
64+ if ( key === 'Custom' ) {
65+ return null ;
66+ }
67+ const label = getLabel ( key , t ) ;
68+ return {
69+ value : key ,
70+ label,
71+ testId : 'system-font-style-trigger' ,
72+ style : {
73+ fontFamily : value ,
74+ } ,
75+ } satisfies RadioItem ;
76+ } )
77+ . filter ( item => item !== null ) ;
78+ } ;
79+
4480const FontFamilySettings = ( ) => {
4581 const t = useI18n ( ) ;
4682 const { editorSettingService } = useServices ( { EditorSettingService } ) ;
4783 const settings = useLiveData ( editorSettingService . editorSetting . settings$ ) ;
4884
49- const getLabel = useCallback (
50- ( fontKey : FontFamily ) => {
51- switch ( fontKey ) {
52- case 'Sans' :
53- return t [ 'com.affine.appearanceSettings.fontStyle.sans' ] ( ) ;
54- case 'Serif' :
55- return t [ 'com.affine.appearanceSettings.fontStyle.serif' ] ( ) ;
56- case 'Mono' :
57- return t [ `com.affine.appearanceSettings.fontStyle.mono` ] ( ) ;
58- case 'Custom' :
59- return t [ 'com.affine.settings.editorSettings.edgeless.custom' ] ( ) ;
60- default :
61- return '' ;
62- }
63- } ,
64- [ t ]
65- ) ;
66-
6785 const radioItems = useMemo ( ( ) => {
68- return fontStyleOptions
69- . map ( ( { key, value } ) => {
70- if ( key === 'Custom' && ! environment . isDesktop ) {
71- return null ;
72- }
73- const label = getLabel ( key ) ;
74- let fontFamily = value ;
75- if ( key === 'Custom' && settings . customFontFamily ) {
76- fontFamily = `${ settings . customFontFamily } , ${ value } ` ;
77- }
78- return {
79- value : key ,
80- label,
81- testId : 'system-font-style-trigger' ,
82- style : {
83- fontFamily,
84- } ,
85- } satisfies RadioItem ;
86- } )
87- . filter ( item => item !== null ) ;
88- } , [ getLabel , settings . customFontFamily ] ) ;
86+ const items = getBaseFontStyleOptions ( t ) ;
87+ if ( ! environment . isDesktop ) return items ;
88+
89+ // resolve custom fonts
90+ const customOption = fontStyleOptions . find ( opt => opt . key === 'Custom' ) ;
91+ if ( customOption ) {
92+ const fontFamily = settings . customFontFamily
93+ ? `${ settings . customFontFamily } , ${ customOption . value } `
94+ : customOption . value ;
95+ items . push ( {
96+ value : customOption . key ,
97+ label : getLabel ( customOption . key , t ) ,
98+ testId : 'system-font-style-trigger' ,
99+ style : { fontFamily } ,
100+ } ) ;
101+ }
102+
103+ return items ;
104+ } , [ settings . customFontFamily , t ] ) ;
89105
90106 const handleFontFamilyChange = useCallback (
91107 ( value : FontFamily ) => {
0 commit comments