@@ -10,6 +10,7 @@ import './ReactCardFlipper.css';
1010 * Width: string (default: auto)
1111 * Height: string (default: auto)
1212 * behavior: click, hover (default: click)
13+ * levitate: boolean (default: false, only works when behavior is set to `click`)
1314**/
1415
1516class ReactCardFlipper extends Component {
@@ -20,11 +21,13 @@ class ReactCardFlipper extends Component {
2021 isFlipped : false ,
2122 width : this . props . width ,
2223 height : this . props . height ,
23- behavior : this . props . behavior ? this . props . behavior : 'click'
24+ behavior : this . props . behavior ? this . props . behavior : 'click' ,
25+ levitate : this . props . levitate ? this . props . levitate : false
2426 }
2527
2628 // bind this 🤙
2729 this . handleFlip = this . handleFlip . bind ( this ) ;
30+ this . handleMouseEvent = this . handleMouseEvent . bind ( this ) ;
2831 }
2932
3033 handleFlip ( e ) {
@@ -34,15 +37,29 @@ class ReactCardFlipper extends Component {
3437 } )
3538 }
3639
40+ handleLevitate ( e ) {
41+ e . currentTarget . classList . toggle ( 'rcf-levitate' ) ;
42+ }
43+
44+ handleMouseEvent ( e ) {
45+ if ( this . state . behavior === 'hover' ) {
46+ return this . handleFlip ( e ) ;
47+ } else if ( this . state . behavior === 'click' && this . state . levitate ) {
48+ return this . handleLevitate ( e ) ;
49+ } else if ( this . state . behavior === 'click' ) {
50+ return
51+ }
52+ }
53+
3754 render ( ) {
3855 const containerStyles = {
3956 width : this . state . width ,
4057 height : this . state . height ,
4158 }
4259
4360 return (
44- < div className = "rcf-container" style = { containerStyles } onClick = { ( e ) => { if ( this . state . behavior === 'click' ) { this . handleFlip ( e ) } } } onMouseEnter = { ( e ) => { if ( this . state . behavior === 'hover' ) { this . handleFlip ( e ) } } }
45- onMouseLeave = { ( e ) => { if ( this . state . behavior === 'hover' ) { this . handleFlip ( e ) } } } >
61+ < div className = "rcf-container" style = { containerStyles } onClick = { ( e ) => { if ( this . state . behavior === 'click' ) { this . handleFlip ( e ) } } } onMouseEnter = { ( e ) => { this . handleMouseEvent ( e ) } }
62+ onMouseLeave = { ( e ) => { this . handleMouseEvent ( e ) } } >
4663 < div className = "rcf-flipper" >
4764 < div className = "rcf-front" style = { containerStyles } >
4865 { this . props . children [ 0 ] }
0 commit comments