Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,16 @@
"pre-commit": "1.x",
"rc-tools": "5.x",
"react": "15.x",
"react-addons-test-utils": "15.x",
"react-dom": "15.x"
},
"precommit": [
"lint"
],
"dependencies": {
"classnames": "2.x",
"prop-types": "^15.5.8",
"rc-animate": "2.x",
"rc-util": "4.0.2"
"rc-util": "4.x"
},
"pre-commit": [
"lint"
Expand Down
49 changes: 23 additions & 26 deletions src/Notice.jsx
Original file line number Diff line number Diff line change
@@ -1,49 +1,48 @@
import React, { PropTypes } from 'react';
import React, { Component } from 'react';
import classNames from 'classnames';
import PropTypes from 'prop-types';

const Notice = React.createClass({
propTypes: {
export default class Notice extends Component {
static propTypes = {
duration: PropTypes.number,
onClose: PropTypes.func,
children: PropTypes.any,
},
};

getDefaultProps() {
return {
onEnd() {
},
onClose() {
},
duration: 1.5,
style: {
right: '50%',
},
};
},
static defaultProps = {
onEnd() {
},
onClose() {
},
duration: 1.5,
style: {
right: '50%',
},
};

componentDidMount() {
if (this.props.duration) {
this.closeTimer = setTimeout(() => {
this.close();
}, this.props.duration * 1000);
}
},
}

componentWillUnmount() {
this.clearCloseTimer();
},
}

clearCloseTimer() {
clearCloseTimer = () => {
if (this.closeTimer) {
clearTimeout(this.closeTimer);
this.closeTimer = null;
}
},
}

close() {
close = () => {
this.clearCloseTimer();
this.props.onClose();
},
}

render() {
const props = this.props;
Expand All @@ -63,7 +62,5 @@ const Notice = React.createClass({
}
</div>
);
},
});

export default Notice;
}
}
49 changes: 23 additions & 26 deletions src/Notification.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { PropTypes } from 'react';
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import ReactDOM from 'react-dom';
import Animate from 'rc-animate';
import createChainedFunction from 'rc-util/lib/createChainedFunction';
Expand All @@ -12,30 +13,26 @@ function getUuid() {
return `rcNotification_${now}_${seed++}`;
}

const Notification = React.createClass({
propTypes: {
class Notification extends Component {
static propTypes = {
prefixCls: PropTypes.string,
transitionName: PropTypes.string,
animation: PropTypes.oneOfType([PropTypes.string, PropTypes.object]),
style: PropTypes.object,
},
};

getDefaultProps() {
return {
prefixCls: 'rc-notification',
animation: 'fade',
style: {
top: 65,
left: '50%',
},
};
},
static defaultProps = {
prefixCls: 'rc-notification',
animation: 'fade',
style: {
top: 65,
left: '50%',
},
};

getInitialState() {
return {
notices: [],
};
},
state = {
notices: [],
};

getTransitionName() {
const props = this.props;
Expand All @@ -44,9 +41,9 @@ const Notification = React.createClass({
transitionName = `${props.prefixCls}-${props.animation}`;
}
return transitionName;
},
}

add(notice) {
add = (notice) => {
const key = notice.key = notice.key || getUuid();
this.setState(previousState => {
const notices = previousState.notices;
Expand All @@ -56,15 +53,15 @@ const Notification = React.createClass({
};
}
});
},
}

remove(key) {
remove = (key) => {
this.setState(previousState => {
return {
notices: previousState.notices.filter(notice => notice.key !== key),
};
});
},
}

render() {
const props = this.props;
Expand All @@ -87,8 +84,8 @@ const Notification = React.createClass({
<Animate transitionName={this.getTransitionName()}>{noticeNodes}</Animate>
</div>
);
},
});
}
}

Notification.newInstance = function newNotificationInstance(properties) {
const { getContainer, ...props } = properties || {};
Expand Down
2 changes: 1 addition & 1 deletion tests/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const React = require('react');
const TestUtils = require('react-addons-test-utils');
const TestUtils = require('react-dom/test-utils');
const expect = require('expect.js');
const Notification = require('../');

Expand Down