budibase/packages/builder/src/components/userInterface/OptionSelect.svelte

34 lines
754 B
Svelte
Raw Normal View History

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 = ""
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 }}
{#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>