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

102 lines
2.3 KiB
Svelte
Raw Normal View History

2020-05-04 17:07:04 +02:00
<script>
import { excludeProps } from "./propertyCategories.js"
2020-05-07 15:30:04 +02:00
import PropertyControl from "./PropertyControl.svelte"
2020-05-08 21:29:15 +02:00
2020-05-05 11:02:10 +02:00
export let name = ""
export let properties = {}
2020-05-04 17:07:04 +02:00
export let componentInstance = {}
export let componentDefinition = {}
export let onPropChanged = () => {}
2020-05-04 17:07:04 +02:00
2020-05-07 15:30:04 +02:00
export let show = false
2020-05-08 21:29:15 +02:00
let showComponentGroup = false
2020-05-04 17:07:04 +02:00
const propExistsOnComponentDef = prop => prop in componentDefinition.props
2020-05-05 11:02:10 +02:00
const capitalize = name => name[0].toUpperCase() + name.slice(1)
2020-05-04 17:07:04 +02:00
2020-05-07 15:30:04 +02:00
function onChange(key, v) {
!!v.target ? onPropChanged(key, v.target.value) : onPropChanged(key, v)
}
2020-05-08 21:29:15 +02:00
$: {
let res = false
let componentProps = Object.keys(componentDefinition.props)
for (let prop in properties) {
if (componentProps.includes(prop)) {
showComponentGroup = true
}
if (showComponentGroup) break
}
}
$: propertyDefinition = Object.entries(properties)
2020-05-04 17:07:04 +02:00
$: icon = show ? "ri-arrow-down-s-fill" : "ri-arrow-right-s-fill"
</script>
2020-05-08 21:29:15 +02:00
<!-- {#if showComponentGroup} -->
2020-05-07 15:30:04 +02:00
<div class="property-group-container">
<div class="property-group-name" on:click={() => (show = !show)}>
2020-05-04 17:07:04 +02:00
<div class="icon">
<i class={icon} />
</div>
2020-05-05 11:02:10 +02:00
<div class="name">{capitalize(name)}</div>
2020-05-04 17:07:04 +02:00
</div>
<div class="property-panel" class:show>
{#each propertyDefinition as [key, definition]}
2020-05-07 15:30:04 +02:00
<!-- {#if propExistsOnComponentDef(key)} -->
<PropertyControl
label={definition.label || capitalize(key)}
control={definition.control}
value={componentInstance[key]}
onChange={value => onChange(key, value)}
props={{ ...excludeProps(definition, ['control']) }} />
<!-- {/if} -->
{/each}
2020-05-04 17:07:04 +02:00
</div>
</div>
2020-05-08 21:29:15 +02:00
<!-- {/if} -->
2020-05-04 17:07:04 +02:00
<style>
.property-group-container {
display: flex;
flex-direction: column;
height: auto;
background: #fbfbfb;
margin: 5px;
padding: 5px;
}
2020-05-05 11:02:10 +02:00
.property-group-name {
2020-05-04 17:07:04 +02:00
cursor: pointer;
flex: 0 0 20px;
display: flex;
flex-flow: row nowrap;
}
2020-05-05 11:02:10 +02:00
.name {
2020-05-04 17:07:04 +02:00
flex: 1;
text-align: left;
2020-05-07 15:30:04 +02:00
padding-top: 2px;
font-size: 14px;
font-weight: 500;
letter-spacing: 0.14px;
color: #393c44;
}
.icon {
flex: 0 0 20px;
text-align: center;
2020-05-04 17:07:04 +02:00
}
.property-panel {
height: 0px;
overflow: hidden;
}
2020-05-04 17:07:04 +02:00
.show {
overflow: auto;
height: auto;
}
</style>