Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Bishwas Bhandari
Bishwas Bhandari

Posted on

     

Svelte Icon Library - Svelicon 🎨

Create Svelte components from Iconify SVG icons with type-safe support. A simple CLI tool for generating Svelte icons.

Features ✨

  • 🎯Iconify Integration: Access and download icons from the Iconify collection.
  • Fast Conversion: Quickly convert SVG icons to Svelte components.
  • 📦TypeScript Support: Generate fully typed components with interfaces for Svelte TypeScript projects.
  • 🎨Customizable Icons: Control icon size, display behavior, and spacing.
  • 🛠️CLI Tool: Easy-to-use command-line interface for Svelte icon generation.
  • 🔄Flexible Output: Generate JavaScript or TypeScript Svelte components.

Svelicon streamlines the process of using Iconify icons in your Svelte projects, offering TypeScript support and flexible customization.

Requirements 🗒️

  • Svelte 5
  • Awesomeness

Usage 🚀

Basic Usage

npx svelicon--withts fluent/person-passkey-28-filled
Enter fullscreen modeExit fullscreen mode

This command downloads theperson-passkey-28-filled icon from thefluent collection and creates a TypeScript Svelte component at

src/icons/FluentPersonPasskey28Filled.svelte
Enter fullscreen modeExit fullscreen mode

CLI Options

npx svelicon[options][collection]/[icon]Options:-o,--output <dir>  Output directory(default:"src/icons")--withts            Generate TypeScript version--withjs            Generate JavaScript version(default:true)-h,--help         Displayhelpforcommand
Enter fullscreen modeExit fullscreen mode

Component Props 🎛️

All generated components accept these props:

interfaceIconProps{display?:boolean;// Whether to display the iconoccupy?:boolean;// Whether to occupy space when hiddensize?:number;// Icon size in em unitsclass?:string;// Add custom CSS classes to the SVG element}
Enter fullscreen modeExit fullscreen mode

Examples 📝

JavaScript Usage

<script>importFluentPersonPasskey28Filledfrom'./icons/FluentPersonPasskey28Filled.svelte';</script><FluentPersonPasskey28Filleddisplay={true}size={1.2}/>
Enter fullscreen modeExit fullscreen mode

TypeScript Usage

<scriptlang="ts">importFluentPersonPasskey28Filled,{typeFluentPersonPasskey28FilledProps}from'./icons/FluentPersonPasskey28Filled.svelte';leticonProps:FluentPersonPasskey28FilledProps={display:true,size:1.2,class:'my-custom-icon'};</script><FluentPersonPasskey28Filled{...iconProps}/>
Enter fullscreen modeExit fullscreen mode

Component Output Structure 🏗️

Generated components include:

<scriptlang="ts"module>exportinterfaceFluentPersonPasskey28FilledProps{display?:boolean;occupy?:boolean;size?:number;class?:string;}</script><scriptlang="ts">const{display=false,occupy=true,size=0.7,class:className=''}:FluentPersonPasskey28FilledProps=$props();</script>{#ifdisplay}<svgclass={className}><!-- icon content --></svg>{:elseifoccupy}<divstyle="height: {size}em; width: {size}em;"/>{/if}
Enter fullscreen modeExit fullscreen mode

Benefits 🌟

  • Zero Runtime Dependencies: Svelte icon components are standalone.
  • Tree-Shakeable: Only import the Svelte icons you use.
  • Type-Safe Svelte: Full TypeScript support for Svelte projects.
  • Small Bundle Size: Minimal impact on your Svelte app's size.
  • Flexible Svelte Icons: Use any Iconify icon in your Svelte project.

https://youtu.be/6cpXq1MHg-A

Contributing 🤝

Contributions are welcome! Please read our Contributing Guide for details.

License 📄

MIT ©Friend of Svelte

Support 💖

If you find this Svelte icon library helpful, please consider:

  • ⭐ Starring the GitHub repo
  • 🐛 Creating issues for bugs and feature requests
  • 🔀 Contributing to the code base

Related Projects 🔗


Made with ❤️ byFriend of Svelte

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

I am a professional Rails/Django web developer and automation expert. Also, learning gameDev in Unity Engine.
  • Location
    Nepal, Bardiya
  • Joined

More fromBishwas Bhandari

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp