From 2466f8414e970e01f6705af512682d4a782d7a49 Mon Sep 17 00:00:00 2001 From: stephane-vanraes Date: Thu, 18 Mar 2021 20:57:45 +0100 Subject: [PATCH] Add documentation and tutorial for svelte:fragment --- site/content/docs/02-template-syntax.md | 44 +++++++++++++++++++ .../08-svelte-fragment/app-a/App.svelte | 11 +++++ .../08-svelte-fragment/app-a/Box.svelte | 20 +++++++++ .../08-svelte-fragment/app-b/App.svelte | 11 +++++ .../08-svelte-fragment/app-b/Box.svelte | 20 +++++++++ .../08-svelte-fragment/text.md | 43 ++++++++++++++++++ 6 files changed, 149 insertions(+) create mode 100644 site/content/tutorial/16-special-elements/08-svelte-fragment/app-a/App.svelte create mode 100644 site/content/tutorial/16-special-elements/08-svelte-fragment/app-a/Box.svelte create mode 100644 site/content/tutorial/16-special-elements/08-svelte-fragment/app-b/App.svelte create mode 100644 site/content/tutorial/16-special-elements/08-svelte-fragment/app-b/Box.svelte create mode 100644 site/content/tutorial/16-special-elements/08-svelte-fragment/text.md diff --git a/site/content/docs/02-template-syntax.md b/site/content/docs/02-template-syntax.md index 2c665376dc..2cd973cf31 100644 --- a/site/content/docs/02-template-syntax.md +++ b/site/content/docs/02-template-syntax.md @@ -1328,6 +1328,28 @@ Named slots allow consumers to target specific areas. They can also have fallbac ``` +Named slots can also be used with components ``. +In order to place content in a slot without losing the flow layout (ie: without using a wrapper element) you can use the special element ``. + +```sv + +
+ No header was provided +

Some content between header and footer

+ +
+ + + + + +

All rights reserved.

+

Copyright (c) 2019 Svelte Industries

+
+
+``` + + #### [`$$slots`](slots_object) --- @@ -1537,3 +1559,25 @@ The `` element provides a place to specify per-component compile ```sv ``` + +### `` + +The `` allows you to place content in a named [docs](docs#slot_name) without wrapping it in a container, this allows to keep intact the flow layout of your document. + +```sv + +
+ No header was provided +

Some content between header and footer

+ +
+ + + +

Hello

+ +

All rights reserved.

+

Copyright (c) 2019 Svelte Industries

+
+
+``` diff --git a/site/content/tutorial/16-special-elements/08-svelte-fragment/app-a/App.svelte b/site/content/tutorial/16-special-elements/08-svelte-fragment/app-a/App.svelte new file mode 100644 index 0000000000..3708b34880 --- /dev/null +++ b/site/content/tutorial/16-special-elements/08-svelte-fragment/app-a/App.svelte @@ -0,0 +1,11 @@ + + + + +
+

All rights reserved.

+

Copyright (c) 2019 Svelte Industries

+
+
\ No newline at end of file diff --git a/site/content/tutorial/16-special-elements/08-svelte-fragment/app-a/Box.svelte b/site/content/tutorial/16-special-elements/08-svelte-fragment/app-a/Box.svelte new file mode 100644 index 0000000000..16c17f90ef --- /dev/null +++ b/site/content/tutorial/16-special-elements/08-svelte-fragment/app-a/Box.svelte @@ -0,0 +1,20 @@ + + +
+ No header was provided +

Some content between header and footer

+ +
diff --git a/site/content/tutorial/16-special-elements/08-svelte-fragment/app-b/App.svelte b/site/content/tutorial/16-special-elements/08-svelte-fragment/app-b/App.svelte new file mode 100644 index 0000000000..2724752b80 --- /dev/null +++ b/site/content/tutorial/16-special-elements/08-svelte-fragment/app-b/App.svelte @@ -0,0 +1,11 @@ + + + + + +

All rights reserved.

+

Copyright (c) 2019 Svelte Industries

+
+
diff --git a/site/content/tutorial/16-special-elements/08-svelte-fragment/app-b/Box.svelte b/site/content/tutorial/16-special-elements/08-svelte-fragment/app-b/Box.svelte new file mode 100644 index 0000000000..16c17f90ef --- /dev/null +++ b/site/content/tutorial/16-special-elements/08-svelte-fragment/app-b/Box.svelte @@ -0,0 +1,20 @@ + + +
+ No header was provided +

Some content between header and footer

+ +
diff --git a/site/content/tutorial/16-special-elements/08-svelte-fragment/text.md b/site/content/tutorial/16-special-elements/08-svelte-fragment/text.md new file mode 100644 index 0000000000..8505256955 --- /dev/null +++ b/site/content/tutorial/16-special-elements/08-svelte-fragment/text.md @@ -0,0 +1,43 @@ +--- +title: +--- + +The `` element allows you to add content to a named slot without breaking the document's flow layout. + +In the example notice how we applied a flex layout with a gap of 2em to the box. + +```sv + + + +
+ No header was provided +

Some content between header and footer

+ +
+``` + +The content in the footer however is not spaced out according to this rythm because wrapping it in a div created a new flow layout. + +We can solve this by changing `
` in the `App` component: + +```sv + +

All rights reserved.

+

Copyright (c) 2019 Svelte Industries

+
+``` +