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

84 lines
1.9 KiB
Svelte
Raw Normal View History

<script>
import {
keys,
map,
} from "lodash/fp";
import {
pipe
} from "../common/core";
2019-08-04 23:21:16 +02:00
import {
createPropDefinitionForDerived
} from "./pagesParsing/createProps";
import {
getExactComponent
} from "./pagesParsing/searchComponents";
import Checkbox from "../common/Checkbox.svelte";
import Textbox from "../common/Textbox.svelte";
import Dropdown from "../common/Dropdown.svelte";
export let props;
2019-08-04 23:21:16 +02:00
export let allComponents;
let propsDefinition = createPropDefinitionForDerived(allComponents, props._component);
let fields = pipe(propsDefinition,[
keys,
map(k => propsDefinition[k])
]);
2019-08-04 23:21:16 +02:00
let component = getExactComponent(allComponents, props._component);
let setProp = (name) => (ev) =>
props[name] = ev.target.checked !== undefined
? ev.target.checked
: ev.target.value;
</script>
2019-08-04 23:21:16 +02:00
<div class="root">
<div class="title">{component.name}</div>
<div class="component-description">{component.description || ""}</div>
2019-08-04 23:21:16 +02:00
{#each propsDefinition as propDef}
<form class="uk-form-horizontal prop-row ">
2019-08-04 23:21:16 +02:00
{#if propDef.type === "bool"}
<Checkbox label={propDef.name}
checked={props[propDef.name]}
on:change={setProp(propDef.name)} />
{:else if propDef.type === "options"}
<Dropdown label={propDef.name}
selected={props[propDef.name]}
options={propDef.options}
on:change={setProp(propDef.name)}/>
2019-08-04 23:21:16 +02:00
{:else}
<Textbox label={propDef.name}
bind:text={props[propDef.name]} />
2019-08-04 23:21:16 +02:00
{/if}
</form>
2019-08-04 23:21:16 +02:00
{/each}
</div>
<style>
2019-08-04 23:21:16 +02:00
.root {
padding: 10px;
font-size:10pt;
}
.title {
font: var(--smallheavybodytext);
}
.prop-row {
padding: 7px 3px;
}
.component-description {
font: var(--lightbodytext);
2019-08-04 23:21:16 +02:00
}
</style>