Getting Started - Svelte Ionicons v1
Requirements #
You need to use the following:
- Svelte 4 or 5
Installation #
Install Svelte and Svelte Ionicons:
npm create svelte@latest myapp
cd myapp
pnpm i -D svelte-ionicons@v1-latest
Basic Usage #
In a svelte file:
<script>
import { Accessibility } from 'svelte-ionicons';
</script>
<Accessibility />
aria-label #
Use ariaLabel
props to edit the aria-label
.
<Accessibility ariaLabel="accessibility svg icon" />
IDE support #
If you are using an LSP-compatible editor, such as VSCode, Atom, Sublime Text, or Neovim, hovering over a component name will display a documentation link, features, props, events, etc.
Faster compiling #
If you need only a few icons from this library in your Svelte app, import them directly. This can optimize compilation speed and improve performance by reducing the amount of code processed during compilation.
<script>
import Accessibility from 'svelte-ionicons/Accessibility.svelte';
</script>
<Accessibility />
Passing down other attributes #
Since all icons have "...$$restProps", you can pass other attibutes as well.
<Accessibility id="my-svg" transform="rotate(45)" />
Using svelte:component #
<script>
import { Accessibility } from 'svelte-ionicons';
</script>
<svelte:component this="{Accessibility}" />
Using onMount #
<script>
import { Accessibility } from 'svelte-ionicons';
import { onMount } from 'svelte';
const props = {
size: '50',
color: '#ff0000'
};
onMount(() => {
const icon = new Accessibility({ target: document.body, props });
});
</script>
Import all #
Use import * as Icon from 'svelte-ionicons
.
<script>
import * as Icon from 'svelte-ionicons';
</script>
<Icon.Accessibility />
<h1>Size</h1>
<Icon.Accessibility size="30" />