-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add conditional slot example (#5383)
- Loading branch information
1 parent
ddd79e3
commit daec256
Showing
6 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
site/content/examples/15-composition/04-conditional-slots/App.svelte
This file contains 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,13 @@ | ||
<script> | ||
import Profile from "./Profile.svelte"; | ||
</script> | ||
|
||
<Profile> | ||
<span slot="name">Bob</span> | ||
<span slot="email">[email protected]</span> | ||
</Profile> | ||
|
||
<Profile> | ||
<span slot="name">Alice</span> | ||
<span slot="phone">12345678</span> | ||
</Profile> |
24 changes: 24 additions & 0 deletions
24
site/content/examples/15-composition/04-conditional-slots/Profile.svelte
This file contains 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,24 @@ | ||
<style> | ||
section { | ||
width: 200px; | ||
display: grid; | ||
grid-template-columns: 1fr 1fr; | ||
padding: 16px; | ||
box-shadow: 2px 2px 4px #dedede; | ||
border: 1px solid #888; | ||
margin-bottom: 16px; | ||
} | ||
</style> | ||
|
||
<section> | ||
<div>Name</div> | ||
<slot name="name" /> | ||
{#if $$slots.email} | ||
<div>Email</div> | ||
<slot name="email" /> | ||
{/if} | ||
{#if $$slots.phone} | ||
<div>Phone</div> | ||
<slot name="phone" /> | ||
{/if} | ||
</section> |
3 changes: 3 additions & 0 deletions
3
site/content/examples/15-composition/04-conditional-slots/meta.json
This file contains 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,3 @@ | ||
{ | ||
"title": "Conditional Slots" | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.