From fd2c50c1aa284b0d0ef91644b525ff82260480b8 Mon Sep 17 00:00:00 2001 From: Pouzor Date: Mon, 29 Jun 2026 00:47:39 +0200 Subject: [PATCH] fix: white background option for export + Firefox download Fixes two issues reported in #165: - Export always produced a black background, making prints with a white page wasteful/unreadable. Adds a Dark/White background choice in the export modal, threaded through both PNG and SVG export. - Firefox refused the download because the programmatic anchor was not attached to the document. The anchor is now appended before click and removed after, which Firefox requires. Closes #165 ha-relevant: yes --- .../src/components/modals/ExportModal.tsx | 41 ++++++++++++++++-- .../modals/__tests__/ExportModal.test.tsx | 30 ++++++++++++- frontend/src/utils/__tests__/export.test.ts | 43 +++++++++++++++++-- frontend/src/utils/export.ts | 28 ++++++++++-- 4 files changed, 129 insertions(+), 13 deletions(-) diff --git a/frontend/src/components/modals/ExportModal.tsx b/frontend/src/components/modals/ExportModal.tsx index b1e3a9b..dcced61 100644 --- a/frontend/src/components/modals/ExportModal.tsx +++ b/frontend/src/components/modals/ExportModal.tsx @@ -2,7 +2,15 @@ import { useState } from 'react' import { Download, Loader2 } from 'lucide-react' import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter } from '@/components/ui/dialog' import { Button } from '@/components/ui/button' -import { exportToPng, exportToSvg, EXPORT_QUALITY_OPTIONS, type ExportQuality, type ExportFormat } from '@/utils/export' +import { + exportToPng, + exportToSvg, + EXPORT_QUALITY_OPTIONS, + EXPORT_BACKGROUND_OPTIONS, + type ExportQuality, + type ExportFormat, + type ExportBackground, +} from '@/utils/export' interface ExportModalProps { open: boolean @@ -13,6 +21,7 @@ interface ExportModalProps { export function ExportModal({ open, onClose, getElement }: ExportModalProps) { const [quality, setQuality] = useState('high') const [format, setFormat] = useState('png') + const [background, setBackground] = useState('dark') const [exporting, setExporting] = useState(false) const handleExport = async () => { @@ -21,9 +30,9 @@ export function ExportModal({ open, onClose, getElement }: ExportModalProps) { setExporting(true) try { if (format === 'svg') { - await exportToSvg(el) + await exportToSvg(el, background) } else { - await exportToPng(el, quality) + await exportToPng(el, quality, background) } onClose() } finally { @@ -70,6 +79,32 @@ export function ExportModal({ open, onClose, getElement }: ExportModalProps) { +
+

Background

+
+ {EXPORT_BACKGROUND_OPTIONS.map((opt) => ( + + ))} +
+
+