@cantonjs/react-scroll-view
Version:
react scroll component using intersection observer API
90 lines (73 loc) • 3.42 kB
JavaScript
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
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; }
import React, { Component } from 'react';
import PropTypes from 'prop-types';
var style = { transition: 'opacity 0.3s' };
var Loading = function (_Component) {
_inherits(Loading, _Component);
function Loading() {
var _ref;
var _temp, _this, _ret;
_classCallCheck(this, Loading);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Loading.__proto__ || Object.getPrototypeOf(Loading)).call.apply(_ref, [this].concat(args))), _this), _this.highlighted = 0, _this.circles = [6, 20, 34], _temp), _possibleConstructorReturn(_this, _ret);
}
_createClass(Loading, [{
key: 'componentDidMount',
value: function componentDidMount() {
var _this2 = this;
var length = this.circles.length;
this.intervalId = setInterval(function () {
var next = _this2.highlighted + 1;
_this2.highlighted = next >= length ? 0 : next;
_this2.forceUpdate();
}, 300);
}
}, {
key: 'shouldComponentUpdate',
value: function shouldComponentUpdate() {
return false;
}
}, {
key: 'componentWillUnmount',
value: function componentWillUnmount() {
clearInterval(this.intervalId);
}
}, {
key: 'render',
value: function render() {
var color = this.props.color,
highlighted = this.highlighted,
circles = this.circles;
return React.createElement(
'svg',
{
xmlns: 'http://www.w3.org/2000/svg',
viewBox: '0 0 40 40',
width: '32px',
height: '32px'
},
circles.map(function (cx, index) {
return React.createElement('circle', {
key: index,
cx: cx,
cy: '20',
r: '3',
fill: color,
opacity: highlighted === index ? 1 : 0.2,
style: style
});
})
);
}
}]);
return Loading;
}(Component);
Loading.propTypes = {
color: PropTypes.string.isRequired
};
export default Loading;