Getting Started - Flowbite Svelte Icons v2
Requirements #
- Svelte 5:Runes
- TailwindCSS
- tailwind-merge
Installation #
Install Svelte and TailwindCSS:
// install Svelte 5
npm create svelte@latest my-project
cd my-project
npx svelte-add@latest tailwindcss
pnpm i
Install flowbite-svelte-icons@next
:
pnpm i -D flowbite-svelte-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;
To make sure the classes used by flowbite-svelte-icons are included by the Tailwindcss, add the
following to tailwind.config.cjs
.
const config = {
content: [
// more lines
"./node_modules/flowbite-svelte-icons/**/*.{html,js,svelte,ts}",
],
// more lines
}
Basic Usages #
In a svelte file:
<script>
import { AddressBookOutline } from 'flowbite-svelte-icons';
</script>
<AddressBookOutline />
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 AddressBookOutline from 'flowbite-svelte-icons/AddressBookOutline.svelte';
</script>
<AddressBookOutline />
Passing down other attributes #
Since all icons have ...restProps
, you can pass other attibutes as well.
<AddressBookOutline id="my-svg" transform="rotate(45)"/>
Import all #
Use import * as Icon from 'flowbite-svelte-icons
.
<script>
import * as Icon from 'flowbite-svelte-icons';
</script>
<Icon.AddressBookOutline />
<h1>Size</h1>
<Icon.AddressBookOutline size="30" />
<h1>Tailwind CSS</h1>
<Icon.AddressBookOutline class="text-blue-500" />
IconSolid and IconOutline #
You can use IconSolid
and IconOutline
to create a custom icon.