Skip to content

Commit a0c5292

Browse files
committed
Using new theme prop
1 parent 6852230 commit a0c5292

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

chartlets.js/src/lib/components/Plot.tsx

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,43 @@
11
import { VegaLite } from "react-vega";
22
import type { TopLevelSpec } from "vega-lite";
3+
import * as vegaThemes from "vega-themes";
34
import { useTheme } from "@mui/material";
45

56
import { type ComponentState } from "@/lib/types/state/component";
67
import type { ComponentProps } from "@/lib/component/Component";
78
import { useSignalListeners } from "@/lib/hooks";
89

10+
type VegaTheme = Omit<typeof vegaThemes, "version">;
11+
12+
const isVegaTheme = (key?: string): key is keyof VegaTheme =>
13+
!!key && key in vegaThemes;
14+
915
interface PlotState extends ComponentState {
16+
theme?: string;
1017
chart?:
1118
| TopLevelSpec // This is the vega-lite specification type
1219
| null;
1320
}
1421

1522
interface PlotProps extends ComponentProps, PlotState {}
1623

17-
export function Plot({ type, id, style, chart, onChange }: PlotProps) {
24+
export function Plot({ type, id, style, theme, chart, onChange }: PlotProps) {
1825
const muiTheme = useTheme();
1926
const signalListeners = useSignalListeners(chart, type, id, onChange);
2027

2128
if (!chart) {
2229
return <div id={id} style={style} />;
2330
}
2431

32+
const vegaTheme = isVegaTheme(theme)
33+
? theme
34+
: muiTheme.palette.mode === "dark"
35+
? "dark"
36+
: undefined;
37+
2538
return (
2639
<VegaLite
27-
theme={muiTheme.palette.mode === "dark" ? "dark" : undefined}
40+
theme={vegaTheme}
2841
spec={chart}
2942
style={style}
3043
signalListeners={signalListeners}

0 commit comments

Comments
 (0)