diff --git a/src/components/TextForm.js b/src/components/TextForm.js index 07549d6..1f974e9 100644 --- a/src/components/TextForm.js +++ b/src/components/TextForm.js @@ -29,6 +29,20 @@ export default function TextForm(props) { navigator.clipboard.writeText(text); props.showAlert("Copied to Clipboard!", "success"); } + + const handleDownload = () => { + // file object + const file = new Blob([text], { type: "text/plain" }); + + // anchor link + const element = document.createElement("a"); + element.href = URL.createObjectURL(file); + element.download = "100ideas-" + Date.now() + ".txt"; + + // simulate link click + document.body.appendChild(element); // Required for this to work in FireFox + element.click(); + }; // Credits: Coding Wala const handleExtraSpaces = () => { @@ -51,6 +65,7 @@ export default function TextForm(props) { +