2021-04-27 21:01:44 +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">
|
2021-05-06 01:22:55 +02:00
|
|
|
import WithTheming from "components/WithTheming.svelte";
|
2021-05-05 01:22:51 +02:00
|
|
|
import Detachable from "components/Detachable.svelte";
|
|
|
|
|
2021-05-06 01:22:55 +02:00
|
|
|
import type { ButtonRegistration } from "./buttons";
|
|
|
|
import { ButtonPosition } from "./buttons";
|
|
|
|
|
|
|
|
import { getContext, hasContext } from "svelte";
|
2021-04-27 21:01:44 +02:00
|
|
|
import { buttonGroupKey } from "./contextKeys";
|
|
|
|
|
2021-05-06 01:22:55 +02:00
|
|
|
export let registration: ButtonRegistration | undefined = undefined;
|
|
|
|
|
|
|
|
let detach_: boolean;
|
|
|
|
let position_: ButtonPosition;
|
|
|
|
let style: string;
|
|
|
|
|
|
|
|
const radius = "calc(var(--toolbar-size) / 7.5)";
|
|
|
|
|
|
|
|
$: {
|
|
|
|
switch (position_) {
|
|
|
|
case ButtonPosition.Standalone:
|
|
|
|
style = `--border-left-radius: ${radius}; --border-right-radius: ${radius}; `;
|
|
|
|
break;
|
|
|
|
case ButtonPosition.Leftmost:
|
|
|
|
style = `--border-left-radius: ${radius}; --border-right-radius: 0; `;
|
|
|
|
break;
|
|
|
|
case ButtonPosition.Center:
|
|
|
|
style = "--border-left-radius: 0; --border-right-radius: 0; ";
|
|
|
|
break;
|
|
|
|
case ButtonPosition.Rightmost:
|
|
|
|
style = `--border-left-radius: 0; --border-right-radius: ${radius}; `;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2021-05-05 15:12:02 +02:00
|
|
|
|
2021-05-06 01:22:55 +02:00
|
|
|
if (registration) {
|
|
|
|
const { detach, position } = registration;
|
|
|
|
detach.subscribe((value: boolean) => (detach_ = value));
|
|
|
|
position.subscribe((value: ButtonPosition) => (position_ = value));
|
|
|
|
} else if (hasContext(buttonGroupKey)) {
|
|
|
|
const { registerButton } = getContext(buttonGroupKey);
|
|
|
|
const { detach, position } = registerButton();
|
|
|
|
detach.subscribe((value: boolean) => (detach_ = value));
|
|
|
|
position.subscribe((value: ButtonPosition) => (position_ = value));
|
|
|
|
} else {
|
|
|
|
detach_ = false;
|
|
|
|
position_ = ButtonPosition.Standalone;
|
|
|
|
}
|
2021-04-27 21:01:44 +02:00
|
|
|
</script>
|
|
|
|
|
2021-05-06 01:22:55 +02:00
|
|
|
<!-- div in WithTheming is necessary to preserve item position -->
|
|
|
|
<WithTheming {style}>
|
|
|
|
<Detachable detach={detach_}>
|
|
|
|
<slot />
|
|
|
|
</Detachable>
|
|
|
|
</WithTheming>
|