-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathParticleSelect.tsx
More file actions
52 lines (46 loc) · 1.41 KB
/
ParticleSelect.tsx
File metadata and controls
52 lines (46 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { Box, Typography } from '@mui/material';
import { SyntheticEvent } from 'react';
import { Particle } from '../../../types/Particle';
import { AutoCompleteSelect } from '../../../util/genericComponents/AutoCompleteSelect';
export interface ParticleSelectProps {
onChange?: (event: SyntheticEvent<Element, Event>, newValue: string) => void;
particles: readonly Particle[];
value?: string;
}
export function ParticleSelect(props: ParticleSelectProps) {
const getOptionLabel = ({ id, name }: Particle) => {
return `${name}`;
};
// Custom render for dropdown options
const renderOption = (liProps: any, particle: Particle) => {
const isMostAbundant = particle.isMostAbundant || false;
// const abundanceText = particle.abundance ? ` (${particle.abundance.toFixed(2)}%)` : '';
return (
<Box
component='li'
{...liProps}>
<Typography
variant='body2'
sx={{
fontWeight: isMostAbundant ? 'bold' : 'normal',
width: '100%'
}}>
{particle.name}
{/* {abundanceText} */}
{isMostAbundant && ' ★'}
</Typography>
</Box>
);
};
return (
<AutoCompleteSelect
onChange={(event, newValue) => {
if (newValue !== null) props.onChange?.call(null, event, newValue.name);
}}
value={props.particles.find(p => p.name === props.value)}
options={props.particles}
getOptionLabel={option => getOptionLabel(option)}
renderOption={renderOption}
/>
);
}