2021-04-16 15:30:33 +02:00
|
|
|
<script>
|
|
|
|
import Field from "./Field.svelte"
|
|
|
|
import RadioGroup from "./Core/RadioGroup.svelte"
|
|
|
|
import { createEventDispatcher } from "svelte"
|
|
|
|
|
|
|
|
export let value = null
|
2021-04-16 17:00:10 +02:00
|
|
|
export let label = null
|
2021-04-16 15:30:33 +02:00
|
|
|
export let disabled = false
|
|
|
|
export let labelPosition = "above"
|
|
|
|
export let error = null
|
|
|
|
export let options = []
|
2021-12-02 18:53:14 +01:00
|
|
|
export let direction = "vertical"
|
2021-04-16 15:30:33 +02:00
|
|
|
export let getOptionLabel = option => extractProperty(option, "label")
|
|
|
|
export let getOptionValue = option => extractProperty(option, "value")
|
|
|
|
|
|
|
|
const dispatch = createEventDispatcher()
|
|
|
|
const onChange = e => {
|
|
|
|
value = e.detail
|
2021-04-20 13:49:02 +02:00
|
|
|
dispatch("change", e.detail)
|
2021-04-16 15:30:33 +02:00
|
|
|
}
|
|
|
|
const extractProperty = (value, property) => {
|
|
|
|
if (value && typeof value === "object") {
|
|
|
|
return value[property]
|
|
|
|
}
|
|
|
|
return value
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2021-04-29 16:24:59 +02:00
|
|
|
<Field {label} {labelPosition} {error}>
|
2021-04-16 15:30:33 +02:00
|
|
|
<RadioGroup
|
|
|
|
{error}
|
|
|
|
{disabled}
|
|
|
|
{value}
|
|
|
|
{options}
|
2021-12-02 18:53:14 +01:00
|
|
|
{direction}
|
2021-04-16 15:30:33 +02:00
|
|
|
{getOptionLabel}
|
|
|
|
{getOptionValue}
|
2021-05-04 12:04:42 +02:00
|
|
|
on:change={onChange}
|
|
|
|
/>
|
2021-04-16 15:30:33 +02:00
|
|
|
</Field>
|