2021-10-01 09:19:36 +02:00
# Lucide React
Implementation of the lucide icon library for react applications
## Installation
2023-06-12 22:10:15 +02:00
::: code-group
```sh [pnpm]
pnpm install lucide-react
2022-10-27 08:19:45 +02:00
```
2021-10-01 09:19:36 +02:00
2023-06-12 22:10:15 +02:00
```sh [yarn]
yarn add lucide-react
```
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-react
```
2023-06-12 22:10:15 +02:00
:::
2021-10-01 09:19:36 +02:00
## How to use
2023-06-12 22:10:15 +02:00
It's build with ES Modules so it's completely tree-shakable.
Each icon can be imported as a React component, what renders a 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
2023-06-12 22:10:15 +02:00
Additional props can be passed to adjust the icon:
2021-10-01 09:19:36 +02:00
2023-06-12 22:10:15 +02:00
```jsx
2021-10-01 09:19:36 +02:00
import { Camera } from 'lucide-react';
// Usage
const App = () => {
2022-10-27 08:19:45 +02:00
return <Camera color="red" size={48} />;
2021-10-01 09:19:36 +02:00
};
export default App;
```
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 |
| `strokeWidth` | * number * | 2 |
| `absoluteStrokeWidth` | * boolean * | false |
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-06-12 22:10:15 +02:00
To apply custom props to change the look of the icon, this can be done by simply pass them as props to the component. All SVG attributes are available as props to style the SVGs. 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
```jsx
2021-10-01 09:19:36 +02:00
// Usage
const App = () => {
2023-06-12 22:10:15 +02:00
return <Camera size={48} fill="red" />;
2021-10-01 09:19:36 +02:00
};
```
2023-06-12 22:10:15 +02:00
## One generic icon component
2021-10-01 09:19:36 +02:00
2023-06-12 22:10:15 +02:00
It is possible to create one generic icon component to load icons. It's not recommended.
2021-10-01 09:19:36 +02:00
2023-06-12 22:10:15 +02:00
::: danger
Example below importing all ES Modules, caution using this example. All icons will be imported. When using bundlers like: `Webpack` , `Rollup` or `Vite` the application build size will grow strongly and harming the performance the application.
:::
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
```jsx
import { icons } from 'lucide-react';
2021-10-01 09:19:36 +02:00
2022-10-27 08:19:45 +02:00
const Icon = ({ name, color, size }) => {
2021-10-01 09:19:36 +02:00
const LucideIcon = icons[name];
2022-10-27 08:19:45 +02:00
return <LucideIcon color={color} size={size} />;
2021-10-01 09:19:36 +02:00
};
export default Icon;
```
2023-06-12 22:10:15 +02:00
#### Using the Icon Component
```jsx
import Icon from './Icon';
const App = () => {
2023-06-28 21:04:37 +02:00
return <Icon name="Home" />;
2023-06-12 22:10:15 +02:00
};
export default App;
```