1
1
// @flow
2
2
3
- import React , { useState , memo } from "react"
3
+ import React , { useRef , memo } from "react"
4
4
import Paper from "@material-ui/core/Paper"
5
5
import { makeStyles } from "@material-ui/core/styles"
6
6
import styles from "./styles"
@@ -10,7 +10,7 @@ import IconButton from "@material-ui/core/IconButton"
10
10
import Button from "@material-ui/core/Button"
11
11
import TrashIcon from "@material-ui/icons/Delete"
12
12
import CheckIcon from "@material-ui/icons/Check"
13
- import UndoIcon from "@material-ui/icons/Undo "
13
+ import TextField from "@material-ui/core/TextField "
14
14
import Select from "react-select"
15
15
import CreatableSelect from "react-select/creatable"
16
16
@@ -30,6 +30,7 @@ type Props = {
30
30
onClose : ( Region ) => null ,
31
31
onOpen : ( Region ) => null ,
32
32
onRegionClassAdded : ( ) => { } ,
33
+ allowComments ?: boolean ,
33
34
}
34
35
35
36
export const RegionLabel = ( {
@@ -42,8 +43,16 @@ export const RegionLabel = ({
42
43
onClose,
43
44
onOpen,
44
45
onRegionClassAdded,
46
+ allowComments,
45
47
} : Props ) => {
46
48
const classes = useStyles ( )
49
+ const commentInputRef = useRef ( null )
50
+ const onCommentInputClick = ( _ ) => {
51
+ // The TextField wraps the <input> tag with two divs
52
+ const commentInput = commentInputRef . current . children [ 0 ] . children [ 0 ]
53
+
54
+ if ( commentInput ) return commentInput . focus ( )
55
+ }
47
56
48
57
return (
49
58
< Paper
@@ -142,6 +151,22 @@ export const RegionLabel = ({
142
151
/>
143
152
</ div >
144
153
) }
154
+ { allowComments && (
155
+ < TextField
156
+ InputProps = { {
157
+ className : classes . commentBox ,
158
+ } }
159
+ fullWidth
160
+ multiline
161
+ rows = { 3 }
162
+ ref = { commentInputRef }
163
+ onClick = { onCommentInputClick }
164
+ value = { region . comment || "" }
165
+ onChange = { ( event ) =>
166
+ onChange ( { ...( region : any ) , comment : event . target . value } )
167
+ }
168
+ />
169
+ ) }
145
170
{ onClose && (
146
171
< div style = { { marginTop : 4 , display : "flex" } } >
147
172
< div style = { { flexGrow : 1 } } />
0 commit comments