mirror of
https://github.com/Unleash/unleash.git
synced 2025-11-10 01:19:53 +01:00
Implements the first step towards implementing the new design for constraint editing. All the edit functionalities work as and when you do them now, but there is no validation of the values you put in that's happening. The inverted / not inverted button and the case sensitivity button are placeholders. They should use icons and have proper descriptions of what they do. I'll do that in a follow-up. The way to enter values is currently always in the section below the main controls. Again, more work on this is coming. Current look: With case sensitive options: <img width="769" alt="image" src="https://github.com/user-attachments/assets/bfdfbac1-cc95-4f26-bf83-277bae839518" /> With legal values: <img width="772" alt="image" src="https://github.com/user-attachments/assets/14f566cc-d02a-46dd-b433-f8b13ee55bcc" />
117 lines
3.1 KiB
TypeScript
117 lines
3.1 KiB
TypeScript
import {
|
|
FormControl,
|
|
InputLabel,
|
|
MenuItem,
|
|
Select,
|
|
type SelectProps,
|
|
type SelectChangeEvent,
|
|
styled,
|
|
} from '@mui/material';
|
|
import { SELECT_ITEM_ID } from 'utils/testIds';
|
|
import KeyboardArrowDownOutlined from '@mui/icons-material/KeyboardArrowDownOutlined';
|
|
import type { SxProps } from '@mui/system';
|
|
import type { Theme } from '@mui/material/styles';
|
|
import { visuallyHidden } from '@mui/utils';
|
|
|
|
export interface ISelectOption {
|
|
key: string;
|
|
title?: string;
|
|
label?: string;
|
|
disabled?: boolean;
|
|
sx?: SxProps<Theme>;
|
|
}
|
|
|
|
export interface IGeneralSelectProps<T extends string = string>
|
|
extends Omit<SelectProps, 'onChange'> {
|
|
name?: string;
|
|
value?: T;
|
|
label?: string;
|
|
options: ISelectOption[];
|
|
onChange: (key: T) => void;
|
|
disabled?: boolean;
|
|
fullWidth?: boolean;
|
|
classes?: any;
|
|
defaultValue?: string;
|
|
visuallyHideLabel?: boolean;
|
|
variant?: 'outlined' | 'filled' | 'standard';
|
|
}
|
|
|
|
const StyledFormControl = styled(FormControl)({
|
|
maxWidth: '100%',
|
|
});
|
|
|
|
function GeneralSelect<T extends string = string>({
|
|
variant = 'outlined',
|
|
name,
|
|
value,
|
|
label = '',
|
|
options,
|
|
onChange,
|
|
id,
|
|
disabled = false,
|
|
className,
|
|
classes,
|
|
fullWidth,
|
|
visuallyHideLabel,
|
|
labelId,
|
|
...rest
|
|
}: IGeneralSelectProps<T>) {
|
|
const onSelectChange = (event: SelectChangeEvent) => {
|
|
event.preventDefault();
|
|
onChange(String(event.target.value) as T);
|
|
};
|
|
|
|
return (
|
|
<StyledFormControl
|
|
variant={variant}
|
|
size='small'
|
|
classes={classes}
|
|
fullWidth={fullWidth}
|
|
>
|
|
{label ? (
|
|
<InputLabel
|
|
sx={visuallyHideLabel ? visuallyHidden : null}
|
|
htmlFor={id}
|
|
id={labelId}
|
|
>
|
|
{label}
|
|
</InputLabel>
|
|
) : null}
|
|
<Select
|
|
name={name}
|
|
disabled={disabled}
|
|
onChange={onSelectChange}
|
|
className={className}
|
|
label={visuallyHideLabel ? '' : label}
|
|
id={id}
|
|
value={value ?? ''}
|
|
MenuProps={{
|
|
sx: {
|
|
'.MuiPopover-paper.MuiMenu-paper': {
|
|
width: 'min-content',
|
|
},
|
|
},
|
|
}}
|
|
IconComponent={KeyboardArrowDownOutlined}
|
|
labelId={labelId}
|
|
{...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>
|
|
</StyledFormControl>
|
|
);
|
|
}
|
|
|
|
export default GeneralSelect;
|