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

103 lines
2.2 KiB
Svelte
Raw Normal View History

2020-08-12 17:30:20 +02:00
<script>
import { Button, TextArea, Label, Body } 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()
console.log("test")
}
2020-08-12 17:30:20 +02:00
</script>
2020-08-25 10:15:51 +02:00
<div class="container">
<div class="list">
2020-08-28 14:43:28 +02:00
<Label size="l" color="dark">Objects</Label>
2020-08-25 10:15:51 +02:00
<ul>
{#each bindableProperties as { readableBinding }}
<li on:click={() => addToText(readableBinding)}>{readableBinding}</li>
{/each}
</ul>
</div>
2020-08-28 14:43:28 +02:00
<div class="text">
<Label size="l" color="dark">Data binding</Label>
<Body size="s" color="dark">
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>
2020-08-28 14:43:28 +02:00
<TextArea bind:value placeholder="" />
<div class="controls">
<a href="#">
<Label size="s" color="light">Learn more about binding</Label>
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;
grid-gap: var(--spacing-l);
grid-template-columns: 1fr auto auto;
}
2020-08-25 10:15:51 +02:00
.list {
width: 150px;
2020-08-28 14:43:28 +02:00
border-right: 1.5px solid blue;
}
.text {
width: 600px;
display: grid;
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>