Anki/ts/editor/PlainTextBadge.svelte
Abdo d108bff862
Fix remaining accessibility warnings (#3241)
* Remove unused build var

* Fix accessibility warnings in CollapseLabel

* Fix accessibility warnings in PlainTextBadge

* Add ARIA role to Autocompleteitem

* Fix accessibility warnings in HandleBackground

* Fix accessibility warnings in HandleControl

* Fix accessibility warnings in EditorField

* Fix accessibility warnings in RichTextBadge

* Fix accessibility warnings in StickyBadge

* Remove ignored a11y warnings
2024-07-10 19:55:08 +07:00

71 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 { getPlatformString, registerShortcut } from "@tslib/shortcuts";
import { onEnterOrSpace } from "@tslib/keys";
import { createEventDispatcher, onDestroy } from "svelte";
import Badge from "$lib/components/Badge.svelte";
import Icon from "$lib/components/Icon.svelte";
import { plainTextIcon } from "$lib/components/icons";
import { context as editorFieldContext } from "./EditorField.svelte";
const animated = !document.body.classList.contains("reduce-motion");
const editorField = editorFieldContext.get();
const keyCombination = "Control+Shift+X";
const dispatch = createEventDispatcher();
export let show = false;
export let off = false;
function toggle() {
dispatch("toggle");
}
let unregister: ReturnType<typeof registerShortcut> | undefined;
editorField.element.then((target) => {
unregister = registerShortcut(toggle, keyCombination, { target });
});
onDestroy(() => unregister?.());
</script>
<span
class="plain-text-badge"
class:visible={show || !animated}
class:highlighted={!off}
on:click|stopPropagation={toggle}
on:keydown={onEnterOrSpace(() => toggle())}
tabindex="-1"
role="button"
>
<Badge
tooltip="{tr.editingToggleHtmlEditor()} ({getPlatformString(keyCombination)})"
iconSize={80}
>
<Icon icon={plainTextIcon} />
</Badge>
</span>
<style lang="scss">
span {
cursor: pointer;
opacity: 0;
&.visible {
opacity: 0.4;
&:hover {
opacity: 0.8;
}
}
&.highlighted {
opacity: 1;
}
}
</style>