Skip to content

Commit 947b1ab

Browse files
committed
feat(): lucide icons support setting strokeWidth
1 parent aff8d0c commit 947b1ab

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed

bricks/icons/docs/eo-icon.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,3 +343,36 @@ children:
343343
fallback:
344344
imgSrc: "https://cdn.jsdelivr.net/npm/[email protected]/icons/y-chart.svg"
345345
```
346+
347+
### Lucide stroke width
348+
349+
Lucide icons support setting `strokeWidth` which defaults to `2` (and restrict to range `[0.5, 3]`).
350+
351+
```yaml preview
352+
- brick: div
353+
properties:
354+
style:
355+
display: grid
356+
gridTemplateColumns: repeat(6, 1fr)
357+
width: fit-content
358+
gap: 0.25em 1em
359+
fontSize: 36px
360+
children:
361+
- brick: :forEach
362+
dataSource: [0.5, 1, 1.5, 2, 2.5, 3]
363+
children:
364+
- brick: eo-icon
365+
properties:
366+
lib: lucide
367+
icon: ambulance
368+
strokeWidth: <% ITEM %>
369+
- brick: :forEach
370+
dataSource: [0.5, 1, 1.5, 2, 2.5, 3]
371+
children:
372+
- brick: span
373+
properties:
374+
textContent: <% ITEM %>
375+
style:
376+
fontSize: 16px
377+
justifySelf: center
378+
```

bricks/icons/src/general-icon/index.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export interface IconProps extends DefineLinearGradientProps, ImgIconProps {
6666
theme?: string;
6767
category?: string;
6868
prefix?: string;
69+
strokeWidth?: number;
6970
}
7071

7172
const LIBS = new Set(["antd", "easyops", "fa", "lucide"]);
@@ -106,6 +107,12 @@ class GeneralIcon extends ReactNextElement implements IconProps {
106107
*/
107108
@property() accessor prefix!: string;
108109

110+
/**
111+
* Lucide 图标描线粗线,限制在区间 `[0.5, 3]`
112+
* @default 2
113+
*/
114+
@property({ type: Number }) accessor strokeWidth: number | undefined;
115+
109116
/**
110117
* 设置当图标未找到时的回退图标
111118
*/
@@ -157,6 +164,7 @@ class GeneralIcon extends ReactNextElement implements IconProps {
157164
theme={this.theme}
158165
category={this.category}
159166
prefix={this.prefix}
167+
strokeWidth={this.strokeWidth}
160168
fallback={this.fallback}
161169
startColor={this.startColor}
162170
endColor={this.endColor}
@@ -188,6 +196,7 @@ function GeneralIconComponent({
188196
theme,
189197
category,
190198
prefix,
199+
strokeWidth,
191200
keepSvgOriginalColor,
192201
imgSrc,
193202
imgStyle,
@@ -258,6 +267,6 @@ function GeneralIconComponent({
258267
) : lib === "fa" ? (
259268
<WrappedFaIcon prefix={prefix} {...commonProps} />
260269
) : lib === "lucide" ? (
261-
<WrappedLucideIcon {...commonProps} />
270+
<WrappedLucideIcon strokeWidth={strokeWidth} {...commonProps} />
262271
) : null;
263272
}

bricks/icons/src/lucide-icon/index.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const { defineElement, property, event } = createDecorators();
1818

1919
export interface LucideIconProps extends DefineLinearGradientProps {
2020
icon?: string;
21+
strokeWidth?: number;
2122
}
2223

2324
const styleText = [lucideStyleText, sharedStyleText].join("\n");
@@ -28,6 +29,12 @@ class LucideIcon extends NextElement implements LucideIconProps {
2829
/** 图标名 */
2930
@property() accessor icon: string | undefined;
3031

32+
/**
33+
* 描线粗线,限制在区间 `[0.5, 3]`
34+
* @default 2
35+
*/
36+
@property({ type: Number }) accessor strokeWidth: number | undefined;
37+
3138
/** 渐变色起始颜色 */
3239
@property() accessor startColor: string | undefined;
3340

@@ -111,6 +118,14 @@ class LucideIcon extends NextElement implements LucideIconProps {
111118
)}"></stop></linearGradient>`;
112119
svg.insertBefore(defs, svg.firstChild);
113120
}
121+
122+
const strokeWidth = this.strokeWidth ?? 2;
123+
if (strokeWidth !== 2) {
124+
svg.setAttribute(
125+
"stroke-width",
126+
String(Math.max(0.5, Math.min(3, strokeWidth)))
127+
);
128+
}
114129
}
115130

116131
this.shadowRoot.replaceChildren(...nodes);

0 commit comments

Comments
 (0)