1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-09-19 17:52:45 +02:00
unleash.unleash/frontend/src/component/common/RoleSelect/RoleSelect.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

71 lines
1.9 KiB
TypeScript

import {
Autocomplete,
AutocompleteProps,
TextField,
styled,
} from '@mui/material';
import { IRole } from 'interfaces/role';
import { RoleDescription } from '../RoleDescription/RoleDescription';
import { ConditionallyRender } from '../ConditionallyRender/ConditionallyRender';
const StyledRoleOption = styled('div')(({ theme }) => ({
display: 'flex',
flexDirection: 'column',
'& > span:last-of-type': {
fontSize: theme.fontSizes.smallerBody,
color: theme.palette.text.secondary,
},
}));
interface IRoleSelectProps
extends Partial<AutocompleteProps<IRole, false, false, false>> {
roles: IRole[];
value: IRole | null;
setValue: (role: IRole | null) => void;
required?: boolean;
}
export const RoleSelect = ({
roles,
value,
setValue,
required,
...rest
}: IRoleSelectProps) => {
const renderRoleOption = (
props: React.HTMLAttributes<HTMLLIElement>,
option: IRole,
) => (
<li {...props}>
<StyledRoleOption>
<span>{option.name}</span>
<span>{option.description}</span>
</StyledRoleOption>
</li>
);
return (
<>
<Autocomplete
openOnFocus
size='small'
value={value}
onChange={(_, role) => setValue(role || null)}
options={roles}
renderOption={renderRoleOption}
getOptionLabel={(option) => option.name}
renderInput={(params) => (
<TextField {...params} label='Role' required={required} />
)}
{...rest}
/>
<ConditionallyRender
condition={Boolean(value)}
show={() => (
<RoleDescription sx={{ marginTop: 1 }} roleId={value!.id} />
)}
/>
</>
);
};