import { SegmentedControl as Kobalte } from "@kobalte/core/segmented-control" import { For, splitProps } from "solid-js" import type { ComponentProps, JSX } from "solid-js" export type RadioGroupProps = Omit< ComponentProps, "value" | "defaultValue" | "onChange" | "children" > & { options: T[] current?: T defaultValue?: T value?: (x: T) => string label?: (x: T) => JSX.Element | string onSelect?: (value: T | undefined) => void class?: ComponentProps<"div">["class"] classList?: ComponentProps<"div">["classList"] size?: "small" | "medium" } export function RadioGroup(props: RadioGroupProps) { const [local, others] = splitProps(props, [ "class", "classList", "options", "current", "defaultValue", "value", "label", "onSelect", "size", ]) const getValue = (item: T): string => { if (local.value) return local.value(item) return String(item) } const getLabel = (item: T): JSX.Element | string => { if (local.label) return local.label(item) return String(item) } const findOption = (v: string): T | undefined => { return local.options.find((opt) => getValue(opt) === v) } return ( local.onSelect?.(findOption(v))} >
{(option) => ( {getLabel(option)} )}
) }