Anki/ts/editor/StickyBadge.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

70 lines
1.8 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 { bridgeCommand } from "@tslib/bridgecommand";
import { getPlatformString, registerShortcut } from "@tslib/shortcuts";
import { onMount } from "svelte";
import Badge from "$lib/components/Badge.svelte";
import Icon from "$lib/components/Icon.svelte";
import { stickyIcon } from "$lib/components/icons";
import { context as editorFieldContext } from "./EditorField.svelte";
const animated = !document.body.classList.contains("reduce-motion");
export let active: boolean;
export let show: boolean;
const editorField = editorFieldContext.get();
const keyCombination = "F9";
export let index: number;
function toggle() {
bridgeCommand(`toggleSticky:${index}`, (value: boolean) => {
active = value;
});
}
function shortcut(target: HTMLElement): () => void {
return registerShortcut(toggle, keyCombination, { target });
}
onMount(() => {
editorField.element.then(shortcut);
});
</script>
<span
class:highlighted={active}
class:visible={show || !animated}
on:click|stopPropagation={toggle}
>
<Badge
tooltip="{tr.editingToggleSticky()} ({getPlatformString(keyCombination)})"
widthMultiplier={0.7}
>
<Icon icon={stickyIcon} />
</Badge>
</span>
<style lang="scss">
span {
cursor: pointer;
opacity: 0;
&.visible {
transition: none;
opacity: 0.4;
&:hover {
opacity: 0.8;
}
}
&.highlighted {
opacity: 1;
}
}
</style>