unplugin / unplugin-icons

🤹 Access thousands of icons as components on-demand universally.
https://www.npmjs.com/package/unplugin-icons
MIT License
3.65k stars 131 forks source link

I import icons dynamically in Svelte? #351

Closed JPaulMora closed 4 months ago

JPaulMora commented 4 months ago

I have a sidebar menu in a svelte +layout.svelte with dynamic links:

<script lang="ts">
        import { menuNavLinks } from '$lib/links';
    import ArrowTD from 'virtual:icons/heroicons/arrow-trending-down-16-solid';
</script>

my links.ts looks like this:

// Navigation Sitemap

export type List = Array<{ href: string; label: string; keywords: string; badge?: string }>;
export const menuNavLinks: Record<string, Array<{ title: string; list: List }>> = {
    '/docs': [
        {
            title: 'Docs',
            list: [
                { href: '/docs/introduction', label: 'Introduction', keywords: 'svelte, sirens, license, release' },
                { href: '/docs/get-started', label: 'Get Started', keywords: 'start, install, cli, tailwind, themes, stylesheets' },
                { href: '/docs/quickstart', label: 'Quickstart', keywords: 'start, setup, tutorial, guide' }
            ]
        },
//etc..

I want to define the icon name as part of this structure and have it auto imported, if that makes sense. Thanks in advance.

JPaulMora commented 4 months ago

Closing this issue, found a partial solution on https://github.com/unplugin/unplugin-icons/issues/5#issuecomment-1015972369. Based on that thread, dynamic icons are not possible.