diff --git a/dist/react-progressbar.js b/dist/react-progressbar.js index 262572c..9f564bc 100644 --- a/dist/react-progressbar.js +++ b/dist/react-progressbar.js @@ -1,18 +1,30 @@ (function (global, factory) { if (typeof define === "function" && define.amd) { - define(['module', 'react', 'react-dom', 'lodash.isequal', 'progressbar.js'], factory); + define(['module', 'react', 'react-dom', 'lodash/isEqual', 'progressbar.js'], factory); } else if (typeof exports !== "undefined") { - factory(module, require('react'), require('react-dom'), require('lodash.isequal'), require('progressbar.js')); + factory(module, require('react'), require('react-dom'), require('lodash/isEqual'), require('progressbar.js')); } else { var mod = { exports: {} }; - factory(mod, global.react, global.reactDom, global.lodash, global.progressbar); + factory(mod, global.react, global.reactDom, global.isEqual, global.progressbar); global.main = mod.exports; } -})(this, function (module, React, ReactDom, isEqual, ProgressBar) { +})(this, function (module, _react, _reactDom, _isEqual, _progressbar) { 'use strict'; + var _react2 = _interopRequireDefault(_react); + + var _isEqual2 = _interopRequireDefault(_isEqual); + + var _progressbar2 = _interopRequireDefault(_progressbar); + + function _interopRequireDefault(obj) { + return obj && obj.__esModule ? obj : { + default: obj + }; + } + var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; @@ -27,118 +39,220 @@ return target; }; - var Shape = React.createClass({ - displayName: 'Shape', - - getDefaultProps: function getDefaultProps() { - return { - ShapeClass: null, - options: {}, - progress: 0, - text: null, - initialAnimate: false, - containerStyle: {}, - containerClassName: '.progressbar-container' - }; - }, + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } + + var _createClass = function () { + function defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + + return function (Constructor, protoProps, staticProps) { + if (protoProps) defineProperties(Constructor.prototype, protoProps); + if (staticProps) defineProperties(Constructor, staticProps); + return Constructor; + }; + }(); + + function _possibleConstructorReturn(self, call) { + if (!self) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } + + return call && (typeof call === "object" || typeof call === "function") ? call : self; + } + + function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); + } + + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + enumerable: false, + writable: true, + configurable: true + } + }); + if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; + } - getInitialState: function getInitialState() { - return { + var Shape = function (_Component) { + _inherits(Shape, _Component); + + function Shape(props) { + _classCallCheck(this, Shape); + + var _this = _possibleConstructorReturn(this, (Shape.__proto__ || Object.getPrototypeOf(Shape)).call(this, props)); + + _this.state = { shape: null }; - }, + return _this; + } - render: function render() { - var style = this.props.containerStyle; - var className = this.props.containerClassName; + _createClass(Shape, [{ + key: 'render', + value: function render() { + var _props = this.props, + style = _props.style, + className = _props.className; - return React.createElement('div', { className: className, style: style, ref: 'progressBar' }); - }, - componentWillReceiveProps: function componentWillReceiveProps(nextProps) { - if (!isEqual(this.props.options, nextProps.options)) { - this._destroy(); - this._create(nextProps, this.props); - return; + return _react2.default.createElement('div', { className: className, style: style, ref: 'progressBar' }); } + }, { + key: 'componentWillReceiveProps', + value: function componentWillReceiveProps(nextProps) { + if (!(0, _isEqual2.default)(this.props.options, nextProps.options)) { + this._destroy(); + this._create(nextProps, this.props); - this._animateProgress(nextProps.progress); - this._setText(nextProps.text); - }, + return; + } - componentDidMount: function componentDidMount() { - this._create(this.props); - }, + this._animateProgress(nextProps.progress); + this._setText(nextProps.text); + } + }, { + key: 'componentDidMount', + value: function componentDidMount() { + this._create(this.props); + } + }, { + key: 'componentWillUnmount', + value: function componentWillUnmount() { + this._destroy(); + } + }, { + key: '_create', + value: function _create(props, oldProps) { + if (this.state.shape !== null) { + throw new Error('Progressbar is already created'); + } - componentWillUnmount: function componentWillUnmount() { - this._destroy(); - }, + // setState function is not used to prevent a new render cycle + // This handling happens outside of React component's lifecycle + var container = (0, _reactDom.findDOMNode)(this.refs.progressBar); - _create: function _create(props, oldProps) { - if (this.state.shape !== null) { - throw new Error('Progressbar is already created'); - } + this.state.shape = new props.ShapeClass(container, props.options); - // setState function is not used to prevent a new render cycle - // This handling happens outside of React component's lifecycle - var container = ReactDom.findDOMNode(this.refs.progressBar); - this.state.shape = new props.ShapeClass(container, props.options); + if (props.initialAnimate) { + if (oldProps) { + this._setProgress(oldProps.progress); + } - if (props.initialAnimate) { - if (oldProps) { - this._setProgress(oldProps.progress); + this._animateProgress(props.progress); + } else { + this._setProgress(props.progress); } - this._animateProgress(props.progress); - } else { - this._setProgress(props.progress); + this._setText(props.text); + } + }, { + key: '_destroy', + value: function _destroy() { + if (this.state.shape) { + this.state.shape.destroy(); + this.state.shape = null; + } + } + }, { + key: '_animateProgress', + value: function _animateProgress(progress) { + this.state.shape.animate(progress); } + }, { + key: '_setProgress', + value: function _setProgress(progress) { + this.state.shape.set(progress); + } + }, { + key: '_setText', + value: function _setText(text) { + if (text) { + this.state.shape.setText(text); + } + } + }]); - this._setText(props.text); - }, + return Shape; + }(_react.Component); - _destroy: function _destroy() { - if (this.state.shape) { - this.state.shape.destroy(); - this.state.shape = null; - } - }, + ; - _animateProgress: function _animateProgress(progress) { - this.state.shape.animate(progress); - }, + var Line = function (_Component2) { + _inherits(Line, _Component2); - _setProgress: function _setProgress(progress) { - this.state.shape.set(progress); - }, + function Line() { + _classCallCheck(this, Line); - _setText: function _setText(text) { - if (text) { - this.state.shape.setText(text); - } + return _possibleConstructorReturn(this, (Line.__proto__ || Object.getPrototypeOf(Line)).apply(this, arguments)); } - }); - var Line = React.createClass({ - displayName: 'Line', - render: function render() { - return React.createElement(Shape, _extends({}, this.props, { ShapeClass: ProgressBar.Line })); - } - }); + _createClass(Line, [{ + key: 'render', + value: function render() { + return _react2.default.createElement(Shape, _extends({}, this.props, { ShapeClass: _progressbar2.default.Line })); + } + }]); - var Circle = React.createClass({ - displayName: 'Circle', - render: function render() { - return React.createElement(Shape, _extends({}, this.props, { ShapeClass: ProgressBar.Circle })); + return Line; + }(_react.Component); + + ; + + var Circle = function (_Component3) { + _inherits(Circle, _Component3); + + function Circle() { + _classCallCheck(this, Circle); + + return _possibleConstructorReturn(this, (Circle.__proto__ || Object.getPrototypeOf(Circle)).apply(this, arguments)); } - }); - var SemiCircle = React.createClass({ - displayName: 'SemiCircle', - render: function render() { - return React.createElement(Shape, _extends({}, this.props, { ShapeClass: ProgressBar.SemiCircle })); + _createClass(Circle, [{ + key: 'render', + value: function render() { + return _react2.default.createElement(Shape, _extends({}, this.props, { ShapeClass: _progressbar2.default.Circle })); + } + }]); + + return Circle; + }(_react.Component); + + ; + + var SemiCircle = function (_Component4) { + _inherits(SemiCircle, _Component4); + + function SemiCircle() { + _classCallCheck(this, SemiCircle); + + return _possibleConstructorReturn(this, (SemiCircle.__proto__ || Object.getPrototypeOf(SemiCircle)).apply(this, arguments)); } - }); + + _createClass(SemiCircle, [{ + key: 'render', + value: function render() { + return _react2.default.createElement(Shape, _extends({}, this.props, { ShapeClass: _progressbar2.default.SemiCircle })); + } + }]); + + return SemiCircle; + }(_react.Component); + + ; module.exports = { Line: Line, diff --git a/local-dev/main.js b/local-dev/main.js index 2e80c15..25d298d 100644 --- a/local-dev/main.js +++ b/local-dev/main.js @@ -1,24 +1,27 @@ -var React = require('react'); -var ReactDom = require('react-dom'); -var ProgressBar = require('../src/main.js'); -var Circle = ProgressBar.Circle; +import React, { Component } from 'react'; +import { render } from 'react-dom'; +import { Circle } from '../src/main.js'; -var App = React.createClass({ - getInitialState: function() { - return { +class App extends Component { + constructor(props) { + super(props); + + this.state = { progress: 0.1, options: {} }; - }, + } - render: function() { + render() { return ; - }, + } - componentDidMount: function() { - var self = this; + componentDidMount() { + const self = this; + setTimeout(function() { console.log('setstate') + self.setState({ progress: 1 }); @@ -26,16 +29,16 @@ var App = React.createClass({ setTimeout(function() { console.log('setstate') + self.setState({ initialAnimate: true, progress: 1 }); }, 500); - } -}); +}; -ReactDom.render( +render( , - document.querySelector('body') + document.querySelector('#progress') ); diff --git a/package.json b/package.json index c8d30a0..4ed0384 100644 --- a/package.json +++ b/package.json @@ -31,8 +31,8 @@ "dependencies": { "lodash.isequal": "^4.1.4", "progressbar.js": "^1.0.1", - "react": "^15.0.1", - "react-dom": "^15.0.1" + "react": "^16.0.0", + "react-dom": "^16.0.0" }, "devDependencies": { "babel": "^6.5.2", @@ -65,11 +65,11 @@ }, "scripts": { "start": "concurrent 'npm run serve' 'npm run watch-js' 'open http://localhost:8080'", - "watch-js": "watchify local-dev/main.js -t reactify -o local-dev/bundle.js --debug --verbose", + "watch-js": "watchify local-dev/main.js -o local-dev/bundle.js --debug --verbose", "build": "babel src/main.js -o ./dist/react-progressbar.js", "serve": "http-server ./local-dev -c 0", "lint": "./tools/lint.sh", "jscs": "jscs ./src ./test", "eslint": "eslint --ext .js ./src ./test" } -} \ No newline at end of file +} diff --git a/src/main.js b/src/main.js index 250404e..a3a6f28 100644 --- a/src/main.js +++ b/src/main.js @@ -1,61 +1,62 @@ -var React = require('react'); -var ReactDom = require('react-dom'); -var isEqual = require('lodash.isequal'); -var ProgressBar = require('progressbar.js'); - -var Shape = React.createClass({ - getDefaultProps: function getDefaultProps() { - return { - ShapeClass: null, - options: {}, - progress: 0, - text: null, - initialAnimate: false, - containerStyle: {}, - containerClassName: '.progressbar-container' - }; - }, +import React, { Component } from 'react'; +import { findDOMNode } from 'react-dom'; +import isEqual from 'lodash/isEqual'; +import ProgressBar from 'progressbar.js'; + +class Shape extends Component { + defaultProps: { + ShapeClass: null, + options: {}, + progress: 0, + text: null, + initialAnimate: false, + containerStyle: {}, + containerClassName: '.progressbar-container' + } + + constructor(props) { + super(props); - getInitialState: function getInitialState() { - return { + this.state = { shape: null }; - }, + } - render: function render() { - var style = this.props.containerStyle; - var className = this.props.containerClassName; + render() { + const {style, className} = this.props; return
; - }, + } - componentWillReceiveProps: function componentWillReceiveProps(nextProps) { + componentWillReceiveProps(nextProps) { if (!isEqual(this.props.options, nextProps.options)) { this._destroy(); this._create(nextProps, this.props); + return; } this._animateProgress(nextProps.progress); this._setText(nextProps.text); - }, + } - componentDidMount: function componentDidMount() { + componentDidMount() { this._create(this.props); - }, + } - componentWillUnmount: function componentWillUnmount() { - this._destroy() - }, + componentWillUnmount() { + this._destroy(); + } - _create: function _create(props, oldProps) { + _create(props, oldProps) { if (this.state.shape !== null) { throw new Error('Progressbar is already created'); } // setState function is not used to prevent a new render cycle // This handling happens outside of React component's lifecycle - var container = ReactDom.findDOMNode(this.refs.progressBar); + var container = findDOMNode(this.refs.progressBar); + this.state.shape = new props.ShapeClass( container, props.options @@ -72,47 +73,47 @@ var Shape = React.createClass({ } this._setText(props.text); - }, + } - _destroy: function _destroy() { + _destroy() { if (this.state.shape) { this.state.shape.destroy(); this.state.shape = null; } - }, + } - _animateProgress: function _animateProgress(progress) { + _animateProgress(progress) { this.state.shape.animate(progress); - }, + } - _setProgress: function _setProgress(progress) { + _setProgress(progress) { this.state.shape.set(progress); - }, + } - _setText: function _setText(text) { + _setText(text) { if (text) { this.state.shape.setText(text); } } -}); +}; -var Line = React.createClass({ +class Line extends Component { render() { return ; } -}); +}; -var Circle = React.createClass({ +class Circle extends Component { render() { return ; } -}); +}; -var SemiCircle = React.createClass({ +class SemiCircle extends Component { render() { return ; } -}); +}; module.exports = { Line: Line,