2020-05-07 15:30:04 +02:00
|
|
|
<script>
|
|
|
|
import { onMount } from "svelte"
|
|
|
|
export let value = ""
|
|
|
|
export let onChange = value => {}
|
|
|
|
export let options = []
|
|
|
|
export let initialValue = ""
|
2020-05-08 10:57:41 +02:00
|
|
|
export let styleBindingProperty = ""
|
|
|
|
|
2020-05-19 18:00:53 +02:00
|
|
|
const handleStyleBind = value =>
|
|
|
|
!!styleBindingProperty ? { style: `${styleBindingProperty}: ${value}` } : {}
|
|
|
|
|
|
|
|
$: isOptionsObject = options.every(o => typeof o === "object")
|
2020-05-07 15:30:04 +02:00
|
|
|
|
|
|
|
onMount(() => {
|
|
|
|
if (!value && !!initialValue) {
|
|
|
|
value = initialValue
|
|
|
|
}
|
|
|
|
})
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<select
|
|
|
|
class="uk-select uk-form-small"
|
|
|
|
{value}
|
|
|
|
on:change={ev => onChange(ev.target.value)}>
|
2020-05-19 18:00:53 +02:00
|
|
|
{#if isOptionsObject}
|
|
|
|
{#each options as { value, label }}
|
|
|
|
<option {...handleStyleBind(value || label)} value={value || label}>
|
2020-05-08 10:57:41 +02:00
|
|
|
{label}
|
|
|
|
</option>
|
2020-05-19 18:00:53 +02:00
|
|
|
{/each}
|
|
|
|
{:else}
|
|
|
|
{#each options as value}
|
|
|
|
<option {...handleStyleBind(value)} {value}>{value}</option>
|
|
|
|
{/each}
|
|
|
|
{/if}
|
2020-05-07 15:30:04 +02:00
|
|
|
</select>
|