Files
Trilium/apps/client/src/widgets/react/FormRadioGroup.tsx

33 lines
1.1 KiB
TypeScript
Raw Normal View History

import type { ComponentChildren } from "preact";
import { useUniqueName } from "./hooks";
2025-08-03 21:18:18 +03:00
interface FormRadioProps {
name: string;
currentValue?: string;
values: {
value: string;
label: string | ComponentChildren;
2025-08-03 21:18:18 +03:00
}[];
onChange(newValue: string): void;
}
export default function FormRadioGroup({ name, values, currentValue, onChange }: FormRadioProps) {
return (
<>
{(values || []).map(({ value, label }) => (
<div className="form-check">
<label className="form-check-label tn-radio">
<input
className="form-check-input"
type="radio"
name={useUniqueName(name)}
2025-08-03 21:18:18 +03:00
value={value}
checked={value === currentValue}
onChange={e => onChange((e.target as HTMLInputElement).value)} />
{label}
</label>
</div>
))}
</>
);
}