Files
ianitor/packages/ui/src/Segmented.svelte

46 lines
1.2 KiB
Svelte

<!-- This Source Code Form is subject to the terms of the Mozilla Public
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at https://mozilla.org/MPL/2.0/. -->
<script lang="ts" generics="T extends string">
// Handoff §2.10: a radio group in a fieldset; arrows move and select (native radios).
let {
legend,
name,
options,
value = $bindable(),
disabled = [],
describedby,
onchange,
}: {
legend: string;
name: string;
options: { value: T; label: string }[];
value: T;
disabled?: T[];
describedby?: string;
onchange?: (v: T) => void;
} = $props();
</script>
<fieldset class="domi-field" aria-describedby={describedby}>
<legend class="domi-field-label">{legend}</legend>
<div class="ia-seg">
{#each options as o (o.value)}
<label>
<input
type="radio"
{name}
value={o.value}
checked={value === o.value}
disabled={disabled.includes(o.value)}
onchange={() => {
value = o.value;
onchange?.(o.value);
}}
/>
{o.label}
</label>
{/each}
</div>
</fieldset>