Skip to content

Commit

Permalink
wip: toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
lvisei committed Dec 6, 2024
1 parent 70a7ac0 commit 0c6ef13
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/ChartCodeRender/Toolbar.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import styled from 'styled-components';

const StyledToolbar = styled.div`
position: absolute;
top: 10px;
right: 10px;
`;

const Toolbar = () => {
return <StyledToolbar className="gpt-vis-toolbar"></StyledToolbar>;
};

export default Toolbar;
8 changes: 7 additions & 1 deletion src/ChartCodeRender/VisChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const StyledGPTVis = styled.div`
min-width: 300px;
height: 300px;
max-width: 100%;
position: relative;
`;
const GlobalStyles = createGlobalStyle`
pre:has(.gpt-vis) {
Expand All @@ -17,13 +18,14 @@ const GlobalStyles = createGlobalStyle`
type RenderVisChartProps = {
content: string;
components: ChartComponents;
toolbar: React.FC<any>;
debug?: boolean;
loadingTimeout: number;
style?: React.CSSProperties;
};

export const RenderVisChart: React.FC<RenderVisChartProps> = memo(
({ style, content, components, debug, loadingTimeout }) => {
({ style, content, components, debug, loadingTimeout, toolbar }) => {
const timeoutRef = useRef<NodeJS.Timeout>();
const [loading, setLoading] = useState(true);
let chartJson: ChartJson;
Expand Down Expand Up @@ -66,10 +68,14 @@ export const RenderVisChart: React.FC<RenderVisChartProps> = memo(
return <p>{`Chart type "${type}" is not supported.`}</p>;
}

const Toolbar = toolbar;
console.log('Toolbar: ', Toolbar);

// Render the supported chart component with data
return (
<StyledGPTVis className="gpt-vis" style={style}>
<GlobalStyles />
<Toolbar />
<ChartComponent {...chartProps} />
</StyledGPTVis>
);
Expand Down
2 changes: 2 additions & 0 deletions src/ChartCodeRender/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { get } from 'lodash';
import React from 'react';
import { DEFAULT_CHART_COMPONENTS } from '../export';
import Toolbar from './Toolbar';
import type { CodeBlockComponent, WithChartCodeOptions } from './type';
import { RenderVisChart } from './VisChart';

Expand Down Expand Up @@ -38,6 +39,7 @@ const withCodeBlock = (options: WithChartCodeOptions): CodeBlockComponent => {
components={components}
debug={debug}
loadingTimeout={loadingTimeout}
toolbar={Toolbar}
/>
);
}
Expand Down

0 comments on commit 0c6ef13

Please sign in to comment.