@@ -7,8 +7,12 @@ import ExpansionPanelDetails from '@material-ui/core/ExpansionPanelDetails';
7
7
import ExpansionPanelActions from '@material-ui/core/ExpansionPanelActions' ;
8
8
import Typography from '@material-ui/core/Typography' ;
9
9
import Input from '@material-ui/core/Input' ;
10
+ import MenuItem from '@material-ui/core/MenuItem' ;
11
+ import RemoveCircleOutlineIcon from '@material-ui/icons/RemoveCircleOutline' ;
12
+ import ListItemText from '@material-ui/core/ListItemText' ;
10
13
import ExpandMoreIcon from '@material-ui/icons/ExpandMore' ;
11
14
import Switch from '@material-ui/core/Switch' ;
15
+ import Chip from '@material-ui/core/Chip' ;
12
16
import IconButton from '@material-ui/core/IconButton' ;
13
17
import DeleteIcon from '@material-ui/icons/Delete' ;
14
18
import FlipToBackIcon from '@material-ui/icons/FlipToBack' ;
@@ -28,6 +32,13 @@ const styles = theme => ({
28
32
fontSize : theme . typography . pxToRem ( 15 ) ,
29
33
fontWeight : theme . typography . fontWeightRegular ,
30
34
} ,
35
+ chips : {
36
+ display : 'flex' ,
37
+ flexWrap : 'wrap' ,
38
+ } ,
39
+ chip : {
40
+ margin : theme . spacing . unit / 4 ,
41
+ } ,
31
42
panel : {
32
43
backgroundColor : '#333333' ,
33
44
} ,
@@ -60,6 +71,15 @@ const styles = theme => ({
60
71
group : {
61
72
margin : `${ theme . spacing . unit } px 0` ,
62
73
} ,
74
+ icon : {
75
+ fontSize : '20px' ,
76
+ color : '#000' ,
77
+ transition : 'all .2s ease' ,
78
+
79
+ '&:hover' : {
80
+ color : 'red' ,
81
+ } ,
82
+ } ,
63
83
} ) ;
64
84
65
85
const LeftColExpansionPanel = ( props ) => {
@@ -79,23 +99,24 @@ const LeftColExpansionPanel = (props) => {
79
99
id,
80
100
stateful,
81
101
color,
82
- parent,
102
+ parents,
103
+ parentIds,
83
104
selectableParents,
84
105
} = component ;
85
106
86
- const parentOptions = [
87
- < option value = 'null' key = '' >
88
- None
89
- </ option > ,
90
- ... selectableParents . map (
91
- selectableParent => < option
92
- value = { selectableParent . id }
93
- key = { selectableParent . id }
94
- >
95
- { selectableParent . title }
96
- </ option > ,
97
- ) ,
98
- ] ;
107
+ const handleParentChange = ( event , parentId = null ) => {
108
+ let newParentId = parentId ;
109
+ if ( event ) {
110
+ const selectedParents = event . target . value ;
111
+ newParentId = selectedParents [ selectedParents . length - 1 ] . id ;
112
+ }
113
+
114
+ return updateComponent ( {
115
+ index ,
116
+ id ,
117
+ newParentId ,
118
+ } ) ;
119
+ } ;
99
120
100
121
return (
101
122
< div className = { classes . root } >
@@ -130,24 +151,35 @@ const LeftColExpansionPanel = (props) => {
130
151
/>
131
152
</ div >
132
153
< div className = { classes . column } >
133
- < InputLabel className = { classes . label } htmlFor = 'parentSelect' > Parent </ InputLabel >
154
+ < InputLabel className = { classes . label } htmlFor = 'parentSelect' > selectedParents </ InputLabel >
134
155
< Select
135
156
className = { classes . light }
136
- native
137
- value = { parent . id }
157
+ multiple
158
+ value = { parents }
138
159
id = 'parentSelect'
139
160
name = 'parentName'
140
- onChange = { ( event ) => {
141
- const newParentId = event . target . value ;
142
- updateComponent ( {
143
- newParentId,
144
- index,
145
- id,
146
- parent,
147
- } ) ;
148
- } }
161
+ disabled = { selectableParents . length < 1 }
162
+ onChange = { handleParentChange }
163
+ input = { < Input id = 'parentSelect' /> }
164
+ renderValue = { selectedP => (
165
+ < div className = { classes . chips } >
166
+ { selectedP . map ( parent => (
167
+ < Chip
168
+ key = { parent . id }
169
+ label = { parent . title }
170
+ className = { classes . chip }
171
+ onDelete = { ( ) => handleParentChange ( null , parent . id ) }
172
+ deleteIcon = { < RemoveCircleOutlineIcon className = { classes . icon } /> }
173
+ />
174
+ ) ) }
175
+ </ div >
176
+ ) }
149
177
>
150
- { parentOptions }
178
+ { selectableParents . map ( parentObj => (
179
+ < MenuItem key = { parentObj . id } value = { parentObj } >
180
+ < ListItemText primary = { parentObj . title } />
181
+ </ MenuItem >
182
+ ) ) }
151
183
</ Select >
152
184
</ div >
153
185
</ ExpansionPanelDetails >
@@ -173,7 +205,7 @@ const LeftColExpansionPanel = (props) => {
173
205
className = { classes . button }
174
206
onClick = { ( ) => {
175
207
deleteComponent ( {
176
- index, id, parent ,
208
+ index, id, parentIds ,
177
209
} ) ;
178
210
} }
179
211
aria-label = 'Delete' >
0 commit comments