UNPKG

polestar-ui-kit

Version:

## Install

184 lines (142 loc) 7.26 kB
"use strict"; 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); } require("core-js/modules/es.array.concat"); require("core-js/modules/es.date.to-string"); require("core-js/modules/es.object.get-prototype-of"); require("core-js/modules/es.object.set-prototype-of"); require("core-js/modules/es.object.to-string"); require("core-js/modules/es.reflect.construct"); require("core-js/modules/es.regexp.to-string"); Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _react = _interopRequireDefault(require("react")); var _propTypes = _interopRequireDefault(require("prop-types")); var _classnames = _interopRequireDefault(require("classnames")); var _polestarIcons = _interopRequireDefault(require("polestar-icons")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": 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 Loading = function (_React$Component) { _inherits(Loading, _React$Component); var _super = _createSuper(Loading); function Loading(props) { var _this; _classCallCheck(this, Loading); _this = _super.call(this, props); _this.applyStyles = function () { if (_this.props.show) { if (!_this.props.fullscreen) { if (_this.props.detectParentHeightAuto && _this.loading.parentNode && _this.loading.parentNode.style) { var parentStyle = _this.loading.parentNode.style; if (parentStyle.position === '') { _this.loading.parentNode.style.position = 'relative'; } } } if (_this.props.spin3d) { _this.spinner.style.animation = "spin3d ".concat(_this.props.easing, " ").concat(_this.props.duration, "ms infinite"); } _this.spinner.style.textShadow = "0 0 .1em ".concat(_this.props.color); } }; _this.state = {}; return _this; } _createClass(Loading, [{ key: "componentDidMount", value: function componentDidMount() { this.applyStyles(); } }, { key: "componentDidUpdate", value: function componentDidUpdate() { this.applyStyles(); } }, { key: "render", value: function render() { var _this2 = this; var maskStyle; switch (this.props.mask) { case 'dark': { maskStyle = "rgba(0, 0, 0, ".concat(this.props.maskOpacity, ")"); break; } case 'light': { maskStyle = "rgba(255, 255, 255, ".concat(this.props.maskOpacity, ")"); break; } default: maskStyle = 'transparent'; } var containerStyle = { backgroundColor: maskStyle }; var spinnerStyle = { color: this.props.color, animationDuration: "".concat(this.props.duration, "ms"), animationTimingFunction: this.props.easing, fontSize: this.props.size }; return this.props.show && _react["default"].createElement("div", { className: (0, _classnames["default"])({ 'ps-loading': true, fullscreen: this.props.fullscreen }), ref: function ref(_ref2) { _this2.loading = _ref2; }, style: containerStyle }, _react["default"].createElement("div", { className: "ps-spinner", ref: function ref(_ref) { _this2.spinner = _ref; }, style: spinnerStyle }, this.props.spinner)); } }]); return Loading; }(_react["default"].Component); Loading.propTypes = { show: _propTypes["default"].bool, fullscreen: _propTypes["default"].bool, mask: _propTypes["default"].oneOf(['dark', 'light', 'none']), maskOpacity: _propTypes["default"].number, color: _propTypes["default"].string, spinner: _propTypes["default"].element, size: _propTypes["default"].number, duration: _propTypes["default"].number, easing: _propTypes["default"].string, spin3d: _propTypes["default"].bool, detectParentHeightAuto: _propTypes["default"].bool }; Loading.defaultProps = { show: true, fullscreen: false, mask: 'dark', maskOpacity: 0.5, color: 'white', spinner: _react["default"].createElement(_polestarIcons["default"], { name: "spinner" }), size: 30, duration: 1000, easing: 'linear', spin3d: false, detectParentHeightAuto: true }; var _default = Loading; exports["default"] = _default;