Skip to content

Commit

Permalink
[added] support for react@0.14.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mzabriskie committed Oct 22, 2015
1 parent 4d3d48f commit 35d6109
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 62 deletions.
32 changes: 17 additions & 15 deletions examples/basic/app.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,18 @@
import React from 'react';
import DOM from 'react-dom';
import FlipCard from '../../lib/main';

let App = React.createClass({

const App = React.createClass({
getInitialState() {
return {
isFlipped: false
};
},

showBack() {
this.setState({
isFlipped: true
});
},

showFront() {
this.setState({
isFlipped: false
});
},

handleOnFlip(flipped) {
if (flipped) {
this.refs.backButton.getDOMNode().focus();
this.refs.backButton.focus();
}
},

Expand Down Expand Up @@ -80,7 +70,19 @@ let App = React.createClass({
</FlipCard>
</div>
);
},

showBack() {
this.setState({
isFlipped: true
});
},

showFront() {
this.setState({
isFlipped: false
});
}
});

React.render(<App/>, document.getElementById('example'));
DOM.render(<App/>, document.getElementById('example'));
49 changes: 25 additions & 24 deletions lib/components/FlipCard.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { PropTypes } from 'react';
import cx from '../helpers/classSet';
import { findDOMNode } from 'react-dom';
import cx from 'classnames';
import contains from '../helpers/contains';
import injectStyle from '../helpers/injectStyle';

Expand All @@ -16,7 +17,7 @@ export default React.createClass({
onFlip: PropTypes.func,
onKeyDown: PropTypes.func,
children(props, propName, componentName) {
let prop = props[propName];
const prop = props[propName];

if (React.Children.count(prop) !== 2) {
return new Error(
Expand Down Expand Up @@ -44,6 +45,10 @@ export default React.createClass({
};
},

componentDidMount() {
this._hideFlippedSide();
},

componentWillReceiveProps(newProps) {
// Make sure both sides are displayed for animation
this._showBothSides();
Expand Down Expand Up @@ -76,15 +81,15 @@ export default React.createClass({
// return focus to the element that triggered flipping to the back.
if (!this.props.flipped &&
this.focusElement &&
contains(this.getDOMNode(), document.activeElement)
contains(findDOMNode(this), document.activeElement)
) {
this.focusElement.focus();
this.focusElement = null;
}
// Direct focus to the back if needed
/* eslint brace-style:0 */
else if (this.focusBack) {
this.refs.back.getDOMNode().focus();
this.refs.back.focus();
this.focusBack = false;
}

Expand All @@ -98,26 +103,6 @@ export default React.createClass({
setTimeout(this._hideFlippedSide, 600);
},

componentDidMount() {
this._hideFlippedSide();
},

_showBothSides() {
this.refs.front.getDOMNode().style.display = '';
this.refs.back.getDOMNode().style.display = '';
},

_hideFlippedSide() {
// This prevents the flipped side from being tabbable
if (this.props.disabled) {
if (this.state.isFlipped) {
this.refs.front.getDOMNode().style.display = 'none';
} else {
this.refs.back.getDOMNode().style.display = 'none';
}
}
},

handleFocus() {
if (this.props.disabled) return;

Expand Down Expand Up @@ -177,5 +162,21 @@ export default React.createClass({
</div>
</div>
);
},

_showBothSides() {
this.refs.front.style.display = '';
this.refs.back.style.display = '';
},

_hideFlippedSide() {
// This prevents the flipped side from being tabbable
if (this.props.disabled) {
if (this.state.isFlipped) {
this.refs.front.style.display = 'none';
} else {
this.refs.back.style.display = 'none';
}
}
}
});
16 changes: 8 additions & 8 deletions lib/components/__tests__/FlipCard-test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let React = require('react/addons');
let TestUtils = React.addons.TestUtils;
let FlipCard = require('../../main');
let { equal, throws } = require('assert');
import React from 'react';
import TestUtils from 'react-addons-test-utils';
import FlipCard from '../../main';
import { equal, throws } from 'assert';

/* eslint func-names:0 */
describe('react-flipcard', function() {
Expand All @@ -12,7 +12,7 @@ describe('react-flipcard', function() {
});

it('should flip vertically', function() {
let card = TestUtils.renderIntoDocument(
const card = TestUtils.renderIntoDocument(
<FlipCard type="vertical">
<div>foo</div>
<div>bar</div>
Expand All @@ -23,7 +23,7 @@ describe('react-flipcard', function() {
});

it('should flip horizontally by default', function() {
let card = TestUtils.renderIntoDocument(
const card = TestUtils.renderIntoDocument(
<FlipCard>
<div>foo</div>
<div>bar</div>
Expand All @@ -34,7 +34,7 @@ describe('react-flipcard', function() {
});

it('should default to enabled', function() {
let card = TestUtils.renderIntoDocument(
const card = TestUtils.renderIntoDocument(
<FlipCard>
<div>foo</div>
<div>bar</div>
Expand All @@ -44,7 +44,7 @@ describe('react-flipcard', function() {
});

it('should allow disabling', function() {
let card = TestUtils.renderIntoDocument(
const card = TestUtils.renderIntoDocument(
<FlipCard disabled={true}>
<div>foo</div>
<div>bar</div>
Expand Down
11 changes: 0 additions & 11 deletions lib/helpers/classSet.js

This file was deleted.

2 changes: 1 addition & 1 deletion lib/helpers/injectStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ export default function() {
if (!style) {
style = document.createElement('style');
style.setAttribute('id', 'react-flipcard-style');
let head = document.querySelector('head');
const head = document.querySelector('head');
head.insertBefore(style, head.firstChild);
}
style.innerHTML = CSS;
Expand Down
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,16 @@
},
"homepage": "https://github.com/mzabriskie/react-flipcard",
"devDependencies": {
"rackt-cli": "^0.4.0",
"react": "^0.13.3"
"rackt-cli": "^0.5.2",
"react": "^0.14.0",
"react-addons-test-utils": "^0.14.0",
"react-dom": "^0.14.0"
},
"peerDependencies": {
"react": "^0.13.3"
"react": "^0.14.0",
"react-dom": "^0.14.0"
},
"dependencies": {
"classnames": "^2.2.0"
}
}

0 comments on commit 35d6109

Please sign in to comment.