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-10-26 15:03:07 +01:00
|
|
|
import { DropdownContainer, DropdownItem } from "components/common/Dropdowns"
|
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
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-27 16:28:13 +01:00
|
|
|
const onComponentChosen = component => {
|
2020-11-04 18:09:45 +01:00
|
|
|
store.actions.components.create(component._component, component.presetProps)
|
|
|
|
const path = store.actions.components.findRoute($store.currentComponentInfo)
|
2020-05-29 15:56:21 +02:00
|
|
|
$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"
|
2020-10-23 11:37:28 +02:00
|
|
|
on:click={() => onCategoryChosen(category, idx)}
|
|
|
|
class:active={idx === selectedIndex}>
|
2020-11-04 18:09:45 +01:00
|
|
|
{#if category.icon}
|
|
|
|
<i class={category.icon} />
|
|
|
|
{/if}
|
2020-10-22 21:22:09 +02:00
|
|
|
<span>{category.name}</span>
|
2020-11-04 18:09:45 +01:00
|
|
|
{#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-23 11:37:28 +02:00
|
|
|
<DropdownMenu
|
|
|
|
on:close={() => (selectedIndex = null)}
|
|
|
|
bind:this={popover}
|
|
|
|
{anchor}
|
|
|
|
align="left">
|
2020-10-26 15:03:07 +01:00
|
|
|
<DropdownContainer>
|
|
|
|
{#each categories[selectedIndex].children as item}
|
|
|
|
{#if !item.showOnPages || item.showOnPages.includes($store.currentPageName)}
|
|
|
|
<DropdownItem
|
|
|
|
icon={item.icon}
|
|
|
|
title={item.name}
|
|
|
|
on:click={() => onComponentChosen(item)} />
|
|
|
|
{/if}
|
|
|
|
{/each}
|
|
|
|
</DropdownContainer>
|
2020-10-22 21:22:09 +02:00
|
|
|
</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-23 11:55:12 +02:00
|
|
|
min-height: 24px;
|
|
|
|
flex-wrap: wrap;
|
|
|
|
gap: var(--spacing-l);
|
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;
|
|
|
|
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
|
|
|
}
|
2020-10-23 11:37:28 +02:00
|
|
|
.category.active,
|
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>
|