You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
svelte/test/runtime/samples/context-api/Tab.svelte

17 lines
382 B

<script>
import { getContext, onDestroy } from 'svelte';
import { TABS } from './Tabs.svelte';
const tab = {};
const { registerTab, unregisterTab, selectTab, selectedTab } = getContext(TABS);
registerTab(tab);
onDestroy(() => {
unregisterTab(tab);
});
</script>
<button class:selected="{$selectedTab === tab}" on:click="{() => selectTab(tab)}">
<slot></slot>
</button>