From deee57314d72ce468ee89bcf90d8f6bc82a53df1 Mon Sep 17 00:00:00 2001 From: David Luzar Date: Thu, 9 Jan 2020 17:37:08 +0100 Subject: [PATCH] support export canvas to clipboard (#232) --- src/components/panels/PanelExport.tsx | 40 ++++++++++++++++++++++++-- src/components/panels/panelExport.scss | 16 +++++++++++ src/global.d.ts | 7 +++++ src/index.tsx | 11 +++---- src/scene/data.ts | 22 ++++++++++++-- src/scene/index.ts | 2 +- src/scene/types.ts | 2 ++ 7 files changed, 89 insertions(+), 11 deletions(-) create mode 100644 src/components/panels/panelExport.scss create mode 100644 src/global.d.ts diff --git a/src/components/panels/PanelExport.tsx b/src/components/panels/PanelExport.tsx index 81bee94c..8b924033 100644 --- a/src/components/panels/PanelExport.tsx +++ b/src/components/panels/PanelExport.tsx @@ -1,17 +1,35 @@ import React from "react"; import { EditableText } from "../EditableText"; import { Panel } from "../Panel"; +import { ExportType } from "../../scene/types"; + +import "./panelExport.scss"; interface PanelExportProps { projectName: string; onProjectNameChange: (name: string) => void; - onExportAsPNG: React.MouseEventHandler; + onExportCanvas: (type: ExportType) => void; exportBackground: boolean; onExportBackgroundChange: (val: boolean) => void; onSaveScene: React.MouseEventHandler; onLoadScene: React.MouseEventHandler; } +// fa-clipboard +const ClipboardIcon = () => ( + + + +); + +const probablySupportsClipboard = + "toBlob" in HTMLCanvasElement.prototype && + "write" in navigator.clipboard && + "ClipboardItem" in window; + export const PanelExport: React.FC = ({ projectName, exportBackground, @@ -19,7 +37,7 @@ export const PanelExport: React.FC = ({ onExportBackgroundChange, onSaveScene, onLoadScene, - onExportAsPNG + onExportCanvas }) => { return ( @@ -32,7 +50,23 @@ export const PanelExport: React.FC = ({ /> )}
Image
- +
+ + {probablySupportsClipboard && ( + + )} +