anki/ts/editor/ColorButtons.svelte

84 lines
2.9 KiB
Svelte
Raw Normal View History

<!--
Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script lang="typescript">
import * as tr from "lib/i18n";
import ButtonGroup from "components/ButtonGroup.svelte";
import ButtonGroupItem from "components/ButtonGroupItem.svelte";
import IconButton from "components/IconButton.svelte";
2021-05-30 22:58:40 +02:00
import ColorPicker from "components/ColorPicker.svelte";
import WithShortcut from "components/WithShortcut.svelte";
2021-05-30 21:44:05 +02:00
import WithColorHelper from "./WithColorHelper.svelte";
2021-05-31 00:17:06 +02:00
import { textColorIcon, highlightColorIcon, arrowIcon } from "./icons";
2021-05-06 02:49:59 +02:00
import { appendInParentheses } from "./helpers";
export let api = {};
2021-05-30 21:44:05 +02:00
const wrapWithForecolor = (color: string) => () => {
document.execCommand("forecolor", false, color);
2021-05-30 22:58:40 +02:00
};
2021-05-30 21:44:05 +02:00
const wrapWithBackcolor = (color: string) => () => {
document.execCommand("backcolor", false, color);
2021-05-30 22:58:40 +02:00
};
</script>
<ButtonGroup {api}>
2021-05-30 22:58:40 +02:00
<WithColorHelper let:colorHelperIcon let:color let:setColor>
2021-05-30 21:44:05 +02:00
<ButtonGroupItem>
<WithShortcut shortcut={"F7"} let:createShortcut let:shortcutLabel>
<IconButton
tooltip={appendInParentheses(
tr.editingSetForegroundColor(),
shortcutLabel
)}
on:click={wrapWithForecolor(color)}
on:mount={createShortcut}
>
{@html textColorIcon}
{@html colorHelperIcon}
</IconButton>
</WithShortcut>
</ButtonGroupItem>
2021-05-30 22:58:40 +02:00
<ButtonGroupItem>
<WithShortcut shortcut={"F8"} let:createShortcut let:shortcutLabel>
<IconButton
tooltip={appendInParentheses(
tr.editingChangeColor(),
shortcutLabel
)}
disables={false}
2021-05-31 00:17:06 +02:00
widthMultiplier={0.5}
2021-05-30 22:58:40 +02:00
>
2021-05-31 00:17:06 +02:00
{@html arrowIcon}
2021-05-30 22:58:40 +02:00
<ColorPicker on:change={setColor} on:mount={createShortcut} />
</IconButton>
</WithShortcut>
</ButtonGroupItem>
2021-05-30 21:44:05 +02:00
</WithColorHelper>
2021-05-30 22:58:40 +02:00
<WithColorHelper let:colorHelperIcon let:color let:setColor>
2021-05-30 21:44:05 +02:00
<ButtonGroupItem>
2021-05-31 00:17:06 +02:00
<IconButton on:click={wrapWithBackcolor(color)}>
{@html highlightColorIcon}
{@html colorHelperIcon}
</IconButton>
2021-05-30 21:44:05 +02:00
</ButtonGroupItem>
2021-05-30 22:58:40 +02:00
<ButtonGroupItem>
2021-05-31 00:17:06 +02:00
<IconButton
tooltip={tr.editingChangeColor()}
disables={false}
widthMultiplier={0.5}
>
{@html arrowIcon}
2021-05-30 22:58:40 +02:00
<ColorPicker on:change={setColor} />
</IconButton>
</ButtonGroupItem>
2021-05-30 21:44:05 +02:00
</WithColorHelper>
</ButtonGroup>