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

128 lines
2.9 KiB
Svelte
Raw Normal View History

<script>
import { goto } from "@sveltech/routify"
import { store } from "builderStore"
import components from "./temporaryPanelStructure.js"
2020-05-04 17:07:04 +02:00
import CategoryTab from "./CategoryTab.svelte"
import { Popover } from "@budibase/bbui"
import { fade, fly } from "svelte/transition"
import Tab from "./ItemTab/Tab.svelte"
const categories = components.categories
2020-10-22 18:46:21 +02:00
let selectedCategory
let width
const close = () => {
2020-10-22 18:46:21 +02:00
selectedCategory = null
}
2020-10-22 18:46:21 +02:00
const onCategoryChosen = (category) => {
if (category.isCategory) {
selectedCategory = selectedCategory === category ? null : category
} else {
onComponentChosen(category)
}
}
const onComponentChosen = (component) => {
2020-07-26 12:54:55 +02:00
store.addChildComponent(component._component, component.presetProps)
2020-05-29 19:32:52 +02:00
// Get ID path
const path = store.getPathToComponent($store.currentComponentInfo)
// Go to correct URL
$goto(`./:page/:screen/${path}`)
close()
}
</script>
<div class="wrapper">
<div
class="container"
bind:clientWidth={width}
2020-10-22 18:46:21 +02:00
class:open={selectedCategory != null}>
{#each categories as category, idx}
<div
class="category"
2020-10-22 18:46:21 +02:00
on:click={() => onCategoryChosen(category)}
class:active={selectedCategory === category}>
2020-10-22 18:46:21 +02:00
{#if category.icon}<i class={category.icon} />{/if}
<span>{category.name}</span>
{#if category.isCategory}<i class="ri-arrow-down-s-line arrow" />{/if}
</div>
{/each}
2020-02-19 22:38:21 +01:00
</div>
{#if selectedCategory != null}
<div class="overlay" on:click={close} />
<div class="dropdown" transition:fly={{ y: -120 }}>
<Tab
list={selectedCategory}
2020-10-22 18:46:21 +02:00
on:selectItem={(e) => onComponentChosen(e.detail)} />
</div>
{/if}
</div>
<style>
.wrapper {
position: relative;
z-index: 1;
}
.container {
2020-10-22 18:46:21 +02:00
padding: var(--spacing-l) 40px;
display: flex;
flex-direction: row;
justify-content: flex-start;
align-items: center;
background-color: white;
z-index: 1;
2020-10-22 18:46:21 +02:00
width: calc(100% - 80px);
overflow: hidden;
}
2020-10-22 18:46:21 +02:00
.container.open {
}
.category {
2020-10-22 18:46:21 +02:00
color: var(--grey-7);
cursor: pointer;
2020-10-22 18:46:21 +02:00
margin-right: var(--spacing-l);
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 {
font-weight: 500;
2020-10-22 18:46:21 +02:00
user-select: none;
}
.category.active,
.category:hover {
2020-10-22 18:46:21 +02:00
color: var(--ink);
}
.category i:not(:last-child) {
font-size: 16px;
}
.overlay {
position: fixed;
top: 0;
left: 0;
z-index: -2;
width: 100vw;
height: 100vh;
}
.dropdown {
position: absolute;
z-index: -1;
top: calc(100% - var(--spacing-xl));
left: 0;
width: calc(100% - 80px);
background-color: white;
padding: var(--spacing-xl) 40px;
box-shadow: 0 0 8px 4px rgba(0, 0, 0, 0.05);
}
</style>