2021-02-15 19:41:56 +01:00
|
|
|
<script>
|
|
|
|
import { Input } from "@budibase/bbui"
|
|
|
|
|
|
|
|
export let object = {}
|
|
|
|
|
2021-02-18 17:58:10 +01:00
|
|
|
let fields = Object.entries(object).map(([name, value]) => ({ name, value }))
|
2021-02-15 19:41:56 +01:00
|
|
|
|
|
|
|
$: object = fields.reduce(
|
|
|
|
(acc, next) => ({ ...acc, [next.name]: next.value }),
|
|
|
|
{}
|
|
|
|
)
|
|
|
|
|
|
|
|
function addEntry() {
|
|
|
|
fields = [...fields, {}]
|
|
|
|
}
|
|
|
|
|
|
|
|
function deleteEntry(idx) {
|
|
|
|
fields.splice(idx, 1)
|
|
|
|
fields = fields
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<!-- Builds Objects with Key Value Pairs. Useful for building things like Request Headers. -->
|
|
|
|
<div class="container">
|
|
|
|
{#each fields as field, idx}
|
2021-02-15 19:59:21 +01:00
|
|
|
<Input placeholder="Key" outline thin bind:value={field.name} />
|
|
|
|
<Input placeholder="Value" outline thin bind:value={field.value} />
|
2021-02-15 19:41:56 +01:00
|
|
|
<i class="ri-close-circle-fill" on:click={() => deleteEntry(idx)} />
|
|
|
|
{/each}
|
|
|
|
</div>
|
|
|
|
<i class="ri-add-circle-fill" on:click={addEntry} />
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.container {
|
|
|
|
display: grid;
|
|
|
|
grid-template-columns: 1fr 1fr 20px;
|
|
|
|
grid-gap: var(--spacing-m);
|
|
|
|
align-items: center;
|
2021-02-15 19:59:21 +01:00
|
|
|
margin-bottom: var(--spacing-m);
|
2021-02-15 19:41:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
.ri-close-circle-fill,
|
|
|
|
.ri-add-circle-fill {
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
</style>
|