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

85 lines
1.8 KiB
Svelte
Raw Normal View History

<script>
import {
keys, map, some, includes,
cloneDeep, isEqual, sortBy,
filter, difference
} from "lodash/fp";
2019-08-14 23:11:59 +02:00
import { pipe } from "../common/core";
import { getInstanceProps } from "./pagesParsing/createProps";
import Checkbox from "../common/Checkbox.svelte";
import Textbox from "../common/Textbox.svelte";
import Dropdown from "../common/Dropdown.svelte";
2019-08-16 16:48:45 +02:00
import PropControl from "./PropControl.svelte";
import IconButton from "../common/IconButton.svelte";
2019-08-14 23:11:59 +02:00
export let componentInfo;
2019-08-16 16:48:45 +02:00
export let instanceProps = null;
2019-08-14 23:11:59 +02:00
export let onPropsChanged = () => {};
export let components;
2019-08-14 23:11:59 +02:00
let errors = [];
let props = {};
2019-08-16 16:48:45 +02:00
let propsDefinitions = [];
2019-08-19 09:51:01 +02:00
let isInstance = false;
2019-08-16 16:48:45 +02:00
const props_to_ignore = ['_component','_children', '_layout'];
$: propDefs = componentInfo && Object.entries(componentInfo).filter(([name])=> !props_to_ignore.includes(name));
function find_type(prop_name) {
if(!componentInfo._component) return;
return components.find(({name}) => name === componentInfo._component).props[prop_name];
2019-08-14 23:11:59 +02:00
}
let setProp = (name, value) => {
onPropsChanged(name, value);
2019-08-14 23:11:59 +02:00
}
2019-08-04 23:21:16 +02:00
const fieldHasError = (propName) =>
2019-08-14 23:11:59 +02:00
some(e => e.propName === propName)(errors);
</script>
2019-08-04 23:21:16 +02:00
<div class="root">
<form class="uk-form-stacked form-root">
{#each propDefs as [prop_name, prop_value], index}
<div class="prop-container">
2019-08-16 16:48:45 +02:00
<PropControl {setProp}
{prop_name}
{prop_value}
prop_type={find_type(prop_name)}
{index}
disabled={false} />
2019-08-16 16:48:45 +02:00
</div>
{/each}
</form>
2019-08-16 16:48:45 +02:00
2019-08-04 23:21:16 +02:00
</div>
<style>
2019-08-04 23:21:16 +02:00
.root {
font-size:10pt;
width: 100%;
}
.form-root {
display: flex;
flex-wrap: wrap;
}
.prop-container {
flex: 1 1 auto;
min-width: 250px;
2019-08-04 23:21:16 +02:00
}
</style>