2022-02-17 17:46:55 +01:00
# Lucide Svelte
Implementation of the lucide icon library for svelte applications.
## Installation
```bash
yarn add lucide-svelte
2022-10-27 08:19:45 +02:00
```
2022-02-17 17:46:55 +01:00
2022-10-27 08:19:45 +02:00
or
2022-02-17 17:46:55 +01:00
2022-10-27 08:19:45 +02:00
```sh
2022-02-17 17:46:55 +01:00
npm install lucide-svelte
```
## How to use
All the icons are Svelte components, that ouputs Svg elements. So each icon can be imported and used as a component. This also helps with the use of threeshaking so you only import the icons you use.
### Example
Default usage:
```html
<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
```
You can pass additional props to adjust the icon.
```html
<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
```
### Available props
2022-10-27 08:19:45 +02:00
| name | type | default |
| ------------- | -------- | ------------ |
| `size` | _ Number _ | 24 |
| `color` | _ String _ | currentColor |
| `strokeWidth` | _ Number _ | 2 |
| `*<SVGProps>` | _ String _ | - |
2022-02-17 17:46:55 +01:00
\* All SVGProps are available to style the svgs. See the list of SVG Presentation Attributes on [MDN ](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/Presentation )
### Example of custom props
```html
<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.
### One generic icon component
It is possible to create one generic icon component to load icons.
> ⚠️ Example below importing all EsModules, caution using this example, not recommended when you bundle your application,the build size will grow strongly. Because it will import all the icons.
#### Icon Component Example
2022-10-27 08:19:45 +02:00
```html
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
```
##### Then you can use it like this
2022-10-27 08:19:45 +02:00
```html
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" />
```