2022-06-28 12:47:01 +02:00
# Lucide React Native
Implementation of the lucide icon library for React Native applications
## Installation
2024-02-27 10:13:42 +01:00
First, ensure that you have `react-native-svg` (version between 12 and 15) installed. Then, install the package:
2022-06-28 12:47:01 +02:00
2023-06-12 22:10:15 +02:00
::: code-group
```sh [pnpm]
pnpm install lucide-react-native
2022-10-27 08:19:45 +02:00
```
2022-06-28 12:47:01 +02:00
2023-06-12 22:10:15 +02:00
```sh [yarn]
yarn add lucide-react-native
```
2022-06-28 12:47:01 +02:00
2023-06-12 22:10:15 +02:00
```sh [npm]
2022-06-28 12:47:01 +02:00
npm install lucide-react-native
```
2024-11-29 09:11:30 +01:00
```sh [bun]
bun add lucide-react-native
```
2023-06-12 22:10:15 +02:00
:::
2022-06-28 12:47:01 +02:00
## How to use
2023-06-12 22:10:15 +02:00
Each icon can be imported as a React component.
2022-06-28 12:47:01 +02:00
### Example
2023-06-12 22:10:15 +02:00
Additional props can be passed to adjust the icon:
2022-06-28 12:47:01 +02:00
2023-06-12 22:10:15 +02:00
```jsx
2022-06-28 12:47:01 +02:00
import { Camera } from 'lucide-react-native';
// Usage
const App = () => {
return <Camera color="red" size={48} />;
};
export default App;
```
2023-06-12 22:10:15 +02:00
## Props
2022-06-28 12:47:01 +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 |
2022-06-28 12:47:01 +02:00
2023-06-12 22:10:15 +02:00
### Applying props
2022-06-28 12:47:01 +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.
2022-06-28 12:47:01 +02:00
2023-06-12 22:10:15 +02:00
```jsx
2022-06-28 12:47:01 +02:00
// Usage
const App = () => {
return <Camera fill="red" />;
};
```
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.
```jsx
import { Icon } from 'lucide-react-native';
import { burger } from '@lucide/lab ';
const App = () => (
<Icon iconNode={burger} />
);
```
2023-06-12 22:10:15 +02:00
## One generic icon component
2022-06-28 12:47:01 +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.
2022-06-28 12:47:01 +02:00
2023-06-12 22:10:15 +02:00
::: warning
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 to keep in mind when using bundlers like `Webpack` , `Rollup` , or `Vite` .
2023-06-12 22:10:15 +02:00
:::
2022-06-28 12:47:01 +02:00
2023-06-12 22:10:15 +02:00
### Icon Component Example
2022-06-28 12:47:01 +02:00
2023-06-12 22:10:15 +02:00
```jsx
2024-01-18 08:27:02 -03:00
import { icons } from 'lucide-react-native';
2022-06-28 12:47:01 +02:00
const Icon = ({ name, color, size }) => {
const LucideIcon = icons[name];
return <LucideIcon color={color} size={size} />;
};
export default Icon;
```
2023-06-12 22:10:15 +02:00
#### Using the Icon Component
```jsx
import Icon from './Icon';
const App = () => {
return <Icon name="home" />;
};
export default App;
```