budibase/packages/builder/src/userInterface/ComponentsList.svelte

159 lines
3.2 KiB
Svelte
Raw Normal View History

<script>
2020-02-03 10:50:30 +01:00
import { splitName } from "./pagesParsing/splitRootComponentName.js"
import { store } from "../builderStore"
import { find, sortBy } from "lodash/fp"
import { ImageIcon, InputIcon, LayoutIcon } from "../common/Icons/"
let componentLibraries = []
let current_view = "text"
const addRootComponent = (c, all) => {
const { libName } = splitName(c.name)
let group = find(r => r.libName === libName)(all)
if (!group) {
group = {
libName,
components: [],
generators: [],
}
all.push(group)
}
2020-02-03 10:50:30 +01:00
group.components.push(c)
}
2020-02-03 10:50:30 +01:00
const onComponentChosen = store.addChildComponent
2020-02-03 10:50:30 +01:00
$: {
const newComponentLibraries = []
2020-02-03 10:50:30 +01:00
for (let comp of sortBy(["name"])($store.components)) {
addRootComponent(comp, newComponentLibraries)
}
2020-02-03 10:50:30 +01:00
componentLibraries = newComponentLibraries
}
</script>
<div class="root">
2020-02-03 10:50:30 +01:00
{#each componentLibraries as lib}
<div class="library-header">{lib.libName}</div>
<div class="library-container">
2020-02-03 10:50:30 +01:00
<ul>
<li>
<button
class:selected={current_view === 'text'}
on:click={() => (current_view = 'text')}>
<InputIcon />
</button>
</li>
<li>
<button
class:selected={current_view === 'layout'}
on:click={() => (current_view = 'layout')}>
<LayoutIcon />
</button>
</li>
<li>
<button
class:selected={current_view === 'media'}
on:click={() => (current_view = 'media')}>
<ImageIcon />
</button>
</li>
</ul>
2020-02-18 11:32:00 +01:00
{#each $store.builtins.concat(lib.components.filter(_ => true)) as component}
2020-02-03 10:50:30 +01:00
<div
class="component"
on:click={() => onComponentChosen(component.name)}>
<div class="name">{splitName(component.name).componentName}</div>
</div>
2020-02-03 10:50:30 +01:00
{/each}
</div>
2020-02-03 10:50:30 +01:00
{/each}
</div>
<style>
2020-02-03 10:50:30 +01:00
.root {
display: flex;
flex-direction: column;
2020-02-03 10:50:30 +01:00
}
2020-02-03 10:50:30 +01:00
.library-header {
font-size: 1.1em;
border-color: var(--primary25);
border-width: 1px 0px;
border-style: solid;
background-color: var(--primary10);
padding: 5px 0;
flex: 0 0 auto;
2020-02-03 10:50:30 +01:00
}
2020-02-03 10:50:30 +01:00
.library-container {
padding: 0 0 10px 10px;
flex: 1 1 auto;
min-height: 0px;
2020-02-03 10:50:30 +01:00
}
2020-02-03 10:50:30 +01:00
.component {
padding: 0 15px;
cursor: pointer;
border: 1px solid #ccc;
border-radius: 2px;
margin: 10px 0;
height: 40px;
box-sizing: border-box;
color: #163057;
display: flex;
align-items: center;
2020-02-03 10:50:30 +01:00
}
2020-02-03 10:50:30 +01:00
.component:hover {
background-color: var(--lightslate);
2020-02-03 10:50:30 +01:00
}
2020-02-03 10:50:30 +01:00
.component > .name {
color: #163057;
display: inline-block;
font-size: 12px;
font-weight: bold;
opacity: 0.6;
2020-02-03 10:50:30 +01:00
}
2020-02-03 10:50:30 +01:00
ul {
list-style: none;
display: flex;
padding: 0;
2020-02-03 10:50:30 +01:00
}
2020-02-03 10:50:30 +01:00
li {
margin-right: 20px;
background: none;
border-radius: 5px;
width: 48px;
height: 48px;
2020-02-03 10:50:30 +01:00
}
2020-02-03 10:50:30 +01:00
li button {
width: 100%;
height: 100%;
background: none;
border: none;
border-radius: 5px;
padding: 12px;
outline: none;
cursor: pointer;
2020-02-03 10:50:30 +01:00
}
2020-02-03 10:50:30 +01:00
.selected {
color: var(--button-text);
2020-02-03 10:50:30 +01:00
background: var(--background-button) !important;
}
</style>