|
| 1 | +(function (global, factory) { |
| 2 | + if (typeof define === "function" && define.amd) { |
| 3 | + define(['module', 'react', 'react-dom', 'lodash.isequal', 'progressbar.js'], factory); |
| 4 | + } else if (typeof exports !== "undefined") { |
| 5 | + factory(module, require('react'), require('react-dom'), require('lodash.isequal'), require('progressbar.js')); |
| 6 | + } else { |
| 7 | + var mod = { |
| 8 | + exports: {} |
| 9 | + }; |
| 10 | + factory(mod, global.react, global.reactDom, global.lodash, global.progressbar); |
| 11 | + global.main = mod.exports; |
| 12 | + } |
| 13 | +})(this, function (module, React, ReactDom, isEqual, ProgressBar) { |
| 14 | + 'use strict'; |
| 15 | + |
| 16 | + var _extends = Object.assign || function (target) { |
| 17 | + for (var i = 1; i < arguments.length; i++) { |
| 18 | + var source = arguments[i]; |
| 19 | + |
| 20 | + for (var key in source) { |
| 21 | + if (Object.prototype.hasOwnProperty.call(source, key)) { |
| 22 | + target[key] = source[key]; |
| 23 | + } |
| 24 | + } |
| 25 | + } |
| 26 | + |
| 27 | + return target; |
| 28 | + }; |
| 29 | + |
| 30 | + var Shape = React.createClass({ |
| 31 | + displayName: 'Shape', |
| 32 | + |
| 33 | + getDefaultProps: function getDefaultProps() { |
| 34 | + return { |
| 35 | + ShapeClass: null, |
| 36 | + options: {}, |
| 37 | + progress: 0, |
| 38 | + text: null, |
| 39 | + initialAnimate: false, |
| 40 | + containerStyle: {}, |
| 41 | + containerClassName: '.progressbar-container' |
| 42 | + }; |
| 43 | + }, |
| 44 | + |
| 45 | + getInitialState: function getInitialState() { |
| 46 | + return { |
| 47 | + shape: null |
| 48 | + }; |
| 49 | + }, |
| 50 | + |
| 51 | + render: function render() { |
| 52 | + var style = this.props.containerStyle; |
| 53 | + var className = this.props.containerClassName; |
| 54 | + |
| 55 | + return React.createElement('div', { className: className, style: style, ref: 'progressBar' }); |
| 56 | + }, |
| 57 | + |
| 58 | + componentWillReceiveProps: function componentWillReceiveProps(nextProps) { |
| 59 | + if (!isEqual(this.props.options, nextProps.options)) { |
| 60 | + this._destroy(); |
| 61 | + this._create(nextProps, this.props); |
| 62 | + return; |
| 63 | + } |
| 64 | + |
| 65 | + this._animateProgress(nextProps.progress); |
| 66 | + this._setText(nextProps.text); |
| 67 | + }, |
| 68 | + |
| 69 | + componentDidMount: function componentDidMount() { |
| 70 | + this._create(this.props); |
| 71 | + }, |
| 72 | + |
| 73 | + componentWillUnmount: function componentWillUnmount() { |
| 74 | + this._destroy(); |
| 75 | + }, |
| 76 | + |
| 77 | + _create: function _create(props, oldProps) { |
| 78 | + if (this.state.shape !== null) { |
| 79 | + throw new Error('Progressbar is already created'); |
| 80 | + } |
| 81 | + |
| 82 | + // setState function is not used to prevent a new render cycle |
| 83 | + // This handling happens outside of React component's lifecycle |
| 84 | + var container = ReactDom.findDOMNode(this.refs.progressBar); |
| 85 | + this.state.shape = new props.ShapeClass(container, props.options); |
| 86 | + |
| 87 | + if (props.initialAnimate) { |
| 88 | + if (oldProps) { |
| 89 | + this._setProgress(oldProps.progress); |
| 90 | + } |
| 91 | + |
| 92 | + this._animateProgress(props.progress); |
| 93 | + } else { |
| 94 | + this._setProgress(props.progress); |
| 95 | + } |
| 96 | + |
| 97 | + this._setText(props.text); |
| 98 | + }, |
| 99 | + |
| 100 | + _destroy: function _destroy() { |
| 101 | + if (this.state.shape) { |
| 102 | + this.state.shape.destroy(); |
| 103 | + this.state.shape = null; |
| 104 | + } |
| 105 | + }, |
| 106 | + |
| 107 | + _animateProgress: function _animateProgress(progress) { |
| 108 | + this.state.shape.animate(progress); |
| 109 | + }, |
| 110 | + |
| 111 | + _setProgress: function _setProgress(progress) { |
| 112 | + this.state.shape.set(progress); |
| 113 | + }, |
| 114 | + |
| 115 | + _setText: function _setText(text) { |
| 116 | + if (text) { |
| 117 | + this.state.shape.setText(text); |
| 118 | + } |
| 119 | + } |
| 120 | + }); |
| 121 | + |
| 122 | + var Line = React.createClass({ |
| 123 | + displayName: 'Line', |
| 124 | + render: function render() { |
| 125 | + return React.createElement(Shape, _extends({}, this.props, { ShapeClass: ProgressBar.Line })); |
| 126 | + } |
| 127 | + }); |
| 128 | + |
| 129 | + var Circle = React.createClass({ |
| 130 | + displayName: 'Circle', |
| 131 | + render: function render() { |
| 132 | + return React.createElement(Shape, _extends({}, this.props, { ShapeClass: ProgressBar.Circle })); |
| 133 | + } |
| 134 | + }); |
| 135 | + |
| 136 | + var SemiCircle = React.createClass({ |
| 137 | + displayName: 'SemiCircle', |
| 138 | + render: function render() { |
| 139 | + return React.createElement(Shape, _extends({}, this.props, { ShapeClass: ProgressBar.SemiCircle })); |
| 140 | + } |
| 141 | + }); |
| 142 | + |
| 143 | + module.exports = { |
| 144 | + Line: Line, |
| 145 | + Circle: Circle, |
| 146 | + SemiCircle: SemiCircle |
| 147 | + }; |
| 148 | +}); |
0 commit comments