Files
lucide/docs/guide/packages/lucide-astro.md

188 lines
4.0 KiB
Markdown
Raw Normal View History

feat(@lucide/astro): add lucide package for Astro (#2665) * feat(lucide-astro): initial commit * test: add test suite * fix module resolution issue * chore: update lock file * chore: update lock file * chore: fix precommit hook failing * sync icons generated by precommit hook * remove useless tab in template * style: add space for readability * docs: add bun installation instructions * fix `clean` script * fix testing setup * remove unnecessary `key` props in Astro icons * fix jest matchers types and undefined behavior * chore: update lock file * setup prettier for formatting Astro files * remove mistakenly added prop from the `Icon` component * docs: add documentation for new Astro package * fix incorrect types in `Icon` component * refactor: use `stroke-width` over `strokeWidth` * fix unexpected module resolution behavior * remove hack in test types * remove review marker * docs: progress on documentation of lucide-astro * chore: remove unnecessary .gitignore * docs: add sidebar entry * edit package description * fix uneven icon heights in homepage packages list * docs: add package to readme table * add workflows for lucide-astro package * docs: add package-logos * use the appropriate Astro logo in light and dark mode * Remove inadvertently added class * Update snapshots to reflect removed class `lucide-icon` * remove dependency on internal `@lucide/shared` package * fix: revert changes * revert grid-2x2-x.json * revert grid-2x2-check.json * revert picture-in-picture svg * add package in labeler workflow * add previously uncommited utils.ts file * fix dom type errors * up one major from legacy package * add package to issue and feature request templates * docs: add acknowledgement of Aviortheking as original creator of the package * format * optimization: more lightweight component footprint * refactor: simplify removal of `data-astro-source` debugging attributes * format * style: fix linting error once again 😠 * wip: rename package to `@lucide/astro` * remove acknowledgment of `lucide-astro` * fix error caused by change in build tooling * chore: upgrade dependencies * chore: rename lucide-astro folder * further renaming * use correct package name in key * more renaming * chore: update lock file * apply review suggestions (#1) set correct path for package in actions * apply suggestions from code review (#2) Co-authored-by: Eric Fennis <eric.fennis@gmail.com> * apply @dotspencer's review resolve correct link to package docs page and github source * Format files --------- Co-authored-by: realguse <realguse@icloud.com> Co-authored-by: Eric Fennis <eric.fennis@gmail.com>
2025-03-31 14:20:33 +00:00
# Lucide Astro
Implementation of the lucide icon library for Astro applications.
## Installation
::: code-group
```sh [pnpm]
pnpm add @lucide/astro
```
```sh [yarn]
yarn add @lucide/astro
```
```sh [npm]
npm install @lucide/astro
```
```sh [bun]
bun add @lucide/astro
```
:::
## How to use
Lucide is built with ES Modules, so it's completely tree-shakable.
Each icon can be imported as an Astro 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.
### Example
Default usage:
```astro
---
import { Skull } from '@lucide/astro';
---
<Skull />
```
Additional props can be passed to adjust the icon:
```astro
---
import { Camera } from '@lucide/astro';
---
<Camera color="#ff3e98" />
```
For faster builds and load times, you can import icons directly from the `@lucide/astro/icons` directory:
```astro
---
import CircleAlert from '@lucide/astro/icons/circle-alert';
---
<CircleAlert color="#ff3e98" />
```
## Props
| name | type | default |
| --------------------- | --------- | ------------ |
| `size` | _number_ | 24 |
| `color` | _string_ | currentColor |
| `stroke-width` | _number_ | 2 |
| `absoluteStrokeWidth` | _boolean_ | false |
### Applying props
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).
```astro
---
import { Phone } from '@lucide/astro';
---
<Phone fill="#333" />
```
This results a filled phone icon.
## Types
The package includes type definitions for all icons. This is useful if you want to dynamically render icons.
### Example
```astro
---
2025-05-03 09:28:29 +02:00
import { House, Library, Cog, type Icon as IconType } from '@lucide/astro';
feat(@lucide/astro): add lucide package for Astro (#2665) * feat(lucide-astro): initial commit * test: add test suite * fix module resolution issue * chore: update lock file * chore: update lock file * chore: fix precommit hook failing * sync icons generated by precommit hook * remove useless tab in template * style: add space for readability * docs: add bun installation instructions * fix `clean` script * fix testing setup * remove unnecessary `key` props in Astro icons * fix jest matchers types and undefined behavior * chore: update lock file * setup prettier for formatting Astro files * remove mistakenly added prop from the `Icon` component * docs: add documentation for new Astro package * fix incorrect types in `Icon` component * refactor: use `stroke-width` over `strokeWidth` * fix unexpected module resolution behavior * remove hack in test types * remove review marker * docs: progress on documentation of lucide-astro * chore: remove unnecessary .gitignore * docs: add sidebar entry * edit package description * fix uneven icon heights in homepage packages list * docs: add package to readme table * add workflows for lucide-astro package * docs: add package-logos * use the appropriate Astro logo in light and dark mode * Remove inadvertently added class * Update snapshots to reflect removed class `lucide-icon` * remove dependency on internal `@lucide/shared` package * fix: revert changes * revert grid-2x2-x.json * revert grid-2x2-check.json * revert picture-in-picture svg * add package in labeler workflow * add previously uncommited utils.ts file * fix dom type errors * up one major from legacy package * add package to issue and feature request templates * docs: add acknowledgement of Aviortheking as original creator of the package * format * optimization: more lightweight component footprint * refactor: simplify removal of `data-astro-source` debugging attributes * format * style: fix linting error once again 😠 * wip: rename package to `@lucide/astro` * remove acknowledgment of `lucide-astro` * fix error caused by change in build tooling * chore: upgrade dependencies * chore: rename lucide-astro folder * further renaming * use correct package name in key * more renaming * chore: update lock file * apply review suggestions (#1) set correct path for package in actions * apply suggestions from code review (#2) Co-authored-by: Eric Fennis <eric.fennis@gmail.com> * apply @dotspencer's review resolve correct link to package docs page and github source * Format files --------- Co-authored-by: realguse <realguse@icloud.com> Co-authored-by: Eric Fennis <eric.fennis@gmail.com>
2025-03-31 14:20:33 +00:00
type MenuItem = {
name: string;
href: string;
icon: typeof IconType;
};
const menuItems: MenuItem[] = [
{
name: 'Home',
href: '/',
2025-05-03 09:28:29 +02:00
icon: House,
feat(@lucide/astro): add lucide package for Astro (#2665) * feat(lucide-astro): initial commit * test: add test suite * fix module resolution issue * chore: update lock file * chore: update lock file * chore: fix precommit hook failing * sync icons generated by precommit hook * remove useless tab in template * style: add space for readability * docs: add bun installation instructions * fix `clean` script * fix testing setup * remove unnecessary `key` props in Astro icons * fix jest matchers types and undefined behavior * chore: update lock file * setup prettier for formatting Astro files * remove mistakenly added prop from the `Icon` component * docs: add documentation for new Astro package * fix incorrect types in `Icon` component * refactor: use `stroke-width` over `strokeWidth` * fix unexpected module resolution behavior * remove hack in test types * remove review marker * docs: progress on documentation of lucide-astro * chore: remove unnecessary .gitignore * docs: add sidebar entry * edit package description * fix uneven icon heights in homepage packages list * docs: add package to readme table * add workflows for lucide-astro package * docs: add package-logos * use the appropriate Astro logo in light and dark mode * Remove inadvertently added class * Update snapshots to reflect removed class `lucide-icon` * remove dependency on internal `@lucide/shared` package * fix: revert changes * revert grid-2x2-x.json * revert grid-2x2-check.json * revert picture-in-picture svg * add package in labeler workflow * add previously uncommited utils.ts file * fix dom type errors * up one major from legacy package * add package to issue and feature request templates * docs: add acknowledgement of Aviortheking as original creator of the package * format * optimization: more lightweight component footprint * refactor: simplify removal of `data-astro-source` debugging attributes * format * style: fix linting error once again 😠 * wip: rename package to `@lucide/astro` * remove acknowledgment of `lucide-astro` * fix error caused by change in build tooling * chore: upgrade dependencies * chore: rename lucide-astro folder * further renaming * use correct package name in key * more renaming * chore: update lock file * apply review suggestions (#1) set correct path for package in actions * apply suggestions from code review (#2) Co-authored-by: Eric Fennis <eric.fennis@gmail.com> * apply @dotspencer's review resolve correct link to package docs page and github source * Format files --------- Co-authored-by: realguse <realguse@icloud.com> Co-authored-by: Eric Fennis <eric.fennis@gmail.com>
2025-03-31 14:20:33 +00:00
},
{
name: 'Blog',
href: '/blog',
icon: Library,
},
{
name: 'Projects',
href: '/projects',
icon: Cog,
},
];
---
{
menuItems.map((item) => (
<a href={item.href}>
<item.icon />
<span>{item.name}</span>
</a>
))
}
```
## 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 of the 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.
```astro
---
import { Icon } from '@lucide/astro';
import { burger, sausage } from '@lucide/lab';
---
<Icon iconNode={burger} />
<Icon iconNode={sausage} color="red"/>
```
## One generic icon component
It is possible to create one generic icon component to load icons, but it is not recommended.
::: danger
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. This may be passable if you're doing SSG and SSR in server environments. However if you're doing SSR in serverless environments, it could negatively affect your app's performance, as a bigger bundle size will translate to an increase in cold starts.
:::
### Icon Component Example
```astro
---
import { icons, type IconProps } from '@lucide/astro';
interface Props extends IconProps {
name: keyof typeof icons;
}
const { name, ...restProps } = Astro.props;
const Icon = icons[name];
---
<Icon {...restProps} />
```
### Using the Icon Component
```astro
---
import LucideIcon from './LucideIcon.astro';
---
<LucideIcon name="Menu" />
```