Skip to content

Commit b51a9a6

Browse files
committed
type(theme): fix type error. (#444)
1 parent 6048cd0 commit b51a9a6

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

themes/theme/src/index.tsx

+13-7
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ type Theme = 'light' | 'dark';
2020

2121
export interface Settings {
2222
/** Editor background. */
23-
background: string;
23+
background?: string;
2424
/** Default text color. */
25-
foreground: string;
25+
foreground?: string;
2626
/** Caret color. */
2727
caret?: string;
2828
/** Selection background. */
@@ -43,14 +43,20 @@ export interface Settings {
4343
fontFamily?: string;
4444
}
4545

46-
export const createTheme = ({ theme, settings, styles }: CreateThemeOptions): Extension => {
46+
export const createTheme = ({ theme, settings = {}, styles = [] }: CreateThemeOptions): Extension => {
4747
const themeOptions: Record<string, StyleSpec> = {
48-
'&': {
49-
backgroundColor: settings.background,
50-
color: settings.foreground,
51-
},
5248
'.cm-gutters': {},
5349
};
50+
const baseStyle: StyleSpec = {};
51+
if (settings.background) {
52+
baseStyle.backgroundColor = settings.background;
53+
}
54+
if (settings.foreground) {
55+
baseStyle.color = settings.foreground;
56+
}
57+
if (settings.background || settings.foreground) {
58+
themeOptions['&'] = baseStyle;
59+
}
5460

5561
if (settings.fontFamily) {
5662
themeOptions['&.cm-editor .cm-scroller'] = {

0 commit comments

Comments
 (0)