Skip to content

Commit bcea0a6

Browse files
committed
feat(chart): improve chart dark theme
1 parent 30b5677 commit bcea0a6

8 files changed

+114
-489
lines changed

src/App.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@import "./styles/highcharts.scss";
2+
13
.App {
24
p {
35
margin: 2vh 4vw;

src/components/MusicChart.tsx

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
/** @jsxImportSource @emotion/react */
22
import { css, SerializedStyles } from '@emotion/react';
3-
import React, { useEffect } from 'react';
3+
import React, { useEffect, useState } from 'react';
44
import Highcharts from 'highcharts';
55
import HighchartsReact from 'highcharts-react-official';
66
import { useTheme } from '../context/ThemeContext';
7-
import { themeGlobalDark, themeGlobalLight } from './charts/ChartTheme';
87

98
interface IMusicChartProps {
109
styles?: SerializedStyles;
@@ -14,15 +13,14 @@ interface IMusicChartProps {
1413

1514
export const MusicChart: React.FC<IMusicChartProps> = (props) => {
1615
const appTheme = useTheme();
16+
const [classTheme, setClassTheme] = useState('');
1717

1818
useEffect(() => {
19-
const themeConfig = appTheme.darkMode ? themeGlobalDark : themeGlobalLight;
20-
const newOptions = {
21-
...props.options,
22-
...themeConfig,
23-
};
24-
props.chartComponent.current?.chart?.update(newOptions);
25-
}, [props.chartComponent, props.options, appTheme]);
19+
const themeClass = appTheme.darkMode
20+
? 'highcharts-dark'
21+
: 'highcharts-light';
22+
setClassTheme(themeClass);
23+
}, [appTheme]);
2624

2725
return (
2826
<div
@@ -39,7 +37,7 @@ export const MusicChart: React.FC<IMusicChartProps> = (props) => {
3937
>
4038
<HighchartsReact
4139
containerProps={{
42-
className: 'react-highcharts-container',
40+
className: `react-highcharts-container ${classTheme}`,
4341
style: { width: '100%', height: '100%' },
4442
}}
4543
highcharts={Highcharts}

0 commit comments

Comments
 (0)