diff --git a/examples/ant-design.js b/examples/ant-design.js index 5d2a7fac..71a994de 100644 --- a/examples/ant-design.js +++ b/examples/ant-design.js @@ -1,43 +1,42 @@ -'use strict'; - import 'rc-dialog/assets/index.less'; import React from 'react'; import ReactDOM from 'react-dom'; import Dialog from 'rc-dialog'; import assign from 'object-assign'; -var MyControl = React.createClass({ - getInitialState(){ +const MyControl = React.createClass({ + getInitialState() { return { visible: false, width: 600, align: { points: ['tc', 'tc'], - offset: [0, 100] + offset: [0, 100], }, destroyOnClose: false, }; }, - onClick: function (e) { + onClick(e) { this.setState({ mousePosition: { x: e.pageX, - y: e.pageY + y: e.pageY, }, - visible: true + visible: true, }); }, - onClose(){ + onClose(e) { + console.log(e); this.setState({ - visible: false + visible: false, }); }, - onDestroyOnCloseChange(e){ + onDestroyOnCloseChange(e) { this.setState({ - destroyOnClose: e.target.checked + destroyOnClose: e.target.checked, }); }, @@ -48,22 +47,23 @@ var MyControl = React.createClass({ }); }, - render: function () { - var dialog; + render() { + let dialog; if (this.state.visible || !this.state.destroyOnClose) { - dialog = 第二个弹框}> - - -

basic modal

- -
-
; + dialog = ( + 第二个弹框}> + +

basic modal

+ +
+
+ ); } return (
@@ -76,13 +76,13 @@ var MyControl = React.createClass({ {dialog}
); - } + }, }); ReactDOM.render(

ant-design dialog

- +
, document.getElementById('__react-content') ); diff --git a/examples/bootstrap.js b/examples/bootstrap.js index 098b6979..411d6da0 100644 --- a/examples/bootstrap.js +++ b/examples/bootstrap.js @@ -1,64 +1,64 @@ -'use strict'; - import 'rc-dialog/assets/bootstrap.less'; import React from 'react'; import ReactDOM from 'react-dom'; import Dialog from 'rc-dialog'; -var MyControl = React.createClass({ - getInitialState(){ +const MyControl = React.createClass({ + getInitialState() { return { - visible:false, - destroyOnClose:false, + visible: false, + destroyOnClose: false, }; }, - onClick: function (e) { + onClick(e) { this.setState({ mousePosition: { - x:e.pageX, - y:e.pageY + x: e.pageX, + y: e.pageY, }, - visible:true + visible: true, }); }, - onClose(){ + onClose() { this.setState({ - visible:false + visible: false, }); }, - onDestroyOnCloseChange(e){ + onDestroyOnCloseChange(e) { this.setState({ - destroyOnClose:e.target.checked + destroyOnClose: e.target.checked, }); }, - render: function () { - var dialog; - if(this.state.visible || !this.state.destroyOnClose){ - dialog= 第二个弹框}> - -

basic modal

-
; - } + render() { + let dialog; + if (this.state.visible || !this.state.destroyOnClose) { + dialog = ( + 第二个弹框}> + +

basic modal

+
+ ); + } return (

- +   -

+

{dialog}
); - } + }, }); ReactDOM.render( diff --git a/package.json b/package.json index 8b73d76d..7448bf19 100644 --- a/package.json +++ b/package.json @@ -55,9 +55,10 @@ "lint" ], "dependencies": { + "classnames": "2.x", "object-assign": "4.x", "rc-align": "2.x", "rc-animate": "2.x", "rc-util": "3.x" } -} \ No newline at end of file +} diff --git a/src/Dialog.jsx b/src/Dialog.jsx index a5774885..2bde87b7 100644 --- a/src/Dialog.jsx +++ b/src/Dialog.jsx @@ -1,10 +1,11 @@ import React, {PropTypes} from 'react'; import ReactDOM from 'react-dom'; import Align from 'rc-align'; -import {KeyCode, classSet} from 'rc-util'; +import { KeyCode } from 'rc-util'; import assign from 'object-assign'; import Animate from 'rc-animate'; import DOMWrap from './DOMWrap'; +import classNames from 'classnames'; function noop() { } @@ -87,9 +88,9 @@ const Dialog = React.createClass({ this.props.onAfterClose(); }, - onMaskClick() { + onMaskClick(e) { if (this.props.closable) { - this.close(); + this.close(e); } ReactDOM.findDOMNode(this.refs.dialog).focus(); }, @@ -98,7 +99,7 @@ const Dialog = React.createClass({ const props = this.props; if (props.closable) { if (e.keyCode === KeyCode.ESC) { - this.close(); + this.close(e); } } // keep focus inside dialog @@ -251,8 +252,8 @@ const Dialog = React.createClass({ return transitionName; }, - close() { - this.props.onClose(); + close(e) { + this.props.onClose(e); }, render() { @@ -262,7 +263,7 @@ const Dialog = React.createClass({ [`${prefixCls}-wrap`]: 1, }; - return (
+ return (
{[this.getMaskElement(), this.getDialogElement()]}
); }, diff --git a/src/DialogWrap.jsx b/src/DialogWrap.jsx index 676044cd..adce50af 100644 --- a/src/DialogWrap.jsx +++ b/src/DialogWrap.jsx @@ -63,8 +63,8 @@ class DialogWrap extends React.Component { } } - onClose() { - this.props.onClose(); + onClose(e) { + this.props.onClose(e); } getDialogContainer() { diff --git a/tests/index.spec.js b/tests/index.spec.js index 133e72ec..5fe28be8 100644 --- a/tests/index.spec.js +++ b/tests/index.spec.js @@ -1,31 +1,30 @@ -'use strict'; - -var expect = require('expect.js'); -var Dialog = require('../index'); +/* eslint-disable func-names */ +const expect = require('expect.js'); +const Dialog = require('../index'); require('../assets/bootstrap.less'); -var $ = require('jquery'); -var React = require('react'); -var ReactDOM = require('react-dom'); -var TestUtils = require('react-addons-test-utils'); -var Simulate = TestUtils.Simulate; -var async = require('async'); -var rcUtil = require('rc-util'); - -describe('dialog', function () { - var title = "第一个title"; - var dialog; - - var container = document.createElement('div'); +const $ = require('jquery'); +const React = require('react'); +const ReactDOM = require('react-dom'); +const TestUtils = require('react-addons-test-utils'); +const Simulate = TestUtils.Simulate; +const async = require('async'); +const rcUtil = require('rc-util'); + +describe('dialog', function() { + const title = '第一个title'; + let dialog; + + const container = document.createElement('div'); container.id = 't1'; document.body.appendChild(container); - var callback1; + let callback1; - beforeEach(function () { + beforeEach(function() { function onClose() { callback1 = 1; dialog.setState({ - visible: false + visible: false, }); } @@ -38,89 +37,87 @@ describe('dialog', function () { ), container); }); - afterEach(function () { + afterEach(function() { ReactDOM.unmountComponentAtNode(container); }); - it('show', function (done) { + it('show', function(done) { dialog.setState({ - visible: true + visible: true, }); - setTimeout(function () { + setTimeout(function() { expect($('.rc-dialog').hasClass('rc-dialog-hidden')).not.to.be.ok(); done(); }, 10); - }); - it('close', function (done) { + it('close', function(done) { dialog.setState({ - visible: true + visible: true, }); dialog.setState({ - visible: false + visible: false, }); - setTimeout(function () { + setTimeout(function() { expect($('.rc-dialog').hasClass('rc-dialog-hidden')).to.be.ok(); done(); }, 10); }); - it('create', function () { + it('create', function() { expect($('.rc-dialog').length).to.be(0); }); - it('mask', function () { + it('mask', function() { dialog.setState({ - visible: true + visible: true, }); expect($('.rc-dialog-mask').length).to.be(1); - }); - it('click close', function (done) { - async.series([function (done) { + it('click close', function(finish) { + async.series([function(done) { dialog.setState({ - visible: true + visible: true, }); setTimeout(done, 10); - }, function (done) { - var btn = $('.rc-dialog-close')[0]; + }, function(done) { + const btn = $('.rc-dialog-close')[0]; Simulate.click(btn); setTimeout(done, 10); - }, function (done) { + }, function(done) { expect(callback1).to.be(1); expect($('.rc-dialog').hasClass('rc-dialog-hidden')).to.be.ok(); done(); - }], done) + }], finish); }); - it('esc to close', function (done) { - async.series([function (done) { + it('esc to close', function(finish) { + async.series([function(done) { dialog.setState({ - visible: true + visible: true, }); setTimeout(done, 10); - }, function (done) { + }, function(done) { Simulate.keyDown($('.rc-dialog')[0], { - keyCode: rcUtil.KeyCode.ESC + keyCode: rcUtil.KeyCode.ESC, }); setTimeout(done, 10); - }, function (done) { + }, function(done) { expect(callback1).to.be(1); expect($('.rc-dialog').hasClass('rc-dialog-hidden')).to.be.ok(); done(); - }], done) + }], finish); }); - it('renderToBody', function () { - var d = ReactDOM.render( + it('renderToBody', function() { + const d = ReactDOM.render(

1

, container); expect($('.renderToBody').length).to.be(0); expect($('.rc-dialog-container').length).to.be(0); d.setState({ - visible: true + visible: true, }); expect($('.rc-dialog-container').length).to.be(1); expect($('.renderToBody').length).to.be(1);