anki/ts/editor-toolbar/EditorToolbar.svelte

75 lines
1.7 KiB
Svelte
Raw Normal View History

<script context="module" lang="typescript">
import "./legacy.css";
import { writable } from "svelte/store";
const disabled = writable(false);
export function enableButtons(): void {
disabled.set(false);
}
export function disableButtons(): void {
disabled.set(true);
}
</script>
2021-03-25 23:32:23 +01:00
<script lang="typescript">
import type { Readable } from "svelte/store";
import type { ToolbarItem } from "./types";
import { setContext } from "svelte";
import { disabledKey, nightModeKey } from "./contextKeys";
import ButtonGroup from "./ButtonGroup.svelte";
2021-03-25 23:32:23 +01:00
export let buttons: Readable<ToolbarItem[]>;
export let menus: Readable<ToolbarItem[]>;
$: _buttons = $buttons;
$: _menus = $menus;
2021-03-31 03:34:08 +02:00
2021-03-25 23:32:23 +01:00
export let nightMode: boolean;
setContext(nightModeKey, nightMode);
2021-03-31 03:34:08 +02:00
setContext(disabledKey, disabled);
export let size: number = 30;
export let wraps: boolean = true;
$: style = `--toolbar-size: ${size}px; --toolbar-wrap: ${
wraps ? "wrap" : "nowrap"
}`;
2021-03-25 21:11:40 +01:00
</script>
2021-03-30 00:51:44 +02:00
<style lang="scss">
nav {
2021-03-30 00:51:44 +02:00
position: sticky;
top: 0;
left: 0;
z-index: 10;
2021-03-30 00:51:44 +02:00
background: var(--bg-color);
border-bottom: 1px solid var(--border);
/* Remove outermost marigns */
& > :global(ul) {
& > :global(li:nth-child(1)) {
margin-left: 0;
}
& > :global(li:nth-last-child(1)) {
margin-right: 0;
}
}
2021-03-30 00:51:44 +02:00
}
</style>
<div {style}>
{#each _menus as menu}
<svelte:component this={menu.component} {...menu} />
{/each}
</div>
<nav {style}>
<ButtonGroup buttons={_buttons} />
</nav>