From 2026b61fe0ab75ce01a2a65f0faadf0f444f54e8 Mon Sep 17 00:00:00 2001 From: manhtai Date: Sun, 5 Sep 2021 15:36:41 +0700 Subject: [PATCH] Lorem ipsum (#29) * Lorem ipsum * Change label --- README.md | 1 + package.json | 1 + src/components/Main.tsx | 8 +++ src/components/text/LoremIpsum.tsx | 103 +++++++++++++++++++++++++++++ src/helpers/fontAwesome.ts | 2 + src/main.dev.ts | 2 + yarn.lock | 9 ++- 7 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 src/components/text/LoremIpsum.tsx diff --git a/README.md b/README.md index 7926102..0861362 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,7 @@ - [x] 14. HTML Entity Encode / Decode - [x] 15. URL Encode / Decode - [x] 16. Backslash Encode / Decode +- [x] 17. Lorem Ipsum Generator ## Demo diff --git a/package.json b/package.json index 34d3387..a21f712 100644 --- a/package.json +++ b/package.json @@ -269,6 +269,7 @@ "jsonwebtoken": "^8.5.1", "jsqr": "^1.4.0", "lodash": "^4.17.21", + "lorem-ipsum": "^2.0.3", "marked": "^2.1.3", "pngjs": "^6.0.0", "qrcode": "^1.4.4", diff --git a/src/components/Main.tsx b/src/components/Main.tsx index 2bbf204..1c69811 100644 --- a/src/components/Main.tsx +++ b/src/components/Main.tsx @@ -22,6 +22,7 @@ import JsConsole from './notebook/JavaScript'; import HtmlEntityCodec from './html/HtmlEntityCodec'; import UrlCodec from './url/UrlCodec'; import BackSlashCodec from './text/BackSlash'; +import LoremIpsum from './text/LoremIpsum'; interface MenuItem { path: string; @@ -60,6 +61,13 @@ const defaultRoutes: MenuItem[] = [ show: true, Component: RegexTester, }, + { + icon: , + path: '/lorem-ipsum', + name: 'Lorem Ipsum Generator', + show: true, + Component: LoremIpsum, + }, { icon: , path: '/markdown-to-html', diff --git a/src/components/text/LoremIpsum.tsx b/src/components/text/LoremIpsum.tsx new file mode 100644 index 0000000..3e0e63d --- /dev/null +++ b/src/components/text/LoremIpsum.tsx @@ -0,0 +1,103 @@ +import React, { useEffect, useState } from 'react'; +import { clipboard } from 'electron'; +import { loremIpsum } from 'lorem-ipsum'; + +type Unit = 'words' | 'sentences' | 'paragraphs'; +type Format = 'html' | 'plain'; + +const LoremIpsum = () => { + const [output, setOutput] = useState(''); + const [copied, setCopied] = useState(false); + const [units, setUnits] = useState('paragraphs'); + const [format, setFormat] = useState('plain'); + const [count, setCount] = useState(5); + + const handleCopyOutput = () => { + setCopied(true); + clipboard.write({ text: output }); + setTimeout(() => setCopied(false), 500); + }; + + const unitsList = ['words', 'sentences', 'paragraphs']; + const formatList = [ + { + f: 'html', + l: 'HTML', + }, + { + f: 'plain', + l: 'Text', + }, + ]; + + useEffect(() => { + setOutput(loremIpsum({ units, count, format })); + }, [units, count, format]); + + return ( +
+
+ + setCount(parseInt(e.target.value, 10) || 5)} + /> + + {unitsList.map((unit) => ( + + ))} + + + + {formatList.map(({ f, l }) => ( + + ))} + + + +
+
+