2021-04-14 16:07:45 +02:00
|
|
|
<script>
|
2021-04-23 11:48:19 +02:00
|
|
|
import { getContext, onMount } from "svelte"
|
|
|
|
import Portal from "svelte-portal"
|
|
|
|
export let title
|
|
|
|
export let icon = ""
|
2021-04-15 14:42:39 +02:00
|
|
|
|
2021-04-23 11:48:19 +02:00
|
|
|
const selected = getContext("tab")
|
|
|
|
let tab
|
|
|
|
let tabInfo
|
|
|
|
const setTabInfo = () => {
|
|
|
|
tabInfo = tab.getBoundingClientRect()
|
|
|
|
if ($selected.title === title) {
|
|
|
|
$selected.info = tabInfo
|
|
|
|
}
|
|
|
|
}
|
2021-04-15 14:42:39 +02:00
|
|
|
|
2021-04-23 11:48:19 +02:00
|
|
|
onMount(() => {
|
|
|
|
setTabInfo()
|
|
|
|
})
|
2021-04-14 16:07:45 +02:00
|
|
|
</script>
|
|
|
|
|
2021-04-23 11:48:19 +02:00
|
|
|
<div
|
|
|
|
bind:this={tab}
|
|
|
|
on:click={() => ($selected = { ...$selected, title, info: tab.getBoundingClientRect() })}
|
|
|
|
class:is-selected={$selected.title === title}
|
|
|
|
class="spectrum-Tabs-item"
|
|
|
|
tabindex="0">
|
|
|
|
{#if icon}
|
|
|
|
<svg
|
|
|
|
class="spectrum-Icon spectrum-Icon--sizeM"
|
|
|
|
focusable="false"
|
|
|
|
aria-hidden="true"
|
|
|
|
aria-label="Folder">
|
|
|
|
<use xlink:href="#spectrum-icon-18-{icon}" />
|
|
|
|
</svg>
|
|
|
|
{/if}
|
|
|
|
<span class="spectrum-Tabs-itemLabel">{title}</span>
|
2021-04-14 16:07:45 +02:00
|
|
|
</div>
|
2021-04-15 14:42:39 +02:00
|
|
|
{#if $selected.title === title}
|
2021-04-23 11:48:19 +02:00
|
|
|
<Portal target=".spectrum-Tabs-content-{$selected.id}">
|
|
|
|
<slot />
|
|
|
|
</Portal>
|
|
|
|
{/if}
|