/* * SPDX-FileCopyrightText: 2024 The Refinery Authors * * SPDX-License-Identifier: EPL-2.0 */ import ChevronRightIcon from '@mui/icons-material/ChevronRight'; import ContentCopyIcon from '@mui/icons-material/ContentCopy'; import DarkModeIcon from '@mui/icons-material/DarkMode'; import ImageIcon from '@mui/icons-material/Image'; import LightModeIcon from '@mui/icons-material/LightMode'; import SaveAltIcon from '@mui/icons-material/SaveAlt'; import ShapeLineIcon from '@mui/icons-material/ShapeLine'; import Box from '@mui/material/Box'; import Button from '@mui/material/Button'; import FormControlLabel from '@mui/material/FormControlLabel'; import Slider from '@mui/material/Slider'; import Stack from '@mui/material/Stack'; import Switch from '@mui/material/Switch'; import ToggleButton from '@mui/material/ToggleButton'; import ToggleButtonGroup from '@mui/material/ToggleButtonGroup'; import Typography from '@mui/material/Typography'; import { styled } from '@mui/material/styles'; import { observer } from 'mobx-react-lite'; import { useCallback } from 'react'; import { useRootStore } from '../RootStoreProvider'; import getLogger from '../utils/getLogger'; import type GraphStore from './GraphStore'; import SlideInPanel from './SlideInPanel'; import exportDiagram from './exportDiagram'; const log = getLogger('graph.ExportPanel'); const SwitchButtonGroup = styled(ToggleButtonGroup, { name: 'ExportPanel-SwitchButtonGroup', })(({ theme }) => ({ marginTop: theme.spacing(2), marginInline: theme.spacing(2), minWidth: '260px', '.MuiToggleButton-root': { width: '100%', fontSize: '1rem', lineHeight: '1.5', }, '& svg': { margin: '0 6px 0 0', }, })); function getLabel(value: number): string { return `${value}%`; } const marks = [100, 200, 300, 400].map((value) => ({ value, label: ( {getLabel(value)} ), })); function ExportPanel({ graph, svgContainer, dialog, }: { graph: GraphStore; svgContainer: HTMLElement | undefined; dialog: boolean; }): JSX.Element { const { exportSettingsStore } = useRootStore(); const icon = useCallback( (show: boolean) => show && !dialog ? : , [dialog], ); const { format } = exportSettingsStore; const emptyGraph = graph.semantics.nodes.length === 0; const buttons = useCallback( (close: () => void) => ( <> {'write' in navigator.clipboard && format === 'png' && ( )} ), [svgContainer, graph, exportSettingsStore, format, emptyGraph], ); return ( exportSettingsStore.setFormat('svg')} > SVG exportSettingsStore.setFormat('png')} > PNG exportSettingsStore.setTheme('light')} > Light exportSettingsStore.setTheme('dark')} > Dark exportSettingsStore.toggleTransparent()} /> } label="Transparent background" /> {exportSettingsStore.format === 'svg' && ( exportSettingsStore.toggleEmbedFonts()} /> } label={ Embed fonts +75 kB, only supported in browsers } /> )} {exportSettingsStore.format === 'png' && ( { if (typeof value === 'number') { exportSettingsStore.setScale(value); } }} /> )} ); } export default observer(ExportPanel);