1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-01-31 18:29:28 +00:00
rolens/frontend/src/components/tabbar.svelte

95 lines
1.8 KiB
Svelte
Raw Normal View History

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}
2023-01-31 16:58:23 +01:00
<button class="btn-sm" on:click={() => dispatch('closeTab', tab.key)}>
2023-01-23 20:47:43 +01:00
<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;
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 {
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
2023-01-31 16:58:23 +01:00
.btn-sm {
2023-01-23 20:47:43 +01:00
position: absolute;
right: 7px;
top: 7px;
}
2023-01-10 17:28:27 +01:00
</style>