From 36a5da4ff6cb0e087de3e15400163064debaef9b Mon Sep 17 00:00:00 2001 From: Kitteh Date: Sun, 23 May 2021 14:33:41 +0100 Subject: [PATCH] Port some elements to tsx. --- package.json | 1 + src/elements/ReactCopyableModal.tsx | 69 +++++++++++++++++++++++++++ src/elements/ReactFileUploadInput.tsx | 20 ++++++++ 3 files changed, 90 insertions(+) create mode 100644 src/elements/ReactCopyableModal.tsx create mode 100644 src/elements/ReactFileUploadInput.tsx diff --git a/package.json b/package.json index 7cd080a..1fa45df 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,7 @@ "@babel/plugin-proposal-object-rest-spread": "^7.14.2", "@babel/plugin-transform-runtime": "^7.14.3", "@babel/preset-env": "^7.14.2", + "@types/file-saver": "^2.0.2", "@types/prismjs": "^1.16.5", "@types/uikit": "^3.3.1", "@typescript-eslint/eslint-plugin": "^4.24.0", diff --git a/src/elements/ReactCopyableModal.tsx b/src/elements/ReactCopyableModal.tsx new file mode 100644 index 0000000..b5aa756 --- /dev/null +++ b/src/elements/ReactCopyableModal.tsx @@ -0,0 +1,69 @@ +import { Component, JSX, createRef } from "preact"; +import { addClipboardNotifications } from "../pageUtils"; +import ClipboardJS from "clipboard"; +import FileSaver from "file-saver"; +import UIkit from "uikit"; +import i18next from "i18next"; + +export type CopyableModalProps = { + name: string; + contentString: string; +}; + +export class CopyableModal extends Component { + ref = createRef(); + copyButtonRef = createRef(); + + saveAsFile(): void { + const blob = new Blob([this.props.contentString], { + type: "text/plain;charset=utf-8", + }); + FileSaver.saveAs(blob, "result.txt"); + } + + componentDidMount(): void { + const clipboard = new ClipboardJS(this.copyButtonRef.current); + addClipboardNotifications(clipboard, 600); + UIkit.modal(this.ref.current).show(); + } + + render(): JSX.Element { + return ( + + + ); + } +} diff --git a/src/elements/ReactFileUploadInput.tsx b/src/elements/ReactFileUploadInput.tsx new file mode 100644 index 0000000..561f52d --- /dev/null +++ b/src/elements/ReactFileUploadInput.tsx @@ -0,0 +1,20 @@ +import { JSX } from "preact"; +import i18next from "i18next"; + +export type FileUploadInputProps = { + name: string; +}; + +export function FileUploadInput(props: FileUploadInputProps): JSX.Element { + return ( +
+ + + +
+ ); +}