Chart Toolbar
boldkit/chart-toolbarFreeComponent
Brutalist chart toolbar overlay — export the wrapped chart as PNG or SVG, download its data as CSV, and toggle fullscreen.
Live preview
live · rendered by the registry
Rendered by boldkit on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://boldkit.dev/r/chart-toolbar.jsonSource
1import * as React from 'react'2import { Download, Image, FileText, Maximize } from 'lucide-react'3import { cn } from '@/lib/utils'4import { Button } from '@/components/ui/button'5import {6 downloadCSV,7 exportPNG,8 exportSVG,9 toggleFullscreen,10} from '@/lib/chart-export'1112export interface ChartToolbarProps extends React.HTMLAttributes<HTMLDivElement> {13 /** Rows fed to the chart — enables the CSV export button when provided. */14 data?: Array<Record<string, unknown>>15 /** Base filename (no extension) for exports. Default 'chart'. */16 filename?: string17 /** Show the PNG export button. Default true. */18 png?: boolean19 /** Show the SVG export button. Default true (no-ops for canvas engines). */20 svg?: boolean21 /** Show the fullscreen toggle. Default true. */22 fullscreen?: boolean23}2425/**26 * Wraps a chart and overlays a brutalist export toolbar (PNG / SVG / CSV /27 * fullscreen). Framework-agnostic under the hood — works with any chart that28 * renders an <svg> (Recharts) or <canvas> into the wrapped container.29 *30 * <ChartToolbar data={rows} filename="sales">31 * <ChartContainer config={config}>…</ChartContainer>32 * </ChartToolbar>33 */34export const ChartToolbar = React.forwardRef<HTMLDivElement, ChartToolbarProps>(35 (36 { data, filename = 'chart', png = true, svg = true, fullscreen = true, className, children, ...props },37 ref38 ) => {39 const innerRef = React.useRef<HTMLDivElement | null>(null)40 React.useImperativeHandle(ref, () => innerRef.current as HTMLDivElement)4142 const withContainer = (fn: (el: HTMLElement) => void) => () => {43 const el = innerRef.current44 if (el) fn(el)45 }4647 return (48 <div ref={innerRef} className={cn('relative', className)} {...props}>49 <div data-chart-export-controls className="absolute right-2 top-2 z-10 flex gap-1">50 {png && (51 <Button52 type="button"53 variant="outline"54 size="icon"55 className="h-8 w-8"56 aria-label="Export chart as PNG"57 title="Export PNG"58 onClick={withContainer((el) => void exportPNG(el, `${filename}.png`))}59 >60 <Image />61 </Button>62 )}63 {svg && (64 <Button65 type="button"66 variant="outline"67 size="icon"68 className="h-8 w-8"69 aria-label="Export chart as SVG"70 title="Export SVG"71// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from boldkit
All 94 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | boldkit | Components | Free | 2 deps | |
| Alertalert | boldkit | Components | Free | 2 deps | |
| Alert Dialogalert-dialog | boldkit | Components | Free | 1 dep | |
| ASCII Shapesascii-shapes | boldkit | Components | Free | no deps | |
| Aspect Ratioaspect-ratio | boldkit | Components | Free | 1 dep | |
| Avataravatar | boldkit | Components | Free | 1 dep | |
| Badgebadge | boldkit | Components | Free | 1 dep | |
| Breadcrumbbreadcrumb | boldkit | Components | Free | 2 deps |
