Convert Iconify SVG icons to type-safe Svelte components with one command.
Instantly downloads Iconify SVG icons, and converts to Svelte components with full TypeScript support.
npx svelicon mdi account
This creates a Svelte component at src/icons/MdiAccount.svelte
.
npx svelicon mdi account --withts
Generates a TypeScript-enabled component with proper type definitions.
npx svelicon [collection] [icon] [options]
Options:
-o, --output <dir> Output directory (default: "src/icons")
--withts Generate TypeScript version
--withjs Generate JavaScript version (default: true)
-h, --help Display help for command
All generated components accept these props:
interface IconProps {
display?: boolean; // Whether to display the icon
occupy?: boolean; // Whether to occupy space when hidden
size?: number; // Icon size in em units
}
<script>
import MdiAccount from './icons/MdiAccount.svelte';
</script>
<MdiAccount display={true} size={1.2} />
<script lang="ts">
import MdiAccount, { type MdiAccountProps } from './icons/MdiAccount.svelte';
let iconProps: MdiAccountProps = {
display: true,
size: 1.2
};
</script>
<MdiAccount {...iconProps} />
Generated components include:
<script lang="ts" module>
export interface MdiAccountProps {
display?: boolean;
occupy?: boolean;
size?: number;
}
</script>
<script lang="ts">
const { display = false, occupy = true, size = 0.7 }: MdiAccountProps = $props();
</script>
{#if display}
<svg><!-- icon content --></svg>
{:else if occupy}
<div style="height: {size}em; width: {size}em;" />
{/if}
Contributions are welcome! Please read our Contributing Guide for details.
MIT © Friend of Svelte
If you find this package helpful, please consider:
Made with ❤️ by Friend of Svelte