anki/ts/editor-toolbar/ButtonGroup.svelte

84 lines
2.1 KiB
Svelte
Raw Normal View History

2021-04-15 15:59:52 +02:00
<!--
Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script lang="typescript">
import type { ToolbarItem } from "./types";
import { getContext } from "svelte";
import { nightModeKey } from "./contextKeys";
2021-04-16 03:10:39 +02:00
export let id: string | undefined = undefined;
export let className = "";
export let items: ToolbarItem[];
function filterHidden({ hidden = false, ...props }) {
return props;
}
const nightMode = getContext(nightModeKey);
</script>
<style lang="scss">
ul {
2021-04-16 17:14:47 +02:00
display: 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: 0 0 calc(var(--toolbar-size) / 10);
2021-04-23 21:25:44 +02:00
&.border-overlap-group {
:global(button),
:global(select) {
margin-left: -1px;
}
}
}
2021-03-30 00:51:44 +02:00
li {
display: inline-block;
> :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
}
}
&.gap-item:not(:nth-child(1)) {
margin-left: 1px;
}
}
</style>
<ul {id} class={className} class:border-overlap-group={!nightMode}>
{#each items as button}
{#if !button.hidden}
<li class:gap-item={nightMode}>
<svelte:component this={button.component} {...filterHidden(button)} />
</li>
{/if}
2021-03-30 00:51:44 +02:00
{/each}
</ul>