diff --git a/.babelrc b/.babelrc index 937a0f9..edd557f 100644 --- a/.babelrc +++ b/.babelrc @@ -1,6 +1,6 @@ { "presets": [ - "es2015", + "env", "stage-0", "stage-1", "react" @@ -10,4 +10,4 @@ "transform-class-properties", "transform-object-rest-spread" ] -} \ No newline at end of file +} diff --git a/examples/area-chart/App.js b/examples/area-chart/App.js index 6a4a7c0..a00c91f 100644 --- a/examples/area-chart/App.js +++ b/examples/area-chart/App.js @@ -1,15 +1,15 @@ /* eslint import/no-unresolved: 0 */ -import React from 'react'; +import React, { PureComponent } from 'react'; import ReactDom from 'react-dom'; import { escapeHTML } from '../util'; import ToolTip from '../ToolTip'; import { AreaChart } from 'react-easy-chart'; import moment from 'moment'; import { timeParse as parse } from 'd3-time-format'; -import { Scrollspy } from 'react-scrollspy'; +import Scrollspy from 'react-scrollspy'; -class AreaChartContainer extends React.Component { +class AreaChartContainer extends PureComponent { constructor(props) { super(props); // Generate multiple Areas of data diff --git a/examples/bar-chart/App.js b/examples/bar-chart/App.js index e870320..0971ec8 100644 --- a/examples/bar-chart/App.js +++ b/examples/bar-chart/App.js @@ -1,13 +1,13 @@ /* eslint import/no-unresolved: 0 */ -import React from 'react'; +import React, { PureComponent } from 'react'; import ReactDOM from 'react-dom'; import { BarChart } from 'react-easy-chart'; import ToolTip from '../ToolTip'; import { escapeHTML } from '../util'; -import { Scrollspy } from 'react-scrollspy'; +import Scrollspy from 'react-scrollspy'; -export default class BarChartContainer extends React.Component { +export default class BarChartContainer extends PureComponent { constructor(props) { super(props); diff --git a/examples/legend/App.js b/examples/legend/App.js index 4924dd0..bd84fbc 100644 --- a/examples/legend/App.js +++ b/examples/legend/App.js @@ -1,6 +1,6 @@ /* eslint import/no-unresolved: 0 */ -import React from 'react'; +import React, { PureComponent } from 'react'; import ReactDOM from 'react-dom'; import { Legend, @@ -8,7 +8,7 @@ import { ScatterplotChart } from 'react-easy-chart'; import { escapeHTML } from '../util'; -import { Scrollspy } from 'react-scrollspy'; +import Scrollspy from 'react-scrollspy'; const pieData = [ { key: 'Cats', value: 100 }, @@ -128,7 +128,7 @@ const bigData = [ } ]; -export default class LegendContainer extends React.Component { +export default class LegendContainer extends PureComponent { constructor(props) { super(props); diff --git a/examples/line-chart/app.js b/examples/line-chart/app.js index 4ea3212..4248c4b 100644 --- a/examples/line-chart/app.js +++ b/examples/line-chart/app.js @@ -1,15 +1,15 @@ /* eslint import/no-unresolved: 0 */ -import React from 'react'; +import React, { PureComponent } from 'react'; import ReactDom from 'react-dom'; import { escapeHTML } from '../util'; import ToolTip from '../ToolTip'; import { LineChart } from 'react-easy-chart'; import moment from 'moment'; import { timeParse as parse } from 'd3-time-format'; -import { Scrollspy } from 'react-scrollspy'; +import Scrollspy from 'react-scrollspy'; -class LineChartContainer extends React.Component { +class LineChartContainer extends PureComponent { constructor(props) { super(props); // Generate multiple lines of data diff --git a/examples/pie-chart/App.js b/examples/pie-chart/App.js index c235fa3..6d4c1b2 100644 --- a/examples/pie-chart/App.js +++ b/examples/pie-chart/App.js @@ -1,11 +1,11 @@ /* eslint import/no-unresolved: 0 */ -import React from 'react'; +import React, { PureComponent } from 'react'; import ReactDOM from 'react-dom'; import ToolTip from '../ToolTip'; import { escapeHTML } from '../util'; import { PieChart } from 'react-easy-chart'; -import { Scrollspy } from 'react-scrollspy'; +import Scrollspy from 'react-scrollspy'; const brandColors = { greyBlueOne: '#1e313c', @@ -18,7 +18,7 @@ const brandColors = { lightGrey: '#e4e8ec' }; -export default class PieChartContainer extends React.Component { +export default class PieChartContainer extends PureComponent { constructor(props) { super(props); diff --git a/examples/scatterplot-chart/App.js b/examples/scatterplot-chart/App.js index 655d7d1..7bfe4ad 100644 --- a/examples/scatterplot-chart/App.js +++ b/examples/scatterplot-chart/App.js @@ -1,12 +1,12 @@ /* eslint import/no-unresolved: 0 */ -import React from 'react'; +import React, { PureComponent } from 'react'; import ReactDOM from 'react-dom'; import { ScatterplotChart } from 'react-easy-chart'; import ToolTip from '../ToolTip'; import Legend from '../Legend'; import { escapeHTML } from '../util'; -import { Scrollspy } from 'react-scrollspy'; +import Scrollspy from 'react-scrollspy'; const exampleText = [ { @@ -253,7 +253,7 @@ const configGen = [ } ]; -export default class ScatterplotContainer extends React.Component { +export default class ScatterplotContainer extends PureComponent { constructor(props) { super(props); diff --git a/karma.conf.js b/karma.conf.js index c068a74..28388c4 100644 --- a/karma.conf.js +++ b/karma.conf.js @@ -16,7 +16,6 @@ module.exports = (config) => { // base path that will be used to resolve all patterns (eg. files, exclude) basePath: processCwd, - // frameworks to use // available frameworks: https://npmjs.org/browse/keyword/karma-adapter frameworks: ['mocha', 'chai', 'sinon', 'phantomjs-shim', 'es6-shim'], @@ -25,9 +24,11 @@ module.exports = (config) => { // list of files / patterns to load in the browser files: [ 'node_modules/phantomjs-polyfill/bind-polyfill.js', - 'tests/index.js' + './tests/**/*.js' + ], + exclude: [ + './tests/index.js' ], - plugins: [ 'karma-chai', @@ -51,7 +52,7 @@ module.exports = (config) => { // preprocess matching files before serving them to the browser // available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor preprocessors: { - 'tests/index.js': ['webpack', 'sourcemap'] + 'tests/**/*.js': ['webpack', 'sourcemap'] }, diff --git a/modules/area-chart/index.js b/modules/area-chart/index.js index 673bec6..2f060a1 100644 --- a/modules/area-chart/index.js +++ b/modules/area-chart/index.js @@ -1,5 +1,5 @@ -import React from 'react'; -import { createElement } from 'react-faux-dom'; +import React, { PureComponent } from 'react'; +import ReactFauxDOM from 'react-faux-dom'; import { createUniqueID, reduce, @@ -23,7 +23,7 @@ import { timeParse as parse } from 'd3-time-format'; const dateParser = {}; -export default class AreaChart extends React.Component { +export default class AreaChart extends PureComponent { static get propTypes() { return { data: PropTypes.array.isRequired, @@ -95,7 +95,7 @@ export default class AreaChart extends React.Component { } createSvgNode({ m, w, h }) { - const node = createElement('svg'); + const node = new ReactFauxDOM.Element('svg'); node.setAttribute('width', w + m.left + m.right); node.setAttribute('height', h + m.top + m.bottom); return node; diff --git a/modules/bar-chart/index.js b/modules/bar-chart/index.js index 8226a2d..14619d6 100644 --- a/modules/bar-chart/index.js +++ b/modules/bar-chart/index.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { PureComponent } from 'react'; import { scaleBand as band, scaleLinear as linear } from 'd3-scale'; import { event as lastEvent, @@ -20,7 +20,7 @@ import { } from '../shared'; import { extent } from 'd3-array'; import { timeParse as parse } from 'd3-time-format'; -import { createElement } from 'react-faux-dom'; +import ReactFauxDOM from 'react-faux-dom'; import PropTypes from 'prop-types'; import { Style } from 'radium'; import merge from 'lodash.merge'; @@ -29,7 +29,7 @@ const dateParser = {}; const colorScale = scale.category20(); -export default class BarChart extends React.Component { +export default class BarChart extends PureComponent { static get propTypes() { return { @@ -154,7 +154,7 @@ export default class BarChart extends React.Component { } createSvgNode({ m, w, h }) { - const node = createElement('svg'); + const node = new ReactFauxDOM.Element('svg'); node.setAttribute('width', w + m.left + m.right); node.setAttribute('height', h + m.top + m.bottom); return node; diff --git a/modules/legend/index.js b/modules/legend/index.js index 4235d82..a152140 100644 --- a/modules/legend/index.js +++ b/modules/legend/index.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { PureComponent } from 'react'; import PropTypes from 'prop-types'; import { Style } from 'radium'; import { scale } from 'd3'; @@ -11,7 +11,7 @@ import defaultStyles from './defaultStyles'; const colors = scale.category20().range(); -export default class Legend extends React.Component { +export default class Legend extends PureComponent { static get propTypes() { return { diff --git a/modules/line-chart/hybrid/index.js b/modules/line-chart/hybrid/index.js index 30f0177..490e66a 100644 --- a/modules/line-chart/hybrid/index.js +++ b/modules/line-chart/hybrid/index.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { PureComponent } from 'react'; import { createUniqueID, defaultStyles, @@ -10,7 +10,7 @@ import merge from 'lodash.merge'; import lineChart from './LineChart'; -export default class LineChart extends React.Component { +export default class LineChart extends PureComponent { constructor(props) { super(props); this.uid = createUniqueID(); diff --git a/modules/line-chart/index.js b/modules/line-chart/index.js index f79694e..c9a07a6 100644 --- a/modules/line-chart/index.js +++ b/modules/line-chart/index.js @@ -1,5 +1,6 @@ import React from 'react'; -import { createElement } from 'react-faux-dom'; +import ReactFauxDOM from 'react-faux-dom'; + import { event as lastEvent, select, @@ -95,7 +96,7 @@ export default class LineChart extends React.Component { } createSvgNode({ m, w, h }) { - const node = createElement('svg'); + const node = new ReactFauxDOM.Element('svg'); node.setAttribute('width', w + m.left + m.right); node.setAttribute('height', h + m.top + m.bottom); return node; diff --git a/modules/line-chart/static/index.js b/modules/line-chart/static/index.js index c945872..0c79c13 100644 --- a/modules/line-chart/static/index.js +++ b/modules/line-chart/static/index.js @@ -1,5 +1,5 @@ -import React from 'react'; -import { createElement } from 'react-faux-dom'; +import React, { PureComponent } from 'react'; +import ReactFauxDOM from 'react-faux-dom'; import { event as lastEvent, select, @@ -24,7 +24,7 @@ import { timeParse as parse } from 'd3-time-format'; const dateParser = {}; -export default class LineChart extends React.Component { +export default class LineChart extends PureComponent { static get propTypes() { return { data: PropTypes.array.isRequired, @@ -95,7 +95,7 @@ export default class LineChart extends React.Component { } createSvgNode({ m, w, h }) { - const node = createElement('svg'); + const node = new ReactFauxDOM.Element('svg'); node.setAttribute('width', w + m.left + m.right); node.setAttribute('height', h + m.top + m.bottom); return node; diff --git a/modules/pie-chart/hybrid/index.js b/modules/pie-chart/hybrid/index.js index 5ea7284..7b3d11b 100644 --- a/modules/pie-chart/hybrid/index.js +++ b/modules/pie-chart/hybrid/index.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { PureComponent } from 'react'; import { scale, layout, @@ -11,7 +11,7 @@ import { createUniqueID, defaultStyles } from '../../shared'; -import { createElement } from 'react-faux-dom'; +import ReactFauxDOM from 'react-faux-dom'; import PropTypes from 'prop-types'; import { Style } from 'radium'; import merge from 'lodash.merge'; @@ -28,7 +28,7 @@ const getSliceFill = (d, i) => ( const getLabelText = (d) => d.data.key; -export default class PieChart extends React.Component { +export default class PieChart extends PureComponent { static get propTypes() { return { data: PropTypes.array.isRequired, @@ -138,7 +138,7 @@ export default class PieChart extends React.Component { } createSvgNode({ size }) { - const node = createElement('svg'); + const node = new ReactFauxDOM.Element('svg'); node.setAttribute('width', size); node.setAttribute('height', size); return node; diff --git a/modules/pie-chart/static/index.js b/modules/pie-chart/static/index.js index 20d6c49..f519bf8 100644 --- a/modules/pie-chart/static/index.js +++ b/modules/pie-chart/static/index.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { PureComponent } from 'react'; import { scale, layout, @@ -10,7 +10,7 @@ import { createUniqueID, defaultStyles } from '../../shared'; -import { createElement } from 'react-faux-dom'; +import ReactFauxDOM from 'react-faux-dom'; import PropTypes from 'prop-types'; import { Style } from 'radium'; import merge from 'lodash.merge'; @@ -27,7 +27,7 @@ const getSliceFill = (d, i) => ( const getLabelText = (d) => d.data.key; -export default class PieChart extends React.Component { +export default class PieChart extends PureComponent { static get propTypes() { return { data: PropTypes.array.isRequired, @@ -97,7 +97,7 @@ export default class PieChart extends React.Component { } createSvgNode({ size }) { - const node = createElement('svg'); + const node = new ReactFauxDOM.Element('svg'); node.setAttribute('width', size); node.setAttribute('height', size); return node; diff --git a/modules/scatterplot-chart/hybrid/index.js b/modules/scatterplot-chart/hybrid/index.js index f49f109..3a0bd01 100644 --- a/modules/scatterplot-chart/hybrid/index.js +++ b/modules/scatterplot-chart/hybrid/index.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { PureComponent } from 'react'; import { scaleLinear as linear, scalePoint as point @@ -14,7 +14,7 @@ import { } from 'd3'; import { timeParse as parse } from 'd3-time-format'; import { extent } from 'd3-array'; -import { createElement } from 'react-faux-dom'; +import ReactFauxDOM from 'react-faux-dom'; import PropTypes from 'prop-types'; import { Style } from 'radium'; import merge from 'lodash.merge'; @@ -32,7 +32,7 @@ const color = scale.category20(); const axisMargin = 18; -export default class ScatterplotChart extends React.Component { +export default class ScatterplotChart extends PureComponent { static get propTypes() { return { axes: PropTypes.bool, @@ -509,7 +509,7 @@ export default class ScatterplotChart extends React.Component { } createSvgNode({ m, w, h }) { - const node = createElement('svg'); + const node = new ReactFauxDOM.Element('svg'); node.setAttribute('width', w + m.left + m.right); node.setAttribute('height', h + m.top + m.bottom); return node; diff --git a/modules/scatterplot-chart/static/index.js b/modules/scatterplot-chart/static/index.js index 5633793..547af23 100644 --- a/modules/scatterplot-chart/static/index.js +++ b/modules/scatterplot-chart/static/index.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { PureComponent } from 'react'; import { scaleLinear as linear, scalePoint as point @@ -14,7 +14,7 @@ import { } from 'd3'; import { timeParse as parse } from 'd3-time-format'; import { extent } from 'd3-array'; -import { createElement } from 'react-faux-dom'; +import ReactFauxDOM from 'react-faux-dom'; import PropTypes from 'prop-types'; import { Style } from 'radium'; import merge from 'lodash.merge'; @@ -32,7 +32,7 @@ const color = scale.category20(); const axisMargin = 18; -export default class ScatterplotChart extends React.Component { +export default class ScatterplotChart extends PureComponent { static get propTypes() { return { axes: PropTypes.bool, @@ -321,7 +321,7 @@ export default class ScatterplotChart extends React.Component { } createSvgNode({ m, w, h }) { - const node = createElement('svg'); + const node = new ReactFauxDOM.Element('svg'); node.setAttribute('width', w + m.left + m.right); node.setAttribute('height', h + m.top + m.bottom); return node; diff --git a/package.json b/package.json index 401097a..6e895a1 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "publish-patch": "npm version patch && npm run babel && npm publish", "publish-minor": "npm version minor && npm run babel && npm publish", "publish-major": "npm version major && npm run babel && npm publish", - "babel": "babel ./modules --out-dir ./lib --source-maps --presets es2015,react,stage-0,stage-1 --plugins babel-plugin-add-module-exports,babel-plugin-transform-class-properties,babel-plugin-transform-object-rest-spread,babel-plugin-transform-react-jsx,babel-plugin-transform-runtime" + "babel": "npx babel ./modules --out-dir ./lib --source-maps --presets env,react,stage-0,stage-1 --plugins babel-plugin-add-module-exports,babel-plugin-transform-class-properties,babel-plugin-transform-object-rest-spread,babel-plugin-transform-react-jsx,babel-plugin-transform-runtime" }, "repository": { "type": "git", @@ -24,7 +24,7 @@ }, "homepage": "https://github.com/rma-consulting/react-easy-chart#readme", "devDependencies": { - "babel-cli": "^6.11.4", + "babel-cli": "^6.26.0", "babel-core": "^6.11.4", "babel-eslint": "^6.1.2", "babel-loader": "^6.2.4", @@ -33,7 +33,7 @@ "babel-plugin-transform-object-rest-spread": "^6.8.0", "babel-plugin-transform-react-jsx": "^6.8.0", "babel-plugin-transform-runtime": "^6.9.0", - "babel-preset-es2015": "^6.9.0", + "babel-preset-env": "^1.6.1", "babel-preset-react": "^6.11.1", "babel-preset-stage-0": "^6.5.0", "babel-preset-stage-1": "^6.5.0", @@ -71,10 +71,11 @@ "open": "0.0.5", "phantomjs-polyfill": "0.0.2", "phantomjs-prebuilt": "2.1.14", - "react": "^15.5.0", - "react-addons-test-utils": "^15.5.0", - "react-dom": "^15.5.0", - "react-scrollspy": "^2.1.1", + "prop-types": "^15.6.0", + "react": "^16.2.0", + "react-dom": "^16.2.0", + "react-scrollspy": "^3.0.2", + "react-test-renderer": "^16.2.0", "rimraf": "^2.4.4", "sinon": "^1.17.4", "sinon-chai": "^2.8.0", @@ -89,9 +90,8 @@ "d3-time-format": "^2.0.3", "lodash.merge": "^4.0.1", "object-hash": "^1.1.4", - "prop-types": "^15.6.0", "radium": "^0.19.1", - "react-faux-dom": "^2.5.0" + "react-faux-dom": "^4.1.0" }, "peerDependencies": { "react": "^15.5.0 || ^16.0.0", diff --git a/tests/area-chart/area-chart.test.js b/tests/area-chart/area-chart.test.js index 92c5da6..039066c 100644 --- a/tests/area-chart/area-chart.test.js +++ b/tests/area-chart/area-chart.test.js @@ -3,10 +3,11 @@ import React from 'react'; import ReactDOM from 'react-dom'; -import ReactTestUtils from 'react-addons-test-utils'; +import ShallowRenderer from 'react-test-renderer/shallow'; import chai, { expect } from 'chai'; // { should as shouldFactory, expect } from 'chai'; import sinon from 'sinon'; import spies from 'chai-spies'; +import ReactTestUtils from 'react-dom/test-utils'; import { AreaChart } from 'react-easy-chart'; // const should = shouldFactory(); @@ -627,7 +628,7 @@ describe('AreaChart component', () => { describe('Rendering the AreaChart', () => { describe('Always', () => { - const renderer = ReactTestUtils.createRenderer(); + const renderer = new ShallowRenderer(); renderer.render( { describe('Rendering the BarChart', () => { describe('Always', () => { - const renderer = ReactTestUtils.createRenderer(); + const renderer = new ShallowRenderer(); renderer.render( { it(`Should render an unordered list with correct number of list items and show the correct label and color for each item`, () => { - const shallowRenderer = ReactTestUtils.createRenderer(); + const shallowRenderer = new ShallowRenderer(); shallowRenderer.render(); const vDom = shallowRenderer.getRenderOutput(); expect(vDom.type).to.equal('div'); @@ -61,7 +62,7 @@ describe('Legend component', () => { }); it('Should set li class prop to horizontal if horizontal is true', () => { - const shallowRenderer = ReactTestUtils.createRenderer(); + const shallowRenderer = new ShallowRenderer(); shallowRenderer.render(); const vDom = shallowRenderer.getRenderOutput(); const li = vDom.props.children[1].props.children[0]; @@ -69,7 +70,7 @@ describe('Legend component', () => { }); it('Should render custom icon colors if a config is provided', () => { - const shallowRenderer = ReactTestUtils.createRenderer(); + const shallowRenderer = new ShallowRenderer(); shallowRenderer.render(); const vDom = shallowRenderer.getRenderOutput(); const ul = vDom.props.children[1]; diff --git a/tests/line-chart/line-chart.test.js b/tests/line-chart/line-chart.test.js index 55ca2cd..da3db27 100644 --- a/tests/line-chart/line-chart.test.js +++ b/tests/line-chart/line-chart.test.js @@ -3,10 +3,11 @@ import React from 'react'; import ReactDOM from 'react-dom'; -import ReactTestUtils from 'react-addons-test-utils'; +import ShallowRenderer from 'react-test-renderer/shallow'; import chai, { expect } from 'chai'; // { should as shouldFactory, expect } from 'chai'; import sinon from 'sinon'; import spies from 'chai-spies'; +import ReactTestUtils from 'react-dom/test-utils'; import { LineChart } from 'react-easy-chart'; // const should = shouldFactory(); @@ -608,7 +609,7 @@ describe('LineChart component', () => { describe('Rendering the LineChart', () => { describe('Always', () => { - const renderer = ReactTestUtils.createRenderer(); + const renderer = new ShallowRenderer(); renderer.render( { describe('Rendering the PieChart', () => { describe('Always', () => { - const renderer = ReactTestUtils.createRenderer(); + const renderer = new ShallowRenderer(); renderer.render( { describe('Rendering the PieChart', () => { describe('Always', () => { - const renderer = ReactTestUtils.createRenderer(); + const renderer = new ShallowRenderer(); renderer.render( { describe('Rendering the ScatterplotChart', () => { describe('Always', () => { - const renderer = ReactTestUtils.createRenderer(); + const renderer = new ShallowRenderer(); renderer.render( { describe('Rendering the ScatterplotChart', () => { describe('Always', () => { - const renderer = ReactTestUtils.createRenderer(); + const renderer = new ShallowRenderer(); renderer.render(