diff --git a/README.md b/README.md index 1fce850..4c39bc3 100644 --- a/README.md +++ b/README.md @@ -44,6 +44,7 @@ Here is the list of all utilities: - [CSS Units Converter](https://jam.dev/utilities/css-units-converter) - [JWT Parser](https://jam.dev/utilities/jwt-parser) - [UUID Generator](https://jam.dev/utilities/uuid-generator) +- [SVG Viewer](https://jam.dev/utilities/svg-viewer) ### Built With diff --git a/components/utils/tools-list.ts b/components/utils/tools-list.ts index 255f3fb..d2486ba 100644 --- a/components/utils/tools-list.ts +++ b/components/utils/tools-list.ts @@ -125,4 +125,10 @@ export const tools = [ "Generate random UUIDs. Useful for creating unique identifiers for various applications such as database keys, session IDs, and more.", link: "/utilities/uuid-generator", }, + { + title: "SVG Viewer", + description: + "Instantly preview and validate SVG code in your browser. Perfect for developers working with vector graphics and debugging SVG markup.", + link: "/utilities/svg-viewer", + }, ]; diff --git a/pages/utilities/svg-viewer.tsx b/pages/utilities/svg-viewer.tsx new file mode 100644 index 0000000..40a163f --- /dev/null +++ b/pages/utilities/svg-viewer.tsx @@ -0,0 +1,128 @@ +import { useCallback, useState } from "react"; +import { Textarea } from "@/components/ds/TextareaComponent"; +import PageHeader from "@/components/PageHeader"; +import { Card } from "@/components/ds/CardComponent"; +import { Label } from "@/components/ds/LabelComponent"; +import Header from "@/components/Header"; +import { CMDK } from "@/components/CMDK"; +import CallToActionGrid from "@/components/CallToActionGrid"; +import Meta from "@/components/Meta"; +import GitHubContribution from "@/components/GitHubContribution"; + +type Status = "idle" | "invalid" | "error"; + +const getStatusMessage = (status: Status) => { + switch (status) { + case "invalid": + return "Input does not contain an SVG tag"; + case "error": + return "Failed to process SVG. Please check your input."; + default: + return null; + } +}; + +export default function SVGViewer() { + const [input, setInput] = useState(""); + const [base64, setBase64] = useState(null); + const [status, setStatus] = useState("idle"); + + const handleChange = useCallback( + (event: React.ChangeEvent) => { + const value = event.currentTarget.value; + setInput(value); + + if (value.trim() === "") { + setBase64(null); + setStatus("idle"); + return; + } + + try { + if (!value.toLowerCase().includes(" { + setBase64(reader.result as string); + setStatus("idle"); + }; + + reader.onerror = () => { + setStatus("error"); + setBase64(null); + }; + + reader.readAsDataURL(blob); + } catch (err) { + console.error("Failed to process SVG:", err); + setStatus("error"); + setBase64(null); + } + }, + [] + ); + + return ( +
+ +
+ + +
+ +
+ +
+ +
+ +