File tree 3 files changed +9
-15
lines changed
3 files changed +9
-15
lines changed Original file line number Diff line number Diff line change @@ -50,8 +50,8 @@ class App extends Component {
50
50
classes : PropTypes . object . isRequired ,
51
51
}
52
52
state = {
53
- isClicked : false ,
54
53
direction : 'up' ,
54
+ isOpen : false ,
55
55
} ;
56
56
57
57
handleChange = event => {
@@ -60,7 +60,7 @@ class App extends Component {
60
60
61
61
render ( ) {
62
62
const { classes } = this . props ;
63
- const { direction } = this . state ;
63
+ const { direction, isOpen } = this . state ;
64
64
return (
65
65
< div className = { classes . root } >
66
66
< h2 > Material Floating Button Menu Demo</ h2 >
@@ -83,12 +83,14 @@ class App extends Component {
83
83
< FloatingMenu
84
84
slideSpeed = { 500 }
85
85
direction = { direction }
86
+ isOpen = { isOpen }
86
87
>
87
88
< MainButton
88
89
iconResting = { MdAdd }
89
90
iconActive = { MdClose }
90
91
iconColor = "white"
91
92
backgroundColor = "black"
93
+ onClick = { ( ) => this . setState ( { isOpen : ! this . state . isOpen } ) }
92
94
size = { 56 }
93
95
/>
94
96
< ChildButton
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ class ChildButton extends Component {
35
35
iconButton : PropTypes . func . isRequired ,
36
36
direction : PropTypes . string . isRequired ,
37
37
iconColor : PropTypes . string ,
38
+ onClick : PropTypes . func ,
38
39
isOpen : PropTypes . bool ,
39
40
size : PropTypes . number ,
40
41
margin : PropTypes . number ,
@@ -45,13 +46,14 @@ class ChildButton extends Component {
45
46
size : '40' ,
46
47
margin : 0 ,
47
48
isOpen : false ,
49
+ onClick : null
48
50
} ;
49
51
50
52
render ( ) {
51
53
const { iconButton : IconButton , ...other } = this . props ;
52
54
53
55
return (
54
- < Wrapper { ...other } >
56
+ < Wrapper { ...other } onClick = { this . props . isOpen ? this . props . onClick : null } >
55
57
< a >
56
58
< IconButton />
57
59
</ a >
Original file line number Diff line number Diff line change @@ -31,28 +31,18 @@ class FloatingMenu extends Component {
31
31
children : PropTypes . arrayOf ( PropTypes . element ) . isRequired ,
32
32
slideSpeed : PropTypes . number ,
33
33
direction : PropTypes . string ,
34
+ isOpen : PropTypes . bool ,
34
35
} ;
35
36
36
37
static defaultProps = {
37
38
className : '' ,
38
39
slideSpeed : 500 ,
39
40
direction : 'down' ,
40
- } ;
41
-
42
- state = {
43
41
isOpen : false ,
44
42
} ;
45
43
46
- toggleMenu = ( event ) => {
47
- event . preventDefault ( ) ;
48
- this . setState ( {
49
- isOpen : ! this . state . isOpen ,
50
- } ) ;
51
- } ;
52
-
53
44
render ( ) {
54
- const { slideSpeed, direction, className } = this . props ;
55
- const { isOpen } = this . state ;
45
+ const { slideSpeed, direction, className, isOpen } = this . props ;
56
46
const childrenWithProps = React . Children . map ( this . props . children , child =>
57
47
React . cloneElement ( child , {
58
48
isOpen,
You can’t perform that action at this time.
0 commit comments