anki/ts/editor-toolbar/ButtonGroup.svelte

82 lines
2.0 KiB
Svelte
Raw Normal View History

<script lang="typescript">
import type { ToolbarItem } from "./types";
import { getContext } from "svelte";
import { nightModeKey } from "./contextKeys";
export let id: string;
export let className = "";
export let buttons: ToolbarItem[];
function filterHidden({ hidden = false, ...props }) {
return props;
}
const nightMode = getContext(nightModeKey);
</script>
<style lang="scss">
ul {
display: inline-flex;
justify-items: start;
flex-wrap: var(--toolbar-wrap);
overflow-y: auto;
2021-03-30 00:51:44 +02:00
padding-inline-start: 0;
margin-bottom: 0;
}
.border-group {
/* buttons' borders exactly overlap each other */
:global(button),
:global(select) {
margin-left: -2px;
}
}
2021-03-30 00:51:44 +02:00
li {
display: inline-block;
margin-bottom: calc(var(--toolbar-size) / 15);
2021-03-30 00:51:44 +02:00
> :global(button),
> :global(select) {
border-radius: 0;
}
2021-03-30 00:51:44 +02:00
&:nth-child(1) {
margin-left: calc(var(--toolbar-size) / 7.5);
2021-03-30 00:51:44 +02:00
> :global(button),
> :global(select) {
/* default 0.25rem */
border-top-left-radius: calc(var(--toolbar-size) / 7.5);
border-bottom-left-radius: calc(var(--toolbar-size) / 7.5);
2021-03-30 00:51:44 +02:00
}
}
2021-03-30 00:51:44 +02:00
&:nth-last-child(1) {
margin-right: calc(var(--toolbar-size) / 7.5);
2021-03-30 00:51:44 +02:00
> :global(button),
> :global(select) {
border-top-right-radius: calc(var(--toolbar-size) / 7.5);
border-bottom-right-radius: calc(var(--toolbar-size) / 7.5);
2021-03-30 00:51:44 +02:00
}
}
&:not(:nth-child(1)) {
margin-left: 1px;
}
}
</style>
<ul {id} class={className} class:border-group={!nightMode}>
2021-03-30 00:51:44 +02:00
{#each buttons as button}
{#if !button.hidden}
<li>
<svelte:component this={button.component} {...filterHidden(button)} />
</li>
{/if}
2021-03-30 00:51:44 +02:00
{/each}
</ul>