Skip to content

Commit 037f046

Browse files
update class tutorial (#1063)
* update class tutorial * update * more * more * rename exercise * Update apps/svelte.dev/content/tutorial/01-svelte/07-classes-and-styles/01-classes/index.md Co-authored-by: Conduitry <git@chor.date> * Update apps/svelte.dev/content/tutorial/01-svelte/07-classes-and-styles/01-classes/index.md Co-authored-by: Conduitry <git@chor.date> --------- Co-authored-by: Conduitry <git@chor.date>
1 parent c961a08 commit 037f046

File tree

32 files changed

+30
-147
lines changed

32 files changed

+30
-147
lines changed

apps/svelte.dev/content/tutorial/01-svelte/07-classes-and-styles/01-classes/+assets/app-b/src/lib/App.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
<div class="container">
66
Flip the card
77
<button
8-
class="card"
9-
class:flipped={flipped}
8+
class={["card", { flipped }]}
109
onclick={() => flipped = !flipped}
1110
>
1211
<div class="front">

apps/svelte.dev/content/tutorial/01-svelte/07-classes-and-styles/01-classes/index.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: The class directive
2+
title: The class attribute
33
---
44

55
Like any other attribute, you can specify classes with a JavaScript attribute. Here, we could add a `flipped` class to the card:
@@ -14,15 +14,16 @@ Like any other attribute, you can specify classes with a JavaScript attribute. H
1414

1515
This works as expected — if you click on the card now, it'll flip.
1616

17-
We can make it nicer though. Adding or removing a class based on some condition is such a common pattern in UI development that Svelte includes a special directive to simplify it:
17+
We can make it nicer though. Adding or removing a class based on some condition is such a common pattern in UI development that Svelte allows you to pass an object or array that is converted to a string by [clsx](https://github.com/lukeed/clsx).
1818

1919
```svelte
2020
/// file: App.svelte
2121
<button
22-
class="card"
23-
+++class:flipped={flipped}+++
22+
+++class={["card", { flipped }]}+++
2423
onclick={() => flipped = !flipped}
2524
>
2625
```
2726

28-
This directive means 'add the `flipped` class whenever `flipped` is truthy'.
27+
This means 'always add the `card` class, and add the `flipped` class whenever `flipped` is truthy'.
28+
29+
For more examples of how to combine conditional classes, [consult the `class` documentation](/docs/svelte/class).

apps/svelte.dev/content/tutorial/01-svelte/07-classes-and-styles/02-class-shorthand/+assets/app-b/src/lib/App.svelte

Lines changed: 0 additions & 93 deletions
This file was deleted.

apps/svelte.dev/content/tutorial/01-svelte/07-classes-and-styles/02-class-shorthand/index.md

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)