Getting Started - Svelte Ant Design Icons v2

sponsor npm License npm

Requirements #

- Svelte 5:Runes

Installation #

Install Svelte and svelte-ant-design-icons v2:

npm create svelte@latest my-project
cd my-project
pnpm i -D svelte-ant-design-icons@next

Enable Runes in svelte.config.js:

import adapter from '@sveltejs/adapter-auto';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';

/** @type {import('@sveltejs/kit').Config} */
const config = {
  preprocess: [vitePreprocess({})],
  compilerOptions: {
    runes: true
  },
  kit: {
    adapter: adapter()
  }
};

export default config;

Basic Usage #

In a svelte file:

<script>
  import { AppstoreAddOutlined } from 'svelte-ant-design-icons';
</script>

<AppstoreAddOutlined />

A11y friendly #

Use title, desc, and ariaLabel props to make your icons accessible.

<AddressBookOutline
  title={{ id: 'my-title', title: 'Red bell' }}
  desc={{ id: 'my-descrip', desc: 'The shape of a red bell' }}
  ariaLabel="red bell"
  color="red"
/>

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 AppstoreAddOutlined from 'svelte-ant-design-icons/AppstoreAddOutlined.svelte';
</script>

<AppstoreAddOutlined />

Passing down other attributes #

Since all icons have ...restProps, you can pass other attibutes as well.

<AppstoreAddOutlined id="my-svg" transform="rotate(45)" />

Using onMount #

<script>
  import { AppstoreAddOutlined } from 'svelte-ant-design-icons';
  import { onMount } from 'svelte';
  const props = {
    size: '50',
    color: '#ff0000'
  };
  onMount(() => {
    const icon = new AppstoreAddOutlined({ target: document.body, props });
  });
</script>

Import all #

Use import * as Icon from 'svelte-ant-design-icons.

<script>
  import * as Icon from 'svelte-ant-design-icons';
</script>

<Icon.AppstoreAddOutlined />

<h1>Size</h1>
<Icon.AppstoreAddOutlined size="30" />