Anki/ts/editor/image-overlay/FloatButtons.svelte
RumovZ 790c52f012
Svg icon (#3135)
* Add sveltekit-svg plugin to fix svg icon styling

Closes #3127.

* Unify svg icon usage

Moves all icons into ts/lib/components/icons.ts and uses a single component to render
them both with eslint and svelte-kit.

* Fix spinning revert icon not being centered

* Use svg earth icon for global label

* Add tooltip to global label icon

* Remove eslint-plugin-simple-import-sort

Imports are already sorted by dprint with conflicting rules.
2024-04-24 02:37:31 +01:00

64 lines
1.9 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 * as tr from "@generated/ftl";
import { removeStyleProperties } from "@tslib/styling";
import { createEventDispatcher } from "svelte";
import ButtonGroup from "$lib/components/ButtonGroup.svelte";
import Icon from "$lib/components/Icon.svelte";
import IconButton from "$lib/components/IconButton.svelte";
import {
floatLeftIcon,
floatNoneIcon,
floatRightIcon,
} from "$lib/components/icons";
export let image: HTMLImageElement;
$: floatStyle = getComputedStyle(image).float;
const dispatch = createEventDispatcher();
</script>
<ButtonGroup size={1.6} wrap={false}>
<IconButton
tooltip={tr.editingFloatLeft()}
active={floatStyle === "left"}
on:click={() => {
image.style.float = "left";
setTimeout(() => dispatch("update"));
}}
--border-left-radius="5px"
>
<Icon icon={floatLeftIcon} />
</IconButton>
<IconButton
tooltip={tr.editingFloatNone()}
active={floatStyle === "none"}
on:click={() => {
// We shortly set to none, because simply unsetting float will not
// trigger floatStyle being reset
image.style.float = "none";
removeStyleProperties(image, "float");
setTimeout(() => dispatch("update"));
}}
>
<Icon icon={floatNoneIcon} />
</IconButton>
<IconButton
tooltip={tr.editingFloatRight()}
active={floatStyle === "right"}
on:click={() => {
image.style.float = "right";
setTimeout(() => dispatch("update"));
}}
--border-right-radius="5px"
>
<Icon icon={floatRightIcon} />
</IconButton>
</ButtonGroup>