2020-05-07 15:30:04 +02:00
|
|
|
<script>
|
2020-05-18 17:32:00 +02:00
|
|
|
import { onMount, getContext } from "svelte"
|
|
|
|
|
2020-05-07 15:30:04 +02:00
|
|
|
export let label = ""
|
|
|
|
export let control = null
|
2020-05-19 18:00:53 +02:00
|
|
|
export let key = ""
|
2020-05-21 15:28:32 +02:00
|
|
|
export let value
|
2020-05-07 15:30:04 +02:00
|
|
|
export let props = {}
|
|
|
|
export let onChange = () => {}
|
2020-05-19 18:00:53 +02:00
|
|
|
|
|
|
|
function handleChange(key, v) {
|
2020-07-26 12:54:55 +02:00
|
|
|
let innerVal = v
|
|
|
|
if (typeof v === "object") {
|
|
|
|
if ("detail" in v) {
|
|
|
|
innerVal = v.detail
|
|
|
|
} else if ("target" in v) {
|
|
|
|
innerVal = props.valueKey ? v.target[props.valueKey] : v.target.value
|
|
|
|
}
|
2020-05-20 12:55:25 +02:00
|
|
|
}
|
2020-07-26 12:54:55 +02:00
|
|
|
onChange(key, innerVal)
|
2020-05-19 18:00:53 +02:00
|
|
|
}
|
|
|
|
|
2020-05-25 16:23:56 +02:00
|
|
|
const safeValue = () => {
|
|
|
|
return value === undefined && props.defaultValue !== undefined
|
|
|
|
? props.defaultValue
|
|
|
|
: value
|
|
|
|
}
|
|
|
|
|
2020-05-21 15:28:32 +02:00
|
|
|
//Incase the component has a different value key name
|
|
|
|
const handlevalueKey = value =>
|
2020-05-25 16:23:56 +02:00
|
|
|
props.valueKey ? { [props.valueKey]: safeValue() } : { value: safeValue() }
|
2020-05-07 15:30:04 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<div class="property-control">
|
|
|
|
<div class="label">{label}</div>
|
|
|
|
<div class="control">
|
|
|
|
<svelte:component
|
|
|
|
this={control}
|
2020-05-21 15:28:32 +02:00
|
|
|
{...handlevalueKey(value)}
|
2020-05-19 18:00:53 +02:00
|
|
|
on:change={val => handleChange(key, val)}
|
|
|
|
onChange={val => handleChange(key, val)}
|
2020-06-11 12:56:16 +02:00
|
|
|
{...props}
|
|
|
|
name={key} />
|
2020-05-07 15:30:04 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.property-control {
|
|
|
|
display: flex;
|
2020-05-26 21:44:24 +02:00
|
|
|
flex-flow: row;
|
2020-05-07 15:30:04 +02:00
|
|
|
margin: 8px 0px;
|
2020-05-26 21:44:24 +02:00
|
|
|
align-items: center;
|
2020-05-07 15:30:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
.label {
|
2020-05-28 17:24:53 +02:00
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2020-05-07 15:30:04 +02:00
|
|
|
font-size: 12px;
|
2020-05-26 21:44:24 +02:00
|
|
|
font-weight: 400;
|
2020-05-07 15:30:04 +02:00
|
|
|
text-align: left;
|
2020-05-26 21:44:24 +02:00
|
|
|
color: var(--ink);
|
|
|
|
margin-right: auto;
|
|
|
|
text-transform: capitalize;
|
2020-05-07 15:30:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
.control {
|
|
|
|
flex: 1;
|
2020-05-30 19:48:20 +02:00
|
|
|
display: flex;
|
2020-05-26 21:44:24 +02:00
|
|
|
padding-left: 2px;
|
|
|
|
max-width: 164px;
|
2020-05-07 15:30:04 +02:00
|
|
|
}
|
|
|
|
</style>
|