afc56a8398
ButtonToolbar.svelte now has to assume that the button elements are two levels below it. This can be simplified once we can use flex-gap.
42 lines
1.1 KiB
Svelte
42 lines
1.1 KiB
Svelte
<!--
|
|
Copyright: Ankitects Pty Ltd and contributors
|
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
-->
|
|
<script lang="ts">
|
|
import Detachable from "./Detachable.svelte";
|
|
|
|
import type { Register, Registration } from "./registration";
|
|
|
|
import { getContext, hasContext } from "svelte";
|
|
import { sectionKey } from "./context-keys";
|
|
|
|
export let id: string | undefined = undefined;
|
|
export let registration: Registration | undefined = undefined;
|
|
|
|
let detached: boolean;
|
|
|
|
if (registration) {
|
|
const { detach } = registration;
|
|
detach.subscribe((value: boolean) => (detached = value));
|
|
} else if (hasContext(sectionKey)) {
|
|
const registerComponent = getContext<Register<Registration>>(sectionKey);
|
|
const { detach } = registerComponent();
|
|
detach.subscribe((value: boolean) => (detached = value));
|
|
} else {
|
|
detached = false;
|
|
}
|
|
</script>
|
|
|
|
<!-- div is necessary to preserve item position -->
|
|
<div class="item" {id}>
|
|
<Detachable {detached}>
|
|
<slot />
|
|
</Detachable>
|
|
</div>
|
|
|
|
<style lang="scss">
|
|
.item {
|
|
display: contents;
|
|
}
|
|
</style>
|