budibase/packages/builder/src/components/userInterface/ComponentDropdownMenu.svelte

107 lines
2.8 KiB
Svelte
Raw Normal View History

2020-06-01 11:18:45 +02:00
<script>
import { MoreIcon } from "components/common/Icons"
import { store } from "builderStore"
import { getComponentDefinition } from "builderStore/store"
import ConfirmDialog from "components/common/ConfirmDialog.svelte"
import { last } from "lodash/fp"
import UIkit from "uikit"
export let component
let confirmDeleteDialog
let dropdownEl
2020-06-01 12:04:32 +02:00
$: dropdown = UIkit.dropdown(dropdownEl, { mode: "click", offset: 0, pos: "bottom-right", "delay-hide": 0, animation: false });
$: dropdown && UIkit.util.on(dropdown, "shown", () => hidden = false)
2020-06-01 11:18:45 +02:00
$: noChildrenAllowed = !component || getComponentDefinition($store, component._component).children === false
$: noPaste = !$store.componentToPaste || $store.componentToPaste._id === component._id
const lastPartOfName = c => (c ? last(c._component.split("/")) : "")
2020-06-01 12:04:32 +02:00
const hideDropdown = () => {
dropdown.hide()
2020-06-01 11:18:45 +02:00
}
</script>
<div class="root" on:click|stopPropagation={() => {}}>
<button>
<MoreIcon />
</button>
2020-06-01 12:04:32 +02:00
<ul class="menu" bind:this={dropdownEl} on:click={hideDropdown}>
2020-06-01 11:18:45 +02:00
<li on:click={() => confirmDeleteDialog.show()}>Delete</li>
<li on:click={() => store.moveUpComponent(component)}>Move up</li>
<li on:click={() => store.moveDownComponent(component)}>Move down</li>
<li on:click={() => store.copyComponent(component)}>Duplicate</li>
<li on:click={() => store.storeComponentForCopy(component, true)}>Cut</li>
<li on:click={() => store.storeComponentForCopy(component)}>Copy</li>
<hr />
<li class:disabled={noPaste} on:click={() => store.pasteComponent(component, "above")}>Paste above</li>
<li class:disabled={noPaste} on:click={() => store.pasteComponent(component, "below")}>Paste below</li>
<li class:disabled={noPaste || noChildrenAllowed} on:click={() => store.pasteComponent(component, "inside")}>Paste inside</li>
</ul>
</div>
<ConfirmDialog
bind:this={confirmDeleteDialog}
title="Confirm Delete"
body={`Are you sure you wish to delete this '${lastPartOfName(component)}' component?`}
okText="Delete Component"
onOk={() => store.deleteComponent(component)} />
<style>
.root {
overflow: hidden;
z-index:9;
}
2020-06-01 12:04:32 +02:00
.hidden {
display: none;
}
2020-06-01 11:18:45 +02:00
.root button {
border-style: none;
border-radius: 2px;
padding: 5px;
2020-06-01 11:25:12 +02:00
background: transparent;
2020-06-01 11:18:45 +02:00
cursor: pointer;
2020-06-01 12:04:32 +02:00
color: var(--button-text);
outline: none;
2020-06-01 11:18:45 +02:00
}
.menu {
z-index: 100000;
overflow: visible;
padding: 10px 0
}
.menu li {
border-style: none;
background-color: transparent;
list-style-type: none;
padding: 4px 5px 4px 15px;
margin: 0;
width: 100%;
box-sizing: border-box;
}
.menu li:not(.disabled) {
cursor: pointer;
color: var(--ink);
}
.menu li:not(.disabled):hover {
color: var(--button-text);
background-color: var(--grey-light);
}
.disabled {
color: var(--grey-dark);
cursor: default;
}
</style>