Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(): faster compilation method #80

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,56 @@ All icons are imported from a single file, where [ICON SLUG] is replaced by a ca
}
</style>
```

## Type Definition for Dynamic Icons in Svelte Components

Sometimes, we want to provide the component dynamically to a component. We can do that by using `svelte:component` feature with the
helper type `SiComponentType` type definition.

```svelte
<script lang="ts">
import type { SiComponentType } from '@icons-pack/svelte-simple-icons';

export let icon: SiComponentType;
export let text: string;
export let click: () => void = () => console.log('do something');
</script>

<button on:click={click}>
<svelte:component
this={icon}
title={text} <!-- optional, along with size and color properties -->
/>
{text}
</button>

<style lang="scss">
button {
display: flex;
flex-direction: row;
text-decoration: none;
white-space: nowrap;
transition: border-color 0.25s;
box-shadow: none;
text-shadow: none;
}

.icon {
margin: 4px 4px 0 0;
}
</style>
```

## Faster Compilations

If you only need a few icons, you can import them individually instead of the entire file to improve compilation.

```svelte
<script>
import SiSvelte from "@icons-pack/svelte-simple-icons/icons/SiSvelte.svelte";
import SiGithub from "@icons-pack/svelte-simple-icons/icons/SiGithub.svelte";
</script>

<SiGithub />
<SiSvelte />
```
16 changes: 10 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
"svelte": "./index.js",
"import": "./index.js"
},
"./icons/*": {
"types": "./icons/*.svelte.d.ts",
"svelte": "./icons/*.svelte"
},
"./package.json": "./package.json"
},
"description": "This package provides the Simple Icons packaged as a set of Svelte components.",
Expand Down Expand Up @@ -51,18 +55,18 @@
"devDependencies": {
"@changesets/changelog-github": "^0.4.8",
"@changesets/cli": "^2.27.1",
"@sveltejs/adapter-auto": "^3.0.0",
"@sveltejs/kit": "^2.5.0",
"@sveltejs/package": "^2.2.5",
"@sveltejs/adapter-auto": "^3.1.1",
"@sveltejs/kit": "^2.5.4",
"@sveltejs/package": "^2.3.0",
"@sveltejs/vite-plugin-svelte": "^3.0.2",
"signale": "^1.4.0",
"simple-icons": "11.5.0",
"svelte": "^4.2.0",
"svelte-check": "^3.6.0",
"svelte": "^4.2.12",
"svelte-check": "^3.6.8",
"tslib": "^2.6.2",
"typescript": "5.2.2",
"uppercamelcase": "^3.0.0",
"vite": "^5.0.0"
"vite": "^5.2.6"
},
"peerDependencies": {
"@sveltejs/kit": "^2.5.0",
Expand Down
Loading
Loading