2020-01-18 00:06:42 +01:00
|
|
|
<script>
|
2020-05-29 15:56:21 +02:00
|
|
|
import { goto } from "@sveltech/routify"
|
2020-10-14 17:47:53 +02:00
|
|
|
import { store } from "builderStore"
|
2020-04-17 09:16:03 +02:00
|
|
|
import components from "./temporaryPanelStructure.js"
|
2020-10-22 21:22:09 +02:00
|
|
|
import { DropdownMenu } from "@budibase/bbui"
|
2020-04-22 08:25:59 +02:00
|
|
|
import Tab from "./ItemTab/Tab.svelte"
|
2020-04-17 09:16:03 +02:00
|
|
|
|
|
|
|
const categories = components.categories
|
2020-10-22 21:22:09 +02:00
|
|
|
let selectedIndex
|
|
|
|
let anchors = []
|
|
|
|
let popover
|
|
|
|
$: anchor = selectedIndex === -1 ? null : anchors[selectedIndex]
|
2020-10-21 10:19:26 +02:00
|
|
|
|
|
|
|
const close = () => {
|
2020-10-22 21:22:09 +02:00
|
|
|
selectedIndex = null
|
|
|
|
popover.hide()
|
2020-10-21 10:19:26 +02:00
|
|
|
}
|
2020-04-21 15:20:57 +02:00
|
|
|
|
2020-10-22 21:22:09 +02:00
|
|
|
const onCategoryChosen = (category, idx) => {
|
2020-10-22 18:46:21 +02:00
|
|
|
if (category.isCategory) {
|
2020-10-22 21:22:09 +02:00
|
|
|
selectedIndex = idx
|
|
|
|
popover.show()
|
2020-10-22 18:46:21 +02:00
|
|
|
} else {
|
|
|
|
onComponentChosen(category)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const onComponentChosen = (component) => {
|
2020-07-26 12:54:55 +02:00
|
|
|
store.addChildComponent(component._component, component.presetProps)
|
2020-05-29 15:56:21 +02:00
|
|
|
const path = store.getPathToComponent($store.currentComponentInfo)
|
|
|
|
$goto(`./:page/:screen/${path}`)
|
2020-10-21 10:19:26 +02:00
|
|
|
close()
|
2020-04-22 08:25:59 +02:00
|
|
|
}
|
2020-01-18 00:06:42 +01:00
|
|
|
</script>
|
|
|
|
|
2020-10-22 21:22:09 +02:00
|
|
|
<div class="container">
|
|
|
|
{#each categories as category, idx}
|
|
|
|
<div
|
|
|
|
bind:this={anchors[idx]}
|
|
|
|
class="category"
|
|
|
|
on:click={() => onCategoryChosen(category, idx)}>
|
|
|
|
{#if category.icon}<i class={category.icon} />{/if}
|
|
|
|
<span>{category.name}</span>
|
|
|
|
{#if category.isCategory}<i class="ri-arrow-down-s-line arrow" />{/if}
|
2020-10-21 10:19:26 +02:00
|
|
|
</div>
|
2020-10-22 21:22:09 +02:00
|
|
|
{/each}
|
2020-01-18 00:06:42 +01:00
|
|
|
</div>
|
2020-10-22 21:22:09 +02:00
|
|
|
<DropdownMenu bind:this={popover} {anchor} align="left">
|
|
|
|
<Tab
|
|
|
|
list={categories[selectedIndex]}
|
|
|
|
on:selectItem={(e) => onComponentChosen(e.detail)} />
|
|
|
|
</DropdownMenu>
|
2020-01-18 00:06:42 +01:00
|
|
|
|
|
|
|
<style>
|
2020-10-21 10:19:26 +02:00
|
|
|
.container {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
justify-content: flex-start;
|
|
|
|
align-items: center;
|
|
|
|
z-index: 1;
|
2020-10-22 21:22:09 +02:00
|
|
|
height: 24px;
|
2020-10-21 10:19:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
.category {
|
2020-10-22 18:46:21 +02:00
|
|
|
color: var(--grey-7);
|
2020-10-21 10:19:26 +02:00
|
|
|
cursor: pointer;
|
2020-10-22 18:46:21 +02:00
|
|
|
margin-right: var(--spacing-l);
|
2020-10-21 10:19:26 +02:00
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
justify-content: flex-start;
|
|
|
|
align-items: center;
|
|
|
|
gap: var(--spacing-xs);
|
2020-10-22 18:46:21 +02:00
|
|
|
font-size: var(--font-size-xs);
|
|
|
|
}
|
|
|
|
.category span {
|
2020-10-21 10:19:26 +02:00
|
|
|
font-weight: 500;
|
2020-10-22 18:46:21 +02:00
|
|
|
user-select: none;
|
2020-10-21 10:19:26 +02:00
|
|
|
}
|
|
|
|
.category:hover {
|
2020-10-22 18:46:21 +02:00
|
|
|
color: var(--ink);
|
|
|
|
}
|
|
|
|
.category i:not(:last-child) {
|
|
|
|
font-size: 16px;
|
2020-10-21 10:19:26 +02:00
|
|
|
}
|
2020-01-18 00:06:42 +01:00
|
|
|
</style>
|