Skip to content

Commit 06c3155

Browse files
committed
Add levitate on hover
1 parent fe3761d commit 06c3155

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

ReactCardFlipper.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
transform-style: preserve-3d;
99
width: auto;
1010
height: auto;
11+
transition: transform 500ms cubic-bezier(.18,.45,.11,.91);
1112
}
1213

1314
.rcf-front, .rcf-back {
@@ -38,6 +39,11 @@
3839
transform: rotateY(180deg);
3940
}
4041

42+
.rcf-levitate {
43+
transform: translateY(-15px);
44+
transition: transform 500ms cubic-bezier(.18,.45,.11,.91);
45+
}
46+
4147
/* IE Support for 11-10 */
4248
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
4349
.rcf-active .rcf-back {

ReactCardFlipper.js

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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 clicked)
1314
**/
1415

1516
class 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]}

Test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ ReactDOM.render(
2222
Great job! You win person of the day.
2323
</div>
2424
</ReactCardFlipper>
25+
<ReactCardFlipper width="300px" height="400px" behavior="click" levitate={true}>
26+
<div className="text-center">
27+
You can click me, and I levitate
28+
</div>
29+
<div className="text-center">
30+
Great job! You win person of the minute.
31+
</div>
32+
</ReactCardFlipper>
2533
</div>
2634
</div>
2735
</div>,

tests/tests.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
.rcf-container {
66
display: inline-block;
7-
margin: 0 20px;
7+
margin: 10px 20px;
88
}
99

1010
.rcf-front, .rcf-back{

0 commit comments

Comments
 (0)