1
1
import CircularProgress from "@material-ui/core/CircularProgress"
2
- import { makeStyles } from "@material-ui/core/styles"
2
+ import { makeStyles , Theme } from "@material-ui/core/styles"
3
3
import TextField from "@material-ui/core/TextField"
4
4
import Autocomplete from "@material-ui/lab/Autocomplete"
5
5
import { useMachine } from "@xstate/react"
6
6
import { User } from "api/typesGenerated"
7
7
import { AvatarData } from "components/AvatarData/AvatarData"
8
8
import debounce from "just-debounce-it"
9
- import { ChangeEvent , useEffect , useState } from "react"
9
+ import { ChangeEvent , FC , useEffect , useState } from "react"
10
10
import { searchUserMachine } from "xServices/users/searchUserXService"
11
+ import { AutocompleteAvatar } from "./AutocompleteAvatar"
11
12
12
13
export type UserAutocompleteProps = {
13
14
value : User | null
14
15
onChange : ( user : User | null ) => void
15
16
label ?: string
16
17
inputMargin ?: "none" | "dense" | "normal"
17
18
inputStyles ?: string
19
+ showAvatar ?: boolean
18
20
}
19
21
20
- export const UserAutocomplete : React . FC < UserAutocompleteProps > = ( {
22
+ export const UserAutocomplete : FC < UserAutocompleteProps > = ( {
21
23
value,
22
24
onChange,
23
25
label,
24
26
inputMargin,
25
27
inputStyles,
28
+ showAvatar = false ,
26
29
} ) => {
27
- const styles = useStyles ( )
30
+ const styles = useStyles ( { showAvatar } )
28
31
const [ isAutocompleteOpen , setIsAutocompleteOpen ] = useState ( false )
29
32
const [ searchState , sendSearch ] = useMachine ( searchUserMachine )
30
33
const { searchResults } = searchState . context
@@ -94,6 +97,9 @@ export const UserAutocomplete: React.FC<UserAutocompleteProps> = ({
94
97
InputProps = { {
95
98
...params . InputProps ,
96
99
onChange : handleFilterChange ,
100
+ startAdornment : (
101
+ < > { showAvatar && selectedValue && < AutocompleteAvatar user = { selectedValue } /> } </ >
102
+ ) ,
97
103
endAdornment : (
98
104
< >
99
105
{ searchState . matches ( "searching" ) ? < CircularProgress size = { 16 } /> : null }
@@ -106,9 +112,14 @@ export const UserAutocomplete: React.FC<UserAutocompleteProps> = ({
106
112
/>
107
113
)
108
114
}
109
- export const useStyles = makeStyles ( ( theme ) => {
115
+
116
+ interface styleProps {
117
+ showAvatar : boolean
118
+ }
119
+
120
+ export const useStyles = makeStyles < Theme , styleProps > ( ( theme ) => {
110
121
return {
111
- autocomplete : {
122
+ autocomplete : ( props ) => ( {
112
123
width : "100%" ,
113
124
114
125
"& .MuiFormControl-root" : {
@@ -118,14 +129,14 @@ export const useStyles = makeStyles((theme) => {
118
129
"& .MuiInputBase-root" : {
119
130
width : "100%" ,
120
131
// Match button small height
121
- height : 40 ,
132
+ height : props . showAvatar ? 60 : 40 ,
122
133
} ,
123
134
124
135
"& input" : {
125
136
fontSize : 16 ,
126
137
padding : `${ theme . spacing ( 0 , 0.5 , 0 , 0.5 ) } !important` ,
127
138
} ,
128
- } ,
139
+ } ) ,
129
140
130
141
avatar : {
131
142
width : theme . spacing ( 4.5 ) ,
0 commit comments