Skip to content

Commit 3c6a656

Browse files
author
Rich Harris
committed
nicer slot exercises
1 parent c34a754 commit 3c6a656

File tree

31 files changed

+613
-270
lines changed

31 files changed

+613
-270
lines changed

content/tutorial/03-advanced-svelte/07-composition/01-slots/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,21 @@ Just like elements can have children...
1111
</div>
1212
```
1313

14-
...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`:
14+
...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 `Card.svelte`:
1515

1616
```svelte
17-
/// file: Box.svelte
18-
<div class="box">
17+
/// file: Card.svelte
18+
<div class="card ">
1919
+++<slot />+++
2020
</div>
2121
```
2222

23-
You can now put things in the box:
23+
You can now put things on the card:
2424

2525
```svelte
2626
/// file: App.svelte
27-
<Box>
28-
+++<h2>Hello!</h2>+++
29-
+++<p>This is a box. It can contain anything.</p>+++
30-
</Box>
27+
<Card>
28+
+++<span>Patrick BATEMAN</span>+++
29+
+++<span>Vice President</span>+++
30+
</Card>
3131
```
Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
<script>
2-
import Box from './Box.svelte';
2+
import Card from './Card.svelte';
33
</script>
44

5-
<Box>
6-
<!-- put content here -->
7-
</Box>
5+
<main>
6+
<Card>
7+
<!-- content goes here -->
8+
</Card>
9+
</main>
10+
11+
<style>
12+
main {
13+
display: grid;
14+
place-items: center;
15+
height: 100%;
16+
background: url(./wood.svg);
17+
}
18+
</style>

content/tutorial/03-advanced-svelte/07-composition/01-slots/app-a/src/lib/Box.svelte

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<div class="card">
2+
<!-- slot goes here -->
3+
</div>
4+
5+
<style>
6+
@font-face {
7+
src: url('/Garamond Classico SC Regular.woff2') format('woff2');
8+
font-family: 'Silian Rail';
9+
font-style: normal;
10+
font-weight: 400;
11+
}
12+
13+
.card {
14+
display: flex;
15+
flex-direction: column;
16+
align-items: center;
17+
justify-content: center;
18+
font-size: min(2vw, 3.5vh, 1.5rem);
19+
font-family: 'Silian Rail';
20+
width: 24em;
21+
aspect-ratio: 3.5 / 2.0;
22+
background: url(./paper.svg);
23+
border-radius: 2px;
24+
filter: drop-shadow(0.1em 0.1em 0.1em rgba(0, 0, 0, 0.2));
25+
padding: 1.5em 1em 1em 1em;
26+
font-variant: small-caps;
27+
text-shadow: -1px -1px 2px rgba(0, 0, 0, 0.2), 1px 1px 2px white;
28+
color: hsl(50, 20%, 35%);
29+
line-height: 1.2;
30+
}
31+
32+
header, footer {
33+
width: 100%;
34+
display: flex;
35+
flex: 1;
36+
}
37+
38+
header {
39+
justify-content: space-between;
40+
}
41+
42+
footer {
43+
font-size: 0.7em;
44+
justify-content: center;
45+
align-items: end;
46+
}
47+
</style>
Lines changed: 10 additions & 0 deletions
Loading
Lines changed: 10 additions & 0 deletions
Loading
Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
11
<script>
2-
import Box from './Box.svelte';
2+
import Card from './Card.svelte';
33
</script>
44

5-
<Box>
6-
<h2>Hello!</h2>
7-
<p>This is a box. It can contain anything.</p>
8-
</Box>
5+
<main>
6+
<Card>
7+
<span>Patrick BATEMAN</span>
8+
<span>Vice President</span>
9+
</Card>
10+
</main>
11+
12+
<style>
13+
main {
14+
display: grid;
15+
place-items: center;
16+
height: 100%;
17+
background: url(./wood.svg);
18+
}
19+
</style>

content/tutorial/03-advanced-svelte/07-composition/01-slots/app-b/src/lib/Box.svelte

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<div class="card">
2+
<slot />
3+
</div>
4+
5+
<style>
6+
@font-face {
7+
src: url('/Garamond Classico SC Regular.woff2') format('woff2');
8+
font-family: 'Silian Rail';
9+
font-style: normal;
10+
font-weight: 400;
11+
}
12+
13+
.card {
14+
display: flex;
15+
flex-direction: column;
16+
align-items: center;
17+
justify-content: center;
18+
font-size: min(2vw, 3.5vh, 1.5rem);
19+
font-family: 'Silian Rail';
20+
width: 24em;
21+
aspect-ratio: 3.5 / 2.0;
22+
background: url(./paper.svg);
23+
border-radius: 2px;
24+
filter: drop-shadow(0.1em 0.1em 0.1em rgba(0, 0, 0, 0.2));
25+
padding: 1.5em 1em 1em 1em;
26+
font-variant: small-caps;
27+
text-shadow: -1px -1px 2px rgba(0, 0, 0, 0.2), 1px 1px 2px white;
28+
color: hsl(50, 20%, 35%);
29+
line-height: 1.2;
30+
}
31+
32+
header, footer {
33+
width: 100%;
34+
display: flex;
35+
flex: 1;
36+
}
37+
38+
header {
39+
justify-content: space-between;
40+
}
41+
42+
footer {
43+
font-size: 0.7em;
44+
justify-content: center;
45+
align-items: end;
46+
}
47+
</style>

0 commit comments

Comments
 (0)