2019-10-24 16:04:39 +02:00
|
|
|
import React from 'react';
|
2022-05-02 15:52:41 +02:00
|
|
|
import {
|
|
|
|
FormControl,
|
|
|
|
InputLabel,
|
|
|
|
MenuItem,
|
|
|
|
Select,
|
|
|
|
SelectChangeEvent,
|
|
|
|
} from '@mui/material';
|
2022-04-01 10:28:15 +02:00
|
|
|
import { SELECT_ITEM_ID } from 'utils/testIds';
|
2019-10-24 16:04:39 +02:00
|
|
|
|
2021-09-27 13:35:32 +02:00
|
|
|
export interface ISelectOption {
|
|
|
|
key: string;
|
|
|
|
title?: string;
|
2021-09-30 11:44:30 +02:00
|
|
|
label?: string;
|
2021-09-27 13:35:32 +02:00
|
|
|
}
|
|
|
|
export interface ISelectMenuProps {
|
|
|
|
name: string;
|
|
|
|
id: string;
|
|
|
|
value?: string;
|
|
|
|
label?: string;
|
|
|
|
options: ISelectOption[];
|
|
|
|
style?: object;
|
2022-05-02 15:52:41 +02:00
|
|
|
onChange?: (event: SelectChangeEvent, child: React.ReactNode) => void;
|
2021-09-30 11:44:30 +02:00
|
|
|
disabled?: boolean;
|
2021-09-27 13:35:32 +02:00
|
|
|
className?: string;
|
|
|
|
classes?: any;
|
|
|
|
}
|
|
|
|
|
|
|
|
const SelectMenu: React.FC<ISelectMenuProps> = ({
|
2021-04-12 15:04:03 +02:00
|
|
|
name,
|
2021-09-27 13:35:32 +02:00
|
|
|
value = '',
|
|
|
|
label = '',
|
2021-04-12 15:04:03 +02:00
|
|
|
options,
|
|
|
|
onChange,
|
|
|
|
id,
|
|
|
|
disabled = false,
|
|
|
|
className,
|
|
|
|
classes,
|
|
|
|
...rest
|
|
|
|
}) => {
|
2021-03-30 15:14:02 +02:00
|
|
|
const renderSelectItems = () =>
|
|
|
|
options.map(option => (
|
2021-09-30 11:44:30 +02:00
|
|
|
<MenuItem
|
|
|
|
key={option.key}
|
|
|
|
value={option.key}
|
|
|
|
title={option.title || ''}
|
2022-04-08 13:13:45 +02:00
|
|
|
data-testid={`${SELECT_ITEM_ID}-${option.label}`}
|
2021-09-30 11:44:30 +02:00
|
|
|
>
|
2021-03-30 15:14:02 +02:00
|
|
|
{option.label}
|
|
|
|
</MenuItem>
|
|
|
|
));
|
|
|
|
|
2019-10-24 16:04:39 +02:00
|
|
|
return (
|
2021-04-12 15:04:03 +02:00
|
|
|
<FormControl variant="outlined" size="small" classes={classes}>
|
2022-04-22 09:54:01 +02:00
|
|
|
<InputLabel htmlFor={id}>{label}</InputLabel>
|
2021-03-30 15:14:02 +02:00
|
|
|
<Select
|
2019-10-24 16:04:39 +02:00
|
|
|
name={name}
|
2020-08-07 11:25:24 +02:00
|
|
|
disabled={disabled}
|
2019-10-24 16:04:39 +02:00
|
|
|
onChange={onChange}
|
2021-03-30 15:14:02 +02:00
|
|
|
className={className}
|
|
|
|
label={label}
|
|
|
|
id={id}
|
2019-10-24 16:04:39 +02:00
|
|
|
value={value}
|
2021-03-30 15:14:02 +02:00
|
|
|
{...rest}
|
2019-10-24 16:04:39 +02:00
|
|
|
>
|
2021-03-30 15:14:02 +02:00
|
|
|
{renderSelectItems()}
|
|
|
|
</Select>
|
|
|
|
</FormControl>
|
2019-10-24 16:04:39 +02:00
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2021-03-30 15:14:02 +02:00
|
|
|
export default SelectMenu;
|