UNPKG

react-cm-ui

Version:
241 lines (204 loc) 12 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _gsap = require("gsap"); var _classnames = _interopRequireDefault(require("classnames")); var _propTypes = _interopRequireDefault(require("prop-types")); var _react = _interopRequireDefault(require("react")); var _constants = require("../../global/constants"); var _withTheme = _interopRequireDefault(require("../../styles/withTheme")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } var propTypes = { className: _propTypes["default"].string, color: _propTypes["default"].oneOf(['backgroundColorHighlight', 'backgroundColorStatic']), dataTestId: _propTypes["default"].string, id: _propTypes["default"].string, size: _propTypes["default"].number, style: _propTypes["default"].shape({}), title: _propTypes["default"].string, theme: _propTypes["default"].shape({ palette: _propTypes["default"].shape({ cyan: _propTypes["default"].shape({}), grey: _propTypes["default"].shape({}) }) }) }; var BLOCK_CLASS = 'activity_indicator'; var defaultProps = { className: undefined, color: 'backgroundColorHighlight', dataTestId: "".concat(_constants.UI_CLASS_NAME, "-").concat(BLOCK_CLASS), id: undefined, size: 68, style: {}, theme: undefined, title: 'Loading' }; var BAR_CLASS = "".concat(BLOCK_CLASS, "--bar"); var BAR_HEIGHT = 68; var CIRCLE_CLASS = "".concat(BLOCK_CLASS, "--circle"); var DURATION_DOWN = 0.55; var DURATION_UP = 0.3; var CIRCLE_SIZE = 16; var CIRCLE_UP_Y_POS = -(BAR_HEIGHT - CIRCLE_SIZE); var ActivityIndicator = /*#__PURE__*/function (_React$PureComponent) { _inherits(ActivityIndicator, _React$PureComponent); var _super = _createSuper(ActivityIndicator); function ActivityIndicator() { var _this; _classCallCheck(this, ActivityIndicator); _this = _super.call(this); _this.barTweenLeft = new _gsap.TimelineMax(); _this.barTweenMiddle = new _gsap.TimelineMax(); _this.barTweenRight = new _gsap.TimelineMax(); _this.circleTweenLeft = new _gsap.TimelineMax(); _this.circleTweenMiddle = new _gsap.TimelineMax(); _this.circleTweenRight = new _gsap.TimelineMax(); return _this; } _createClass(ActivityIndicator, [{ key: "componentDidMount", value: function componentDidMount() { // const principleDefaultEase = CustomEase.create('custom', 'M0,0 C0.302,0.116 0.302,1 1,1') var barToUpOptions = { ease: _gsap.Power1.easeOut, // eslint-disable-line no-undef height: BAR_HEIGHT, opacity: 1 }; var barToDownOptions = { ease: _gsap.Back.easeOut.config(1.5), // eslint-disable-line no-undef height: CIRCLE_SIZE, opacity: 0 }; var circleToUpOptions = { ease: _gsap.Power1.easeOut, // eslint-disable-line no-undef y: CIRCLE_UP_Y_POS }; var circleToDownOptions = { ease: _gsap.Back.easeOut.config(1.5), // eslint-disable-line no-undef y: 0 }; this.barTweenLeft.delay(0).set(".".concat(BAR_CLASS, "-left"), { height: CIRCLE_SIZE, opacity: 0 }).to(".".concat(BAR_CLASS, "-left"), DURATION_UP, barToUpOptions).to(".".concat(BAR_CLASS, "-left"), DURATION_DOWN, barToDownOptions).repeat(-1).repeatDelay(0.5); this.barTweenMiddle.delay(0.45).set(".".concat(BAR_CLASS, "-middle"), { height: CIRCLE_SIZE, opacity: 0 }).to(".".concat(BAR_CLASS, "-middle"), DURATION_UP, barToUpOptions).to(".".concat(BAR_CLASS, "-middle"), DURATION_DOWN, barToDownOptions).repeat(-1).repeatDelay(0.5); this.barTweenRight.delay(0.9).set(".".concat(BAR_CLASS, "-right"), { height: CIRCLE_SIZE, opacity: 0 }).to(".".concat(BAR_CLASS, "-right"), DURATION_UP, barToUpOptions).to(".".concat(BAR_CLASS, "-right"), DURATION_DOWN, barToDownOptions).repeat(-1).repeatDelay(0.5); this.circleTweenLeft.delay(0).set(".".concat(BAR_CLASS, "-left"), { y: 0 }).to(".".concat(CIRCLE_CLASS, "-left"), DURATION_UP, circleToUpOptions).to(".".concat(CIRCLE_CLASS, "-left"), DURATION_DOWN, circleToDownOptions).repeat(-1).repeatDelay(0.5); this.circleTweenMiddle.delay(0.45).set(".".concat(BAR_CLASS, "-middle"), { y: 0 }).to(".".concat(CIRCLE_CLASS, "-middle"), DURATION_UP, circleToUpOptions).to(".".concat(CIRCLE_CLASS, "-middle"), DURATION_DOWN, circleToDownOptions).repeat(-1).repeatDelay(0.5); this.circleTweenRight.delay(0.9).set(".".concat(BAR_CLASS, "-right"), { y: 0 }).to(".".concat(CIRCLE_CLASS, "-right"), DURATION_UP, circleToUpOptions).to(".".concat(CIRCLE_CLASS, "-right"), DURATION_DOWN, circleToDownOptions).repeat(-1).repeatDelay(0.5); } }, { key: "render", value: function render() { var _this$props = this.props, className = _this$props.className, color = _this$props.color, dataTestId = _this$props.dataTestId, id = _this$props.id, size = _this$props.size, style = _this$props.style, theme = _this$props.theme, title = _this$props.title; var _theme$palette = theme.palette, cyan = _theme$palette.cyan, grey = _theme$palette.grey; var rootClasses = (0, _classnames["default"])('ui', BLOCK_CLASS, className); var transformScaleDecimal = 1 / 68 * size; var backgroundColorStyle; switch (color) { case 'backgroundColorStatic': backgroundColorStyle = grey[400]; break; case 'backgroundColorHighlight': backgroundColorStyle = cyan[500]; break; default: break; } return /*#__PURE__*/_react["default"].createElement("div", { className: rootClasses, "data-testid": dataTestId, id: id, style: _objectSpread(_objectSpread({}, style), {}, { transform: "scale(".concat(transformScaleDecimal, ")"), transformOrigin: 0 }), title: title }, /*#__PURE__*/_react["default"].createElement("div", { className: "".concat(BLOCK_CLASS, "--left") }, /*#__PURE__*/_react["default"].createElement("div", { className: "".concat(CIRCLE_CLASS, " ").concat(CIRCLE_CLASS, "-left"), style: { backgroundColor: backgroundColorStyle } }), /*#__PURE__*/_react["default"].createElement("div", { className: "".concat(BAR_CLASS, " ").concat(BAR_CLASS, "-left"), style: { backgroundColor: backgroundColorStyle } })), /*#__PURE__*/_react["default"].createElement("div", { className: "".concat(BLOCK_CLASS, "--middle") }, /*#__PURE__*/_react["default"].createElement("div", { className: "".concat(CIRCLE_CLASS, " ").concat(CIRCLE_CLASS, "-middle"), style: { backgroundColor: backgroundColorStyle } }), /*#__PURE__*/_react["default"].createElement("div", { className: "".concat(BAR_CLASS, " ").concat(BAR_CLASS, "-middle"), style: { backgroundColor: backgroundColorStyle } })), /*#__PURE__*/_react["default"].createElement("div", { className: "".concat(BLOCK_CLASS, "--right") }, /*#__PURE__*/_react["default"].createElement("div", { className: "".concat(CIRCLE_CLASS, " ").concat(CIRCLE_CLASS, "-right"), style: { backgroundColor: backgroundColorStyle } }), /*#__PURE__*/_react["default"].createElement("div", { className: "".concat(BAR_CLASS, " ").concat(BAR_CLASS, "-right"), style: { backgroundColor: backgroundColorStyle } }))); } }]); return ActivityIndicator; }(_react["default"].PureComponent); ActivityIndicator.propTypes = propTypes; ActivityIndicator.defaultProps = defaultProps; var _default = (0, _withTheme["default"])(ActivityIndicator); exports["default"] = _default;