diff --git a/src/components/ImageExportDialog.scss b/src/components/ImageExportDialog.scss index bb64fb1e6..d9ccd68b9 100644 --- a/src/components/ImageExportDialog.scss +++ b/src/components/ImageExportDialog.scss @@ -87,6 +87,18 @@ } } + &--img-bcg { + padding: 0; + background: none; + border: none; + border-radius: 0; + + & > canvas { + max-width: calc(100%); + max-height: calc(100%); + } + } + @include isMobile { margin-top: 24px; max-width: unset; diff --git a/src/components/ImageExportDialog.tsx b/src/components/ImageExportDialog.tsx index 0ae98727b..52a30a0f7 100644 --- a/src/components/ImageExportDialog.tsx +++ b/src/components/ImageExportDialog.tsx @@ -1,4 +1,5 @@ import React, { useEffect, useRef, useState } from "react"; +import clsx from "clsx"; import type { ActionManager } from "../actions/manager"; import type { AppClassProperties, BinaryFiles, UIAppState } from "../types"; @@ -62,6 +63,12 @@ type ImageExportModalProps = { onExportImage: AppClassProperties["onExportImage"]; }; +function isBackgroundImageKey( + key: string, +): key is keyof typeof EXPORT_BACKGROUND_IMAGES { + return key in EXPORT_BACKGROUND_IMAGES; +} + const ImageExportModal = ({ appState, elements, @@ -78,9 +85,9 @@ const ImageExportModal = ({ const [exportWithBackground, setExportWithBackground] = useState( appState.exportBackground, ); - const [exportBackgroundImage, setExportBackgroundImage] = useState( - DEFAULT_EXPORT_BACKGROUND_IMAGE, - ); + const [exportBackgroundImage, setExportBackgroundImage] = useState< + keyof typeof EXPORT_BACKGROUND_IMAGES + >(DEFAULT_EXPORT_BACKGROUND_IMAGE); const [exportDarkMode, setExportDarkMode] = useState( appState.exportWithDarkMode, @@ -105,6 +112,7 @@ const ImageExportModal = ({ } const maxWidth = previewNode.offsetWidth; const maxHeight = previewNode.offsetHeight; + if (!maxWidth) { return; } @@ -127,13 +135,25 @@ const ImageExportModal = ({ console.error(error); setRenderError(error); }); - }, [appState, files, exportedElements]); + }, [ + appState, + appState.exportBackground, + appState.exportBackgroundImage, + files, + exportedElements, + ]); return (

{t("imageExportDialog.header")}

-
+
{renderError && }
@@ -183,12 +203,14 @@ const ImageExportModal = ({ placeholder={t("imageExportDialog.label.backgroundImage")} value={exportBackgroundImage} onChange={(value) => { - setExportBackgroundImage(value); - actionManager.executeAction( - actionChangeExportBackgroundImage, - "ui", - value, - ); + if (isBackgroundImageKey(value)) { + setExportBackgroundImage(value); + actionManager.executeAction( + actionChangeExportBackgroundImage, + "ui", + EXPORT_BACKGROUND_IMAGES[value].path, + ); + } }} /> ; +type SelectItems = Record; export type SelectProps = { items: SelectItems; @@ -43,7 +43,7 @@ const Select = ({ {Object.entries(items).map(([itemValue, itemLabel]) => ( - {itemLabel} + {itemLabel.label} ))} diff --git a/src/constants.ts b/src/constants.ts index b827ad1a5..5ccc8bf59 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -226,6 +226,8 @@ export const MAX_DECIMALS_FOR_SVG_EXPORT = 2; export const EXPORT_SCALES = [1, 2, 3]; export const DEFAULT_EXPORT_PADDING = 10; // px +export const EXPORT_BG_PADDING = 24; // px +export const EXPORT_BG_BORDER_RADIUS = 12; // px export const DEFAULT_MAX_IMAGE_WIDTH_OR_HEIGHT = 1440; @@ -318,13 +320,13 @@ export const DEFAULT_SIDEBAR = { export const LIBRARY_DISABLED_TYPES = new Set(["embeddable", "image"] as const); export const EXPORT_BACKGROUND_IMAGES = { - "/backgrounds/bubbles.svg": "bubbles", - "/backgrounds/bubbles2.svg": "bubbles 2", - "/backgrounds/bricks.svg": "bricks", - "/backgrounds/lines.svg": "lines", - "/backgrounds/lines2.svg": "lines 2", + solid: { path: null, label: "solid color" }, + bubbles: { path: "/backgrounds/bubbles.svg", label: "bubbles" }, + bubbles2: { path: "/backgrounds/bubbles2.svg", label: "bubbles 2" }, + bricks: { path: "/backgrounds/bricks.svg", label: "bricks" }, + lines: { path: "/backgrounds/lines.svg", label: "lines" }, + lines2: { path: "/backgrounds/lines2.svg", label: "lines 2" }, } as const; -export const DEFAULT_EXPORT_BACKGROUND_IMAGE = Object.keys( - EXPORT_BACKGROUND_IMAGES, -)[0]; +export const DEFAULT_EXPORT_BACKGROUND_IMAGE: keyof typeof EXPORT_BACKGROUND_IMAGES = + "solid" as const;