diff --git a/client/src/pages/tools/text/CharCounter/CharCounter.jsx b/client/src/pages/tools/text/CharCounter/CharCounter.jsx new file mode 100644 index 0000000..7ebc1e8 --- /dev/null +++ b/client/src/pages/tools/text/CharCounter/CharCounter.jsx @@ -0,0 +1,42 @@ +import InfoArea from "@/common/components/InfoArea"; +import Button from "@/common/components/Button"; +import {faShare} from "@fortawesome/free-solid-svg-icons"; +import TextArea from "@/pages/tools/base64/components/TextArea"; +import {useState} from "react"; +import "./styles.sass"; +import {useSearchParams} from "react-router-dom"; + +export const CharCounter = () => { + const [searchParams] = useSearchParams(); + const [inputString, setInputString] = useState(searchParams.get("input") || ""); + + const calculateWords = () => inputString.split("\n").filter(line => line !== "").map(line => line.split(" ") + .filter(word => word !== "").length).reduce((a, b) => a + b, 0); + + const shareLink = () => { + const url = new URL(window.location.href); + url.searchParams.set("input", inputString); + navigator.clipboard.writeText(url.href); + } + + return ( + <> + + + + + setInputString(e.target.value)} placeholder="Text eingeben..." /> + + + {inputString.length} Zeichen + + + {calculateWords()} Wörter + + + {inputString.split("\n").filter(line => line !== "").length} Zeilen + + + > + ); +} \ No newline at end of file