refactor: update components to svelte5 in ct-svelte-vite package

This commit is contained in:
Marcin Wiśniowski 2025-02-15 17:22:49 +01:00
parent 0d97d5bd49
commit c2c3b1d91b
5 changed files with 24 additions and 18 deletions

View file

@ -1,7 +1,5 @@
<script lang="ts"> <script>
import { createEventDispatcher } from "svelte"; const { title, onsubmit } = $props();
export let title: string;
const dispatch = createEventDispatcher();
</script> </script>
<button on:click={() => dispatch('submit', 'hello')}>{title}</button> <button onclick={() => onsubmit('hello')}>{title}</button>

View file

@ -1,14 +1,12 @@
<script lang="ts"> <script>
import { update, remountCount } from '../store' import { update, remountCount } from '../store'
import { createEventDispatcher } from "svelte"; const { count, onsubmit, main, children } = $props()
export let count: number;
const dispatch = createEventDispatcher();
update(); update();
</script> </script>
<button on:click={() => dispatch('submit', 'hello')}> <button onclick={() => onsubmit?.('hello')}>
<span data-testid="props">{count}</span> <span data-testid="props">{count}</span>
<span data-testid="remount-count">{remountCount}</span> <span data-testid="remount-count">{remountCount}</span>
<slot name="main" /> {@render main?.()}
<slot /> {@render children?.()}
</button> </button>

View file

@ -1,7 +1,11 @@
<script>
const {children} = $props()
</script>
<div> <div>
<h1>Welcome!</h1> <h1>Welcome!</h1>
<main> <main>
<slot /> {@render children?.()}
</main> </main>
<footer> <footer>
Thanks for visiting. Thanks for visiting.

View file

@ -1,11 +1,17 @@
<script>
const {header, main, footer} = $props()
console.log({header, main, footer});
</script>
<div> <div>
<header> <header>
<slot name="header" /> {@render header?.()}
</header> </header>
<main> <main>
<slot name="main" /> {@render main?.()}
</main> </main>
<footer> <footer>
<slot name="footer" /> {@render footer?.()}
</footer> </footer>
</div> </div>

View file

@ -5,7 +5,7 @@ import NamedSlots from '@/components/NamedSlots.svelte';
test('render a default slot', async ({ mount }) => { test('render a default slot', async ({ mount }) => {
const component = await mount(DefaultSlot, { const component = await mount(DefaultSlot, {
slots: { slots: {
default: 'Main Content', children: 'Main Content',
}, },
}); });
await expect(component).toContainText('Main Content'); await expect(component).toContainText('Main Content');