| 1 | <script lang="ts"> |
| 2 | import Folder from "carbon-icons-svelte/lib/Folder.svelte"; |
| 3 | import SidebarTab from "./SidebarTab.svelte"; |
| 4 | import FileTree from "./FileTree.svelte"; |
| 5 | import { fitTerminal } from "./Terminal.svelte"; |
| 6 | |
| 7 | </script> |
| 8 | |
| 9 | <div id="sidebar"> |
| 10 | {#each $sidebartabs as tab} |
| 11 | <SidebarTab id={`tool-${tab.id}`} active={$activeid === tab.id} label={tab.tabname} on:click={() => {toggleActive(tab)}}> |
| 12 | <svelte:component this={tab.icon}/> |
| 13 | </SidebarTab> |
| 14 | {/each} |
| 15 | |
| 16 | <div class="divider" /> |
| 17 | </div> |
| 18 | |
| 19 | <script lang="ts" context="module"> |
| 20 | import { writable, get } from "svelte/store"; |
| 21 | class Tool { |
| 22 | tabname: string; |
| 23 | content; |
| 24 | constructor(tabname: string, content) { |
| 25 | this.tabname = tabname; |
| 26 | this.content = content; |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | const sidebartabs = writable([{id: 0, tabname: "Explorer", icon: Folder, content: FileTree}]); |
| 31 | |
| 32 | export let activeid = writable(-1); |
| 33 | let active = -1; |
| 34 | export let showsidebarview = writable(false); |
| 35 | export let tool = writable(null); |
| 36 | |
| 37 | export const toggleActive = (tab: { id: any; tabname: any; icon: any, content: any }) => { |
| 38 | if (active === tab.id) { |
| 39 | active = -1; |
| 40 | activeid.set(-1); |
| 41 | showsidebarview.set(false); |
| 42 | } |
| 43 | else { |
| 44 | activeid.set(tab.id); |
| 45 | active = tab.id; |
| 46 | showsidebarview.set(true); |
| 47 | tool.set(new Tool(tab.tabname, tab.content)); |
| 48 | } |
| 49 | fitTerminal(); |
| 50 | } |
| 51 | |
| 52 | export function openFileTree() { |
| 53 | const tab = get(sidebartabs)[0]; |
| 54 | if (active === tab.id) return; |
| 55 | |
| 56 | activeid.set(tab.id); |
| 57 | active = tab.id; |
| 58 | showsidebarview.set(true); |
| 59 | tool.set(new Tool(tab.tabname, tab.content)); |
| 60 | } |
| 61 | </script> |
| 62 | |
| 63 | <style lang="scss"> |
| 64 | #sidebar { |
| 65 | height: 100%; |
| 66 | min-width: 3rem; |
| 67 | display: flex; |
| 68 | flex-direction: column; |
| 69 | } |
| 70 | .divider { |
| 71 | width: 2.3rem; |
| 72 | height: .0625rem; |
| 73 | margin: 0 auto; |
| 74 | } |
| 75 | </style> |