import { ChartContext, Flavor } from './contexts' import { ReactNode, useEffect, useState } from 'react' import { Route, Routes, useLocation } from 'react-router-dom' import { css } from 'otion' type ChartContainerProps = { children: ReactNode title: ReactNode } type ButtonProps = { children: ReactNode onClick: () => void } const canvases = [ 'bar', 'calendar', 'chord', 'choropleth', 'circle-packing', 'geomap', 'heatmap', 'line', 'network', 'parallel-coordinates', 'pie', 'scatterplot', 'swarmplot', 'treemap', 'waffle', ] const htmls = ['circle-packing', 'treemap', 'waffle'] function Button({ children, onClick }: ButtonProps) { const [isPressing, setIsPressing] = useState(false) useEffect(() => { const timeout = setTimeout(() => { setIsPressing(false) }, 250) return () => clearTimeout(timeout) }, [isPressing]) return ( ) } export default function ChartContainer({ children, title, }: ChartContainerProps) { const [key, setKey] = useState(0) const [flavor, setFlavor] = useState('svg') const { pathname } = useLocation() useEffect(() => { setFlavor('svg') }, [pathname]) return ( {title}
setKey((state) => state + 1)}> Generate Data } /> {canvases.map((path) => ( setFlavor((value) => value !== 'canvas' ? 'canvas' : 'svg' ) }> Use {flavor !== 'canvas' ? 'Canvas' : 'SVG'} } /> ))} {htmls.map((path) => ( setFlavor((value) => (value !== 'html' ? 'html' : 'svg')) }> Use {flavor !== 'html' ? 'HTML' : 'SVG'} } /> ))}
{children}
) }