budibase/packages/builder/src/components/userInterface/ComponentsHierarchyChildren...

112 lines
2.5 KiB
Svelte
Raw Normal View History

<script>
import { goto } from "@sveltech/routify"
import { store } from "builderStore"
import { last } from "lodash/fp"
2020-05-07 11:53:34 +02:00
import { pipe } from "components/common/core"
2020-06-01 11:18:45 +02:00
import ComponentDropdownMenu from "./ComponentDropdownMenu.svelte"
2020-02-20 18:11:41 +01:00
import {
XCircleIcon,
ChevronUpIcon,
ChevronDownIcon,
CopyIcon,
} from "../common/Icons"
2020-02-03 10:50:30 +01:00
export let components = []
export let currentComponent
export let onSelect = () => {}
export let level = 0
2020-06-01 11:25:12 +02:00
2020-02-03 10:50:30 +01:00
const capitalise = s => s.substring(0, 1).toUpperCase() + s.substring(1)
2020-02-20 18:11:41 +01:00
const get_name = s => (!s ? "" : last(s.split("/")))
2020-02-25 16:21:23 +01:00
const get_capitalised_name = name => pipe(name, [get_name, capitalise])
2020-02-18 17:51:28 +01:00
const selectComponent = component => {
// Set current component
store.selectComponent(component)
// Get ID path
const path = store.getPathToComponent(component)
// Go to correct URL
$goto(`./:page/:screen/${path}`)
}
</script>
<ul>
2020-02-19 11:17:31 +01:00
{#each components as component, index (component._id)}
<li on:click|stopPropagation={() => selectComponent(component)}>
2020-02-19 11:17:31 +01:00
<div
2020-02-24 16:00:48 +01:00
class="budibase__nav-item item"
2020-02-03 10:50:30 +01:00
class:selected={currentComponent === component}
style="padding-left: {level * 20 + 53}px">
2020-06-01 22:34:03 +02:00
<div class="nav-item">
<i class="icon ri-arrow-right-circle-fill" />
{get_capitalised_name(component._component)}
</div>
2020-06-01 11:18:45 +02:00
<div class="actions">
2020-06-01 13:15:44 +02:00
<ComponentDropdownMenu {component} />
2020-02-19 11:17:31 +01:00
</div>
</div>
{#if component._children}
2020-02-03 10:50:30 +01:00
<svelte:self
components={component._children}
{currentComponent}
{onSelect}
2020-06-01 11:25:12 +02:00
level={level + 1} />
{/if}
</li>
{/each}
</ul>
<style>
ul {
list-style: none;
padding-left: 0;
margin: 0;
}
2020-02-19 11:17:31 +01:00
.item {
display: grid;
grid-template-columns: 1fr auto auto auto;
2020-02-20 18:09:35 +01:00
padding: 0px 5px 0px 15px;
2020-02-19 11:17:31 +01:00
margin: auto 0px;
border-radius: 3px;
2020-02-20 18:11:41 +01:00
height: 35px;
2020-02-19 11:17:31 +01:00
align-items: center;
}
2020-02-18 17:51:28 +01:00
2020-06-01 11:18:45 +02:00
.actions {
2020-02-18 17:51:28 +01:00
display: none;
2020-06-01 16:31:55 +02:00
height: 24px;
width: 24px;
color: var(--ink);
2020-02-19 11:17:31 +01:00
padding: 0px 5px;
border-style: none;
background: rgba(0, 0, 0, 0);
cursor: pointer;
2020-06-01 11:18:45 +02:00
position: relative;
2020-02-18 17:51:28 +01:00
}
.item:hover {
2020-06-01 16:31:55 +02:00
background: var(--grey-light);
cursor: pointer;
}
2020-06-01 11:18:45 +02:00
.item:hover .actions {
2020-02-18 17:51:28 +01:00
display: block;
}
2020-06-01 22:18:25 +02:00
.nav-item {
display: flex;
align-items: center;
font-size: 14px;
color: var(--ink);
}
.icon {
color: var(--ink-light);
margin-right: 8px;
}
</style>