/** * @upsetjs/react * https://github.com/upsetjs/upsetjs * * Copyright (c) 2021 Samuel Gratzl */ import React from 'react'; import type { UpSetExportOptions } from '../interfaces'; export default function ExportButtons({ transform, styleId, exportButtons, exportChart, }: { transform: string; styleId: string; exportButtons?: boolean | UpSetExportOptions; exportChart: (evt: React.MouseEvent) => void; }) { if (!exportButtons) { return null; } const svgWidth = 26; const pngWidth = 26; const vegaWidth = 34; const dumpWidth = 34; const shareWidth = 42; const space = 2; let acc = 0; const buttons: React.ReactNode[] = []; if (exportButtons === true || exportButtons.svg !== false) { acc += svgWidth; buttons.push( Download SVG Image SVG ); acc += space; } if (exportButtons === true || exportButtons.png !== false) { acc += pngWidth; buttons.push( Download PNG Image PNG ); acc += space; } if (exportButtons === true || exportButtons.vega !== false) { acc += vegaWidth; buttons.push( Download VEGA-Lite Specification VEGA ); acc += space; } if (exportButtons === true || exportButtons.dump !== false) { acc += dumpWidth; buttons.push( Download UpSet.js JSON Dump DUMP ); acc += space; } if (exportButtons === true || exportButtons.share !== false) { acc += shareWidth; buttons.push( Open a shareable URL SHARE ); acc += space; } return ( {buttons} ); }