diff --git a/examples/basic/app.js b/examples/basic/app.js index 7fdf7eb..c8a1314 100644 --- a/examples/basic/app.js +++ b/examples/basic/app.js @@ -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(); } }, @@ -80,7 +70,19 @@ let App = React.createClass({ ); + }, + + showBack() { + this.setState({ + isFlipped: true + }); + }, + + showFront() { + this.setState({ + isFlipped: false + }); } }); -React.render(, document.getElementById('example')); +DOM.render(, document.getElementById('example')); diff --git a/lib/components/FlipCard.js b/lib/components/FlipCard.js index bda421f..f3979ee 100644 --- a/lib/components/FlipCard.js +++ b/lib/components/FlipCard.js @@ -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'; @@ -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( @@ -44,6 +45,10 @@ export default React.createClass({ }; }, + componentDidMount() { + this._hideFlippedSide(); + }, + componentWillReceiveProps(newProps) { // Make sure both sides are displayed for animation this._showBothSides(); @@ -76,7 +81,7 @@ 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; @@ -84,7 +89,7 @@ export default React.createClass({ // 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; } @@ -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; @@ -177,5 +162,21 @@ export default React.createClass({ ); + }, + + _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'; + } + } } }); diff --git a/lib/components/__tests__/FlipCard-test.js b/lib/components/__tests__/FlipCard-test.js index 1d41108..0612625 100644 --- a/lib/components/__tests__/FlipCard-test.js +++ b/lib/components/__tests__/FlipCard-test.js @@ -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() { @@ -12,7 +12,7 @@ describe('react-flipcard', function() { }); it('should flip vertically', function() { - let card = TestUtils.renderIntoDocument( + const card = TestUtils.renderIntoDocument(
foo
bar
@@ -23,7 +23,7 @@ describe('react-flipcard', function() { }); it('should flip horizontally by default', function() { - let card = TestUtils.renderIntoDocument( + const card = TestUtils.renderIntoDocument(
foo
bar
@@ -34,7 +34,7 @@ describe('react-flipcard', function() { }); it('should default to enabled', function() { - let card = TestUtils.renderIntoDocument( + const card = TestUtils.renderIntoDocument(
foo
bar
@@ -44,7 +44,7 @@ describe('react-flipcard', function() { }); it('should allow disabling', function() { - let card = TestUtils.renderIntoDocument( + const card = TestUtils.renderIntoDocument(
foo
bar
diff --git a/lib/helpers/classSet.js b/lib/helpers/classSet.js deleted file mode 100644 index 7223186..0000000 --- a/lib/helpers/classSet.js +++ /dev/null @@ -1,11 +0,0 @@ -module.exports = function classSet(classNames) { - let result = null; - if (typeof classNames === 'object') { - result = Object.keys(classNames).filter((className) => { - return classNames[className]; - }).join(' '); - } else { - result = Array.prototype.join.call(arguments, ' '); - } - return result; -}; diff --git a/lib/helpers/injectStyle.js b/lib/helpers/injectStyle.js index 80a4dfb..f254efa 100644 --- a/lib/helpers/injectStyle.js +++ b/lib/helpers/injectStyle.js @@ -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; diff --git a/package.json b/package.json index f90a416..7fe7090 100644 --- a/package.json +++ b/package.json @@ -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" } }