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 = ""
|
|
|
|
|
|
|
|
$: bindOptionToStyle = !!styleBindingProperty
|
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)}>
|
|
|
|
{#each options as { value, label }}
|
2020-05-08 10:57:41 +02:00
|
|
|
{#if bindOptionToStyle}
|
|
|
|
<option
|
|
|
|
style={`${styleBindingProperty}: ${value || label};`}
|
|
|
|
value={value || label}>
|
|
|
|
{label}
|
|
|
|
</option>
|
|
|
|
{:else}
|
|
|
|
<option value={value || label}>{label}</option>
|
|
|
|
{/if}
|
2020-05-07 15:30:04 +02:00
|
|
|
{/each}
|
|
|
|
</select>
|