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

79 lines
1.9 KiB
Svelte
Raw Normal View History

2021-03-31 11:59:07 +02:00
<script>
import Field from "./Field.svelte"
import Select from "./Core/Select.svelte"
import { createEventDispatcher } from "svelte"
2021-03-31 11:59:07 +02:00
export let value = null
2021-03-31 11:59:07 +02:00
export let label = undefined
export let disabled = false
export let readonly = false
export let labelPosition = "above"
export let error = null
export let placeholder = "Choose an option"
export let options = []
export let getOptionLabel = option => extractProperty(option, "label")
export let getOptionValue = option => extractProperty(option, "value")
2023-11-24 17:19:39 +01:00
export let getOptionSubtitle = option => option?.subtitle
export let getOptionIcon = option => option?.icon
export let getOptionColour = option => option?.colour
2023-11-24 17:19:39 +01:00
export let useOptionIconImage = false
2022-08-01 16:23:41 +02:00
export let isOptionEnabled
2021-05-06 14:57:36 +02:00
export let quiet = false
export let autoWidth = false
export let sort = false
export let tooltip = ""
2023-02-13 10:47:08 +01:00
export let autocomplete = false
export let customPopoverHeight
2023-02-28 13:29:13 +01:00
export let align
export let footer = null
2023-08-24 12:38:50 +02:00
export let tag = null
export let helpText = null
export let compare
2024-04-10 09:37:33 +02:00
export let onOptionMouseenter = () => {}
export let onOptionMouseleave = () => {}
const dispatch = createEventDispatcher()
const onChange = e => {
value = e.detail
dispatch("change", e.detail)
2021-03-31 11:59:07 +02:00
}
const extractProperty = (value, property) => {
if (value && typeof value === "object") {
return value[property]
}
return value
}
</script>
2021-03-31 11:59:07 +02:00
<Field {helpText} {label} {labelPosition} {error} {tooltip}>
<Select
2021-05-06 14:57:36 +02:00
{quiet}
{error}
{disabled}
{readonly}
{value}
{options}
{placeholder}
{autoWidth}
{sort}
2023-02-28 13:29:13 +01:00
{align}
{footer}
{getOptionLabel}
{getOptionValue}
{getOptionIcon}
{getOptionColour}
2023-11-24 17:19:39 +01:00
{getOptionSubtitle}
2023-02-28 17:21:54 +01:00
{useOptionIconImage}
2022-08-01 16:23:41 +02:00
{isOptionEnabled}
2023-02-13 10:47:08 +01:00
{autocomplete}
{customPopoverHeight}
2023-08-24 12:38:50 +02:00
{tag}
{compare}
2024-04-10 09:37:33 +02:00
{onOptionMouseenter}
{onOptionMouseleave}
on:change={onChange}
on:click
/>
</Field>