feat: add symbol prop to <Icon> for <use> integration in UI frameworks #238
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
This PR introduces a new prop symbol to the Icon component, allowing the component to return an SVG
<symbol>
element instead of a full<svg>
element. The symbol includes theid
andviewBox
attributes, making it easier to reference icons using<use>
, particularly in UI frameworks like Vue, React, or Svelte.Motivation:
Previously, the
Icon
component allowed reusing icons, but in UI frameworks such as Vue, React, or Svelte, it required passing the icons through slots, which could be inconvenient. With the introduction of thesymbol
prop, icons can now be referenced via the<use>
element, enabling a more flexible and efficient way to use icons across the application, without relying on slots.Changes:
Added a symbol prop to the Icon component.
When
symbol={true}
, the component will return a<symbol>
element with the appropriateid
andviewBox
attributes instead of rendering a standalone<svg>
element.This update allows developers to reference icons using
<use>
, improving flexibility and integration in UI frameworks.Example Usage:
Benefits:
Provides a more flexible way to reuse icons in frameworks like Vue, React, or Svelte, without the need to use slots.
Allows referencing icons with
<use>
, making it easier to integrate icons into the DOM structure.Reduces redundant SVG code by reusing the same symbol definition across multiple instances.
Testing:
This feature has been tested with various icon sets and confirmed to work smoothly with Astro islands and other UI frameworks. The default behavior (rendering a full SVG) remains unchanged if the symbol prop is not used.
Related Issue:
#151