Disable RevertButton tooltip on touch devices

The tooltip will show after you clicked Revert. There's no sensible way
to show the tooltip, without also triggering the functionality
This commit is contained in:
Henrik Giesel 2021-06-12 17:48:53 +02:00
parent 98c57ce3f8
commit abca240de7
4 changed files with 25 additions and 9 deletions

View file

@ -1,6 +1,7 @@
// Copyright: Ankitects Pty Ltd and contributors // 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
export const nightModeKey = Symbol("nightMode"); export const nightModeKey = Symbol("nightMode");
export const touchDeviceKey = Symbol("touchDevice");
export const disabledKey = Symbol("disabled"); export const disabledKey = Symbol("disabled");
export const sectionKey = Symbol("section"); export const sectionKey = Symbol("section");

View file

@ -4,9 +4,11 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
--> -->
<script lang="ts"> <script lang="ts">
import * as tr from "lib/i18n"; import * as tr from "lib/i18n";
import { getContext } from "svelte";
import WithTooltip from "./WithTooltip.svelte"; import WithTooltip from "./WithTooltip.svelte";
import Badge from "./Badge.svelte"; import Badge from "./Badge.svelte";
import { revertIcon } from "./icons"; import { revertIcon } from "./icons";
import { touchDeviceKey } from "components/contextKeys";
import { isEqual as isEqualLodash, cloneDeep } from "lodash-es"; import { isEqual as isEqualLodash, cloneDeep } from "lodash-es";
type T = unknown; type T = unknown;
@ -32,14 +34,24 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
function revert(): void { function revert(): void {
value = cloneDeep(defaultValue); value = cloneDeep(defaultValue);
} }
const touchDevice = getContext<boolean>(touchDeviceKey);
</script> </script>
<span class:invisible={!modified}> <span class:invisible={!modified}>
<WithTooltip tooltip={tr.deckConfigRevertButtonTooltip()} let:createTooltip> {#if touchDevice}
<Badge <Badge class="px-1" on:click={revert}>{@html revertIcon}</Badge>
class="px-1" {:else}
on:mount={(event) => createTooltip(event.detail.span)} <WithTooltip
on:click={revert}>{@html revertIcon}</Badge trigger="hover"
tooltip={tr.deckConfigRevertButtonTooltip()}
let:createTooltip
> >
</WithTooltip> <Badge
class="px-1"
on:mount={(event) => createTooltip(event.detail.span)}
on:click={revert}>{@html revertIcon}</Badge
>
</WithTooltip>
{/if}
</span> </span>

View file

@ -39,4 +39,4 @@
}); });
</script> </script>
<slot {createTooltip} /> <slot {createTooltip} {tooltipObject} />

View file

@ -14,7 +14,7 @@ import SpinBoxFloat from "./SpinBoxFloat.svelte";
import EnumSelector from "./EnumSelector.svelte"; import EnumSelector from "./EnumSelector.svelte";
import CheckBox from "./CheckBox.svelte"; import CheckBox from "./CheckBox.svelte";
import { nightModeKey, modalsKey } from "components/contextKeys"; import { nightModeKey, touchDeviceKey, modalsKey } from "components/contextKeys";
export async function deckOptions( export async function deckOptions(
target: HTMLDivElement, target: HTMLDivElement,
@ -31,13 +31,16 @@ export async function deckOptions(
}), }),
]); ]);
const nightMode = checkNightMode();
const context = new Map(); const context = new Map();
const nightMode = checkNightMode();
context.set(nightModeKey, nightMode); context.set(nightModeKey, nightMode);
const modals = new Map(); const modals = new Map();
context.set(modalsKey, modals); context.set(modalsKey, modals);
const touchDevice = "ontouchstart" in document.documentElement;
context.set(touchDeviceKey, touchDevice);
const state = new DeckOptionsState(deckId, info); const state = new DeckOptionsState(deckId, info);
return new DeckOptionsPage({ return new DeckOptionsPage({
target, target,