withastro / roadmap

Ideas, suggestions, and formal RFC proposals for the Astro project.
290 stars 29 forks source link

Built-in SVG components #699

Open natemoo-re opened 11 months ago

natemoo-re commented 11 months ago

Summary

Let's support importing and using .svg files as Astro components.

Background & Motivation

Users have reported that .svg files are currently difficult to use—this is a problem we should provide an optimized solution for. Working with .svgs doesn’t need to be difficult or bloat your client-side JavaScript.

The Astro team has discussed and experimented with an "icon" primitive since before Astro v1.0 shipped. Now that we have shipped 3.0 with full astro:assets support, I firmly believe all of the pieces are in place to finally make this happen.

Goals

Non-Goals

gvkhna commented 11 months ago

Please support promise imports, like src={import(‘file.svg’)}. Please, thank you!

+1, “ provide a great component for each supported framework”. I still don’t know how to in-line svg files with react/vite, always very brittle, end up copy pasting. 👍

stramel commented 10 months ago

Would love to see the ability to extend the built-in SVG support for icon sets in the future using something like @iconify/json.

I also think that framework support would be a good Goal. We get lots of questions about how to use icons within frameworks. Typically this has been solved using slots

azat-io commented 3 months ago

It's something I'm really looking forward to. ❤️

The main problem with importing via <Fragment set:html={HomeIcon} /> is the inability to use CSS classes with inlined SVGs.

What will importing SVG files look like?

---
import HomeIcon from '~/icons/home.svg?component'
---

<HomeIcon class="icon" />
blackPeppper commented 2 months ago

when need it to convert repeated SVGs to be use symbol like astro-icon

Gismogy commented 1 month ago

It's something I'm really looking forward to. ❤️

The main problem with importing via <Fragment set:html={HomeIcon} /> is the inability to use CSS classes with inlined SVGs.

What will importing SVG files look like?

---
import HomeIcon from '~/icons/home.svg?component'
---

<HomeIcon class="icon" />

I was actually more thinking for its own tag like Picture has its own picture tag. Might that be a idea?

cxa commented 1 month ago

Before this builtin component is out, and if you don't like to save svg copies inside places like src/icons with astro-icon, you can try https://github.com/cxa/astro-inline-svg:

---
import Svg from "@cxa/astro-inline-svg";
import sunRiseSVG from "lucide-static/icons/sunrise.svg?raw";
---

<Svg raw={sunRiseSVG} class="sun-rise" stroke-width={1.5} />