2021-03-31 11:59:07 +02:00
|
|
|
<script>
|
2021-04-15 12:50:56 +02:00
|
|
|
import Field from "./Field.svelte"
|
2021-04-15 20:28:08 +02:00
|
|
|
import Select from "./Core/Select.svelte"
|
2021-04-15 12:50:56 +02:00
|
|
|
import { createEventDispatcher } from "svelte"
|
2021-03-31 11:59:07 +02:00
|
|
|
|
2021-04-15 12:50:56 +02:00
|
|
|
export let value = null
|
2021-03-31 11:59:07 +02:00
|
|
|
export let label = undefined
|
|
|
|
export let disabled = false
|
2021-04-19 15:04:07 +02:00
|
|
|
export let readonly = false
|
2021-04-15 12:50:56 +02:00
|
|
|
export let labelPosition = "above"
|
|
|
|
export let error = null
|
2021-04-16 10:01:21 +02:00
|
|
|
export let placeholder = "Choose an option"
|
2021-04-15 12:50:56 +02:00
|
|
|
export let options = []
|
2021-04-16 12:04:50 +02:00
|
|
|
export let getOptionLabel = option => extractProperty(option, "label")
|
|
|
|
export let getOptionValue = option => extractProperty(option, "value")
|
2021-07-13 18:30:59 +02:00
|
|
|
export let getOptionIcon = option => option?.icon
|
2021-05-06 14:57:36 +02:00
|
|
|
export let quiet = false
|
2021-06-23 15:21:37 +02:00
|
|
|
export let autoWidth = false
|
2021-08-20 11:03:21 +02:00
|
|
|
export let sort = false
|
2021-03-31 11:59:07 +02:00
|
|
|
|
2021-04-15 12:50:56 +02:00
|
|
|
const dispatch = createEventDispatcher()
|
|
|
|
const onChange = e => {
|
|
|
|
value = e.detail
|
2021-04-20 13:49:02 +02:00
|
|
|
dispatch("change", e.detail)
|
2021-03-31 11:59:07 +02:00
|
|
|
}
|
2021-07-07 14:41:09 +02:00
|
|
|
|
2021-04-16 12:04:50 +02:00
|
|
|
const extractProperty = (value, property) => {
|
|
|
|
if (value && typeof value === "object") {
|
|
|
|
return value[property]
|
|
|
|
}
|
|
|
|
return value
|
|
|
|
}
|
2021-04-15 12:50:56 +02:00
|
|
|
</script>
|
2021-03-31 11:59:07 +02:00
|
|
|
|
2021-04-29 16:24:59 +02:00
|
|
|
<Field {label} {labelPosition} {error}>
|
2021-04-15 12:50:56 +02:00
|
|
|
<Select
|
2021-05-06 14:57:36 +02:00
|
|
|
{quiet}
|
2021-04-15 12:50:56 +02:00
|
|
|
{error}
|
|
|
|
{disabled}
|
2021-04-19 15:04:07 +02:00
|
|
|
{readonly}
|
2021-04-15 12:50:56 +02:00
|
|
|
{value}
|
|
|
|
{options}
|
|
|
|
{placeholder}
|
2021-06-23 15:21:37 +02:00
|
|
|
{autoWidth}
|
2021-08-20 11:03:21 +02:00
|
|
|
{sort}
|
2021-04-15 12:50:56 +02:00
|
|
|
{getOptionLabel}
|
|
|
|
{getOptionValue}
|
2021-07-07 14:41:09 +02:00
|
|
|
{getOptionIcon}
|
2021-04-19 15:04:07 +02:00
|
|
|
on:change={onChange}
|
2021-05-04 12:04:42 +02:00
|
|
|
on:click
|
|
|
|
/>
|
2021-04-15 12:50:56 +02:00
|
|
|
</Field>
|