From b51a9a6293d26009b0915fc88f4d3b11932c34e1 Mon Sep 17 00:00:00 2001 From: jaywcjlove <398188662@qq.com> Date: Tue, 17 Jan 2023 18:28:44 +0800 Subject: [PATCH] type(theme): fix type error. (#444) --- themes/theme/src/index.tsx | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/themes/theme/src/index.tsx b/themes/theme/src/index.tsx index 0d7f373c8..216898f6e 100644 --- a/themes/theme/src/index.tsx +++ b/themes/theme/src/index.tsx @@ -20,9 +20,9 @@ type Theme = 'light' | 'dark'; export interface Settings { /** Editor background. */ - background: string; + background?: string; /** Default text color. */ - foreground: string; + foreground?: string; /** Caret color. */ caret?: string; /** Selection background. */ @@ -43,14 +43,20 @@ export interface Settings { fontFamily?: string; } -export const createTheme = ({ theme, settings, styles }: CreateThemeOptions): Extension => { +export const createTheme = ({ theme, settings = {}, styles = [] }: CreateThemeOptions): Extension => { const themeOptions: Record = { - '&': { - backgroundColor: settings.background, - color: settings.foreground, - }, '.cm-gutters': {}, }; + const baseStyle: StyleSpec = {}; + if (settings.background) { + baseStyle.backgroundColor = settings.background; + } + if (settings.foreground) { + baseStyle.color = settings.foreground; + } + if (settings.background || settings.foreground) { + themeOptions['&'] = baseStyle; + } if (settings.fontFamily) { themeOptions['&.cm-editor .cm-scroller'] = {