theme switcher
This commit is contained in:
23
src/components/Icon.astro
Normal file
23
src/components/Icon.astro
Normal file
@@ -0,0 +1,23 @@
|
||||
---
|
||||
export interface Props {
|
||||
name: string,
|
||||
};
|
||||
|
||||
const { name } = Astro.props;
|
||||
|
||||
const icons = import.meta.glob<{string: string}>('@components/icons/*.svg', { query: '?raw', import: 'default' });
|
||||
const path = `/src/components/icons/${name}.svg`;
|
||||
if (icons[path] === undefined) {
|
||||
throw new Error(`Icon ${name} does not exist.`);
|
||||
}
|
||||
const icon = await icons[path]();
|
||||
---
|
||||
|
||||
<Fragment set:html={icon} />
|
||||
|
||||
<style>
|
||||
svg {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user