2021-04-19 13:05:11 +02:00
|
|
|
<script>
|
|
|
|
import Field from "./Field.svelte"
|
|
|
|
import Combobox from "./Core/Combobox.svelte"
|
|
|
|
import { createEventDispatcher } from "svelte"
|
|
|
|
|
|
|
|
export let value = null
|
|
|
|
export let label = undefined
|
|
|
|
export let disabled = false
|
|
|
|
export let labelPosition = "above"
|
|
|
|
export let error = null
|
2021-04-29 16:24:59 +02:00
|
|
|
export let placeholder = "Choose an option or type"
|
2021-04-19 13:05:11 +02:00
|
|
|
export let options = []
|
|
|
|
export let getOptionLabel = option => extractProperty(option, "label")
|
|
|
|
export let getOptionValue = option => extractProperty(option, "value")
|
|
|
|
|
|
|
|
const dispatch = createEventDispatcher()
|
|
|
|
const onChange = e => {
|
|
|
|
value = e.detail
|
2021-04-20 13:49:02 +02:00
|
|
|
dispatch("change", e.detail)
|
2021-04-19 13:05:11 +02:00
|
|
|
}
|
|
|
|
const extractProperty = (value, property) => {
|
|
|
|
if (value && typeof value === "object") {
|
|
|
|
return value[property]
|
|
|
|
}
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2021-04-29 16:24:59 +02:00
|
|
|
<Field {label} {labelPosition} {error}>
|
2021-04-19 13:05:11 +02:00
|
|
|
<Combobox
|
|
|
|
{error}
|
|
|
|
{disabled}
|
|
|
|
{value}
|
|
|
|
{options}
|
|
|
|
{placeholder}
|
|
|
|
{getOptionLabel}
|
|
|
|
{getOptionValue}
|
2021-05-04 12:04:42 +02:00
|
|
|
on:change={onChange}
|
2021-11-10 12:23:35 +01:00
|
|
|
on:pick
|
|
|
|
on:type
|
2021-05-04 12:04:42 +02:00
|
|
|
/>
|
2021-04-19 13:05:11 +02:00
|
|
|
</Field>
|