Skip to content

[astro-components] add named slots example using Fragment#5968

Merged
sarah11918 merged 6 commits into
mainfrom
named-fragment-slots
Dec 28, 2023
Merged

[astro-components] add named slots example using Fragment#5968
sarah11918 merged 6 commits into
mainfrom
named-fragment-slots

Conversation

@sarah11918
Copy link
Copy Markdown
Member

@sarah11918 sarah11918 commented Dec 27, 2023

Description (required)

This adds another example to the section on named slots that shows using the named slot attribute on the Fragment component (<Fragment slot="header">) because the only existing examples showed adding the attribute to HTML elements.

In response to a request from an issue. Also note that this pattern is used and documented in the AstroWind template: https://astrowind.vercel.app/astrowind-template-in-depth , so it seemed reasonable to include an example here!

Am open to refining this example, or choosing a better one. Note that this one adds style classes (not style attributes) and therefore is maybe reflective of how it might be used, but not copy/pasteable. We could also choose to show inline styles if we cared instead.

Direct deploy preview: https://docs-git-named-fragment-slots-astrodotbuild.vercel.app/en/core-concepts/astro-components/#named-slots

Related issues & labels (optional)

@sarah11918 sarah11918 added the add new content Document something that is not in docs. May require testing, confirmation, or affect other pages. label Dec 27, 2023
@vercel
Copy link
Copy Markdown

vercel Bot commented Dec 27, 2023

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

Name Status Preview Comments Updated (UTC)
docs ✅ Ready (Inspect) Visit Preview Dec 28, 2023 5:04pm
1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
docs-i18n ⬜️ Ignored (Inspect) Visit Preview Dec 28, 2023 5:04pm

@VoxelMC
Copy link
Copy Markdown
Contributor

VoxelMC commented Dec 27, 2023

The changes look great, Sarah! It's always nice to have another example for a bit of an abstract concept. :)

Comment on lines +274 to +278
<Fragment slot="header"> <!-- pass table header -->
<tr><th>Column 1</th><th>Column 2</th></tr>
</Fragment>

<Fragment slot="body"> <!-- pass table body -->
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Suggested change
<Fragment slot="header"> <!-- pass table header -->
<tr><th>Column 1</th><th>Column 2</th></tr>
</Fragment>
<Fragment slot="body"> <!-- pass table body -->
<Fragment slot="header"> <!-- passed into table header -->
<tr><th>Column 1</th><th>Column 2</th></tr>
</Fragment>
<Fragment slot="body"> <!-- passed into table body -->

I don't know if this makes sense, but it does in my head. For clarity - the slots terminology doesn't seem to have a clear directionality to it, in my opinion (name <--> slot attributes).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

So, my attempt at this has been to use the phrase "slot placeholder" when talking about the <slot /> element itself (that happens to have a name attribute, but I'm not emphasizing this). Then, when talking about the content that will go into the slot, I do say "slot attribute" because in this case, the slot is in fact an attribute, not an element.

So, I'm trying to less equate attributes and more distinguish which role "slot" has in each case... hopefully somewhat successfully? 😅

Comment thread src/content/docs/en/core-concepts/astro-components.mdx Outdated
Comment thread src/content/docs/en/core-concepts/astro-components.mdx Outdated
sarah11918 and others added 2 commits December 28, 2023 12:21
Co-authored-by: Maurici Abad Gutierrez <hello@mauriciabad.com>
Co-authored-by: Maurici Abad Gutierrez <hello@mauriciabad.com>
Comment thread src/content/docs/en/core-concepts/astro-components.mdx
Co-authored-by: voxel!() <voxelmc@hotmail.com>
@sarah11918
Copy link
Copy Markdown
Member Author

Thanks everyone! Going to merge this as NWTWWHB now! 🥳

@sarah11918 sarah11918 merged commit c9ee2b2 into main Dec 28, 2023
@sarah11918 sarah11918 deleted the named-fragment-slots branch December 28, 2023 16:56
ematipico pushed a commit that referenced this pull request Jan 26, 2024
Co-authored-by: Maurici Abad Gutierrez <hello@mauriciabad.com>
Co-authored-by: voxel!() <voxelmc@hotmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

add new content Document something that is not in docs. May require testing, confirmation, or affect other pages.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Slots can also be Fragments besides HTML elements, but it's not explained

3 participants