mirror of https://github.com/sveltejs/svelte
parent
b2c3eb7ba8
commit
46fc0dec0b
@ -0,0 +1,7 @@
|
||||
<script>
|
||||
import Box from './Box.svelte';
|
||||
</script>
|
||||
|
||||
<Box>
|
||||
<!-- put content here -->
|
||||
</Box>
|
@ -0,0 +1,10 @@
|
||||
<style>
|
||||
.box {
|
||||
border: 2px solid black;
|
||||
padding: 0.5em;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="box">
|
||||
<!-- content should be injected here -->
|
||||
</div>
|
@ -0,0 +1,8 @@
|
||||
<script>
|
||||
import Box from './Box.svelte';
|
||||
</script>
|
||||
|
||||
<Box>
|
||||
<h2>Hello!</h2>
|
||||
<p>This is a box. It can contain anything.</p>
|
||||
</Box>
|
@ -0,0 +1,10 @@
|
||||
<style>
|
||||
.box {
|
||||
border: 2px solid black;
|
||||
padding: 0.5em;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="box">
|
||||
<slot></slot>
|
||||
</div>
|
@ -0,0 +1,28 @@
|
||||
---
|
||||
title: Slots
|
||||
---
|
||||
|
||||
Just like elements can have children...
|
||||
|
||||
```html
|
||||
<div>
|
||||
<p>I'm a child of the div</p>
|
||||
</div>
|
||||
```
|
||||
|
||||
...so can components. Before a component can accept children, though, it needs to know where to put them. We do this with the `<slot>` element. Put this inside `Box.svelte`:
|
||||
|
||||
```html
|
||||
<div class="box">
|
||||
<slot></slot>
|
||||
</div>
|
||||
```
|
||||
|
||||
You can now put things in the box:
|
||||
|
||||
```html
|
||||
<Box>
|
||||
<h2>Hello!</h2>
|
||||
<p>This is a box. It can contain anything.</p>
|
||||
</Box>
|
||||
```
|
@ -0,0 +1,3 @@
|
||||
{
|
||||
"title": "Component composition"
|
||||
}
|
Loading…
Reference in new issue