feat(copy-svg): add functionality to copy SVG as a fully functional Angular standalone component

This commit is contained in:
rperez
2024-12-04 18:08:28 +00:00
parent d24b70001d
commit e135bb8570
4 changed files with 118 additions and 1 deletions
+28
View File
@@ -0,0 +1,28 @@
export function generateAngularComponent(svgContent: string, componentName: string): string {
const updatedSvgContent = svgContent.replace(
/<svg([^>]*)>/,
`<svg$1 [attr.width]="size.width" [attr.height]="size.height">`
);
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 };
}
`;
}