-
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
13 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
...al/02-advanced-svelte/07-special-elements/05-svelte-html/+assets/app-a/src/lib/App.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<script> | ||
let darkmode = $state(false); | ||
</script> | ||
|
||
<svelte:html /> | ||
|
||
<button onclick={() => darkmode = !darkmode}>toggle dark mode</button> |
7 changes: 7 additions & 0 deletions
7
...al/02-advanced-svelte/07-special-elements/05-svelte-html/+assets/app-b/src/lib/App.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<script> | ||
let darkmode = $state(false); | ||
</script> | ||
|
||
<svelte:html class={darkmode ? 'dark' : 'light'} /> | ||
|
||
<button onclick={() => darkmode = !darkmode}>toggle dark mode</button> |
16 changes: 16 additions & 0 deletions
16
...content/tutorial/02-advanced-svelte/07-special-elements/05-svelte-html/index.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
--- | ||
title: <svelte:html> | ||
--- | ||
|
||
The `<svelte:html>` element allows you to listen to events _and_ set attributes on the `<html>`. This is useful to for example set the `lang` tag dynamically, or to update `class`es that influence the whole page. | ||
|
||
Add a conditional `class` attribute to the `<svelte:html>` tag... | ||
|
||
```svelte | ||
<!--- file: App.svelte ---> | ||
<svelte:html | ||
+++class={darkmode ? 'dark' : 'light'}+++ | ||
/> | ||
``` | ||
|
||
...and click the button to toggle the mode. |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.