mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
Make gear button show dropdown menu
This commit is contained in:
parent
48b7ae3cd0
commit
4e4683a122
3 changed files with 41 additions and 7 deletions
|
@ -8,6 +8,8 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
import { setContext } from "svelte";
|
import { setContext } from "svelte";
|
||||||
import { dropdownKey } from "./contextKeys";
|
import { dropdownKey } from "./contextKeys";
|
||||||
|
|
||||||
|
export let disabled = false;
|
||||||
|
|
||||||
setContext(dropdownKey, {
|
setContext(dropdownKey, {
|
||||||
dropdown: true,
|
dropdown: true,
|
||||||
"data-bs-toggle": "dropdown",
|
"data-bs-toggle": "dropdown",
|
||||||
|
@ -17,8 +19,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
const menuId = Math.random().toString(36).substring(2);
|
const menuId = Math.random().toString(36).substring(2);
|
||||||
let dropdown: Dropdown;
|
let dropdown: Dropdown;
|
||||||
|
|
||||||
function activateDropdown(_event: MouseEvent): void {
|
function activateDropdown(): void {
|
||||||
dropdown.toggle();
|
if (!disabled) {
|
||||||
|
dropdown.toggle();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Normally dropdown and trigger are associated with a
|
/* Normally dropdown and trigger are associated with a
|
||||||
|
|
|
@ -3,7 +3,9 @@ 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="ts">
|
<script lang="ts">
|
||||||
import { onMount, createEventDispatcher } from "svelte";
|
import type { DropdownProps } from "components/dropdown";
|
||||||
|
import { dropdownKey } from "components/contextKeys";
|
||||||
|
import { onMount, createEventDispatcher, getContext } from "svelte";
|
||||||
|
|
||||||
let className = "";
|
let className = "";
|
||||||
export { className as class };
|
export { className as class };
|
||||||
|
@ -12,12 +14,20 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
let spanRef: HTMLSpanElement;
|
let spanRef: HTMLSpanElement;
|
||||||
|
|
||||||
|
const dropdownProps = getContext<DropdownProps>(dropdownKey) ?? { dropdown: false };
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
dispatch("mount", { span: spanRef });
|
dispatch("mount", { span: spanRef });
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<span bind:this={spanRef} class={`badge ${className}`} on:click>
|
<span
|
||||||
|
bind:this={spanRef}
|
||||||
|
class={`badge ${className}`}
|
||||||
|
class:dropdown-toggle={dropdownProps.dropdown}
|
||||||
|
{...dropdownProps}
|
||||||
|
on:click
|
||||||
|
>
|
||||||
<slot />
|
<slot />
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
|
@ -26,6 +36,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
color: inherit;
|
color: inherit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.dropdown-toggle::after {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
span :global(svg) {
|
span :global(svg) {
|
||||||
vertical-align: -0.125rem;
|
vertical-align: -0.125rem;
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,13 +37,29 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<WithDropdownMenu let:createDropdown let:menuId>
|
<WithDropdownMenu
|
||||||
<Badge class={className} on:mount={(event) => createDropdown(event.detail.span)}>
|
disabled={!modified}
|
||||||
|
let:createDropdown
|
||||||
|
let:activateDropdown
|
||||||
|
let:menuId
|
||||||
|
>
|
||||||
|
<Badge
|
||||||
|
class={className}
|
||||||
|
on:mount={(event) => createDropdown(event.detail.span)}
|
||||||
|
on:click={activateDropdown}
|
||||||
|
>
|
||||||
{@html gearIcon}
|
{@html gearIcon}
|
||||||
</Badge>
|
</Badge>
|
||||||
|
|
||||||
<DropdownMenu id={menuId}>
|
<DropdownMenu id={menuId}>
|
||||||
<DropdownItem on:click={revert}>
|
<DropdownItem
|
||||||
|
on:click={() => {
|
||||||
|
revert();
|
||||||
|
// Otherwise the menu won't close when the item is clicked
|
||||||
|
// TODO: investigate why this is necessary
|
||||||
|
activateDropdown();
|
||||||
|
}}
|
||||||
|
>
|
||||||
{tr.deckConfigRevertButtonTooltip()}<Badge>{@html revertIcon}</Badge>
|
{tr.deckConfigRevertButtonTooltip()}<Badge>{@html revertIcon}</Badge>
|
||||||
</DropdownItem>
|
</DropdownItem>
|
||||||
</DropdownMenu>
|
</DropdownMenu>
|
||||||
|
|
Loading…
Reference in a new issue