Add mostly working addcards topbar

This commit is contained in:
Henrik Giesel 2021-04-24 00:00:32 +02:00
parent baeaa29dae
commit 9f7a187d4a
8 changed files with 43 additions and 18 deletions

View file

@ -68,21 +68,31 @@ class AddCards(QDialog):
editor.web.eval( editor.web.eval(
f""" f"""
const notetypeChooser = editorToolbar.labelButton({{ const notetypeChooser = editorToolbar.withLabel({{
label: `{tr.notetypes_type()}`,
className: "flex-grow-1",
button: editorToolbar.labelButton({{
label: `Choose note type`, label: `Choose note type`,
className: "flex-grow-1",
onClick: () => bridgeCommand("choosenotetype"), onClick: () => bridgeCommand("choosenotetype"),
disables: false, disables: false,
}})
}}); }});
const deckChooser = editorToolbar.labelButton({{ const deckChooser = editorToolbar.withLabel({{
label: `{tr.decks_deck()}`,
className: "flex-grow-1",
button: editorToolbar.labelButton({{
label: `Choose deck`, label: `Choose deck`,
className: "flex-grow-1",
onClick: () => bridgeCommand("choosedeck"), onClick: () => bridgeCommand("choosedeck"),
disables: false, disables: false,
}})
}}); }});
$editorToolbar.insertButton(editorToolbar.buttonGroup({{ $editorToolbar.insertButton(editorToolbar.buttonGroup({{
id: "choosers", id: "choosers",
fullWidth: true, className: "flex-basis-100",
items: [notetypeChooser, deckChooser], items: [notetypeChooser, deckChooser],
}}), 0); }}), 0);
""" """

View file

@ -6,4 +6,5 @@ export interface ButtonGroupProps {
id: string; id: string;
className?: string; className?: string;
items: ToolbarItem[]; items: ToolbarItem[];
fullWidth?: boolean;
} }

View file

@ -3,7 +3,7 @@ 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 type { DynamicSvelteComponent } from "sveltelib/dynamicComponent"; import type { ToolbarItem } from "./types";
import { getContext } from "svelte"; import { getContext } from "svelte";
import { nightModeKey } from "./contextKeys"; import { nightModeKey } from "./contextKeys";

View file

@ -24,7 +24,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
import { disabledKey, nightModeKey } from "./contextKeys"; import { disabledKey, nightModeKey } from "./contextKeys";
import ButtonGroup from "./ButtonGroup.svelte"; import ButtonGroup from "./ButtonGroup.svelte";
import type { ButtonGroupProps } from "./ButtonGroup";
export let buttons: Readable<IterableToolbarItem>[]; export let buttons: Readable<IterableToolbarItem>[];
export let menus: Readable<ToolbarItem[]>; export let menus: Readable<ToolbarItem[]>;

View file

@ -3,6 +3,9 @@
import type { ToolbarItem } from "./types"; import type { ToolbarItem } from "./types";
export interface WithLabelProps { export interface WithLabelProps {
id?: string;
className?: string;
button: ToolbarItem; button: ToolbarItem;
label: string; label: string;
} }

View file

@ -3,20 +3,25 @@ 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 type { DynamicSvelteComponent } from "sveltelib/dynamicComponent";
import type { ToolbarItem } from "./types"; import type { ToolbarItem } from "./types";
import type { Modifier } from "lib/shortcuts";
import { onDestroy } from "svelte"; export let id: string;
import { registerShortcut, getPlatformString } from "lib/shortcuts"; export let className = "";
export let button: ToolbarItem;
export let label: string; export let label: string;
export let button: ToolbarItem;
</script> </script>
<style lang="scss">
label {
display: flex;
padding: 0 calc(var(--toolbar-size) / 10);
}
</style>
<!-- svelte-ignore a11y-label-has-associated-control --> <!-- svelte-ignore a11y-label-has-associated-control -->
<label> <label {id} class={className}>
{label} <span class="me-1">{label}</span>
<svelte:component this={button.component} {...button} /> <svelte:component this={button.component} {...button} />
</label> </label>

View file

@ -9,10 +9,12 @@ import {
iconButton, iconButton,
commandIconButton, commandIconButton,
selectButton, selectButton,
dropdownMenu, dropdownMenu,
dropdownItem, dropdownItem,
buttonDropdown, buttonDropdown,
withDropdownMenu, withDropdownMenu,
withLabel,
} from "editor-toolbar/dynamicComponents"; } from "editor-toolbar/dynamicComponents";
export const editorToolbar: Record< export const editorToolbar: Record<
@ -30,4 +32,5 @@ export const editorToolbar: Record<
dropdownItem, dropdownItem,
buttonDropdown, buttonDropdown,
withDropdownMenu, withDropdownMenu,
withLabel,
}; };

View file

@ -59,3 +59,7 @@
opacity: 0.5; opacity: 0.5;
} }
} }
.flex-basis-100 {
flex-basis: 100%;
}