mirror of
https://github.com/Unleash/unleash.git
synced 2025-09-24 17:51:14 +02:00
Follows up on https://github.com/Unleash/unleash/pull/4853 to add Biome to the frontend as well.  Added a few `biome-ignore` to speed up the process but we may want to check and fix them in the future.
90 lines
2.2 KiB
TypeScript
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;
|