2021-10-01 09:19:36 +02:00
# Lucide Vue Next
Implementation of the lucide icon library for Vue 3 applications.
2023-06-12 22:10:15 +02:00
## Vue 3 or Vue 2
::: tip
This version of lucide is for Vue 3, For Vue 2 got to [lucide-vue -> ](lucide-vue )
:::
2021-10-01 09:19:36 +02:00
## Installation
2023-06-12 22:10:15 +02:00
::: code-group
2022-02-01 19:26:07 +01:00
2023-06-12 22:10:15 +02:00
```sh [pnpm]
pnpm install lucide-vue-next
2022-02-01 19:26:07 +01:00
```
2021-10-01 09:19:36 +02:00
2023-06-12 22:10:15 +02:00
```sh [yarn]
yarn add lucide-vue-next
```
2021-10-01 09:19:36 +02:00
2023-06-12 22:10:15 +02:00
```sh [npm]
2021-10-01 09:19:36 +02:00
npm install lucide-vue-next
```
2023-06-12 22:10:15 +02:00
:::
2021-10-01 09:19:36 +02: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 Vue 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.
2021-10-01 09:19:36 +02:00
### Example
You can pass additional props to adjust the icon.
2023-06-12 22:10:15 +02:00
```vue
2024-04-26 17:59:04 +02:00
<script setup>
import { Camera } from 'lucide-vue-next';
</script>
2021-10-01 09:19:36 +02:00
<template>
<Camera
color="red"
:size="32"
/>
</template>
```
2023-06-12 22:10:15 +02:00
## Props
2021-10-01 09:19:36 +02:00
2023-04-20 16:08:34 +02:00
| name | type | default |
| ----------------------- | --------- | ------------ |
| `size` | * number * | 24 |
| `color` | * string * | currentColor |
| `stroke-width` | * number * | 2 |
| `absolute-stroke-width` | * boolean * | false |
| `default-class` | * string * | lucide-icon |
2021-10-01 09:19:36 +02:00
2023-06-12 22:10:15 +02:00
### Applying props
2021-10-01 09:19:36 +02: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 ).
2021-10-01 09:19:36 +02:00
2023-06-12 22:10:15 +02:00
```vue
2021-10-01 09:19:36 +02:00
<template>
<Camera fill="red" />
</template>
```
2024-04-26 17:59:04 +02:00
## With Lucide lab or custom icons
[Lucide lab ](https://github.com/lucide-icons/lucide-lab ) is a collection of icons that are not part of the Lucide main library.
They can be used by using the `Icon` component.
All props like regular lucide icons can be passed to adjust the icon appearance.
### Using the `Icon` component
This creates a single icon based on the iconNode passed and renders a Lucide icon component.
```vue
<script setup>
import { Icon } from 'lucide-vue-next';
import { burger } from '@lucide/lab ';
</script>
<template>
<Icon :iconNode={burger} />
</template>
```
2023-06-12 22:10:15 +02:00
## One generic icon component
2021-10-01 09:19:36 +02: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.
2021-10-01 09:19:36 +02: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
:::
2021-10-01 09:19:36 +02:00
2023-06-12 22:10:15 +02:00
### Icon Component Example
2021-10-01 09:19:36 +02:00
2023-06-12 22:10:15 +02:00
```vue
2022-10-23 18:30:39 +02:00
<script setup>
import { computed } from 'vue';
2021-10-01 09:19:36 +02:00
import * as icons from "lucide-vue-next";
2022-10-23 18:30:39 +02:00
const props = defineProps({
name: {
type: String,
required: true
2021-10-01 09:19:36 +02:00
},
2022-10-23 18:30:39 +02:00
size: Number,
color: String,
strokeWidth: Number,
defaultClass: String
})
2022-02-01 19:26:07 +01:00
2022-10-23 18:30:39 +02:00
const icon = computed(() => icons[props.name]);
2021-10-01 09:19:36 +02:00
</script>
2023-06-12 22:10:15 +02:00
<template>
<component
:is="icon"
:size="size"
:color="color"
:stroke-width="strokeWidth" :default-class="defaultClass"
/>
</template>
2021-10-01 09:19:36 +02:00
```
2023-06-12 22:10:15 +02:00
### Using the Icon Component
2021-10-01 09:19:36 +02:00
2023-06-12 22:10:15 +02:00
All other props listed above also work on the `Icon` Component.
```vue
2021-10-01 09:19:36 +02:00
<template>
<div id="app">
<Icon name="Airplay" />
</div>
</template>
```