From 6c4ccbbc1a1f3074093422f648010d496631e599 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Tue, 5 Mar 2019 21:10:28 -0500 Subject: [PATCH] spruce up slot examples --- .../14-composition/01-slots/app-a/Box.svelte | 8 +++- .../14-composition/01-slots/app-b/Box.svelte | 8 +++- .../02-slot-fallbacks/app-a/App.svelte | 8 ++++ .../02-slot-fallbacks/app-a/Box.svelte | 14 ++++++ .../02-slot-fallbacks/app-b/App.svelte | 10 ++++ .../02-slot-fallbacks/app-b/Box.svelte | 16 +++++++ .../14-composition/02-slot-fallbacks/text.md | 24 ++++++++++ .../03-named-slots/app-a/App.svelte | 7 +++ .../03-named-slots/app-a/ContactCard.svelte | 47 +++++++++++++++++++ .../03-named-slots/app-b/App.svelte | 14 ++++++ .../03-named-slots/app-b/ContactCard.svelte | 47 +++++++++++++++++++ .../14-composition/03-named-slots/text.md | 44 +++++++++++++++++ site/static/tutorial/icons/email.svg | 4 ++ site/static/tutorial/icons/map-marker.svg | 4 ++ 14 files changed, 251 insertions(+), 4 deletions(-) create mode 100644 site/content/tutorial/14-composition/02-slot-fallbacks/app-a/App.svelte create mode 100644 site/content/tutorial/14-composition/02-slot-fallbacks/app-a/Box.svelte create mode 100644 site/content/tutorial/14-composition/02-slot-fallbacks/app-b/App.svelte create mode 100644 site/content/tutorial/14-composition/02-slot-fallbacks/app-b/Box.svelte create mode 100644 site/content/tutorial/14-composition/02-slot-fallbacks/text.md create mode 100644 site/content/tutorial/14-composition/03-named-slots/app-a/App.svelte create mode 100644 site/content/tutorial/14-composition/03-named-slots/app-a/ContactCard.svelte create mode 100644 site/content/tutorial/14-composition/03-named-slots/app-b/App.svelte create mode 100644 site/content/tutorial/14-composition/03-named-slots/app-b/ContactCard.svelte create mode 100644 site/content/tutorial/14-composition/03-named-slots/text.md create mode 100644 site/static/tutorial/icons/email.svg create mode 100644 site/static/tutorial/icons/map-marker.svg diff --git a/site/content/tutorial/14-composition/01-slots/app-a/Box.svelte b/site/content/tutorial/14-composition/01-slots/app-a/Box.svelte index 9b3b7c22f9..62f0b92dc0 100644 --- a/site/content/tutorial/14-composition/01-slots/app-a/Box.svelte +++ b/site/content/tutorial/14-composition/01-slots/app-a/Box.svelte @@ -1,7 +1,11 @@ diff --git a/site/content/tutorial/14-composition/01-slots/app-b/Box.svelte b/site/content/tutorial/14-composition/01-slots/app-b/Box.svelte index 4a6a89aa3c..7ed13f386f 100644 --- a/site/content/tutorial/14-composition/01-slots/app-b/Box.svelte +++ b/site/content/tutorial/14-composition/01-slots/app-b/Box.svelte @@ -1,7 +1,11 @@ diff --git a/site/content/tutorial/14-composition/02-slot-fallbacks/app-a/App.svelte b/site/content/tutorial/14-composition/02-slot-fallbacks/app-a/App.svelte new file mode 100644 index 0000000000..cd0ebde935 --- /dev/null +++ b/site/content/tutorial/14-composition/02-slot-fallbacks/app-a/App.svelte @@ -0,0 +1,8 @@ + + + +

Hello!

+

This is a box. It can contain anything.

+
\ No newline at end of file diff --git a/site/content/tutorial/14-composition/02-slot-fallbacks/app-a/Box.svelte b/site/content/tutorial/14-composition/02-slot-fallbacks/app-a/Box.svelte new file mode 100644 index 0000000000..7ed13f386f --- /dev/null +++ b/site/content/tutorial/14-composition/02-slot-fallbacks/app-a/Box.svelte @@ -0,0 +1,14 @@ + + +
+ +
\ No newline at end of file diff --git a/site/content/tutorial/14-composition/02-slot-fallbacks/app-b/App.svelte b/site/content/tutorial/14-composition/02-slot-fallbacks/app-b/App.svelte new file mode 100644 index 0000000000..e30be6d1fc --- /dev/null +++ b/site/content/tutorial/14-composition/02-slot-fallbacks/app-b/App.svelte @@ -0,0 +1,10 @@ + + + +

Hello!

+

This is a box. It can contain anything.

+
+ + \ No newline at end of file diff --git a/site/content/tutorial/14-composition/02-slot-fallbacks/app-b/Box.svelte b/site/content/tutorial/14-composition/02-slot-fallbacks/app-b/Box.svelte new file mode 100644 index 0000000000..66c580632c --- /dev/null +++ b/site/content/tutorial/14-composition/02-slot-fallbacks/app-b/Box.svelte @@ -0,0 +1,16 @@ + + +
+ + no content was provided + +
\ No newline at end of file diff --git a/site/content/tutorial/14-composition/02-slot-fallbacks/text.md b/site/content/tutorial/14-composition/02-slot-fallbacks/text.md new file mode 100644 index 0000000000..c8fbde91dc --- /dev/null +++ b/site/content/tutorial/14-composition/02-slot-fallbacks/text.md @@ -0,0 +1,24 @@ +--- +title: Slot fallbacks +--- + +A component can specify *fallbacks* for any slots that are left empty, by putting content inside the `` element: + +```html +
+ + no content was provided + +
+``` + +We can now create instances of `` eithout any children: + +```html + +

Hello!

+

This is a box. It can contain anything.

+
+ + +``` \ No newline at end of file diff --git a/site/content/tutorial/14-composition/03-named-slots/app-a/App.svelte b/site/content/tutorial/14-composition/03-named-slots/app-a/App.svelte new file mode 100644 index 0000000000..c15b38ad1c --- /dev/null +++ b/site/content/tutorial/14-composition/03-named-slots/app-a/App.svelte @@ -0,0 +1,7 @@ + + + + + \ No newline at end of file diff --git a/site/content/tutorial/14-composition/03-named-slots/app-a/ContactCard.svelte b/site/content/tutorial/14-composition/03-named-slots/app-a/ContactCard.svelte new file mode 100644 index 0000000000..c09404a282 --- /dev/null +++ b/site/content/tutorial/14-composition/03-named-slots/app-a/ContactCard.svelte @@ -0,0 +1,47 @@ + + +
+

+ + Unknown name + +

+ +
+ + Unknown address + +
+ + +
\ No newline at end of file diff --git a/site/content/tutorial/14-composition/03-named-slots/app-b/App.svelte b/site/content/tutorial/14-composition/03-named-slots/app-b/App.svelte new file mode 100644 index 0000000000..8047809359 --- /dev/null +++ b/site/content/tutorial/14-composition/03-named-slots/app-b/App.svelte @@ -0,0 +1,14 @@ + + + + + P. Sherman + + + + 42 Wallaby Way
+ Sydney +
+
\ No newline at end of file diff --git a/site/content/tutorial/14-composition/03-named-slots/app-b/ContactCard.svelte b/site/content/tutorial/14-composition/03-named-slots/app-b/ContactCard.svelte new file mode 100644 index 0000000000..1acf290943 --- /dev/null +++ b/site/content/tutorial/14-composition/03-named-slots/app-b/ContactCard.svelte @@ -0,0 +1,47 @@ + + +
+

+ + Unknown name + +

+ +
+ + Unknown address + +
+ + +
\ No newline at end of file diff --git a/site/content/tutorial/14-composition/03-named-slots/text.md b/site/content/tutorial/14-composition/03-named-slots/text.md new file mode 100644 index 0000000000..169f028830 --- /dev/null +++ b/site/content/tutorial/14-composition/03-named-slots/text.md @@ -0,0 +1,44 @@ +--- +title: Named slots +--- + +The previous example contained a *default slot*, which renders the direct children of a component. Sometimes you will need more control over placement, such as with this ``. In those cases, we can use *named slots*. + +In `ContactCard.svelte`, add a `name` attribute to each slot: + +```html +
+

+ + Unknown name + +

+ +
+ + Unknown address + +
+ + +
+``` + +Then, add elements with corresponding `slot="..."` attributes inside the `` component: + +```html + + + P. Sherman + + + + 42 Wallaby Way
+ Sydney +
+
+``` \ No newline at end of file diff --git a/site/static/tutorial/icons/email.svg b/site/static/tutorial/icons/email.svg new file mode 100644 index 0000000000..db656054ff --- /dev/null +++ b/site/static/tutorial/icons/email.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/site/static/tutorial/icons/map-marker.svg b/site/static/tutorial/icons/map-marker.svg new file mode 100644 index 0000000000..4e9466c7bd --- /dev/null +++ b/site/static/tutorial/icons/map-marker.svg @@ -0,0 +1,4 @@ + + + + \ No newline at end of file