diff --git a/src/components/copySvg.svelte b/src/components/copySvg.svelte index 80f0746..4f3ecaa 100644 --- a/src/components/copySvg.svelte +++ b/src/components/copySvg.svelte @@ -15,11 +15,13 @@ import { buttonStyles } from '@/ui/styles'; import { cn } from '@/utils/cn'; import { componentTemplate } from '@/utils/componentTemplate'; + import { generateAngularComponent } from '@/utils/generateAngularComponent'; //Icons: import ReactIcon from './icons/reactIcon.svelte'; import VueIcon from './icons/vueIcon.svelte'; import SvelteIcon from './icons/svelteIcon.svelte'; + import AngularIcon from './icons/angularIcon.svelte'; // Props: export let iconSize = 24; @@ -163,6 +165,33 @@ toast.error(`Failed to copy ${framework} component`); } }; + + // Copy SVG as Standalone Angular component: + const convertSvgAngularComponent = async () => { + isLoading = true; + optionsOpen = false; + + const title = svgInfo.title.split(' ').join(''); + const svgUrlToCopy = getSvgUrl(); + const content = await getSvgContent(svgUrlToCopy); + + if (!content) { + toast.error('Failed to fetch the SVG content', { + duration: 5000 + }); + isLoading = false; + return; + } + + const angularComponent = generateAngularComponent(content, title); + await clipboard(angularComponent); + + toast.success(`Copied as Standalone Angular component`, { + description: `${svgInfo.title} - ${svgInfo.category}` + }); + + isLoading = false; + }; (optionsOpen = isOpen)}> @@ -185,6 +214,7 @@ React Vue Svelte + Angular
@@ -265,6 +295,19 @@
+ +
+ +
+
diff --git a/src/components/icons/angularIcon.svelte b/src/components/icons/angularIcon.svelte new file mode 100644 index 0000000..361850a --- /dev/null +++ b/src/components/icons/angularIcon.svelte @@ -0,0 +1,46 @@ + + + + + diff --git a/src/ui/tabs/tabs-list.svelte b/src/ui/tabs/tabs-list.svelte index f3c0672..bacbcf4 100644 --- a/src/ui/tabs/tabs-list.svelte +++ b/src/ui/tabs/tabs-list.svelte @@ -9,7 +9,7 @@ diff --git a/src/utils/generateAngularComponent.ts b/src/utils/generateAngularComponent.ts new file mode 100644 index 0000000..1644c88 --- /dev/null +++ b/src/utils/generateAngularComponent.ts @@ -0,0 +1,28 @@ +export function generateAngularComponent(svgContent: string, componentName: string): string { + const updatedSvgContent = svgContent.replace( + /]*)>/, + `` + ); + + return ` +/** + * ------------------------------------------------------------------------- + * This Angular standalone component was generated by svgl.app + * 🧩 A beautiful library with SVG logos + * ------------------------------------------------------------------------- + */ + +import { Component, Input } from '@angular/core'; + +@Component({ + selector: 'svg-${componentName}', + standalone: true, + template: \` + ${updatedSvgContent.trim()} + \`, +}) +export class ${componentName}Component { + @Input({ required: true }) size: { width: number; height: number }; +} +`; +}