Revert button with gear icon, that shows revert dropdown item
This commit is contained in:
parent
292ba665af
commit
48b7ae3cd0
@ -23,20 +23,18 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
|
|
||||||
/* Normally dropdown and trigger are associated with a
|
/* Normally dropdown and trigger are associated with a
|
||||||
/* common ancestor with .dropdown class */
|
/* common ancestor with .dropdown class */
|
||||||
function createDropdown(event: CustomEvent): void {
|
function createDropdown(element: HTMLElement): void {
|
||||||
const button: HTMLButtonElement = event.detail.button;
|
|
||||||
|
|
||||||
/* Prevent focus on menu activation */
|
/* Prevent focus on menu activation */
|
||||||
const noop = () => {};
|
const noop = () => {};
|
||||||
Object.defineProperty(button, "focus", { value: noop });
|
Object.defineProperty(element, "focus", { value: noop });
|
||||||
|
|
||||||
const menu = (button.getRootNode() as Document) /* or shadow root */
|
const menu = (element.getRootNode() as Document) /* or shadow root */
|
||||||
.getElementById(menuId);
|
.getElementById(menuId);
|
||||||
|
|
||||||
if (!menu) {
|
if (!menu) {
|
||||||
console.log(`Could not find menu "${menuId}" for dropdown menu.`);
|
console.log(`Could not find menu "${menuId}" for dropdown menu.`);
|
||||||
} else {
|
} else {
|
||||||
dropdown = new Dropdown(button);
|
dropdown = new Dropdown(element);
|
||||||
|
|
||||||
/* Set custom menu without using common element with .dropdown */
|
/* Set custom menu without using common element with .dropdown */
|
||||||
(dropdown as any)._menu = menu;
|
(dropdown as any)._menu = menu;
|
||||||
|
@ -38,6 +38,7 @@ copy_bootstrap_icons(
|
|||||||
icons = [
|
icons = [
|
||||||
"arrow-counterclockwise.svg",
|
"arrow-counterclockwise.svg",
|
||||||
"info-circle.svg",
|
"info-circle.svg",
|
||||||
|
"gear.svg",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -28,6 +28,5 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
|
|
||||||
span :global(svg) {
|
span :global(svg) {
|
||||||
vertical-align: -0.125rem;
|
vertical-align: -0.125rem;
|
||||||
opacity: 0.3;
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
@ -4,11 +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 WithDropdownMenu from "components/WithDropdownMenu.svelte";
|
||||||
import WithTooltip from "./WithTooltip.svelte";
|
import DropdownMenu from "components/DropdownMenu.svelte";
|
||||||
|
import DropdownItem from "components/DropdownItem.svelte";
|
||||||
import Badge from "./Badge.svelte";
|
import Badge from "./Badge.svelte";
|
||||||
import { revertIcon } from "./icons";
|
import { gearIcon, 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;
|
||||||
@ -30,28 +30,21 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
|
|
||||||
let modified: boolean;
|
let modified: boolean;
|
||||||
$: modified = !isEqual(value, defaultValue);
|
$: modified = !isEqual(value, defaultValue);
|
||||||
|
$: className = !modified ? "opacity-25" : "";
|
||||||
|
|
||||||
function revert(): void {
|
function revert(): void {
|
||||||
value = cloneDeep(defaultValue);
|
value = cloneDeep(defaultValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
const touchDevice = getContext<boolean>(touchDeviceKey);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<span class:invisible={!modified}>
|
<WithDropdownMenu let:createDropdown let:menuId>
|
||||||
{#if touchDevice}
|
<Badge class={className} on:mount={(event) => createDropdown(event.detail.span)}>
|
||||||
<Badge class="px-1" on:click={revert}>{@html revertIcon}</Badge>
|
{@html gearIcon}
|
||||||
{:else}
|
</Badge>
|
||||||
<WithTooltip
|
|
||||||
trigger="hover"
|
<DropdownMenu id={menuId}>
|
||||||
tooltip={tr.deckConfigRevertButtonTooltip()}
|
<DropdownItem on:click={revert}>
|
||||||
let:createTooltip
|
{tr.deckConfigRevertButtonTooltip()}<Badge>{@html revertIcon}</Badge>
|
||||||
>
|
</DropdownItem>
|
||||||
<Badge
|
</DropdownMenu>
|
||||||
class="px-1"
|
</WithDropdownMenu>
|
||||||
on:mount={(event) => createTooltip(event.detail.span)}
|
|
||||||
on:click={revert}>{@html revertIcon}</Badge
|
|
||||||
>
|
|
||||||
</WithTooltip>
|
|
||||||
{/if}
|
|
||||||
</span>
|
|
||||||
|
@ -69,7 +69,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
|
|
||||||
<ButtonGroupItem>
|
<ButtonGroupItem>
|
||||||
<WithDropdownMenu let:createDropdown let:activateDropdown let:menuId>
|
<WithDropdownMenu let:createDropdown let:activateDropdown let:menuId>
|
||||||
<LabelButton on:mount={createDropdown} on:click={activateDropdown} />
|
<LabelButton
|
||||||
|
on:mount={(event) => createDropdown(event.detail.button)}
|
||||||
|
on:click={activateDropdown}
|
||||||
|
/>
|
||||||
<DropdownMenu id={menuId}>
|
<DropdownMenu id={menuId}>
|
||||||
<DropdownItem on:click={() => dispatch("add")}
|
<DropdownItem on:click={() => dispatch("add")}
|
||||||
>{tr.deckConfigAddGroup()}</DropdownItem
|
>{tr.deckConfigAddGroup()}</DropdownItem
|
||||||
|
@ -18,7 +18,9 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||||||
><Label for={forId}><slot /></Label><WithTooltip
|
><Label for={forId}><slot /></Label><WithTooltip
|
||||||
tooltip={marked(markdownTooltip)}
|
tooltip={marked(markdownTooltip)}
|
||||||
let:createTooltip
|
let:createTooltip
|
||||||
><Badge on:mount={(event) => createTooltip(event.detail.span)}
|
><Badge
|
||||||
|
class="opacity-50"
|
||||||
|
on:mount={(event) => createTooltip(event.detail.span)}
|
||||||
>{@html infoCircle}</Badge
|
>{@html infoCircle}</Badge
|
||||||
></WithTooltip
|
></WithTooltip
|
||||||
></span
|
></span
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
// Import icons from bootstrap
|
// Import icons from bootstrap
|
||||||
|
|
||||||
import revertIcon from "./arrow-counterclockwise.svg";
|
export { default as revertIcon } from "./arrow-counterclockwise.svg";
|
||||||
import infoCircle from "./info-circle.svg";
|
export { default as infoCircle } from "./info-circle.svg";
|
||||||
|
export { default as gearIcon } from "./gear.svg";
|
||||||
export { revertIcon, infoCircle };
|
|
||||||
|
@ -6,6 +6,19 @@ $body-bg: var(--window-bg);
|
|||||||
$link-hover-color: var(--link);
|
$link-hover-color: var(--link);
|
||||||
$link-hover-decoration: none;
|
$link-hover-decoration: none;
|
||||||
|
|
||||||
|
$utilities: (
|
||||||
|
"opacity": (
|
||||||
|
property: opacity,
|
||||||
|
values: (
|
||||||
|
0: 0,
|
||||||
|
25: 0.25,
|
||||||
|
50: 0.5,
|
||||||
|
75: 0.75,
|
||||||
|
100: 1,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
@import "ts/sass/bootstrap/bootstrap-reboot";
|
@import "ts/sass/bootstrap/bootstrap-reboot";
|
||||||
@import "ts/sass/bootstrap/bootstrap-utilities";
|
@import "ts/sass/bootstrap/bootstrap-utilities";
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user