2021-11-17 18:32:57 +00:00
|
|
|
import clsx from 'clsx';
|
2021-12-20 17:21:19 +00:00
|
|
|
import { SelectHTMLAttributes } from 'react';
|
2021-11-17 18:32:57 +00:00
|
|
|
|
2024-04-11 00:11:38 +00:00
|
|
|
import { AutomationTestingProps } from '@/types';
|
|
|
|
|
|
|
|
export interface Option<T extends string | number>
|
|
|
|
extends Partial<AutomationTestingProps> {
|
2021-11-17 18:32:57 +00:00
|
|
|
value: T;
|
|
|
|
label: string;
|
2024-04-11 00:11:38 +00:00
|
|
|
disabled?: boolean;
|
2021-11-17 18:32:57 +00:00
|
|
|
}
|
|
|
|
|
2024-04-11 00:11:38 +00:00
|
|
|
interface Props<T extends string | number> extends AutomationTestingProps {
|
2021-11-17 18:32:57 +00:00
|
|
|
options: Option<T>[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export function Select<T extends number | string>({
|
|
|
|
options,
|
|
|
|
className,
|
2024-04-11 00:11:38 +00:00
|
|
|
'data-cy': dataCy,
|
2021-12-20 17:21:19 +00:00
|
|
|
...props
|
|
|
|
}: Props<T> & SelectHTMLAttributes<HTMLSelectElement>) {
|
2021-11-17 18:32:57 +00:00
|
|
|
return (
|
|
|
|
<select
|
2021-12-20 17:21:19 +00:00
|
|
|
// eslint-disable-next-line react/jsx-props-no-spreading
|
|
|
|
{...props}
|
|
|
|
className={clsx('form-control', className)}
|
2024-04-11 00:11:38 +00:00
|
|
|
data-cy={dataCy}
|
2021-11-17 18:32:57 +00:00
|
|
|
>
|
|
|
|
{options.map((item) => (
|
2024-04-11 00:11:38 +00:00
|
|
|
<option
|
|
|
|
value={item.value}
|
|
|
|
key={item.value}
|
|
|
|
disabled={item.disabled}
|
|
|
|
data-cy={`${dataCy}-${item.value}`}
|
|
|
|
>
|
2021-11-22 16:13:40 +00:00
|
|
|
{item.label}
|
|
|
|
</option>
|
2021-11-17 18:32:57 +00:00
|
|
|
))}
|
|
|
|
</select>
|
|
|
|
);
|
|
|
|
}
|