Files
lucide/docs/packages/lucide-react.md
T

76 lines
1.4 KiB
Markdown
Raw Permalink Normal View History

2021-10-01 09:19:36 +02:00
# Lucide React
Implementation of the lucide icon library for react applications
## Installation
```bash
2021-10-01 09:19:36 +02:00
yarn add lucide-react
```
2021-10-01 09:19:36 +02:00
or
2021-10-01 09:19:36 +02:00
```sh
2021-10-01 09:19:36 +02:00
npm install lucide-react
```
## How to use
2022-10-03 16:36:33 +02:00
It's build with ESmodules so it's completely tree-shakable.
2021-10-01 09:19:36 +02:00
Each icon can be imported as a react component.
### Example
You can pass additional props to adjust the icon.
```js
2021-10-01 09:19:36 +02:00
import { Camera } from 'lucide-react';
// Returns ReactComponent
// Usage
const App = () => {
return <Camera color="red" size={48} />;
2021-10-01 09:19:36 +02:00
};
export default App;
```
### Props
| name | type | default |
| ------------- | -------- | ------------ |
| `size` | _Number_ | 24 |
| `color` | _String_ | currentColor |
| `strokeWidth` | _Number_ | 2 |
2021-10-01 09:19:36 +02:00
### Custom props
You can also pass custom props that will be added in the svg as attributes.
```js
2021-10-01 09:19:36 +02:00
// Usage
const App = () => {
return <Camera fill="red" />;
2021-10-01 09:19:36 +02:00
};
```
### One generic icon component
It is possible to create one generic icon component to load icons.
> :warning: Example below importing all EsModules, caution using this example, not recommended when you using bundlers, your application build size will grow strongly.
2021-10-01 09:19:36 +02:00
#### Icon Component Example
```js
2021-10-01 09:19:36 +02:00
import * as icons from 'lucide-react';
const Icon = ({ name, color, size }) => {
2021-10-01 09:19:36 +02:00
const LucideIcon = icons[name];
return <LucideIcon color={color} size={size} />;
2021-10-01 09:19:36 +02:00
};
export default Icon;
```