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,30 +16,32 @@ 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 {
21- constructor ( props ) {
28+ constructor ( props ) {
2229 super ( props ) ;
2330 this . state = {
24- isHovered : false ,
2531 dialogOpen : false ,
2632 } ;
2733 this . handleClick = this . handleClick . bind ( this ) ;
2834 this . handleDialogBox = this . handleDialogBox . bind ( this ) ;
2935 }
3036
31- handleClick ( ) {
37+
38+ handleClick ( ) {
3239 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- }
40+ this . props . handleClick ( this . props . name , true ) ;
3841 }
3942 }
4043
41- handleDialogBox ( actionConfirmed ) {
44+ handleDialogBox ( actionConfirmed ) {
4245 if ( this . props . handleClick && actionConfirmed ) {
4346 // this.props.deleteMethod(this.props.name);
4447 this . props . deleteNetParamsObj ( { paramPath : this . props . paramPath , paramName : this . props . name } ) ;
@@ -47,98 +50,111 @@ export default class NetPyNEThumbnail extends React.Component {
4750 this . setState ( { dialogOpen : false } ) ;
4851 }
4952
50- getCommonProps ( ) {
53+ getCommonProps ( ) {
5154 return {
5255 id : this . props . name ,
5356 color : this . props . selected ? 'primary' : 'secondary' ,
5457 onClick : ( ) => this . handleClick ( ) ,
55- onMouseEnter : ( ) => this . setState ( { isHovered : true } ) ,
56- onMouseLeave : ( ) => this . setState ( { isHovered : false } ) ,
5758 } ;
5859 }
5960
60- render ( ) {
61+
62+
63+ render ( ) {
6164 const {
6265 name, selected, isButton = false , isCog = false ,
6366 } = this . props ;
64- const { dialogOpen, isHovered } = this . state ;
67+ const { dialogOpen } = this . state ;
6568
6669 let label ;
67- if ( isHovered && selected ) {
68- label = '' ;
69- } else if ( name . length > 14 ) {
70+ if ( name . length > 14 ) {
7071 label = `${ name . slice ( 0 , 11 ) } ...` ;
7172 } else {
7273 label = name ;
7374 }
7475
7576 const props = this . getCommonProps ( ) ;
7677 return (
77- < div >
78- { getButton ( isCog , isButton , label , selected , isHovered , name , props ) }
78+ < >
79+ < Tooltip position = "bottom" title = { < HoverActions deleteAction = { ( ) => this . setState ( { dialogOpen : true } ) } /> } interactive >
80+ < Box position = "relative" >
81+ { getButton ( isCog , isButton , label , selected , props ) }
82+
83+ </ Box >
84+ </ Tooltip >
7985 < DeleteDialogBox
8086 open = { dialogOpen }
8187 onDialogResponse = { this . handleDialogBox }
8288 textForDialog = { name }
8389 />
84- </ div >
90+ </ >
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+
106+ const HoverActions = ( { deleteAction } ) => (
107+ < Box style = { styles . toolbar } >
108+ < Tooltip title = { "Delete item" } placement = "top" >
109+ < IconButton size = "small" onClick = { deleteAction } >
110+ < Icon fontSize = "inherit" className = "fa fa-trash-o" />
111+ </ IconButton >
112+ </ Tooltip >
113+ </ Box >
114+
115+ )
116+
117+
118+
119+ const getCogButton = ( label , selected , others ) => (
120+
121+ < IconButton
122+ className = { `gearThumbButton ${ selected ? 'selectedGearButton' : '' } ` }
123+ { ...others }
124+ >
125+ < div >
126+
127+ < span className = "gearThumbLabel" >
128+ { label }
129+ </ span >
130+ < Icon color = "primary" className = "gpt-fullgear" />
131+ </ div >
132+ </ IconButton >
117133
118134) ;
119135
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 >
136+ const getRegularButton = ( label , selected , others ) => (
137+
138+ < Button
139+ variant = "contained"
140+ style = { styles . btn }
141+ className = { `rectangularActionButton ${ selected ? 'selectedRectangularActionButton ' : '' } ` }
142+ { ...others }
143+ >
144+
145+ { label }
146+ </ Button >
147+
131148
132149) ;
133150
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 >
151+ const getFabButton = ( label , selected , others ) => (
152+
153+ < Fab
154+ className = { `actionButton ${ selected ? 'selectedActionButton' : '' } ` }
155+ { ...others }
156+ >
157+ { label }
158+ </ Fab >
143159
144160) ;
0 commit comments