budibase/packages/bbui/src/Form/Combobox.svelte

43 lines
1.0 KiB
Svelte
Raw Normal View History

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
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
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>
<Field {label} {labelPosition} {error}>
2021-04-19 13:05:11 +02:00
<Combobox
{error}
{disabled}
{value}
{options}
{placeholder}
{getOptionLabel}
{getOptionValue}
on:change={onChange}
on:pick
on:type
/>
2021-04-19 13:05:11 +02:00
</Field>