1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-24 17:51:14 +02:00
unleash.unleash/frontend/src/component/common/GeneralSelect/GeneralSelect.tsx
Nuno Góis 4167a60588
feat: biome lint frontend (#4903)
Follows up on https://github.com/Unleash/unleash/pull/4853 to add Biome
to the frontend as well.


![image](https://github.com/Unleash/unleash/assets/14320932/1906faf1-fc29-4172-a4d4-b2716d72cd65)

Added a few `biome-ignore` to speed up the process but we may want to
check and fix them in the future.
2023-10-02 13:25:46 +01:00

90 lines
2.2 KiB
TypeScript

import React from 'react';
import {
FormControl,
InputLabel,
MenuItem,
Select,
SelectProps,
SelectChangeEvent,
} from '@mui/material';
import { SELECT_ITEM_ID } from 'utils/testIds';
import { KeyboardArrowDownOutlined } from '@mui/icons-material';
import { SxProps } from '@mui/system';
import { Theme } from '@mui/material/styles';
export interface ISelectOption {
key: string;
title?: string;
label?: string;
disabled?: boolean;
sx?: SxProps<Theme>;
}
export interface IGeneralSelectProps extends Omit<SelectProps, 'onChange'> {
name?: string;
value?: string;
label?: string;
options: ISelectOption[];
onChange: (key: string) => void;
disabled?: boolean;
fullWidth?: boolean;
classes?: any;
defaultValue?: string;
}
const GeneralSelect: React.FC<IGeneralSelectProps> = ({
name,
value = '',
label = '',
options,
onChange,
id,
disabled = false,
className,
classes,
fullWidth,
...rest
}) => {
const onSelectChange = (event: SelectChangeEvent) => {
event.preventDefault();
onChange(String(event.target.value));
};
return (
<FormControl
variant='outlined'
size='small'
classes={classes}
fullWidth={fullWidth}
>
<InputLabel htmlFor={id}>{label}</InputLabel>
<Select
name={name}
disabled={disabled}
onChange={onSelectChange}
className={className}
label={label}
id={id}
value={value}
IconComponent={KeyboardArrowDownOutlined}
{...rest}
>
{options.map((option) => (
<MenuItem
sx={option.sx}
key={option.key}
value={option.key}
title={option.title || ''}
data-testid={`${SELECT_ITEM_ID}-${option.label}`}
disabled={option.disabled}
>
{option.label}
</MenuItem>
))}
</Select>
</FormControl>
);
};
export default GeneralSelect;