-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Add documentation and tutorial for svelte:fragment #6097
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
Merged
dummdidumm
merged 5 commits into
sveltejs:master
from
stephane-vanraes:svelte-fragments-docs
Mar 29, 2021
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2466f84
Add documentation and tutorial for svelte:fragment
stephane-vanraes 2ddb127
Apply suggestions from code review
stephane-vanraes a697a2b
Add new line to tutorial
stephane-vanraes dabe8f8
Apply suggestions for svelte:fragment docs and tut
stephane-vanraes f409945
Minor tweaks to doc for svelte:fragment
stephane-vanraes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
site/content/tutorial/16-special-elements/08-svelte-fragment/app-a/App.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<script> | ||
import Box from './Box.svelte' | ||
</script> | ||
|
||
<Box> | ||
<div slot="footer"> | ||
<p>All rights reserved.</p> | ||
<p>Copyright (c) 2019 Svelte Industries</p> | ||
</div> | ||
</Box> |
20 changes: 20 additions & 0 deletions
20
site/content/tutorial/16-special-elements/08-svelte-fragment/app-a/Box.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<style> | ||
.box { | ||
width: 300px; | ||
border: 1px solid #aaa; | ||
border-radius: 2px; | ||
box-shadow: 2px 2px 8px rgba(0,0,0,0.1); | ||
padding: 1em; | ||
margin: 0 0 1em 0; | ||
|
||
display: flex; | ||
flex-direction: column; | ||
gap: 1em; | ||
} | ||
</style> | ||
|
||
<div class="box"> | ||
<slot name="header">No header was provided</slot> | ||
<p>Some content between header and footer</p> | ||
<slot name="footer"></slot> | ||
</div> |
10 changes: 10 additions & 0 deletions
10
site/content/tutorial/16-special-elements/08-svelte-fragment/app-b/App.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<script> | ||
import Box from './Box.svelte' | ||
</script> | ||
|
||
<Box> | ||
<svelte:fragment slot="footer"> | ||
<p>All rights reserved.</p> | ||
<p>Copyright (c) 2019 Svelte Industries</p> | ||
</svelte:fragment> | ||
</Box> |
20 changes: 20 additions & 0 deletions
20
site/content/tutorial/16-special-elements/08-svelte-fragment/app-b/Box.svelte
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<style> | ||
.box { | ||
width: 300px; | ||
border: 1px solid #aaa; | ||
border-radius: 2px; | ||
box-shadow: 2px 2px 8px rgba(0,0,0,0.1); | ||
padding: 1em; | ||
margin: 0 0 1em 0; | ||
|
||
display: flex; | ||
flex-direction: column; | ||
gap: 1em; | ||
} | ||
</style> | ||
|
||
<div class="box"> | ||
<slot name="header">No header was provided</slot> | ||
<p>Some content between header and footer</p> | ||
<slot name="footer"></slot> | ||
</div> |
35 changes: 35 additions & 0 deletions
35
site/content/tutorial/16-special-elements/08-svelte-fragment/text.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
--- | ||
title: <svelte:fragment> | ||
--- | ||
|
||
The `<svelte:fragment>` element allows you to place content in a named slot without wrapping it in a container DOM element. This keeps the flow layout of your document intact. | ||
|
||
In the example notice how we applied a flex layout with a gap of `1em` to the box. | ||
|
||
```sv | ||
<!-- Box.svelte --> | ||
<style> | ||
.box { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 1em; | ||
} | ||
</style> | ||
|
||
<div class="box"> | ||
<slot name="header">No header was provided</slot> | ||
<p>Some content between header and footer</p> | ||
<slot name="footer"></slot> | ||
</div> | ||
``` | ||
|
||
However, the content in the footer is not spaced out according to this rhythm because wrapping it in a div created a new flow layout. | ||
|
||
We can solve this by changing `<div slot="footer">` in the `App` component. Replace the `<div>` with `<svelte:fragment>`: | ||
|
||
```sv | ||
<svelte:fragment slot="footer"> | ||
<p>All rights reserved.</p> | ||
<p>Copyright (c) 2019 Svelte Industries</p> | ||
</svelte:fragment> | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.