Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade to react 16 #18

Merged
merged 5 commits into from
Jun 26, 2018
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
7 changes: 3 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@
<body>
<div id="UXCoreDemo"></div>
<script src="./node_modules/console-polyfill/index.js"></script>
<script src="./node_modules/es5-shim/es5-shim.min.js"></script>
<script src="./node_modules/es5-shim/es5-sham.min.js"></script>
<script src="./node_modules/react/dist/react-with-addons.js"></script>
<script src="./node_modules/react-dom/dist/react-dom.js"></script>
<script src="./node_modules/babel-polyfill/dist/polyfill.min.js"></script>
<script src="./node_modules/react/umd/react.development.js"></script>
<script src="./node_modules/react-dom/umd/react-dom.development.js"></script>
<script src="./dist/demo.js"></script>
</body>
</html>
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uxcore-popover",
"version": "0.5.5",
"version": "0.6.0",
"description": "uxcore-popover component for uxcore.",
"repository": "https://github.com/uxcore/uxcore-popover.git",
"author": "eternalsky",
Expand Down Expand Up @@ -34,23 +34,24 @@
"devDependencies": {
"console-polyfill": "^0.2.2",
"enzyme": "^3.0.0",
"enzyme-adapter-react-15": "^1.0.0",
"es5-shim": "^4.5.8",
"enzyme-adapter-react-16": "1.x",
"expect.js": "~0.3.1",
"kuma-base": "1.x",
"react": "15.x",
"react-dom": "15.x",
"react-test-renderer": "15.x",
"react": "16.x",
"react-dom": "16.x",
"react-test-renderer": "16.x",
"uxcore-kuma": "*",
"uxcore-tools": "0.2.x"
"uxcore-tools": "^0.3.0",
"babel-polyfill": "6.x"
},
"dependencies": {
"classnames": "^2.1.2",
"object-assign": "^4.0.0",
"prop-types": "15.x",
"rc-tooltip": "^3.3.0",
"react-lifecycles-compat": "^3.0.4",
"uxcore-button": "^0.4.0"
},
"contributors": [],
"license": "MIT"
}
}
17 changes: 10 additions & 7 deletions src/Popover.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import React from 'react';
import Tooltip from 'rc-tooltip';
import Button from 'uxcore-button';
import PropTypes from 'prop-types';
import { polyfill } from 'react-lifecycles-compat';

class Popover extends React.Component {

Expand All @@ -21,14 +22,14 @@ class Popover extends React.Component {
};
}

componentWillReceiveProps(nextProps) {
const me = this;

if (('visible' in nextProps) && (nextProps.visible !== me.props.visible)) {
me.setState({
visible: nextProps.visible,
});
static getDerivedStateFromProps(props, states = {}) {
if (('visible' in props) && props.visible !== states._visible) {
return {
visible: props.visible,
_visible: props.visible
}
}
return null;
}

handleOkClick() {
Expand Down Expand Up @@ -163,4 +164,6 @@ Popover.propTypes = {

Popover.displayName = 'Popover';

polyfill(Popover)

export default Popover;
33 changes: 22 additions & 11 deletions tests/Popover.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import expect from 'expect.js';
import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils, { Simulate } from 'react-dom/test-utils';
import Enzyme from 'enzyme';
import Adapter from 'enzyme-adapter-react-16';
import Popover from '../src';

describe('Popover', () => {
Expand Down Expand Up @@ -47,15 +49,17 @@ describe('Popover', () => {
);
expect(component.state.visible).equal(false);
component.setState({ ...component.state, visible: true }, () => {
expect(component.state.visible).equal(true);
setTimeout(() => {
expect(component.state.visible).equal(true);
}, 0)
component.handleOkClick();
component.handleCancelClick();
setTimeout(() => {
expect(onVisibleChangeCalled).equal(true);
expect(onCancleCalled).equal(true);
expect(onOkCalled).equal(true);
}, 200);
component.componentWillReceiveProps({...props, visible: true});
}, 0);
component.constructor.getDerivedStateFromProps({...props, visible: true}, {})
});
});

Expand All @@ -68,19 +72,26 @@ describe('Popover', () => {
<span>目标删除后将不可恢复,如有子目标将会删除!</span>
</div>
</div>);
const props = {
placement: "right",
title: '右边',
overlay: overlay,
onCancle: () => { onCancleCalled = true },
onVisibleChange: () => { onVisibleChangeCalled = true },
onOk: (cb) => {
cb();
onOkCalled = true;
}
}
const component = TestUtils.renderIntoDocument(
<Popover placement="right" title={'右边'} overlay={overlay}
onCancle = {() => {onCancleCalled = true}}
onVisibleChange = {() => {onVisibleChangeCalled = true}}
onOk = {(cb) => {
cb();
onOkCalled = true;
}}>
<Popover
{...props}
>
<span>右边</span>
</Popover>
);
expect(component.state.visible).equal(false);
component.componentWillReceiveProps({visible: true});
component.constructor.getDerivedStateFromProps({...props, visible: true}, {});
component.handleOkClick();
component.handleCancelClick();
component.handleVisibleChange();
Expand Down