1
- import { TextField } from '@material-ui/core' ;
1
+ import { Grid , Icon , TextField , Typography } from '@material-ui/core' ;
2
2
import {
3
3
Autocomplete ,
4
4
AutocompleteRenderInputParams ,
5
5
FilterOptionsState ,
6
6
} from '@material-ui/lab' ;
7
7
import { matchSorter } from 'match-sorter' ;
8
8
import React , { ChangeEvent , FC } from 'react' ;
9
+ import { dirnameFromPath , filenameFromPath } from '../utils/format' ;
10
+ import { getIconUrlForPath } from '../utils/icons' ;
9
11
import { Module } from '../utils/types' ;
10
12
11
13
type Props = {
@@ -27,6 +29,26 @@ const SelectModules: FC<Props> = ({ modules, label, value, onChange }) => {
27
29
const renderInput = ( params : AutocompleteRenderInputParams ) => (
28
30
< TextField { ...params } label = { label } variant = "outlined" />
29
31
) ;
32
+ const renderOption = ( option : Module ) => (
33
+ < Grid container spacing = { 2 } alignItems = "center" >
34
+ < Grid item >
35
+ < Icon fontSize = "small" style = { { textAlign : 'center' } } >
36
+ < img
37
+ src = { getIconUrlForPath ( option . path ) }
38
+ style = { { display : 'flex' , height : 'inherit' , width : 'inherit' } }
39
+ />
40
+ </ Icon >
41
+ </ Grid >
42
+ < Grid item >
43
+ < Typography variant = "subtitle1" >
44
+ { filenameFromPath ( option . path ) }
45
+ </ Typography >
46
+ </ Grid >
47
+ < Grid item >
48
+ < Typography variant = "body2" > { dirnameFromPath ( option . path ) } </ Typography >
49
+ </ Grid >
50
+ </ Grid >
51
+ ) ;
30
52
const handleChange = ( _ : ChangeEvent < { } > , value : Module [ ] ) => {
31
53
onChange ?.( value ) ;
32
54
} ;
@@ -40,6 +62,7 @@ const SelectModules: FC<Props> = ({ modules, label, value, onChange }) => {
40
62
value = { value }
41
63
getOptionLabel = { getOptionLabel }
42
64
renderInput = { renderInput }
65
+ renderOption = { renderOption }
43
66
filterOptions = { filterOptions }
44
67
onChange = { handleChange }
45
68
getOptionSelected = { areModulesEqual }
0 commit comments