feat(react/ribbon): reintroduce combobox collection properties

This commit is contained in:
Elian Doran
2025-08-23 23:54:14 +03:00
parent 2b8b185b5b
commit d7e36bdf93
4 changed files with 41 additions and 119 deletions

View File

@@ -39,15 +39,22 @@ export default function FormSelect<T>({ name, id, onChange, style, ...restProps
/**
* Similar to {@link FormSelect}, but the top-level elements are actually groups.
*/
export function FormSelectWithGroups<T>({ name, id, values, keyProperty, titleProperty, currentValue, onChange }: FormSelectProps<T, FormSelectGroup<T>>) {
export function FormSelectWithGroups<T>({ name, id, values, keyProperty, titleProperty, currentValue, onChange }: FormSelectProps<T, FormSelectGroup<T> | T>) {
return (
<FormSelectBody name={name} id={id} onChange={onChange}>
{values.map(({ title, items }) => {
return (
<optgroup label={title}>
<FormSelectGroup values={items} keyProperty={keyProperty} titleProperty={titleProperty} currentValue={currentValue} />
</optgroup>
);
{values.map((item) => {
if (!item) return <></>;
if (typeof item === "object" && "items" in item) {
return (
<optgroup label={item.title}>
<FormSelectGroup values={item.items} keyProperty={keyProperty} titleProperty={titleProperty} currentValue={currentValue} />
</optgroup>
);
} else {
return (
<FormSelectGroup values={[ item ]} keyProperty={keyProperty} titleProperty={titleProperty} currentValue={currentValue} />
)
}
})}
</FormSelectBody>
)