converts component adding buttons in design section

This commit is contained in:
Keviin Åberg Kultalahti 2021-04-26 17:34:28 +02:00
parent f0e25612a1
commit 0146cd0c88
3 changed files with 50 additions and 53 deletions

View File

@ -1,6 +1,9 @@
<script> <script>
import Popover from "../Popover/Popover.svelte" import Popover from "../Popover/Popover.svelte"
import Menu from "../Menu/Menu.svelte" import Menu from "../Menu/Menu.svelte"
export let supressOpen = false
let anchor let anchor
let dropdown let dropdown
@ -23,7 +26,7 @@
} }
</script> </script>
<div class="contents" use:getAnchor on:click={dropdown.show}> <div class="contents" use:getAnchor>
<slot name="button" /> <slot name="button" />
</div> </div>
<Popover bind:this={dropdown} {anchor} align="left"> <Popover bind:this={dropdown} {anchor} align="left">

View File

@ -1,12 +1,25 @@
<script> <script>
export let icon = undefined; export let dataCy
export let disabled = undefined; export let icon = undefined
export let disabled = undefined
</script> </script>
<li on:click|preventDefault class="spectrum-Menu-item" class:is-disabled={disabled} role="menuitem" tabindex="0"> <li
data-cy={dataCy}
on:click|preventDefault
class="spectrum-Menu-item"
class:is-disabled={disabled}
role="menuitem"
tabindex="0"
>
{#if icon} {#if icon}
<svg class="spectrum-Icon spectrum-Icon--sizeM spectrum-Menu-itemIcon" focusable="false" aria-hidden="true" aria-label={icon}> <svg
<use xlink:href="#spectrum-icon-18-{icon}"></use> class="spectrum-Icon spectrum-Icon--sizeM spectrum-Menu-itemIcon"
focusable="false"
aria-hidden="true"
aria-label={icon}
>
<use xlink:href="#spectrum-icon-18-{icon}" />
</svg> </svg>
{/if} {/if}
<span class="spectrum-Menu-itemLabel"><slot /></span> <span class="spectrum-Menu-itemLabel"><slot /></span>

View File

@ -1,14 +1,8 @@
<script> <script>
import { goto } from "@roxi/routify" import { ActionMenu, ActionGroup, ActionButton, MenuItem, Icon } from "@budibase/bbui"
import { import { store, currentAssetName } from "builderStore"
store, import { iterateeAry } from "lodash/fp/_mapping"
currentAssetName,
selectedComponent,
currentAssetId,
} from "builderStore"
import structure from "./componentStructure.json" import structure from "./componentStructure.json"
import { Popover } from "@budibase/bbui"
import { DropdownContainer, DropdownItem } from "components/common/Dropdowns"
$: enrichedStructure = enrichStructure(structure, $store.components) $: enrichedStructure = enrichStructure(structure, $store.components)
@ -19,7 +13,7 @@
const enrichStructure = (structure, definitions) => { const enrichStructure = (structure, definitions) => {
let enrichedStructure = [] let enrichedStructure = []
structure.forEach(item => { structure.forEach((item) => {
if (typeof item === "string") { if (typeof item === "string") {
const def = definitions[`@budibase/standard-components/${item}`] const def = definitions[`@budibase/standard-components/${item}`]
if (def) { if (def) {
@ -39,50 +33,37 @@
return enrichedStructure return enrichedStructure
} }
const onItemChosen = async (item, idx) => { const onItemChosen = async (item, idx, open) => {
if (item.isCategory) { if (item.isCategory) {
// Select and open this category // Select and open this category
selectedIndex = idx selectedIndex = idx
popover.show() open()
} else { } else {
// Add this component // Add this component
await store.actions.components.create(item.component) await store.actions.components.create(item.component)
popover.hide()
} }
} }
</script> </script>
<div class="container"> <ActionGroup>
{#each enrichedStructure as item, idx} {#each enrichedStructure as item, idx}
<div <ActionMenu supressOpen={item.isCategory} let:open let:closeOnClick>
bind:this={anchors[idx]} <ActionButton icon={item.icon} xs primary quiet slot="button" on:click={() => onItemChosen(item, idx, open)}>
class="category" {item.name}
data-cy={item.isCategory ? `category-${item.name}` : `component-${item.name}`} </ActionButton>
on:click={() => onItemChosen(item, idx)} {#each item.children || [] as item}
class:active={idx === selectedIndex}>
{#if item.icon}<i class={item.icon} />{/if}
<span>{item.name}</span>
{#if item.isCategory}<i class="ri-arrow-down-s-line arrow" />{/if}
</div>
{/each}
</div>
<Popover
on:close={() => (selectedIndex = null)}
bind:this={popover}
{anchor}
align="left">
<DropdownContainer>
{#each enrichedStructure[selectedIndex].children as item}
{#if !item.showOnAsset || item.showOnAsset.includes($currentAssetName)} {#if !item.showOnAsset || item.showOnAsset.includes($currentAssetName)}
<DropdownItem <MenuItem
data-cy={`component-${item.name}`} dataCy={`component-${item.name}`}
icon={item.icon} icon={item.icon}
title={item.name} on:click={closeOnClick(onItemChosen(item))}>
on:click={() => onItemChosen(item)} /> {item.name}
</MenuItem>
{/if} {/if}
{/each} {/each}
</DropdownContainer> </ActionMenu>
</Popover> {/each}
</ActionGroup>
<style> <style>
.container { .container {