Skip to content

Commit 09d9af8

Browse files
fix(examples): update vite svelte 5 example to svelte 5 syntax (#5109)
1 parent 6c99b32 commit 09d9af8

File tree

4 files changed

+29
-18
lines changed

4 files changed

+29
-18
lines changed

examples/vite-svelte/src/App.svelte

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
<script lang="ts">
22
import { fade, fly } from 'svelte/transition'
33
import Footer from './Footer.svelte'
4-
let logo = false
5-
let red = false
6-
let x = 'abc?cbd'
4+
5+
let logo = $state(false)
6+
let red = $state(false)
7+
let x = $state('abc?cbd')
8+
$inspect(x)
9+
const button = $derived(logo ? 'Hide logo' : 'Show logo')
10+
const span = $derived(red ? 'Normal' : 'Red')
11+
712
function toggleLogo() {
813
logo = !logo
914
}
15+
1016
function toggleSpan() {
1117
red = !red
1218
}
13-
$: button = logo ? 'Hide logo' : 'Show logo'
14-
$: span = red ? 'Normal' : 'Red'
15-
$: console.log(x)
1619
</script>
1720

1821
<main>
@@ -24,22 +27,28 @@
2427

2528
<h1 class="animate-bounce">Hello Typescript!</h1>
2629

30+
<h2 class="text-lg font-semibold text-orange-600">Use shift+ctrl for the inspector</h2>
31+
2732
<br/>
2833

2934
<div class:bg-red-400={red}>BG Color should change</div>
3035

3136
<br/>
3237

33-
<button class="bg-red-100" on:click={toggleLogo}>{button}</button>
34-
<button on:click={toggleSpan}>Change BG Color: {span}</button>
38+
<button class="bg-red-100" onclick={toggleLogo}>{button}</button>
39+
<button onclick={toggleSpan}>Change BG Color: {span}</button>
3540

3641
<br />
3742

43+
<input bind:value={x} type="text" name="" id="">
44+
3845
<div class="absolute mt-20px bottom-0">absolute</div>
3946

4047
</main>
4148

4249
<Footer />
50+
<Footer foo={true} name=Footer2 />
51+
<Footer customclasses={"bg-blue-500 text-xl"} name=Footer3 />
4352

4453

4554
<style>
Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
11
<script lang="ts">
2-
let foo = true
2+
const { foo = false, customclasses = "", name = "Footer" } = $props()
33
</script>
4+
45
<footer>
5-
<div
6-
class="bar"
7-
class:foo
8-
>Footer</div>
9-
<div class="bar" class:foo>Footer2</div>
6+
<div class="bar {customclasses}" class:foo>{name}</div>
107
</footer>
11-
12-

examples/vite-svelte/src/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
import { mount } from 'svelte'
12
import App from './App.svelte'
23

34
import 'uno.css'
45

5-
const app = new App({
6+
const app = mount(App, {
67
target: document.getElementById('app'),
78
})
89

examples/vite-svelte/vite.config.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ import { defineConfig } from 'vite'
66
export default defineConfig({
77
plugins: [
88
UnoCSS(),
9-
svelte(),
9+
svelte({
10+
inspector: {
11+
toggleKeyCombo: 'control-shift',
12+
showToggleButton: 'always',
13+
toggleButtonPos: 'bottom-right',
14+
},
15+
}),
1016
],
1117
})

0 commit comments

Comments
 (0)