Skip to content

feat(core): rewrite to use built-in svg components #239

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 25 commits into
base: next
Choose a base branch
from

Conversation

stramel
Copy link
Collaborator

@stramel stramel commented Sep 25, 2024

Warning

These changes are still highly volatile and likely to change. Proceed with caution

Building on top of the hopefully soon to be accepted Built-in SVG components in withastro/astro#12067. Discussed here withastro/roadmap#699

This adds virtual paths to the Iconify collections and icons. Simply import astro:icons/<collection>/<icon> in order to use the icon component.

This changes also removes the functionality associated with local svg imports since this is now covered through Astro.

Another big change is that we're no longer running SVGO. I'm assuming that Iconify is handling most of the optimizations for us. Any local icon optimizations would be moved into the astro repo (likely post MVP)

TODO:

  • rewrite functionality to use the built-in SVG components
  • fix typings for virtual module imports
  • update demo to use new imports
  • fix type assertions on the integration/vite plugin
  • add better error handling
  • add logging
  • provide offline support
  • fix import.meta.env being undefined
  • clean up
  • agree upon virtual module naming
  • documentation

Possible Future Enhancements:

Typescript Plugin: We could write a typescript plugin that could autosuggest collections and icons as you type. We could also add additional validation for collection + icon combinations. We could also warn on deprecated usages.

Dev Toolbar: We could write a dev toolbar that could highlight all icons, show deprecated icons, and list all icons on the page. We could also potentially suggest icons that would be good candidates for sprite mode.

@stramel stramel requested a review from natemoo-re September 25, 2024 05:23
@stramel stramel self-assigned this Sep 25, 2024
Copy link

changeset-bot bot commented Sep 25, 2024

🦋 Changeset detected

Latest commit: 8d750ae

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
astro-icon Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link

vercel bot commented Sep 25, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
api-astroicon 🛑 Canceled (Inspect) Mar 31, 2025 4:14pm
astroicon ✅ Ready (Inspect) Visit Preview 💬 Add feedback Mar 31, 2025 4:14pm

@stramel stramel changed the base branch from main to next September 26, 2024 00:05
@stramel stramel marked this pull request as ready for review September 26, 2024 03:33
height = DEFAULT_ICON_SIZE,
body,
} = data;
const svg = `<svg data-icon="${collection}:${icon}" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">${body}</svg>`;
Copy link
Collaborator Author

@stramel stramel Mar 31, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@natemoo-re Should we switch this to {collection}/{icon}? This would match the import rather than having a separate way of referencing the combination

Suggested change
const svg = `<svg data-icon="${collection}:${icon}" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">${body}</svg>`;
const svg = `<svg data-icon="${collection}/${icon}" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">${body}</svg>`;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant