Initial RuneStone project
This commit is contained in:
@@ -0,0 +1,114 @@
|
||||
<script lang="ts">
|
||||
import type { OpenBuffer } from "$lib/workspace/types";
|
||||
|
||||
type Props = {
|
||||
tabs: OpenBuffer[];
|
||||
activePath: string | null;
|
||||
onSelect: (relPath: string) => void;
|
||||
onClose: (relPath: string) => void;
|
||||
};
|
||||
|
||||
let { tabs, activePath, onSelect, onClose }: Props = $props();
|
||||
|
||||
function onMiddleDown(event: MouseEvent) {
|
||||
if (event.button === 1) {
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
|
||||
function onMiddleUp(event: MouseEvent, relPath: string) {
|
||||
if (event.button === 1) {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
onClose(relPath);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="tabs" role="tablist" aria-label="Open files">
|
||||
{#each tabs as tab (tab.relPath)}
|
||||
<div class="tab" class:active={tab.relPath === activePath}>
|
||||
<button
|
||||
type="button"
|
||||
role="tab"
|
||||
aria-selected={tab.relPath === activePath}
|
||||
title={tab.kind === "empty" ? tab.name : tab.relPath}
|
||||
onclick={() => onSelect(tab.relPath)}
|
||||
onmousedown={onMiddleDown}
|
||||
onmouseup={(event) => onMiddleUp(event, tab.relPath)}
|
||||
>
|
||||
{tab.name}{tab.contents !== tab.saved ? " •" : ""}
|
||||
</button>
|
||||
<button
|
||||
class="close"
|
||||
type="button"
|
||||
aria-label="Close {tab.name}"
|
||||
title="Close {tab.name}"
|
||||
onclick={() => onClose(tab.relPath)}
|
||||
onmousedown={onMiddleDown}
|
||||
onmouseup={(event) => onMiddleUp(event, tab.relPath)}
|
||||
>
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
{/each}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.tabs {
|
||||
display: flex;
|
||||
min-height: 32px;
|
||||
overflow-x: auto;
|
||||
background: var(--rs-bg-elevated);
|
||||
border-bottom: 1px solid var(--rs-border);
|
||||
}
|
||||
|
||||
.tab {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
max-width: 220px;
|
||||
flex-shrink: 0;
|
||||
border-radius: var(--rs-item-selection-radius) var(--rs-item-selection-radius) 0 0;
|
||||
border-right: 1px solid var(--rs-border);
|
||||
background: var(--rs-bg);
|
||||
}
|
||||
|
||||
.tab.active {
|
||||
background: var(--rs-bg-active);
|
||||
box-shadow: inset 0 2px var(--rs-accent);
|
||||
}
|
||||
|
||||
.tab > button:first-child {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
color: var(--rs-text-dim);
|
||||
text-align: left;
|
||||
padding: 0 8px 0 12px;
|
||||
height: 32px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.tab.active > button:first-child {
|
||||
color: var(--rs-text-strong);
|
||||
}
|
||||
|
||||
.close {
|
||||
border: 0;
|
||||
border-radius: var(--rs-control-radius);
|
||||
background: transparent;
|
||||
color: var(--rs-text-dim);
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
margin-right: 4px;
|
||||
flex: 0 0 22px;
|
||||
}
|
||||
|
||||
.close:hover {
|
||||
color: var(--rs-text-strong);
|
||||
background: var(--rs-bg);
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user