chore: some refactoring and added phosphor icons
parent
e49e2ff0c5
commit
d511ce3663
@ -0,0 +1,21 @@
|
|||||||
|
const icons = Object.fromEntries(
|
||||||
|
Object.entries(
|
||||||
|
import.meta.glob<{ default: ImageMetadata }>(`node_modules/@phosphor-icons/core/assets/light/*.svg`, {
|
||||||
|
eager: true,
|
||||||
|
})
|
||||||
|
).map(([path, module]) => [path.split('/').pop()!.split('.')[0].replace('-light', ''), module])
|
||||||
|
)
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
name: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export const PhosphorIcon = ({ name }: Props) => {
|
||||||
|
const icon = icons[name]
|
||||||
|
|
||||||
|
if (!icon) {
|
||||||
|
throw new Error(`Icon "${name}" not found`)
|
||||||
|
}
|
||||||
|
|
||||||
|
return <img class="phosphor-icon" src={icon.default.src} alt={name} />
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
---
|
||||||
|
import { Image } from 'astro:assets'
|
||||||
|
|
||||||
|
type Props = {
|
||||||
|
name: string
|
||||||
|
}
|
||||||
|
|
||||||
|
const { name } = Astro.props
|
||||||
|
|
||||||
|
const icons = Object.fromEntries(
|
||||||
|
Object.entries(
|
||||||
|
import.meta.glob<{ default: ImageMetadata }>(`node_modules/@phosphor-icons/core/assets/light/*.svg`)
|
||||||
|
).map(([path, module]) => [path.split('/').pop()!.split('.')[0].replace('-light', ''), module])
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!icons[name]) {
|
||||||
|
throw new Error(`Icon "${name}" not found`)
|
||||||
|
}
|
||||||
|
---
|
||||||
|
|
||||||
|
<Image class="phosphor-icon" src={icons[name]()} alt={name} />
|
Loading…
Reference in New Issue