2021-04-12 06:18:30 +02:00
|
|
|
<!--
|
|
|
|
Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
-->
|
2023-09-14 01:06:15 +02:00
|
|
|
<script context="module" lang="ts">
|
|
|
|
export interface Choice<T> {
|
|
|
|
label: string;
|
|
|
|
value: T;
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2021-04-12 06:18:30 +02:00
|
|
|
<script lang="ts">
|
2023-09-09 01:00:55 +02:00
|
|
|
import Select from "./Select.svelte";
|
|
|
|
import SelectOption from "./SelectOption.svelte";
|
2021-05-30 19:46:39 +02:00
|
|
|
|
2023-09-14 01:06:15 +02:00
|
|
|
type T = $$Generic;
|
|
|
|
|
|
|
|
export let value: T;
|
|
|
|
export let choices: Choice<T>[] = [];
|
|
|
|
export let disabled: boolean = false;
|
|
|
|
export let disabledChoices: T[] = [];
|
2022-12-01 10:24:26 +01:00
|
|
|
|
2023-09-14 01:06:15 +02:00
|
|
|
$: label = choices.find((c) => c.value === value)?.label;
|
2021-04-12 06:18:30 +02:00
|
|
|
</script>
|
|
|
|
|
2023-09-14 01:06:15 +02:00
|
|
|
<Select bind:value {label} {disabled}>
|
|
|
|
{#each choices as { label: optionLabel, value: optionValue }}
|
|
|
|
<SelectOption
|
|
|
|
value={optionValue}
|
|
|
|
disabled={disabledChoices.includes(optionValue)}
|
|
|
|
>
|
|
|
|
{optionLabel}
|
2023-06-01 03:11:26 +02:00
|
|
|
</SelectOption>
|
2021-05-28 00:52:49 +02:00
|
|
|
{/each}
|
2022-09-27 04:16:45 +02:00
|
|
|
</Select>
|