mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Merge pull request #1211 from hgiesel/bettercolor
Implement new text color / highlight color buttons
This commit is contained in:
commit
dd1cb0112a
9 changed files with 119 additions and 117 deletions
|
@ -3,72 +3,21 @@ Copyright: Ankitects Pty Ltd and contributors
|
||||||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
-->
|
-->
|
||||||
<script lang="typescript">
|
<script lang="typescript">
|
||||||
import { onMount, createEventDispatcher, getContext } from "svelte";
|
import { onMount, createEventDispatcher } from "svelte";
|
||||||
import { nightModeKey } from "./contextKeys";
|
|
||||||
|
|
||||||
export let id: string | undefined = undefined;
|
|
||||||
let className = "";
|
|
||||||
export { className as class };
|
|
||||||
|
|
||||||
export let tooltip: string | undefined = undefined;
|
|
||||||
|
|
||||||
const nightMode = getContext(nightModeKey);
|
|
||||||
|
|
||||||
function delegateToInput() {
|
|
||||||
inputRef.click();
|
|
||||||
}
|
|
||||||
|
|
||||||
let buttonRef: HTMLButtonElement;
|
|
||||||
let inputRef: HTMLInputElement;
|
let inputRef: HTMLInputElement;
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
onMount(() => dispatch("mount", { button: buttonRef, input: inputRef }));
|
onMount(() => dispatch("mount", { input: inputRef }));
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<button
|
<input tabindex="-1" bind:this={inputRef} type="color" on:change />
|
||||||
bind:this={buttonRef}
|
|
||||||
tabindex="-1"
|
|
||||||
{id}
|
|
||||||
class={`btn ${className}`}
|
|
||||||
class:btn-day={!nightMode}
|
|
||||||
class:btn-night={nightMode}
|
|
||||||
title={tooltip}
|
|
||||||
on:click={delegateToInput}
|
|
||||||
on:mousedown|preventDefault
|
|
||||||
>
|
|
||||||
<input tabindex="-1" bind:this={inputRef} type="color" on:change />
|
|
||||||
</button>
|
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
@use "ts/sass/button_mixins" as button;
|
|
||||||
|
|
||||||
@import "ts/sass/bootstrap/functions";
|
|
||||||
@import "ts/sass/bootstrap/variables";
|
|
||||||
|
|
||||||
button {
|
|
||||||
width: calc(var(--buttons-size) - 0px);
|
|
||||||
height: calc(var(--buttons-size) - 0px);
|
|
||||||
|
|
||||||
padding: 4px;
|
|
||||||
overflow: hidden;
|
|
||||||
|
|
||||||
border-top-left-radius: var(--border-left-radius);
|
|
||||||
border-bottom-left-radius: var(--border-left-radius);
|
|
||||||
|
|
||||||
border-top-right-radius: var(--border-right-radius);
|
|
||||||
border-bottom-right-radius: var(--border-right-radius);
|
|
||||||
}
|
|
||||||
|
|
||||||
@include button.btn-day($with-disabled: false) using ($base) {
|
|
||||||
@include button.rainbow($base);
|
|
||||||
}
|
|
||||||
|
|
||||||
@include button.btn-night($with-disabled: false) using ($base) {
|
|
||||||
@include button.rainbow($base);
|
|
||||||
}
|
|
||||||
|
|
||||||
input {
|
input {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
export let disables = true;
|
export let disables = true;
|
||||||
export let tabbable = false;
|
export let tabbable = false;
|
||||||
|
|
||||||
|
export let iconSize: number = 75;
|
||||||
|
export let widthMultiplier: number = 1;
|
||||||
|
|
||||||
let buttonRef: HTMLButtonElement;
|
let buttonRef: HTMLButtonElement;
|
||||||
|
|
||||||
const disabled = getContext<Readable<boolean>>(disabledKey);
|
const disabled = getContext<Readable<boolean>>(disabledKey);
|
||||||
|
@ -37,6 +40,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
class:dropdown-toggle={dropdownProps.dropdown}
|
class:dropdown-toggle={dropdownProps.dropdown}
|
||||||
class:btn-day={!nightMode}
|
class:btn-day={!nightMode}
|
||||||
class:btn-night={nightMode}
|
class:btn-night={nightMode}
|
||||||
|
style={`--icon-size: ${iconSize}%`}
|
||||||
title={tooltip}
|
title={tooltip}
|
||||||
{...dropdownProps}
|
{...dropdownProps}
|
||||||
disabled={_disabled}
|
disabled={_disabled}
|
||||||
|
@ -44,7 +48,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
on:click
|
on:click
|
||||||
on:mousedown|preventDefault
|
on:mousedown|preventDefault
|
||||||
>
|
>
|
||||||
<span class="p-1"><slot /></span>
|
<span style={`--width-multiplier: ${widthMultiplier};`}> <slot /> </span>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
|
@ -60,18 +64,25 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
span {
|
span {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
position: relative;
|
||||||
vertical-align: middle;
|
vertical-align: middle;
|
||||||
|
|
||||||
/* constrain icon */
|
/* constrain icon */
|
||||||
width: calc(var(--buttons-size) - 2px);
|
width: calc((var(--buttons-size) - 2px) * var(--width-multiplier));
|
||||||
height: calc(var(--buttons-size) - 2px);
|
height: calc(var(--buttons-size) - 2px);
|
||||||
|
|
||||||
& > :global(svg),
|
& > :global(svg),
|
||||||
& > :global(img) {
|
& > :global(img) {
|
||||||
|
position: absolute;
|
||||||
|
width: var(--icon-size);
|
||||||
|
height: var(--icon-size);
|
||||||
|
top: calc((100% - var(--icon-size)) / 2);
|
||||||
|
bottom: calc((100% - var(--icon-size)) / 2);
|
||||||
|
left: calc((100% - var(--icon-size)) / 2);
|
||||||
|
right: calc((100% - var(--icon-size)) / 2);
|
||||||
|
|
||||||
fill: currentColor;
|
fill: currentColor;
|
||||||
vertical-align: unset;
|
vertical-align: unset;
|
||||||
width: 100%;
|
|
||||||
height: 100%;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,6 @@ compile_sass(
|
||||||
|
|
||||||
compile_sass(
|
compile_sass(
|
||||||
srcs = [
|
srcs = [
|
||||||
"color.scss",
|
|
||||||
"fields.scss",
|
"fields.scss",
|
||||||
],
|
],
|
||||||
group = "base_css",
|
group = "base_css",
|
||||||
|
@ -113,6 +112,10 @@ copy_mdi_icons(
|
||||||
"function-variant.svg",
|
"function-variant.svg",
|
||||||
"code-brackets.svg",
|
"code-brackets.svg",
|
||||||
"xml.svg",
|
"xml.svg",
|
||||||
|
|
||||||
|
"format-color-text.svg",
|
||||||
|
"format-color-highlight.svg",
|
||||||
|
"color-helper.svg",
|
||||||
],
|
],
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
)
|
)
|
||||||
|
|
|
@ -10,54 +10,74 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
import IconButton from "components/IconButton.svelte";
|
import IconButton from "components/IconButton.svelte";
|
||||||
import ColorPicker from "components/ColorPicker.svelte";
|
import ColorPicker from "components/ColorPicker.svelte";
|
||||||
import WithShortcut from "components/WithShortcut.svelte";
|
import WithShortcut from "components/WithShortcut.svelte";
|
||||||
|
import WithColorHelper from "./WithColorHelper.svelte";
|
||||||
|
|
||||||
import { squareFillIcon } from "./icons";
|
import { textColorIcon, highlightColorIcon, arrowIcon } from "./icons";
|
||||||
import { appendInParentheses } from "./helpers";
|
import { appendInParentheses } from "./helpers";
|
||||||
|
|
||||||
import "./color.css";
|
|
||||||
|
|
||||||
export let api = {};
|
export let api = {};
|
||||||
|
|
||||||
const foregroundColorKeyword = "--foreground-color";
|
const wrapWithForecolor = (color: string) => () => {
|
||||||
let color = "black";
|
|
||||||
|
|
||||||
$: {
|
|
||||||
document.documentElement.style.setProperty(foregroundColorKeyword, color);
|
|
||||||
}
|
|
||||||
|
|
||||||
function wrapWithForecolor(): void {
|
|
||||||
document.execCommand("forecolor", false, color);
|
document.execCommand("forecolor", false, color);
|
||||||
}
|
};
|
||||||
|
|
||||||
function setWithCurrentColor({ currentTarget }: Event): void {
|
const wrapWithBackcolor = (color: string) => () => {
|
||||||
color = (currentTarget as HTMLInputElement).value;
|
document.execCommand("backcolor", false, color);
|
||||||
}
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ButtonGroup {api}>
|
<ButtonGroup {api}>
|
||||||
<ButtonGroupItem>
|
<WithColorHelper let:colorHelperIcon let:color let:setColor>
|
||||||
<WithShortcut shortcut={"F7"} let:createShortcut let:shortcutLabel>
|
<ButtonGroupItem>
|
||||||
<IconButton
|
<WithShortcut shortcut={"F7"} let:createShortcut let:shortcutLabel>
|
||||||
class="forecolor"
|
<IconButton
|
||||||
tooltip={appendInParentheses(
|
tooltip={appendInParentheses(
|
||||||
tr.editingSetForegroundColor(),
|
tr.editingSetForegroundColor(),
|
||||||
shortcutLabel
|
shortcutLabel
|
||||||
)}
|
)}
|
||||||
on:click={wrapWithForecolor}
|
on:click={wrapWithForecolor(color)}
|
||||||
on:mount={createShortcut}
|
on:mount={createShortcut}
|
||||||
>
|
>
|
||||||
{@html squareFillIcon}
|
{@html textColorIcon}
|
||||||
</IconButton>
|
{@html colorHelperIcon}
|
||||||
</WithShortcut>
|
</IconButton>
|
||||||
</ButtonGroupItem>
|
</WithShortcut>
|
||||||
|
</ButtonGroupItem>
|
||||||
|
|
||||||
<ButtonGroupItem>
|
<ButtonGroupItem>
|
||||||
<WithShortcut shortcut={"F8"} let:createShortcut let:shortcutLabel>
|
<WithShortcut shortcut={"F8"} let:createShortcut let:shortcutLabel>
|
||||||
<ColorPicker
|
<IconButton
|
||||||
tooltip={appendInParentheses(tr.editingChangeColor(), shortcutLabel)}
|
tooltip={appendInParentheses(
|
||||||
on:change={setWithCurrentColor}
|
tr.editingChangeColor(),
|
||||||
on:mount={createShortcut}
|
shortcutLabel
|
||||||
/>
|
)}
|
||||||
</WithShortcut>
|
disables={false}
|
||||||
</ButtonGroupItem>
|
widthMultiplier={0.5}
|
||||||
|
>
|
||||||
|
{@html arrowIcon}
|
||||||
|
<ColorPicker on:change={setColor} on:mount={createShortcut} />
|
||||||
|
</IconButton>
|
||||||
|
</WithShortcut>
|
||||||
|
</ButtonGroupItem>
|
||||||
|
</WithColorHelper>
|
||||||
|
|
||||||
|
<WithColorHelper let:colorHelperIcon let:color let:setColor>
|
||||||
|
<ButtonGroupItem>
|
||||||
|
<IconButton on:click={wrapWithBackcolor(color)}>
|
||||||
|
{@html highlightColorIcon}
|
||||||
|
{@html colorHelperIcon}
|
||||||
|
</IconButton>
|
||||||
|
</ButtonGroupItem>
|
||||||
|
|
||||||
|
<ButtonGroupItem>
|
||||||
|
<IconButton
|
||||||
|
tooltip={tr.editingChangeColor()}
|
||||||
|
disables={false}
|
||||||
|
widthMultiplier={0.5}
|
||||||
|
>
|
||||||
|
{@html arrowIcon}
|
||||||
|
<ColorPicker on:change={setColor} />
|
||||||
|
</IconButton>
|
||||||
|
</ButtonGroupItem>
|
||||||
|
</WithColorHelper>
|
||||||
</ButtonGroup>
|
</ButtonGroup>
|
||||||
|
|
|
@ -42,6 +42,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
tr.editingAttachPicturesaudiovideo(),
|
tr.editingAttachPicturesaudiovideo(),
|
||||||
shortcutLabel
|
shortcutLabel
|
||||||
)}
|
)}
|
||||||
|
iconSize={70}
|
||||||
on:click={onAttachment}
|
on:click={onAttachment}
|
||||||
on:mount={createShortcut}
|
on:mount={createShortcut}
|
||||||
>
|
>
|
||||||
|
@ -54,6 +55,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
<WithShortcut shortcut={"F5"} let:createShortcut let:shortcutLabel>
|
<WithShortcut shortcut={"F5"} let:createShortcut let:shortcutLabel>
|
||||||
<IconButton
|
<IconButton
|
||||||
tooltip={appendInParentheses(tr.editingRecordAudio(), shortcutLabel)}
|
tooltip={appendInParentheses(tr.editingRecordAudio(), shortcutLabel)}
|
||||||
|
iconSize={70}
|
||||||
on:click={onRecord}
|
on:click={onRecord}
|
||||||
on:mount={createShortcut}
|
on:mount={createShortcut}
|
||||||
>
|
>
|
||||||
|
@ -164,6 +166,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
<WithShortcut shortcut={"Control+Shift+X"} let:createShortcut let:shortcutLabel>
|
<WithShortcut shortcut={"Control+Shift+X"} let:createShortcut let:shortcutLabel>
|
||||||
<IconButton
|
<IconButton
|
||||||
tooltip={appendInParentheses(tr.editingHtmlEditor(), shortcutLabel)}
|
tooltip={appendInParentheses(tr.editingHtmlEditor(), shortcutLabel)}
|
||||||
|
iconSize={70}
|
||||||
on:click={onHtmlEdit}
|
on:click={onHtmlEdit}
|
||||||
on:mount={createShortcut}
|
on:mount={createShortcut}
|
||||||
>
|
>
|
||||||
|
|
27
ts/editor/WithColorHelper.svelte
Normal file
27
ts/editor/WithColorHelper.svelte
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
<!--
|
||||||
|
Copyright: Ankitects Pty Ltd and contributors
|
||||||
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
-->
|
||||||
|
<script lang="typescript">
|
||||||
|
import { colorHelperIcon } from "./icons";
|
||||||
|
|
||||||
|
export let color = "black";
|
||||||
|
|
||||||
|
function setColor({ currentTarget }: Event): void {
|
||||||
|
color = (currentTarget! as HTMLInputElement).value;
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<div style={`--color-helper-color: ${color}`}>
|
||||||
|
<slot {colorHelperIcon} {color} {setColor} />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<style lang="scss">
|
||||||
|
div {
|
||||||
|
display: contents;
|
||||||
|
|
||||||
|
:global(#mdi-color-helper) {
|
||||||
|
fill: var(--color-helper-color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
|
@ -1,7 +0,0 @@
|
||||||
:root {
|
|
||||||
--foreground-color: black;
|
|
||||||
}
|
|
||||||
|
|
||||||
.forecolor {
|
|
||||||
color: var(--foreground-color) !important;
|
|
||||||
}
|
|
|
@ -21,9 +21,15 @@ export { default as indentIcon } from "./text-indent-left.svg";
|
||||||
export { default as outdentIcon } from "./text-indent-right.svg";
|
export { default as outdentIcon } from "./text-indent-right.svg";
|
||||||
|
|
||||||
export { default as squareFillIcon } from "./square-fill.svg";
|
export { default as squareFillIcon } from "./square-fill.svg";
|
||||||
|
export { default as textColorIcon } from "./format-color-text.svg";
|
||||||
|
export { default as highlightColorIcon } from "./format-color-highlight.svg";
|
||||||
|
export { default as colorHelperIcon } from "./color-helper.svg";
|
||||||
|
|
||||||
export { default as paperclipIcon } from "./paperclip.svg";
|
export { default as paperclipIcon } from "./paperclip.svg";
|
||||||
export { default as micIcon } from "./mic.svg";
|
export { default as micIcon } from "./mic.svg";
|
||||||
export { default as bracketsIcon } from "./code-brackets.svg";
|
export { default as bracketsIcon } from "./code-brackets.svg";
|
||||||
export { default as functionIcon } from "./function-variant.svg";
|
export { default as functionIcon } from "./function-variant.svg";
|
||||||
export { default as xmlIcon } from "./xml.svg";
|
export { default as xmlIcon } from "./xml.svg";
|
||||||
|
|
||||||
|
export const arrowIcon =
|
||||||
|
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill="transparent" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M2 5l6 6 6-6"/></svg>';
|
||||||
|
|
|
@ -116,13 +116,3 @@ $focus-color: $blue;
|
||||||
box-shadow: inset 0 calc(var(--buttons-size) / 15) calc(var(--buttons-size) / 5)
|
box-shadow: inset 0 calc(var(--buttons-size) / 15) calc(var(--buttons-size) / 5)
|
||||||
rgba(black, $intensity);
|
rgba(black, $intensity);
|
||||||
}
|
}
|
||||||
|
|
||||||
@mixin rainbow($base) {
|
|
||||||
background: content-box
|
|
||||||
linear-gradient(217deg, rgba(255, 0, 0, 0.8), rgba(255, 0, 0, 0) 70.71%),
|
|
||||||
content-box
|
|
||||||
linear-gradient(127deg, rgba(0, 255, 0, 0.8), rgba(0, 255, 0, 0) 70.71%),
|
|
||||||
content-box
|
|
||||||
linear-gradient(336deg, rgba(0, 0, 255, 0.8), rgba(0, 0, 255, 0) 70.71%),
|
|
||||||
border-box $base;
|
|
||||||
}
|
|
||||||
|
|
Loading…
Reference in a new issue