11import * as React from 'react' ;
22import { makeStyles } from '@material-ui/core/styles' ;
3- import Box from '@material-ui/core/Box' ;
43import Grid from '@material-ui/core/Grid' ;
54import Typography from '@material-ui/core/Typography' ;
5+ import Box from '@material-ui/core/Box' ;
66import IconButton from '@material-ui/core/IconButton' ;
77import TreeItem from '@material-ui/lab/TreeItem' ;
88import Visibility from '@material-ui/icons/Visibility' ;
99import ColorLens from '@material-ui/icons/ColorLens' ;
10+ import Shuffle from '@material-ui/icons/Shuffle' ;
1011import { ChromePicker } from 'react-color' ;
1112import { experimentLabelColor } from '../../theme' ;
1213
@@ -44,6 +45,16 @@ const ControlPanelTreeItem = (props) => {
4445 event . stopPropagation ( ) ;
4546 } ;
4647
48+ const generateRandomColor = ( ) => {
49+ const randomColor = {
50+ r : parseFloat ( ( Math . random ( ) * 1.00 ) . toFixed ( 2 ) ) ,
51+ g : parseFloat ( ( Math . random ( ) * 1.00 ) . toFixed ( 2 ) ) ,
52+ b : parseFloat ( ( Math . random ( ) * 1.00 ) . toFixed ( 2 ) ) ,
53+ a : 1 ,
54+ } ;
55+ setColor ( randomColor ) ;
56+ } ;
57+
4758 const {
4859 label,
4960 type,
@@ -57,6 +68,7 @@ const ControlPanelTreeItem = (props) => {
5768 return (
5869 < TreeItem
5970 nodeId = { nodeId }
71+ onLabelClick = { ( e ) => { e . stopPropagation ( ) ; e . preventDefault ( ) ; } }
6072 label = { (
6173 < Grid
6274 container
@@ -67,23 +79,28 @@ const ControlPanelTreeItem = (props) => {
6779 flexDirection = "row"
6880 justifyContent = "space-between"
6981 >
70- < Grid item xs = { 4 } > < Typography onClick = { ( event ) => onNodeSelect ( event , nodeId ) } > { label } </ Typography > </ Grid >
82+ < Grid item xs = { 4 } > < Typography onClick = { ( ) => onNodeSelect ( nodeId ) } > { label } </ Typography > </ Grid >
7183 < Grid item xs = { 4 } justifyContent = "center" > < Typography > { type } </ Typography > </ Grid >
7284 < Grid item xs = { 4 } justifyContent = "flex-end" className = { classes . controls } >
7385 { isHoveredOver
7486 ? (
7587 < >
7688
7789 < IconButton onClick = { ( event ) => onVisibilityClick ( event , nodeId ) } > < Visibility /> </ IconButton >
78- < IconButton onClick = { ( ) => setShowColorPicker ( ! showColorPicker ) } > < ColorLens /> </ IconButton >
90+ < IconButton onClick = { generateRandomColor } > < Shuffle /> </ IconButton >
91+ < IconButton onClick = { ( ) => setShowColorPicker ( true ) } > < ColorLens /> </ IconButton >
7992 {
8093 showColorPicker
8194 ? (
82- < ChromePicker
83- className = { classes . colorPicker }
84- color = { color }
85- onChangeComplete = { ( e , color ) => handleColorSelection ( e , color , nodeId ) }
86- />
95+ < Box
96+ onMouseLeave = { ( ) => setShowColorPicker ( false ) }
97+ >
98+ < ChromePicker
99+ className = { classes . colorPicker }
100+ color = { color }
101+ onChangeComplete = { ( color , event ) => handleColorSelection ( color , event , nodeId ) }
102+ />
103+ </ Box >
87104 ) : null
88105 }
89106
0 commit comments