2022-02-17 17:46:55 +01:00
# Lucide Svelte
Implementation of the lucide icon library for svelte applications.
## Installation
2023-06-12 22:10:15 +02:00
::: code-group
```sh [pnpm]
pnpm install lucide-svelte
2022-10-27 08:19:45 +02:00
```
2022-02-17 17:46:55 +01:00
2023-06-12 22:10:15 +02:00
```sh [yarn]
yarn add lucide-svelte
```
2022-02-17 17:46:55 +01:00
2023-06-12 22:10:15 +02:00
```sh [npm]
2022-02-17 17:46:55 +01:00
npm install lucide-svelte
```
2023-06-12 22:10:15 +02:00
:::
2022-02-17 17:46:55 +01:00
## How to use
2023-09-02 13:48:45 -06:00
Lucide is built with ES Modules, so it's completely tree-shakable.
2023-06-12 22:10:15 +02:00
2023-09-02 13:48:45 -06:00
Each icon can be imported as a Svelte component, which renders an inline SVG element. This way, only the icons that are imported into your project are included in the final bundle. The rest of the icons are tree-shaken away.
2022-02-17 17:46:55 +01:00
### Example
Default usage:
2023-06-12 22:10:15 +02:00
```svelte
2022-02-17 17:46:55 +01:00
<script>
2022-10-27 08:19:45 +02:00
import { Skull } from 'lucide-svelte';
2022-02-17 17:46:55 +01:00
</script>
2022-10-27 08:19:45 +02:00
<Skull />
2022-02-17 17:46:55 +01:00
```
2023-06-12 22:10:15 +02:00
Additional props can be passed to adjust the icon:
2022-02-17 17:46:55 +01:00
2023-06-12 22:10:15 +02:00
```svelte
2022-02-17 17:46:55 +01:00
<script>
2022-10-27 08:19:45 +02:00
import { Camera } from 'lucide-svelte';
2022-02-17 17:46:55 +01:00
</script>
2022-08-08 13:34:44 -05:00
<Camera color="#ff3e98 " />
2022-02-17 17:46:55 +01:00
```
2023-06-12 22:10:15 +02:00
## Props
2022-02-17 17:46:55 +01:00
2023-04-20 16:08:34 +02:00
| name | type | default |
| --------------------- | --------- | ------------ |
| `size` | * number * | 24 |
| `color` | * string * | currentColor |
| `strokeWidth` | * number * | 2 |
| `absoluteStrokeWidth` | * boolean * | false |
2023-06-12 22:10:15 +02:00
### Applying props
2022-02-17 17:46:55 +01:00
2023-09-02 13:48:45 -06:00
To customize the appearance of an icon, you can pass custom properties as props directly to the component. The component accepts all SVG attributes as props, which allows flexible styling of the SVG elements. See the list of SVG Presentation Attributes on [MDN ](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/Presentation ).
2022-02-17 17:46:55 +01:00
2023-06-12 22:10:15 +02:00
```svelte
2022-02-17 17:46:55 +01:00
<script>
2022-10-27 08:19:45 +02:00
import { Phone } from 'lucide-svelte';
2022-02-17 17:46:55 +01:00
</script>
2022-10-27 08:19:45 +02:00
<Phone fill="#333 " />
2022-02-17 17:46:55 +01:00
```
This results a filled phone icon.
2023-06-12 22:10:15 +02:00
## One generic icon component
2022-02-17 17:46:55 +01:00
2023-09-02 13:48:45 -06:00
It is possible to create one generic icon component to load icons, but it is not recommended.
2022-02-17 17:46:55 +01:00
2023-06-12 22:10:15 +02:00
::: danger
2023-09-02 13:48:45 -06:00
The example below imports all ES Modules, so exercise caution when using it. Importing all icons will significantly increase the build size of the application, negatively affecting its performance. This is especially important when using bundlers like `Webpack` , `Rollup` , or `Vite` .
2023-06-12 22:10:15 +02:00
:::
2022-02-17 17:46:55 +01:00
2023-06-12 22:10:15 +02:00
### Icon Component Example
2022-02-17 17:46:55 +01:00
2023-06-12 22:10:15 +02:00
```svelte
2022-02-17 17:46:55 +01:00
<script>
2022-10-27 08:19:45 +02:00
import * as icons from 'lucide-svelte';
2022-02-17 17:46:55 +01:00
export let name;
</script>
2022-10-27 08:19:45 +02:00
<svelte:component this="{icons[name]}" {...$$props} />
2022-02-17 17:46:55 +01:00
```
2023-06-12 22:10:15 +02:00
#### Using the Icon Component
2022-02-17 17:46:55 +01:00
2023-06-12 22:10:15 +02:00
```svelte
2022-02-17 17:46:55 +01:00
<script>
2022-10-27 08:19:45 +02:00
import LucideIcon from './LucideIcon';
2022-02-17 17:46:55 +01:00
</script>
<LucideIcon name="Menu" />
```
2023-06-12 22:10:15 +02:00