diff --git a/ts/editor-toolbar/ButtonGroup.svelte b/ts/editor-toolbar/ButtonGroup.svelte index e139adfcd..9a9d876c6 100644 --- a/ts/editor-toolbar/ButtonGroup.svelte +++ b/ts/editor-toolbar/ButtonGroup.svelte @@ -1,10 +1,6 @@ - - diff --git a/ts/editor-toolbar/ColorPicker.svelte b/ts/editor-toolbar/ColorPicker.svelte index c53dbb24b..ac2a94d3e 100644 --- a/ts/editor-toolbar/ColorPicker.svelte +++ b/ts/editor-toolbar/ColorPicker.svelte @@ -1,15 +1,14 @@ - diff --git a/ts/editor-toolbar/CommandIconButton.svelte b/ts/editor-toolbar/CommandIconButton.svelte index b5efcaaa0..2d5232191 100644 --- a/ts/editor-toolbar/CommandIconButton.svelte +++ b/ts/editor-toolbar/CommandIconButton.svelte @@ -34,9 +34,12 @@ - + {@html icon} - + diff --git a/ts/editor-toolbar/DropdownIconButton.svelte b/ts/editor-toolbar/DropdownIconButton.svelte deleted file mode 100644 index f03a8dce8..000000000 --- a/ts/editor-toolbar/DropdownIconButton.svelte +++ /dev/null @@ -1,25 +0,0 @@ - - - diff --git a/ts/editor-toolbar/DropdownMenu.svelte b/ts/editor-toolbar/DropdownMenu.svelte new file mode 100644 index 000000000..d800a240d --- /dev/null +++ b/ts/editor-toolbar/DropdownMenu.svelte @@ -0,0 +1,40 @@ + + + diff --git a/ts/editor-toolbar/EditorToolbar.svelte b/ts/editor-toolbar/EditorToolbar.svelte index 5336136b2..33b00b8b8 100644 --- a/ts/editor-toolbar/EditorToolbar.svelte +++ b/ts/editor-toolbar/EditorToolbar.svelte @@ -5,7 +5,7 @@ import { disabledKey, nightModeKey } from "./contextKeys"; import ButtonGroup from "./ButtonGroup.svelte"; - import type { Buttons } from "./ButtonGroup.svelte"; + import type { Buttons } from "./types"; export let buttons: Buttons = []; export let nightMode: boolean; @@ -25,7 +25,7 @@ background: var(--bg-color); border-bottom: 1px solid var(--border); - /* Remove most outer marigns */ + /* Remove outermost marigns */ & > :global(ul) { & > :global(li:nth-child(1)) { margin-left: 0; diff --git a/ts/editor-toolbar/IconButton.svelte b/ts/editor-toolbar/IconButton.svelte index 613a53433..fc5960f48 100644 --- a/ts/editor-toolbar/IconButton.svelte +++ b/ts/editor-toolbar/IconButton.svelte @@ -1,11 +1,14 @@ - + {@html icon} - + diff --git a/ts/editor-toolbar/LabelButton.svelte b/ts/editor-toolbar/LabelButton.svelte index 9428dd568..4e366d18b 100644 --- a/ts/editor-toolbar/LabelButton.svelte +++ b/ts/editor-toolbar/LabelButton.svelte @@ -1,5 +1,27 @@ - + diff --git a/ts/editor-toolbar/InnerButton.svelte b/ts/editor-toolbar/SquareButton.svelte similarity index 75% rename from ts/editor-toolbar/InnerButton.svelte rename to ts/editor-toolbar/SquareButton.svelte index 43030ce7e..041e4548c 100644 --- a/ts/editor-toolbar/InnerButton.svelte +++ b/ts/editor-toolbar/SquareButton.svelte @@ -3,31 +3,24 @@ import type { Readable } from "svelte/store"; import { disabledKey } from "./contextKeys"; - export let className: string = ""; + export let id = ""; + export let className = ""; + export let props: Record = {}; + export let onClick: (event: ClickEvent) => void; export let active = false; - const disabledStore = getContext(disabledKey) + const disabledStore = getContext(disabledKey); $: disabled = $disabledStore; diff --git a/ts/editor-toolbar/color.scss b/ts/editor-toolbar/color.scss index f9d459eea..6e6077eb4 100644 --- a/ts/editor-toolbar/color.scss +++ b/ts/editor-toolbar/color.scss @@ -7,11 +7,11 @@ } .rainbow { - background: linear-gradient(217deg, rgba(255, 0, 0, 0.8), rgba(255, 0, 0, 0) 70.71%), - linear-gradient(127deg, rgba(0, 255, 0, 0.8), rgba(0, 255, 0, 0) 70.71%), - linear-gradient(336deg, rgba(0, 0, 255, 0.8), rgba(0, 0, 255, 0) 70.71%); - - background-clip: content-box; - /* Boostrap .rounded has .25rem */ - border-radius: 0.375rem; + 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 white; } diff --git a/ts/editor-toolbar/color.ts b/ts/editor-toolbar/color.ts index c03ce380c..862cb7801 100644 --- a/ts/editor-toolbar/color.ts +++ b/ts/editor-toolbar/color.ts @@ -20,12 +20,12 @@ function wrapWithForecolor(color: string): void { export const forecolorButton = { component: IconButton, icon: squareFillIcon, - className: "forecolor p-1", + className: "forecolor", onClick: () => wrapWithForecolor(getForecolor()), }; export const colorpickerButton = { component: ColorPicker, - className: "rainbow p-1", + className: "rainbow", onChange: ({ currentTarget }) => setForegroundColor(currentTarget.value), }; diff --git a/ts/editor-toolbar/index.ts b/ts/editor-toolbar/index.ts index dff93d5c0..bee5b626f 100644 --- a/ts/editor-toolbar/index.ts +++ b/ts/editor-toolbar/index.ts @@ -6,7 +6,7 @@ import { setupI18n, ModuleName } from "anki/i18n"; import EditorToolbarSvelte from "./EditorToolbar.svelte"; import LabelButton from "./LabelButton.svelte"; -import DropdownIconButton from "./DropdownIconButton.svelte"; +import DropdownMenu from "./DropdownMenu.svelte"; // @ts-ignore export { updateActiveButtons, clearActiveButtons } from "./CommandIconButton.svelte"; @@ -46,8 +46,6 @@ const defaultButtons = [ ], [forecolorButton, colorpickerButton], [attachmentButton, recordButton, clozeButton, mathjaxButton, htmlButton], - [ { component: DropdownIconButton }], - ]; class EditorToolbar extends HTMLElement { @@ -57,16 +55,18 @@ class EditorToolbar extends HTMLElement { connectedCallback(): void { this.disabled = writable(false); - setupI18n({ modules: [ModuleName.STATISTICS, ModuleName.SCHEDULING] }).then(() => { - this.component = new EditorToolbarSvelte({ - target: this, - props: { - buttons: defaultButtons, - nightMode: checkNightMode(), - disabled: this.disabled, - }, - }); - }) + setupI18n({ modules: [ModuleName.STATISTICS, ModuleName.SCHEDULING] }).then( + () => { + this.component = new EditorToolbarSvelte({ + target: this, + props: { + buttons: defaultButtons, + nightMode: checkNightMode(), + disabled: this.disabled, + }, + }); + } + ); } enableButtons(): void { diff --git a/ts/editor-toolbar/types.ts b/ts/editor-toolbar/types.ts new file mode 100644 index 000000000..0a47bda9c --- /dev/null +++ b/ts/editor-toolbar/types.ts @@ -0,0 +1,12 @@ +import type { SvelteComponent } from "svelte/internal"; + +export interface ButtonDefinition { + component: SvelteComponent; + id?: string; + className?: string; + props?: Record; + button: HTMLButtonElement; + [arg: string]: unknown; +} + +export type Buttons = ButtonDefinition | Buttons[];