feat(packages): extract icon build logic into @lucide/shared (#4409)

* feat(packages): extract build logic to @lucide/shared, still wip

* feat(): unify icon build logic some more, add nonScalingStroke option, marking absoluteStrokeWidth as deprecated

* feat(): unify icon build logic some more, add nonScalingStroke option, marking absoluteStrokeWidth as deprecated

* feat(packages): extract build logic to @lucide/shared, still wip

* feat(): unify icon build logic some more, add nonScalingStroke option, marking absoluteStrokeWidth as deprecated

* feat(): unify icon build logic some more, add nonScalingStroke option, marking absoluteStrokeWidth as deprecated

* chore(icons): revert git hook changes made to icons

* fix(packages/astro,react-native,vue): fix iconNode type
fix(packages/vue): fix hasA11yProp

* fix(packages/solid): make component reactive & add unit tests for checking prop changes

* test(packages/vue): add reactivity tests to @lucide/vue

* fix(packages): replace cpy-cli, accidentally removed during main merge

* docs(packages): upgrade react documentation with nonScalingStroke

* fix(tests): update snapshots for lucide-react

* feat(docs): upgraded package guides with nonScalingStroke, dropping absoluteStrokeWidth

* fix(vue,react-native): fix linting issues

* fix(icons): add proper fallback for icon width in calculatedStrokeWidth

* fix(packages/svelte): add globalProps.class to icons

* fix(packages/shared): wrap width, height & size in isDefined

* Update types.ts

* fix(packages/svelte): do not pass propsClass to mergeClasses

---------

Co-authored-by: Eric Fennis <eric.fennis@gmail.com>
This commit is contained in:
Karsa
2026-09-04 16:38:01 +02:00
committed by GitHub
co-authored by Eric Fennis
parent 07a2c792ef
commit 99d25bdee2
178 changed files with 3257 additions and 3166 deletions
+54 -46
View File
@@ -2,6 +2,7 @@
title: Combining icons - Angular
description: Learn how to combine multiple icons into a single icon nested SVG elements in your Angular application.
---
<script setup>
import Sandpack from '~/.vitepress/theme/components/editors/SandpackAngular.vue'
</script>
@@ -14,28 +15,32 @@ This is useful for if you want to be creative and make your own custom icons by
::: sandpack {template=angular showTabs=false editorHeight=400 editorWidthPercentage=60 dependencies="@lucide/angular"}
```ts /src/app/app.component.ts [active]
import { Component, ViewEncapsulation } from "@angular/core";
import { LucideScan, LucideUser } from "@lucide/angular";
import { Component, ViewEncapsulation } from '@angular/core';
import { LucideScan, LucideUser } from '@lucide/angular';
@Component({
selector: 'app',
imports: [LucideScan, LucideUser],
template: `
<svg lucideScan [size]="48">
<svg lucideUser
[size]="12"
x="6"
y="6"
[strokeWidth]="4"
[absoluteStrokeWidth]="true"
/>
</svg>`,
template: ` <svg
lucideScan
[size]="48"
[nonScalingStroke]="true"
>
<svg
lucideUser
[size]="12"
x="6"
y="6"
[strokeWidth]="4"
[nonScalingStroke]="true"
/>
</svg>`,
styleUrls: ['./app.component.css'],
encapsulation: ViewEncapsulation.None,
})
export class App {
}
export class App {}
```
:::
This is valid SVG and all SVG properties are supported on the icons.
@@ -53,28 +58,29 @@ You can also use SVG elements to create your own icons.
For example, you can add a notification badge to an icon by using the `circle` SVG element.
::: sandpack {template=angular showTabs=false editorHeight=400 editorWidthPercentage=60 dependencies="@lucide/angular"}
```ts /src/app/app.component.ts [active]
import { Component, ViewEncapsulation, signal } from "@angular/core";
import { LucideMail } from "@lucide/angular";
import { Component, ViewEncapsulation, signal } from '@angular/core';
import { LucideMail } from '@lucide/angular';
@Component({
selector: 'app',
imports: [LucideMail],
template: `
<svg lucideMail [size]="48">
@if (hasUnreadMessages()) {
<circle
r="3"
cx="21"
cy="5"
stroke="none"
fill="#F56565"
/>
}
</svg>`,
template: ` <svg
lucideMail
[size]="48"
>
@if (hasUnreadMessages()) {
<circle
r="3"
cx="21"
cy="5"
stroke="none"
fill="#F56565"
/>
}
</svg>`,
styleUrls: ['./app.component.css'],
encapsulation: ViewEncapsulation.None,
})
@@ -82,38 +88,40 @@ export class App {
protected readonly hasUnreadMessages = signal<boolean>(true);
}
```
:::
### Example with text element
You can also use the `text` SVG element to add text to your icon.
::: sandpack {template=angular showTabs=false editorHeight=400 editorWidthPercentage=60 dependencies="@lucide/angular"}
```ts /src/app/app.component.ts [active]
import { Component, ViewEncapsulation } from "@angular/core";
import { LucideFile } from "@lucide/angular";
import { Component, ViewEncapsulation } from '@angular/core';
import { LucideFile } from '@lucide/angular';
@Component({
selector: 'app',
imports: [LucideFile],
template: `
<svg lucideFile [size]="48">
<text
x="7.5"
y="19"
font-size="8"
font-family="Verdana,sans-serif"
stroke-width="1"
>
JS
</text>
</svg>`,
template: ` <svg
lucideFile
[size]="48"
>
<text
x="7.5"
y="19"
font-size="8"
font-family="Verdana,sans-serif"
stroke-width="1"
>
JS
</text>
</svg>`,
styleUrls: ['./app.component.css'],
encapsulation: ViewEncapsulation.None,
})
export class App {
}
export class App {}
```
:::
+31 -32
View File
@@ -2,6 +2,7 @@
title: Global Styling - Angular
description: Learn how to style all icons globally in your Angular application using CSS or the provideLucideConfig provider.
---
<script setup>
import Sandpack from '~/.vitepress/theme/components/editors/SandpackAngular.vue'
</script>
@@ -29,9 +30,9 @@ import { provideLucideConfig } from '@lucide/angular';
export const appConfig: ApplicationConfig = {
providers: [
provideLucideConfig({
strokeWidth: 1.5
strokeWidth: 1.5,
}),
]
],
};
```
@@ -65,7 +66,7 @@ All Lucide icons include the `lucide` class. You can use this class in your styl
```
```ts /src/app/app.component.ts
import { Component, ViewEncapsulation } from "@angular/core";
import { Component, ViewEncapsulation } from '@angular/core';
import {
LucideCakeSlice,
LucideCandy,
@@ -76,7 +77,7 @@ import {
LucideSandwich,
LucideWine,
LucideDessert,
} from "@lucide/angular";
} from '@lucide/angular';
@Component({
selector: 'app',
@@ -92,28 +93,27 @@ import {
LucideDessert,
],
template: `<div class="grid">
<svg lucideCakeSlice />
<svg lucideCandy />
<svg lucideApple />
<svg lucideCookie />
<svg lucideMartini />
<svg lucideIceCream2 />
<svg lucideSandwich />
<svg lucideWine />
<svg lucideDessert />
</div>`,
<svg lucideCakeSlice />
<svg lucideCandy />
<svg lucideApple />
<svg lucideCookie />
<svg lucideMartini />
<svg lucideIceCream2 />
<svg lucideSandwich />
<svg lucideWine />
<svg lucideDessert />
</div>`,
styleUrls: ['./app.component.css', './icon.css'],
encapsulation: ViewEncapsulation.None,
})
export class App {
}
export class App {}
```
:::
### Absolute stroke width
### Non-scaling strokes
To keep the stroke width constant regardless of icon size, apply `vector-effect: non-scaling-stroke` to the icon's children. See [absolute-stroke-width](../basics/stroke-width.md#absolute-stroke-width) for more details.
To keep the stroke width constant regardless of icon size, apply `vector-effect: non-scaling-stroke` to the icon's children. See [non-scaling strokes](../basics/stroke-width.md#non-scaling-strokes) for more details.
::: sandpack {template=angular editorHeight=300 dependencies="@lucide/angular"}
@@ -137,7 +137,7 @@ To keep the stroke width constant regardless of icon size, apply `vector-effect:
```
```ts /src/app/app.component.ts
import { Component, ViewEncapsulation } from "@angular/core";
import { Component, ViewEncapsulation } from '@angular/core';
import {
LucideTentTree,
LucideCaravan,
@@ -148,7 +148,7 @@ import {
LucideMap,
LucideCloudMoon,
LucideSparkles,
} from "@lucide/angular";
} from '@lucide/angular';
@Component({
selector: 'app',
@@ -164,21 +164,20 @@ import {
LucideSparkles,
],
template: `<div class="grid">
<svg lucideTentTree />
<svg lucideCaravan />
<svg lucideFlameKindling />
<svg lucideMountainSnow />
<svg lucideTrees />
<svg lucideAxe />
<svg lucideMap />
<svg lucideCloudMoon />
<svg lucideSparkles />
</div>`,
<svg lucideTentTree />
<svg lucideCaravan />
<svg lucideFlameKindling />
<svg lucideMountainSnow />
<svg lucideTrees />
<svg lucideAxe />
<svg lucideMap />
<svg lucideCloudMoon />
<svg lucideSparkles />
</div>`,
styleUrls: ['./app.component.css', './icon.css'],
encapsulation: ViewEncapsulation.None,
})
export class App {
}
export class App {}
```
:::
+23 -19
View File
@@ -1,7 +1,8 @@
---
title: Stroke width - Angular
description: Learn how to adjust the stroke width of icons in your Angular application using the `strokeWidth` input or adjust the strokeWidth appearance using the `absoluteStrokeWidth` input.
description: Learn how to adjust the stroke width of icons in your Angular application using the `strokeWidth` input or adjust the strokeWidth appearance using the `nonScalingStroke` input.
---
<script setup>
import Sandpack from '~/.vitepress/theme/components/editors/SandpackAngular.vue'
</script>
@@ -18,55 +19,58 @@ The `strokeWidth` can be adjusted to create a different look of the icons.
::: sandpack {template=angular showTabs=false editorHeight=400 editorWidthPercentage=60 dependencies="@lucide/angular"}
```ts /src/app/app.component.ts [active]
import { Component, ViewEncapsulation } from "@angular/core";
import { LucideFolderLock } from "@lucide/angular";
import { Component, ViewEncapsulation } from '@angular/core';
import { LucideFolderLock } from '@lucide/angular';
@Component({
selector: 'app',
imports: [LucideFolderLock],
template: `<svg lucideFolderLock [strokeWidth]="1" />`,
template: `<svg
lucideFolderLock
[strokeWidth]="1"
/>`,
styleUrls: ['./app.component.css'],
encapsulation: ViewEncapsulation.None,
})
export class App {
}
export class App {}
```
:::
## Absolute stroke width
## Non-scaling strokes
When binding the `size` input, the icon's stroke width will be relative to its size, this is the default SVG behavior. The `absoluteStrokeWidth` input is introduced to adjust this behavior to make the stroke width constant no matter the size of the icon.
When binding the `size` input, the icon's stroke width will be relative to its size, this is the default SVG behavior. The `nonScalingStroke` input is introduced to adjust this behavior to make the stroke width constant no matter the size of the icon.
This means that when `absoluteStrokeWidth` is enabled and the `size` of the icons is set to `48px` the `strokeWidth` will still be `2px` on the screen.
This means that when `nonScalingStroke` is enabled and the `size` of the icons is set to `48px` the `strokeWidth` will still be `2px` on the screen.
Note `2px` is the default stroke width for a Lucide icon, this can be adjusted to all sizes.
![Absolute stroke width comparison](../../../images/absolute-stroke-width-compare.png?raw=true "Absolute stroke width comparison")
<!--@include: ../../../images/non-scaling-stroke-compare.svg -->
### Adjusting stroke width with `absoluteStrokeWidth` input
### Adjusting stroke width with `nonScalingStroke` input
Setting `absoluteStrokeWidth` to `true` will make the stroke width absolute.
Setting `nonScalingStroke` to `true` will make the stroke width non-scaling.
::: sandpack {template=angular showTabs=false editorHeight=400 editorWidthPercentage=60 dependencies="@lucide/angular"}
```ts /src/app/app.component.ts [active]
import { Component, ViewEncapsulation } from "@angular/core";
import { LucideRollerCoaster } from "@lucide/angular";
import { Component, ViewEncapsulation } from '@angular/core';
import { LucideRollerCoaster } from '@lucide/angular';
@Component({
selector: 'app',
imports: [LucideRollerCoaster],
template: `
<svg
<svg
lucideRollerCoaster
[size]="96"
[absoluteStrokeWidth]="true"
[nonScalingStroke]="true"
></svg>
`,
`,
styleUrls: ['./app.component.css'],
encapsulation: ViewEncapsulation.None,
})
export class App {
}
export class App {}
```
:::
+17 -10
View File
@@ -2,6 +2,7 @@
title: Getting started - Angular
description: This guide will help you get started with Lucide in your Angular project.
---
<script setup>
import OverviewLink from '../../.vitepress/theme/components/base/OverviewLink.vue'
import OverviewLinkGrid from '../../.vitepress/theme/components/base/OverviewLinkGrid.vue'
@@ -56,7 +57,7 @@ import { LucideFileText } from '@lucide/angular';
template: '<svg lucideFileText></svg>',
imports: [LucideFileText],
})
export class App { }
export class App {}
```
### Dynamic icon component
@@ -74,7 +75,7 @@ import { LucideDynamicIcon, LucideCircleCheck, LucideCircleX } from '@lucide/ang
})
export class App {
protected readonly model = signal<boolean>(true);
protected readonly icon = computed(() => this.model() ? LucideCircleCheck : LucideCircleX);
protected readonly icon = computed(() => (this.model() ? LucideCircleCheck : LucideCircleX));
}
```
@@ -82,18 +83,24 @@ export class App {
To customize the appearance of an icon, you can use the following inputs:
| name | type | default |
| ----------------------- | --------- | ------------ |
| `size` | *number* | 24 |
| `color` | *string* | currentColor |
| `strokeWidth` | *number* | 2 |
| `absoluteStrokeWidth` | *boolean* | false |
| `title` | *string* | null |
| name | type | default |
| ------------------ | --------- | ------------ |
| `size` | _number_ | 24 |
| `color` | _string_ | currentColor |
| `strokeWidth` | _number_ | 2 |
| `nonScalingStroke` | _boolean_ | false |
| `title` | _string_ | null |
Because icons render as SVG elements, all standard SVG attributes can also be applied. See the list of SVG Presentation Attributes on [MDN](https://developer.mozilla.org/en-US/docs/Web/SVG/Attribute/Presentation).
```html
<svg lucideHouse [size]="48" color="red" [strokeWidth]="1" title="Home"></svg>
<svg
lucideHouse
[size]="48"
color="red"
[strokeWidth]="1"
title="Home"
></svg>
```
For more examples and details on how to use these inputs, continue the guide: