11import React , { Component } from 'react' ;
22import Fab from '@material-ui/core/Fab' ;
33import Button from '@material-ui/core/Button' ;
4+ import Box from '@material-ui/core/Box' ;
45import IconButton from '@material-ui/core/IconButton' ;
56import Icon from '@material-ui/core/Icon' ;
67import DeleteDialogBox from './DeleteDialogBox' ;
@@ -15,13 +16,18 @@ const styles = {
1516 position : 'absolute' ,
1617 color : 'white' ,
1718 } ,
19+ toolbar : {
20+
21+ fontSize : '0.7em' ,
22+ zIndex : 1000 ,
23+
24+ } ,
1825} ;
1926
2027export default class NetPyNEThumbnail extends React . Component {
2128 constructor ( props ) {
2229 super ( props ) ;
2330 this . state = {
24- isHovered : false ,
2531 dialogOpen : false ,
2632 } ;
2733 this . handleClick = this . handleClick . bind ( this ) ;
@@ -30,19 +36,21 @@ export default class NetPyNEThumbnail extends React.Component {
3036
3137 handleClick ( ) {
3238 if ( this . props . handleClick ) {
33- if ( this . props . selected && this . state . isHovered ) {
34- this . setState ( { dialogOpen : true } ) ;
35- } else {
36- this . props . handleClick ( this . props . name , true ) ;
37- }
39+ this . props . handleClick ( this . props . name , true ) ;
3840 }
3941 }
4042
4143 handleDialogBox ( actionConfirmed ) {
42- if ( this . props . handleClick && actionConfirmed ) {
44+ const {
45+ handleClick, paramPath, name, onDelete, deleteNetParamsObj,
46+ } = this . props ;
47+ if ( handleClick && actionConfirmed ) {
4348 // this.props.deleteMethod(this.props.name);
44- this . props . deleteNetParamsObj ( { paramPath : this . props . paramPath , paramName : this . props . name } ) ;
45- this . props . onDelete && this . props . onDelete ( ) ;
49+ deleteNetParamsObj ( {
50+ paramPath,
51+ paramName : name ,
52+ } ) ;
53+ tonDelete && onDelete ( ) ;
4654 }
4755 this . setState ( { dialogOpen : false } ) ;
4856 }
@@ -52,93 +60,97 @@ export default class NetPyNEThumbnail extends React.Component {
5260 id : this . props . name ,
5361 color : this . props . selected ? 'primary' : 'secondary' ,
5462 onClick : ( ) => this . handleClick ( ) ,
55- onMouseEnter : ( ) => this . setState ( { isHovered : true } ) ,
56- onMouseLeave : ( ) => this . setState ( { isHovered : false } ) ,
5763 } ;
5864 }
5965
6066 render ( ) {
6167 const {
6268 name, selected, isButton = false , isCog = false ,
6369 } = this . props ;
64- const { dialogOpen, isHovered } = this . state ;
70+ const { dialogOpen } = this . state ;
6571
6672 let label ;
67- if ( isHovered && selected ) {
68- label = '' ;
69- } else if ( name . length > 14 ) {
73+ if ( name . length > 14 ) {
7074 label = `${ name . slice ( 0 , 11 ) } ...` ;
7175 } else {
7276 label = name ;
7377 }
7478
7579 const props = this . getCommonProps ( ) ;
7680 return (
77- < div >
78- { getButton ( isCog , isButton , label , selected , isHovered , name , props ) }
81+ < Box position = "relative" >
82+ < Tooltip position = "bottom" title = { < HoverActions deleteAction = { ( ) => this . setState ( { dialogOpen : true } ) } /> } interactive >
83+ { getButton ( isCog , isButton , label , selected , props ) }
84+ </ Tooltip >
7985 < DeleteDialogBox
8086 open = { dialogOpen }
8187 onDialogResponse = { this . handleDialogBox }
8288 textForDialog = { name }
8389 />
84- </ div >
90+ </ Box >
8591 ) ;
8692 }
8793}
8894
89- const getButton = ( isCogButton , isRegularButton , label , selected , isHovered , tooltip , props ) => {
95+ const getButton = ( isCogButton , isRegularButton , label , selected , tooltip , props ) => {
9096 if ( isCogButton ) {
91- return getCogButton ( label , selected , isHovered , tooltip , props ) ;
97+ return getCogButton ( label , selected , tooltip , props ) ;
9298 }
9399 if ( isRegularButton ) {
94- return getRegularButton ( label , selected , isHovered , tooltip , props ) ;
100+ return getRegularButton ( label , selected , tooltip , props ) ;
95101 }
96- return getFabButton ( label , selected , isHovered , tooltip , props ) ;
102+ return getFabButton ( label , selected , tooltip , props ) ;
97103} ;
98104
99- const getCogButton = ( label , selected , isHovered , tooltip , others ) => (
100- < Tooltip title = { tooltip } placement = "top" >
101- < IconButton
102- className = { `gearThumbButton ${ selected ? 'selectedGearButton' : '' } ` }
103- { ...others }
104- >
105- < div >
106- { ( isHovered && selected )
107- ? < Icon className = "fa fa-trash-o" style = { styles . cog } />
108- : (
109- < span className = "gearThumbLabel" >
110- { label }
111- </ span >
112- ) }
113- < Icon color = "primary" className = "gpt-fullgear" />
114- </ div >
115- </ IconButton >
116- </ Tooltip >
105+ const HoverActions = ( { deleteAction } ) => (
106+ < Box style = { styles . toolbar } >
107+ < Tooltip title = "Delete item" placement = "top" >
108+ < IconButton size = "small" onClick = { deleteAction } >
109+ < Icon fontSize = "inherit" className = "fa fa-trash-o" />
110+ </ IconButton >
111+ </ Tooltip >
112+ </ Box >
117113
118114) ;
119115
120- const getRegularButton = ( label , selected , isHovered , tooltip , others ) => (
121- < Tooltip title = { tooltip } placement = "top" >
122- < Button
123- variant = "contained"
124- style = { styles . btn }
125- className = { `rectangularActionButton ${ selected ? 'selectedRectangularActionButton ' : '' } ` }
126- { ...others }
127- >
128- { ( isHovered && selected ) ? < Icon className = "fa fa-trash-o" /> : label }
129- </ Button >
130- </ Tooltip >
116+ const getCogButton = ( label , selected , others ) => (
117+
118+ < IconButton
119+ className = { `gearThumbButton ${ selected ? 'selectedGearButton' : '' } ` }
120+ { ...others }
121+ >
122+ < div >
123+
124+ < span className = "gearThumbLabel" >
125+ { label }
126+ </ span >
127+ < Icon color = "primary" className = "gpt-fullgear" />
128+ </ div >
129+ </ IconButton >
131130
132131) ;
133132
134- const getFabButton = ( label , selected , isHovered , tooltip , others ) => (
135- < Tooltip title = { tooltip } placement = "top" >
136- < Fab
137- className = { `actionButton ${ selected ? 'selectedActionButton' : '' } ` }
138- { ...others }
139- >
140- { ( isHovered && selected ) ? < Icon className = "fa fa-trash-o" /> : label }
141- </ Fab >
142- </ Tooltip >
133+ const getRegularButton = ( label , selected , others ) => (
134+
135+ < Button
136+ variant = "contained"
137+ style = { styles . btn }
138+ className = { `rectangularActionButton ${ selected ? 'selectedRectangularActionButton ' : '' } ` }
139+ { ...others }
140+ >
141+
142+ { label }
143+ </ Button >
144+
145+ ) ;
146+
147+ const getFabButton = ( label , selected , others ) => (
148+
149+ < Fab
150+ className = { `actionButton ${ selected ? 'selectedActionButton' : '' } ` }
151+ { ...others }
152+ >
153+ { label }
154+ </ Fab >
143155
144156) ;
0 commit comments