File tree Expand file tree Collapse file tree 3 files changed +9
-15
lines changed Expand file tree Collapse file tree 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 {
5050 classes : PropTypes . object . isRequired ,
5151 }
5252 state = {
53- isClicked : false ,
5453 direction : 'up' ,
54+ isOpen : false ,
5555 } ;
5656
5757 handleChange = event => {
@@ -60,7 +60,7 @@ class App extends Component {
6060
6161 render ( ) {
6262 const { classes } = this . props ;
63- const { direction } = this . state ;
63+ const { direction, isOpen } = this . state ;
6464 return (
6565 < div className = { classes . root } >
6666 < h2 > Material Floating Button Menu Demo</ h2 >
@@ -83,12 +83,14 @@ class App extends Component {
8383 < FloatingMenu
8484 slideSpeed = { 500 }
8585 direction = { direction }
86+ isOpen = { isOpen }
8687 >
8788 < MainButton
8889 iconResting = { MdAdd }
8990 iconActive = { MdClose }
9091 iconColor = "white"
9192 backgroundColor = "black"
93+ onClick = { ( ) => this . setState ( { isOpen : ! this . state . isOpen } ) }
9294 size = { 56 }
9395 />
9496 < ChildButton
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ class ChildButton extends Component {
3535 iconButton : PropTypes . func . isRequired ,
3636 direction : PropTypes . string . isRequired ,
3737 iconColor : PropTypes . string ,
38+ onClick : PropTypes . func ,
3839 isOpen : PropTypes . bool ,
3940 size : PropTypes . number ,
4041 margin : PropTypes . number ,
@@ -45,13 +46,14 @@ class ChildButton extends Component {
4546 size : '40' ,
4647 margin : 0 ,
4748 isOpen : false ,
49+ onClick : null
4850 } ;
4951
5052 render ( ) {
5153 const { iconButton : IconButton , ...other } = this . props ;
5254
5355 return (
54- < Wrapper { ...other } >
56+ < Wrapper { ...other } onClick = { this . props . isOpen ? this . props . onClick : null } >
5557 < a >
5658 < IconButton />
5759 </ a >
Original file line number Diff line number Diff line change @@ -31,28 +31,18 @@ class FloatingMenu extends Component {
3131 children : PropTypes . arrayOf ( PropTypes . element ) . isRequired ,
3232 slideSpeed : PropTypes . number ,
3333 direction : PropTypes . string ,
34+ isOpen : PropTypes . bool ,
3435 } ;
3536
3637 static defaultProps = {
3738 className : '' ,
3839 slideSpeed : 500 ,
3940 direction : 'down' ,
40- } ;
41-
42- state = {
4341 isOpen : false ,
4442 } ;
4543
46- toggleMenu = ( event ) => {
47- event . preventDefault ( ) ;
48- this . setState ( {
49- isOpen : ! this . state . isOpen ,
50- } ) ;
51- } ;
52-
5344 render ( ) {
54- const { slideSpeed, direction, className } = this . props ;
55- const { isOpen } = this . state ;
45+ const { slideSpeed, direction, className, isOpen } = this . props ;
5646 const childrenWithProps = React . Children . map ( this . props . children , child =>
5747 React . cloneElement ( child , {
5848 isOpen,
You can’t perform that action at this time.
0 commit comments