Skip to content
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

Add svg component reference #9911

Open
wants to merge 5 commits into
base: 5.0.0-beta
Choose a base branch
from
Open

Add svg component reference #9911

wants to merge 5 commits into from

Conversation

natemoo-re
Copy link
Member

Description (required)

This PR adds a new section to the Images guide to introduce using .svg imports as components.

For Astro version: 5.x. See astro PR #12067.

Copy link

netlify bot commented Nov 5, 2024

Deploy Preview for astro-docs-2 ready!

Name Link
🔨 Latest commit 6262d9c
🔍 Latest deploy log https://app.netlify.com/sites/astro-docs-2/deploys/6730e1038b732700080cd886
😎 Deploy Preview https://deploy-preview-9911--astro-docs-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

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

People are going to love this @natemoo-re , thanks for chipping in on the docs for this feature! Some quick comments below! 🎉

src/content/docs/en/guides/images.mdx Outdated Show resolved Hide resolved
src/content/docs/en/guides/images.mdx Outdated Show resolved Hide resolved
src/content/docs/en/guides/images.mdx Outdated Show resolved Hide resolved
import Logo from '../assets/logo.svg';
---

<Logo />
Copy link
Member

Choose a reason for hiding this comment

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

Question: what happens if no attributes are passed? Is meta data from the .svg file used so that the image is basically presented as is? Are there any required attributes, or will this just work like this?

I'm not sure it's entirely necessary to actually state more here as long as someone can literally just do this and get SOME kind of image (even if not the way they want it to eventually look). Just want to make sure nothing is required, and everything else is an optional tweak of the logo file.

Copy link

Choose a reason for hiding this comment

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

If nothing is passed it will just use any attributes that are on the SVG file. I think this is the expected functionality.

@sarah11918 sarah11918 added add new content Document something that is not in docs. May require testing, confirmation, or affect other pages. merge-on-release Don't merge this before the feature is released! (MQ=approved but WAIT for feature release!) 5.0.0-beta labels Nov 5, 2024
@stramel
Copy link

stramel commented Nov 7, 2024

Should we also mention the default mode option in the config?

@sarah11918
Copy link
Member

@stramel - yes, we absolutely do need to mention that, too! I had reviewed this before that was in the other PR. When the docs/wording etc. there are confirmed, then we can come back and add here! 🙌

@natemoo-re
Copy link
Member Author

Made the updates that @sarah11918 suggested! Let me know if there's anything else I can do to help get this over the line!

Copy link
Member

@sarah11918 sarah11918 left a comment

Choose a reason for hiding this comment

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

Thanks @natemoo-re and @stramel !

I also added the stuff for mode and now I will need your help because the section title title and intro paragraph are for "inlining svg" and ... now they're not always inlined! 😅

I think with my suggestions here this is good (correct whatever is necessary!) EXCEPT that we probably need to now be more general about this section. So, maybe this is "SVG components"? And the intro is more like, "Astro provides support for local .svg files as components..." Does that framing sound right?

```


As a convenience, SVG components also accept a `size` property. `size` is a shorthand which sets both the `width` and `height` properties to the same value.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
As a convenience, SVG components also accept a `size` property. `size` is a shorthand which sets both the `width` and `height` properties to the same value.
#### `size`
As a convenience, SVG components also accept a `size` property. `size` is a shorthand which sets both the `width` and `height` properties to the same value.

<!-- Using the size prop to set both width and height -->
<Logo size={48} />
```

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#### `mode`
Add the `mode` attribute on any SVG component to override your default configured `svg.mode` technique for handling imported SVG files.
The following example generates a sprite sheet instead of inlining the logo's SVG content into the HTML output:
```astro
---
import Logo from '../assets/logo.svg';
---
<Logo size={64} mode="sprite" />
```

You can set attributes such as `width`, `height`, `fill`, `stroke`, and other common SVG attributes on the imported component. These attributes will automatically be applied to the underlying `<svg>` element. Properties passed to the component will override duplicate properties that exist in the original `.svg` file.


```astro
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
```astro
```astro
---
import Logo from '../assets/logo.svg';
---

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5.0.0-beta add new content Document something that is not in docs. May require testing, confirmation, or affect other pages. merge-on-release Don't merge this before the feature is released! (MQ=approved but WAIT for feature release!)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants