2025-08-14 18:51:32 +03:00
|
|
|
interface FormSelectProps<T> {
|
2025-08-14 18:18:45 +03:00
|
|
|
currentValue?: string;
|
|
|
|
|
onChange(newValue: string): void;
|
2025-08-14 18:51:32 +03:00
|
|
|
values: T[];
|
|
|
|
|
keyProperty: keyof T;
|
|
|
|
|
titleProperty: keyof T;
|
2025-08-14 18:18:45 +03:00
|
|
|
}
|
|
|
|
|
|
2025-08-14 18:51:32 +03:00
|
|
|
export default function FormSelect<T>({ currentValue, values, onChange, keyProperty, titleProperty }: FormSelectProps<T>) {
|
2025-08-14 18:18:45 +03:00
|
|
|
return (
|
|
|
|
|
<select
|
|
|
|
|
class="form-select"
|
|
|
|
|
onChange={e => onChange((e.target as HTMLInputElement).value)}
|
|
|
|
|
>
|
|
|
|
|
{values.map(item => {
|
|
|
|
|
return (
|
|
|
|
|
<option
|
2025-08-14 18:51:32 +03:00
|
|
|
value={item[keyProperty] as any}
|
|
|
|
|
selected={item[keyProperty] === currentValue}
|
2025-08-14 18:18:45 +03:00
|
|
|
>
|
2025-08-14 18:51:32 +03:00
|
|
|
{item[titleProperty] as any}
|
2025-08-14 18:18:45 +03:00
|
|
|
</option>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</select>
|
|
|
|
|
)
|
|
|
|
|
}
|