Skip to content

Commit 5d7243c

Browse files
committed
feat: g2 default theme follow streamlit
1 parent e875d59 commit 5d7243c

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

streamlit_g2/__init__.py

-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,6 @@ def st_g2(options, style=None, key=None):
8383

8484
options = {
8585
"autoFit": True,
86-
"theme": "dark",
8786
"type": "interval",
8887
"data": [
8988
{ "genre": "Sports", "sold": 275 },

streamlit_g2/frontend/src/g2.tsx

+11-2
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,25 @@ import {
33
Streamlit,
44
withStreamlitConnection,
55
ComponentProps,
6+
Theme,
67
} from 'streamlit-component-lib';
78
import { Chart } from '@berryv/g2-react';
89

10+
/**
11+
* G2 Theme follow streamlit.
12+
*/
13+
function getDefaultTheme(theme: Theme | undefined): 'dark' | 'light' {
14+
return theme?.base === 'dark' ? 'dark' : 'light';
15+
}
16+
917
const G2Component: React.FC<ComponentProps> = (props) => {
10-
const { style, options } = props.args
18+
const { theme, args } = props;
19+
const { style, options } = args;
1120

1221
return (
1322
<Chart
1423
style={{width: '100%', height: 400, ...style}}
15-
options={options}
24+
options={{ theme: getDefaultTheme(theme), ...options }}
1625
onInit={() => Streamlit.setFrameHeight()}
1726
/>
1827
)

0 commit comments

Comments
 (0)