[!IMPORTANT] For Svelte 3 and Svelte 4 please use
@inqling/svelte-icons
. For Svelte 5 and beyond, this package has been renamed to@designthen/svelte-icons
.
Combines Heroicons V2 → & Simple Icons → as easy to use SVG components in your svelte project.
Checkout the changelog to see what's new.
Copying SVG code into your project can become tedious and messy. With icons it can become particularly unnecessary as you probably don't need to edit the SVG markup. This library simply makes it easier to import each icon and have it scale based on it's inherited font-size.
This library adapts the following repositories for use in Svelte:
# npm
npm i @designthen/svelte-icons@latest
#yarn
yarn add @designthen/svelte-icons@latest
#pnpm
pnpm add @designthen/svelte-icons@latest
View an example in /src/routes/+page.svelte
Note that component names can't start with a number, so icons like 1Password
are prefixed with I
and renamed to I1Password
. You might ask why we don't rename icons like 1Password
to OnePassword
? Well, that's because the original icon is called 1Password
and we want it to be easy to search for with intellisense.
<script>
// using default exports for single icons
import StarSolid from '@designthen/svelte-icons/heroicon-24-solid/star-solid';
// using named exports for multiple icons in a pack
import { Github, I500px } from '@designthen/svelte-icons/simple-icons';
</script>
Icon Pack | Import Path |
---|---|
Heroicons solid | @designthen/svelte-icons/heroicon-24-solid |
Heroicons outline | @designthen/svelte-icons/heroicon-24-outline |
Heroicons small | @designthen/svelte-icons/heroicon-20-solid |
Simple Icons | @designthen/svelte-icons/simple-icons |
From each pack you can import multiple icons from a pack at once, or import a single icon directly.
Icons should behave as you expect most components.
<script>
// import 1 icon directly (recommended)
import GitHub from '@designthen/svelte-icons/simple-icons/github.svelte';
// import multiple icons from a pack
import { Svelte, OnePassword } from '@designthen/svelte-icons/simple-icons';
</script>
<style>
:global(.icon) {
height: 24px;
}
section :global(svg) {
fill: red;
}
</style>
<OnePassword class="icon" style="width:24px;" />
<Svelte class="icon" style="width:24px;" />
<GitHub class="icon" style="width:24px;" />
pnpm install
.pnpm icon:update
to clone and import the latest SVG's from the following repositories:pnpm format
to ensure consistent formatting. Now you'll see that only new or updated icon files have changed.npx changeset
to create a new changeset.minor
version bump.We're open to adding new icon packs.
A script should be written for each new pack added - this is fairly simple and is mostly copying and pasting from the existing scripts. In the future I will add more details about writing a "clone script".
/import
with one level of folder structure.yarn import-svg
to convert all SVG files to svelte components./src/lib/...
.Example folder structure
import/
⮑ heroicons-solid/
⮑ icon1.svg
⮑ icon2.svg
⮑ ..
⮑ heroicons-outline/
⮑ icon1.svg
⮑ icon2.svg
⮑ ...
⮑ .gitkeep
README.md (you're here)
package.json
...
Above you'll see we answer How to I contribute my work?
. Here we explain how to use changesets to trigger a new version to be prepared. Once a PR has been approved that contains a changeset, a new version will be build and deployed to npm via github actions.