11---
2- import { Icons } from ' ../../libs/icons'
2+ const icons = import .meta .glob <string >(' /src/icons/*.svg' , {
3+ query: ' ?raw' ,
4+ import: ' default' ,
5+ eager: true
6+ })
37
48interface Props {
5- name: keyof typeof Icons
9+ name: string
610 label? : string
711 color? : string
812 size? : string
@@ -12,20 +16,19 @@ interface Props {
1216const { name, label, size = ' 1em' , color, class : className, ... props } = Astro .props
1317const a11yAttrs = label ? ({ ' aria-label' : label } as const ) : ({ ' aria-hidden' : ' true' } as const )
1418
15- let svgContent = Icons [name ];
16- let viewBox = ' 0 0 24 24' ; // Default viewBox
19+ const svgContentRaw = icons [` /src/icons/${name }.svg ` ]
20+ let svgContent = ' '
21+ let viewBox = ' 0 0 24 24'
1722
18- // Check if the SVG content starts with an <svg> tag
19- if ( typeof svgContent === ' string ' && svgContent . trim (). startsWith ( ' <svg ' )) {
20- const viewBoxMatch = svgContent .match (/ viewBox="([^ "] * )"/ );
23+ if ( svgContentRaw ) {
24+ svgContent = svgContentRaw
25+ const viewBoxMatch = svgContent .match (/ viewBox="([^ "] * )"/ )
2126 if (viewBoxMatch && viewBoxMatch [1 ]) {
22- viewBox = viewBoxMatch [1 ];
27+ viewBox = viewBoxMatch [1 ]
2328 }
24-
25- // Extract content inside the <svg> tags
26- const contentMatch = svgContent .match (/ <svg[^ >] * >(. *? )<\/ svg>/ s );
29+ const contentMatch = svgContent .match (/ <svg[^ >] * >(. *? )<\/ svg>/ s )
2730 if (contentMatch && contentMatch [1 ]) {
28- svgContent = contentMatch [1 ];
31+ svgContent = contentMatch [1 ]
2932 }
3033}
3134---
0 commit comments