43 lines
1.4 KiB
Svelte
43 lines
1.4 KiB
Svelte
<!-- SPDX-License-Identifier: CPAL-1.0
|
|
- Copyright (c) 2026 Marek Novák. Part of Ianitor, under the Common Public Attribution
|
|
- License 1.0: see LICENSE (its Exhibit A is this file's notice). -->
|
|
<script lang="ts" generics="T extends string">
|
|
import { Segmented as DomiSegmented } from "@domi/ui";
|
|
|
|
// Handoff §2.10: a few choices of one thing, with its name shown above them. The control is @domi/ui's Segmented
|
|
// (a radio group with one Tab stop; arrows, Home and End move the choice); Ianitor keeps the visible name.
|
|
// `name` is kept for the call sites; @domi/ui's group needs none.
|
|
let {
|
|
legend,
|
|
name: _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();
|
|
|
|
const uid = $props.id();
|
|
const choices = $derived(options.map((o) => ({ value: o.value, label: o.label, disabled: disabled.includes(o.value) })));
|
|
</script>
|
|
|
|
<div class="ia-field" role="group" aria-labelledby="ia-seg-{uid}" aria-describedby={describedby}>
|
|
<span class="ia-field-label" id="ia-seg-{uid}">{legend}</span>
|
|
<div>
|
|
<DomiSegmented
|
|
label={legend}
|
|
options={choices}
|
|
bind:value={() => value, (v) => (value = v as T)}
|
|
onchange={(v) => onchange?.(v as T)}
|
|
/>
|
|
</div>
|
|
</div>
|