-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat(types): add SvgComponent type and update SVG module declaration #13651
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
Conversation
🦋 Changeset detectedLatest commit: f600121 The changes in this PR will be included in the next version bump. 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is blocked because it contains a minor
changeset. A reviewer will merge this at the next release if approved.
Should this be
But we can change it to |
I think this is good as a minor thanks! |
Changes done. @florian-lefebvre Note: I didn't use GitHub UI to accept your suggestions, but rather just replicated them in my local and made a commit to ensure there are no syntax errors and it has proper formatting. :) |
This is an expermental feature, so it can be a patch |
@ascorbic As per v5.7.0 release notes, the SVG feature is no longer experimental. Can you clarify again whether this change should be |
🤦♂️ You're right of course. In my defence is been a long week with lots of features |
@ADTC maintainers are responsible for documenting the features they implement. This means that you will have send a PR to Also, the Build is falling, so we can't merge it until this is fixed. |
Yes I know the build is failing but I don't know how to fix it. 😢 I was hoping @Princesseuh might have some insight. |
I'm not sure, sorry. It has been too much time since I've set up client.d.ts and all of that to remember the exact rules that make TypeScript happy. In retrospect, maybe astro-jsx.d.ts shouldn't have lived "outside" of the package, it's wonky, but I set that up 3 years ago now 😅 |
We're going to need docs for this one! I'm going to enlist the help of @ArmandPhilippot here! 😄 |
Let me know if I can help in any way! |
I think we can describe the type in Type utilities and maybe add However, I'm not sure how to describe it... because, as I understand it, the use case is to pass an imported SVG as a component via props. But, we only document passing components with slots, not as props. While it works with some components (like Maybe we could describe the type using what we document in Common prop type patterns?
Something like: // component-a.astro
---
import type { SvgComponent } from "astro/types";
type Props = {
children: SvgComponent;
}
---
<div><slot /></div> // component-b.astro
---
import ComponentA from "./component-a.astro";
import MyLogo from "../assets/logo.svg";
---
{/* This would work: */}
<ComponentA><MyLogo /></ComponentA>
{/* This won't work, Typescript will complain: */}
<ComponentA>Anything except an imported SVG.</ComponentA>
{/* 'ComponentA' components don't accept text as child elements. Text in JSX has the type 'string', but the expected type of 'children' is 'SvgComponent'.ts(2747) */} |
If we need examples, I think something about a user menu would be better: import type { SvgComponent } from "astro/types";
import HomeIcon from './Home.svg'
interface Link {
url: string
text: string
icon: SvgComponent
}
const links: Link[] = [
{
url: '/',
text: 'Home',
icon: HomeIcon
}
] |
OK, so some thoughts:
|
I think your suggestion makes a lot of sense Sarah |
I'm thinking something like what we do in the Layouts guide maybe? We explain creating layout components (how they wrap, slots etc.) and then have a Using TypeScript with layouts section which is basically that... OK, you made a layout. If you additionally want type safety, here's what it looks like to type things. We could use this as a model for adding a sub-section, so the flow goes like:
|
I agree Florian's example looks better! I guess I was too focused on the "using them as props" concern, but this can be done in the same component. I think the "Type utilities" section is the only place where we document types from So, yes, a new sub-section in SVG components may be enough! |
FYI I initially wanted to export the type from |
OK, added a first attempt here! Let's continue the docs discussion there! withastro/docs#12406 |
Co-authored-by: Sarah Rainsberger <[email protected]>
Changes
SvgComponent
type as per discussion here.Testing
No tests needed, I think?
Docs
Docs will need to mention that the
SvgComponent
component is available for use, similar to the mentions of other types likeImageMetadata
./cc @withastro/maintainers-docs for feedback!