Skip to content

Commit

Permalink
support es6 and react 0.13
Browse files Browse the repository at this point in the history
  • Loading branch information
yiminghe committed Mar 17, 2015
1 parent 1f46af1 commit cf229bf
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 108 deletions.
4 changes: 3 additions & 1 deletion HISTORY.md
@@ -1,7 +1,9 @@
# History
----

generated by https://github.com/yiminghe/gh-history
## 3.0.0 / 2015-03-17

support es6 and react 0.13

## 2.1.0 / 2015-03-05

Expand Down
9 changes: 0 additions & 9 deletions gh-pages.sh

This file was deleted.

62 changes: 32 additions & 30 deletions lib/Dialog.js
Expand Up @@ -5,8 +5,8 @@ var React = require('react');
function noop() {
}

var Dialog = React.createClass({
prefixClsFn: function () {
class Dialog extends React.Component{
prefixClsFn() {
var prefixCls = this.props.prefixCls;
var args = Array.prototype.slice.call(arguments, 0);
return args.map(function (s) {
Expand All @@ -15,37 +15,29 @@ var Dialog = React.createClass({
}
return prefixCls + '-' + s;
}).join(' ');
},
}

getInitialState: function () {
return {
constructor(props) {
super(props);
this.state = {
visible: this.props.visible
};
},

getDefaultProps: function () {
return {
className: '',
closable: true,
prefixCls: 'rc-dialog',
visible: false,
onBeforeClose: noop,
onShow: noop,
onClose: noop
};
},

componentWillReceiveProps: function (props) {
this.prefixClsFn = this.prefixClsFn.bind(this);
this.requestClose = this.requestClose.bind(this);
}

componentWillReceiveProps(props) {
if (this.state.visible !== props.visible) {
if (props.visible) {
this.show();
} else {
this.close();
}
}
},
}

show: function () {
show() {
var self = this;
if (!this.state.visible) {
var props = this.props;
Expand All @@ -56,9 +48,9 @@ var Dialog = React.createClass({
props.onShow();
});
}
},
}

close: function () {
close() {
if (this.state.visible) {
var props = this.props;
this.setState({
Expand All @@ -67,15 +59,15 @@ var Dialog = React.createClass({
props.onClose();
});
}
},
}

requestClose: function () {
requestClose() {
if (this.props.onBeforeClose(this) !== false) {
this.close();
}
},
}

render: function () {
render() {
var self = this;
var props = this.props;
var visible = self.state.visible;
Expand Down Expand Up @@ -110,14 +102,24 @@ var Dialog = React.createClass({
</div>
</div>
);
},
}

componentDidMount: function () {
componentDidMount() {
if (this.state.visible) {
this.refs.dialog.getDOMNode().focus();
this.props.onShow();
}
}
});
}

Dialog.defaultProps = {
className: '',
closable: true,
prefixCls: 'rc-dialog',
visible: false,
onBeforeClose: noop,
onShow: noop,
onClose: noop
};

module.exports = Dialog;
21 changes: 8 additions & 13 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "rc-dialog",
"version": "2.1.0",
"version": "3.0.0",
"description": "dialog ui component for react",
"keywords": [
"react",
Expand All @@ -11,8 +11,8 @@
],
"homepage": "http://github.com/react-component/dialog",
"maitainers": [
"dxq613@gmail.com",
"yiminghe@gmail.com"
"yiminghe@gmail.com",
"dxq613@gmail.com"
],
"repository": {
"type": "git",
Expand All @@ -32,8 +32,9 @@
"port": 8000
},
"scripts": {
"example": "rm -rf build && webpack -d && rc-tools run jsx2html",
"build": "rc-tools run build",
"less": "rc-tools run less",
"gh-pages": "rc-tools run gh-pages",
"history": "rc-tools run history",
"start": "node --harmony node_modules/.bin/rc-server",
"publish": "rc-tools run tag && spm publish",
Expand All @@ -46,19 +47,13 @@
"devDependencies": {
"async": "^0.9.0",
"bootstrap": "^3.3.2",
"css-loader": "^0.9.1",
"expect.js": "~0.3.1",
"file-loader": "^0.8.1",
"jquery": "^1.11.2",
"jsx-loader": "^0.12.2",
"precommit-hook": "^1.0.7",
"rc-server": "^2.0.0",
"rc-tools": "^1.1.0",
"react": "~0.12.1",
"sinon": "^1.12.2",
"style-loader": "^0.8.3",
"url-loader": "^0.5.5",
"webpack": "~1.5.3"
"rc-tools": "2.x",
"react": "~0.13.0",
"sinon": "^1.12.2"
},
"precommit": [
"lint",
Expand Down
19 changes: 8 additions & 11 deletions tests/index.spec.js
Expand Up @@ -21,25 +21,22 @@ describe('dialog', function () {
var callback1;
var callback2;

beforeEach(function (done) {
beforeEach(function () {
callback1 = sinon.spy();
callback2 = sinon.spy();
React.render((<Dialog
style={{width:600}}
dialog = React.render((<Dialog
style={{width: 600}}
title={title} onClose={callback1} onShow={callback2}>
<p>第一个dialog</p>
</Dialog>), container, function () {
dialog = this;
done();
});
</Dialog>), container);
});

afterEach(function () {
React.unmountComponentAtNode(container);
});

it('show', function (done) {
dialog.setProps({'visible': true});
dialog.show();
setTimeout(function () {
expect($('#t1 .rc-dialog-wrap').hasClass('rc-dialog-hidden')).not.to.be.ok();
done();
Expand All @@ -48,7 +45,7 @@ describe('dialog', function () {
});

it('hide', function (done) {
dialog.setProps({'visible': false});
dialog.hide();
setTimeout(function () {
expect($('#t1 .rc-dialog-wrap').hasClass('rc-dialog-wrap-hidden')).to.be.ok();
done();
Expand All @@ -69,7 +66,7 @@ describe('dialog', function () {
});

it('show', function (done) {
dialog.setProps({'visible': true});
dialog.show();
setTimeout(function () {
expect(callback2.called).to.be(true);
expect($('#t1 .rc-dialog-wrap').hasClass('rc-dialog-wrap-hidden')).not.to.be.ok();
Expand All @@ -79,7 +76,7 @@ describe('dialog', function () {

it('click close', function (done) {
async.series([function (done) {
dialog.setProps({'visible': true});
dialog.show();
setTimeout(done, 10);
}, function (done) {
var btn = $('#t1 .rc-dialog-header a')[0];
Expand Down
44 changes: 0 additions & 44 deletions webpack.config.js

This file was deleted.

0 comments on commit cf229bf

Please sign in to comment.