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

96 lines
1.9 KiB
Svelte
Raw Normal View History

<script>
2020-02-03 10:50:30 +01:00
import { last } from "lodash/fp"
import { pipe } from "../common/core"
2020-02-18 17:51:28 +01:00
import { XCircleIcon } 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-02-18 17:51:28 +01:00
export let onDeleteComponent
2020-02-18 17:51:28 +01:00
2020-02-03 10:50:30 +01:00
const capitalise = s => s.substring(0, 1).toUpperCase() + s.substring(1)
2020-02-18 17:51:28 +01:00
const get_name = s => !s ? "" : last(s.split("/"))
const get_capitalised_name = name =>
pipe(
name,
[get_name, capitalise]
)
2020-02-18 17:51:28 +01:00
</script>
<ul>
{#each components as component}
2020-02-03 10:50:30 +01:00
<li on:click|stopPropagation={() => onSelect(component)}>
<span
class="item"
class:selected={currentComponent === component}
style="padding-left: {level * 20 + 67}px">
2020-02-18 17:51:28 +01:00
<span class="item-name">{get_capitalised_name(component._component)}</span>
<button
class="delete-component"
on:click={() => onDeleteComponent(component)}>
<XCircleIcon />
</button>
</span>
{#if component._children}
2020-02-03 10:50:30 +01:00
<svelte:self
components={component._children}
{currentComponent}
{onSelect}
2020-02-18 17:51:28 +01:00
level={level + 1}
{onDeleteComponent} />
{/if}
</li>
{/each}
</ul>
<style>
ul {
list-style: none;
padding-left: 0;
margin: 0;
}
.item {
2020-02-18 17:51:28 +01:00
display: flex;
flex-direction: row;
padding: 11px 5px 11px 67px;
border-radius: 3px;
}
2020-02-18 17:51:28 +01:00
.item > span {
width: 1px;
flex: 1 1 auto;
}
.item > button {
display: none;
height: 20px;
color: var(--slate)
}
.item:hover {
2020-02-18 17:51:28 +01:00
background: #fafafa;
cursor: pointer;
}
2020-02-18 17:51:28 +01:00
.item:hover > button {
border-style: none;
background: rgba(0,0,0,0);
display: block;
cursor: pointer;
}
.item:hover > button:hover {
color: var(--button-text);
}
.selected {
color: var(--button-text);
2020-02-03 10:50:30 +01:00
background: var(--background-button) !important;
}
</style>