Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add svg to vue sfc converter #409

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions pages/svg-to-vue-sfc.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import * as React from "react";
import { SvgConverter } from "@components/SvgConverter";
import { useState } from "react";
import { defaultSettings, formFields } from "@constants/svgoConfig";
import { useCallback } from "react";
import { Transformer } from "@components/ConversionPanel";
import isSvg from "is-svg";
import { getWorker } from "@utils/workerWrapper";
import SvgoWorker from "@workers/svgo.worker";

let prettier, svgo, svgr;
export default function Index() {
const name = "SVG to Vue SFC";
const [settings, setSettings] = useState(defaultSettings);
const [optimizedValue, setOptimizedValue] = useState("");

const transformer = useCallback<Transformer>(
async ({ value }) => {
if (!isSvg(value)) throw new Error("This is not a valid svg code.");

svgo = svgo || getWorker(SvgoWorker);

let _value = value;

if (settings.optimizeSvg) {
_value = await svgo.send({
value,
settings
});
}

setOptimizedValue(_value);

return `
<template>
${_value}
</template>
`;
},
[settings]
);

return (
<SvgConverter
transformer={transformer}
formFields={formFields(defaultSettings)}
setSettings={setSettings}
optimizedValue={optimizedValue}
settings={settings}
name={name}
resultTitle={"Vue Component"}
/>
);
}
6 changes: 5 additions & 1 deletion utils/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ export const categorizedRoutes = [
path: "/svg-to-react-native",
packageName: "@svgr/core",
packageUrl: "https://github.com/smooth-code/svgr"
},
{
label: "to Vue SFC",
path: "/svg-to-vue-sfc"
}
]
},
Expand Down Expand Up @@ -222,7 +226,7 @@ export const categorizedRoutes = [
label: "to Typescript",
path: "/js-object-to-typescript",
desc: "An online REPL for converting JS Object to Typescript."
},
}
]
},
{
Expand Down