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

128 lines
2.8 KiB
Svelte
Raw Normal View History

2020-08-12 17:30:20 +02:00
<script>
import groupBy from "lodash/fp/groupBy"
import {
Button,
TextArea,
Label,
Body,
Heading,
Spacer,
} from "@budibase/bbui"
2020-08-25 10:15:51 +02:00
import { createEventDispatcher } from "svelte"
const dispatch = createEventDispatcher()
export let bindableProperties
2020-08-28 14:43:28 +02:00
console.log("Bindable Props: ", bindableProperties)
2020-08-25 10:15:51 +02:00
export let value = ""
export let close
2020-08-25 10:15:51 +02:00
function addToText(readableBinding) {
value = value + `{{ ${readableBinding} }}`
}
let originalValue = value
2020-08-25 10:15:51 +02:00
$: dispatch("update", value)
function cancel() {
dispatch("update", originalValue)
close()
}
$: ({ instance, context } = groupBy("type", bindableProperties))
2020-08-12 17:30:20 +02:00
</script>
2020-09-01 11:16:41 +02:00
<div class="container" data-cy="binding-dropdown-modal">
2020-08-25 10:15:51 +02:00
<div class="list">
<Heading extraSmall>Objects</Heading>
{#if context}
<Heading extraSmall>Tables</Heading>
<ul>
{#each context as { readableBinding }}
<li on:click={() => addToText(readableBinding)}>{readableBinding}</li>
{/each}
</ul>
{/if}
{#if instance}
<Heading extraSmall>Components</Heading>
<ul>
{#each instance as { readableBinding }}
<li on:click={() => addToText(readableBinding)}>{readableBinding}</li>
{/each}
</ul>
{/if}
2020-08-25 10:15:51 +02:00
</div>
2020-08-28 14:43:28 +02:00
<div class="text">
<Heading extraSmall>Data binding</Heading>
<Spacer small />
<Body extraSmall lh>
Binding connects one piece of data to another and makes it dynamic. Click
the objects on the left, to add them to the textbox.
</Body>
<Spacer large />
2020-08-28 14:43:28 +02:00
<TextArea bind:value placeholder="" />
<div class="controls">
<a href="https://docs.budibase.com">
<Body small grey>Learn more about binding</Body>
2020-08-28 14:43:28 +02:00
</a>
<Button on:click={cancel} secondary>Cancel</Button>
<Button on:click={close} primary>Done</Button>
2020-08-28 14:43:28 +02:00
</div>
</div>
2020-08-25 10:15:51 +02:00
</div>
2020-08-12 17:30:20 +02:00
<style>
2020-08-25 10:15:51 +02:00
.container {
display: grid;
grid-template-columns: auto auto;
}
2020-08-28 14:43:28 +02:00
.list,
2020-08-25 10:15:51 +02:00
.text {
2020-08-28 14:43:28 +02:00
padding: var(--spacing-m);
2020-08-25 10:15:51 +02:00
}
.controls {
margin-top: var(--spacing-m);
display: grid;
align-items: baseline;
grid-gap: var(--spacing-l);
grid-template-columns: 1fr auto auto;
}
2020-08-25 10:15:51 +02:00
.list {
width: 150px;
border-right: 1.5px solid var(--grey-4);
padding: var(--spacing-xl);
2020-08-28 14:43:28 +02:00
}
.text {
width: 600px;
padding: var(--spacing-xl);
font-family: var(--font-sans);
2020-08-25 10:15:51 +02:00
}
.text :global(p) {
margin: 0;
}
2020-08-12 17:30:20 +02:00
ul {
list-style: none;
padding-left: 0;
margin: 0;
2020-08-25 11:40:48 +02:00
padding: 0;
2020-08-12 17:30:20 +02:00
}
2020-08-25 11:40:48 +02:00
2020-08-12 17:30:20 +02:00
li {
display: flex;
font-family: var(--font-sans);
font-size: var(--font-size-xs);
color: var(--ink);
padding: var(--spacing-s) var(--spacing-m);
margin: auto 0px;
align-items: center;
cursor: pointer;
}
2020-08-25 11:40:48 +02:00
li:hover {
background-color: var(--grey-2);
}
li:active {
color: var(--blue);
}
2020-08-12 17:30:20 +02:00
</style>