2023-01-10 17:28:27 +01:00
|
|
|
<script>
|
|
|
|
import { createEventDispatcher } from 'svelte';
|
2023-01-23 20:47:43 +01:00
|
|
|
import Icon from './icon.svelte';
|
2023-01-10 17:28:27 +01:00
|
|
|
|
|
|
|
export let tabs = [];
|
|
|
|
export let selectedKey = {};
|
2023-01-23 20:47:43 +01:00
|
|
|
export let canAddTab = false;
|
2023-01-10 17:28:27 +01:00
|
|
|
|
|
|
|
const dispatch = createEventDispatcher();
|
|
|
|
|
|
|
|
function select(tabKey) {
|
|
|
|
selectedKey = tabKey;
|
|
|
|
dispatch('select', tabKey);
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<nav class="tabs">
|
|
|
|
<ul>
|
|
|
|
{#each tabs as tab (tab.key)}
|
2023-01-23 20:47:43 +01:00
|
|
|
<li class:active={tab.key === selectedKey}>
|
|
|
|
<button class="tab" on:click={() => select(tab.key)}>{tab.title}</button>
|
|
|
|
{#if tab.closable}
|
|
|
|
<button class="close" on:click={() => dispatch('closeTab', tab.key)}>
|
|
|
|
<Icon name="x" />
|
|
|
|
</button>
|
|
|
|
{/if}
|
2023-01-10 17:28:27 +01:00
|
|
|
</li>
|
|
|
|
{/each}
|
2023-01-23 20:47:43 +01:00
|
|
|
|
|
|
|
{#if canAddTab}
|
|
|
|
<li class="tab add">
|
|
|
|
<button class="tab" on:click={() => dispatch('addTab')}>
|
|
|
|
<Icon name="+" />
|
|
|
|
</button>
|
|
|
|
</li>
|
|
|
|
{/if}
|
2023-01-10 17:28:27 +01:00
|
|
|
</ul>
|
|
|
|
</nav>
|
|
|
|
|
|
|
|
<style>
|
2023-01-23 20:47:43 +01:00
|
|
|
ul {
|
2023-01-10 17:28:27 +01:00
|
|
|
overflow-x: scroll;
|
|
|
|
display: flex;
|
|
|
|
list-style: none;
|
|
|
|
}
|
2023-01-23 20:47:43 +01:00
|
|
|
li {
|
2023-01-10 17:28:27 +01:00
|
|
|
display: inline-block;
|
|
|
|
flex-grow: 1;
|
2023-01-23 20:47:43 +01:00
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
|
|
|
|
li.add {
|
|
|
|
flex: 0 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
.tabs :global(svg) {
|
|
|
|
width: 13px;
|
|
|
|
height: 13px;
|
|
|
|
vertical-align: bottom;
|
|
|
|
}
|
|
|
|
li.active :global(svg) {
|
|
|
|
color: #fff;
|
2023-01-10 17:28:27 +01:00
|
|
|
}
|
2023-01-23 20:47:43 +01:00
|
|
|
|
|
|
|
button.tab {
|
2023-01-10 17:28:27 +01:00
|
|
|
width: 100%;
|
|
|
|
padding: 0.7rem 1rem;
|
|
|
|
border: 1px solid #ccc;
|
2023-01-19 20:57:22 +01:00
|
|
|
border-right: none;
|
2023-01-10 17:28:27 +01:00
|
|
|
cursor: pointer;
|
2023-01-13 16:56:48 +01:00
|
|
|
background-color: #fff;
|
2023-01-10 17:28:27 +01:00
|
|
|
}
|
2023-01-23 20:47:43 +01:00
|
|
|
button.tab:hover {
|
|
|
|
background-color: #eee;
|
|
|
|
}
|
|
|
|
button.tab:active {
|
|
|
|
background-color: #ddd;
|
|
|
|
}
|
|
|
|
li:last-child button.tab {
|
2023-01-19 20:57:22 +01:00
|
|
|
border-right: 1px solid #ccc;
|
|
|
|
}
|
2023-01-23 20:47:43 +01:00
|
|
|
li.active button.tab {
|
2023-01-10 17:28:27 +01:00
|
|
|
color: #fff;
|
|
|
|
background-color: #00008b;
|
|
|
|
border-color: #00008b;
|
|
|
|
cursor: not-allowed;
|
|
|
|
}
|
2023-01-23 20:47:43 +01:00
|
|
|
|
|
|
|
button.close {
|
|
|
|
position: absolute;
|
|
|
|
right: 7px;
|
|
|
|
top: 7px;
|
|
|
|
padding: 3px;
|
|
|
|
border-radius: 2px;
|
|
|
|
}
|
|
|
|
button.close:hover {
|
|
|
|
background-color: rgba(0, 0, 0, 0.1);
|
|
|
|
}
|
|
|
|
button.close:active {
|
|
|
|
background-color: rgba(0, 0, 0, 0.2);
|
|
|
|
}
|
2023-01-10 17:28:27 +01:00
|
|
|
</style>
|