1+ /* eslint-disable no-nested-ternary */
12import React , { Component } from 'react' ;
23import styled from 'styled-jss' ;
34import PropTypes from 'prop-types' ;
45
56const Wrapper = styled ( 'li' ) (
6- ( { isOpen, slideSpeed, backgroundColor, size, iconColor, margin , direction } ) => ( {
7+ ( { isOpen, slideSpeed, backgroundColor, size, iconColor, spacing , direction } ) => ( {
78 backgroundColor,
89 display : 'flex' ,
910 border : 'none' ,
@@ -20,43 +21,61 @@ const Wrapper = styled('li')(
2021 transition : `all ${ slideSpeed } ms` ,
2122 width : size ,
2223 height : size ,
23- marginTop : ( direction === 'down' ) ? margin : 0 ,
24- marginBottom : ( direction === 'up' ) ? margin : 0 ,
25- marginLeft : ( direction === 'right' ) ? margin : 0 ,
26- marginRight : ( direction === 'left' ) ? margin : 0 ,
27- '& > a > svg' : {
28- fill : iconColor ,
29- } ,
24+ marginTop : direction === 'down' ? spacing : 0 ,
25+ marginBottom : direction === 'up' ? spacing : 0 ,
26+ marginLeft : direction === 'right' ? spacing : 0 ,
27+ marginRight : direction === 'left' ? spacing : 0 ,
28+ color : iconColor ,
3029 } ) ,
3130) ;
3231
3332class ChildButton extends Component {
3433 static propTypes = {
35- iconButton : PropTypes . func . isRequired ,
36- direction : PropTypes . string . isRequired ,
37- iconColor : PropTypes . string ,
34+ icon : PropTypes . node . isRequired ,
35+ direction : PropTypes . string ,
36+ index : PropTypes . number ,
3837 onClick : PropTypes . func ,
3938 isOpen : PropTypes . bool ,
4039 size : PropTypes . number ,
41- margin : PropTypes . number ,
40+ spacing : PropTypes . number ,
4241 } ;
4342
4443 static defaultProps = {
44+ direction : 'up' ,
45+ index : 1 ,
4546 iconColor : 'black' ,
4647 size : '40' ,
47- margin : 0 ,
48+ spacing : 0 ,
4849 isOpen : false ,
49- onClick : null
50+ onClick : null ,
5051 } ;
5152
5253 render ( ) {
53- const { iconButton : IconButton , ...other } = this . props ;
54+ const {
55+ icon,
56+ index,
57+ direction,
58+ size,
59+ spacing,
60+ isOpen,
61+ onClick,
62+ } = this . props ;
63+ const offsetX =
64+ direction === 'right' ? ( size + spacing ) * index :
65+ direction === 'left' ? ( size + spacing ) * index * - 1 : 0 ;
66+ const offsetY =
67+ direction === 'down' ? ( size + spacing ) * index :
68+ direction === 'up' ? ( size + spacing ) * index * - 1 : 0 ;
5469
5570 return (
56- < Wrapper { ...other } onClick = { this . props . isOpen ? this . props . onClick : null } >
57- < a >
58- < IconButton />
59- </ a >
71+ < Wrapper
72+ { ...this . props }
73+ onClick = { isOpen ? onClick : null }
74+ style = { {
75+ transform : `translate(${ isOpen ? 0 : - offsetX } px, ${ isOpen ? 0 : - offsetY } px)` ,
76+ } }
77+ >
78+ { icon }
6079 </ Wrapper >
6180 ) ;
6281 }
0 commit comments