Skip to content

Commit

Permalink
make mode an optional property on any theme provided to CodeBlock
Browse files Browse the repository at this point in the history
thomasmost committed Jul 25, 2023

Unverified

This user has not yet uploaded their public signing key.
1 parent fae8f1a commit 072f5f5
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 4 additions & 0 deletions packages/react-code-blocks/src/types.ts
Original file line number Diff line number Diff line change
@@ -42,6 +42,10 @@ export interface CodeBlockTheme {

export type ThemeModes = 'light' | 'dark';
export interface Theme extends CodeBlockTheme {
mode?: ThemeModes;
}

export interface ModeSafeTheme extends Theme {
mode: ThemeModes;
}

6 changes: 3 additions & 3 deletions packages/react-code-blocks/src/utils/getTheme.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { ThemeProps, Theme } from 'types';
import { ThemeProps, ModeSafeTheme } from 'types';

const DEFAULT_THEME_MODE = 'light';

// Resolves the different types of theme objects in the current API
export default function getTheme(props?: ThemeProps): Theme {
export default function getTheme(props?: ThemeProps): ModeSafeTheme {
// If format not supported (or no theme provided), return standard theme
return { mode: DEFAULT_THEME_MODE, ...props?.theme };
return { mode: DEFAULT_THEME_MODE, ...props?.theme } as ModeSafeTheme;
}
3 changes: 2 additions & 1 deletion packages/react-code-blocks/src/utils/themed.ts
Original file line number Diff line number Diff line change
@@ -12,6 +12,7 @@ export default function themed(modesOrVariant: {
| undefined
) {
var theme = getTheme(props);
return modes[theme.mode];
let themeMode = theme.mode;
return modes[themeMode];
};
}

0 comments on commit 072f5f5

Please sign in to comment.