Skip to content

组合图标

🌐 Combining icons

你可以通过嵌套 SVG 元素将多个图标合并为单个图标。如果你想通过组合现有图标来创建自定义图标,这非常有用。

🌐 You can combine multiple icons into a single icon by nesting SVG elements. This is useful if you want to create custom icons icons by combining existing ones.

<script>
import Scan from '@lucide/svelte/icons/scan';
import User from '@lucide/svelte/icons/user';
</script>

<div class="app">
  <Scan size="48">
    <User
      size="12"
      x="6"
      y="6"
      absoluteStrokeWidth
    />
  </Scan>
</div>

这是有效的,因为SVG 可以嵌套,并且图标上支持所有 SVG 属性。 可以调整 xy 坐标来按你喜欢的位置放置图标。

🌐 This is valid, since SVGs can be nested, and all SVG properties are supported on the icons. The x and y coordinates can be adjusted to position the icons as you like.

限制

在组合图标时,你需要确保 xy 坐标在外部图标(24x24)的 viewBox 范围内。

使用原生 SVG 元素

🌐 With native SVG elements

你也可以将 Lucide 图标与原生 SVG 元素结合,以构建自定义图标变体。

🌐 You can also combine Lucide icons with native SVG elements to build custom icon variations.

带通知徽章的示例

🌐 Example with notification badge

例如,你可以使用 circle SVG 元素向图标添加通知徽章。

🌐 For example, you can add a notification badge to an icon by using the circle SVG element.

<script>
import Mail from '@lucide/svelte/icons/mail';

const hasUnreadMessages = true;
</script>

<div class="app">
  <Mail size="48">
    {#if hasUnreadMessages}
      <circle
        r="3"
        cx="21"
        cy="5"
        stroke="none"
        fill="#F56565"
      />
    {/if}
  </Mail>
</div>

带有文本元素的示例

🌐 Example with text element

你也可以使用 text SVG 元素向你的图标添加文本。

🌐 You can also use the text SVG element to add text to your icon.

<script>
import File from '@lucide/svelte/icons/file';
</script>

<div class="app">
  <File size="48">
    <text
      x="7.5"
      y="19"
      font-size="8"
      font-family="Verdana,sans-serif"
      stroke-width="1"
    >
      JS
    </text>
  </File>
</div>