UNPKG

5.05 kBJavaScriptView Raw
1"use strict";
2var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
3 if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
4 return cooked;
5};
6var __extends = (this && this.__extends) || (function () {
7 var extendStatics = function (d, b) {
8 extendStatics = Object.setPrototypeOf ||
9 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
10 function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
11 return extendStatics(d, b);
12 };
13 return function (d, b) {
14 extendStatics(d, b);
15 function __() { this.constructor = d; }
16 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
17 };
18})();
19var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
20 if (k2 === undefined) k2 = k;
21 Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
22}) : (function(o, m, k, k2) {
23 if (k2 === undefined) k2 = k;
24 o[k2] = m[k];
25}));
26var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
27 Object.defineProperty(o, "default", { enumerable: true, value: v });
28}) : function(o, v) {
29 o["default"] = v;
30});
31var __importStar = (this && this.__importStar) || function (mod) {
32 if (mod && mod.__esModule) return mod;
33 var result = {};
34 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
35 __setModuleDefault(result, mod);
36 return result;
37};
38Object.defineProperty(exports, "__esModule", { value: true });
39/** @jsx jsx */
40var React = __importStar(require("react"));
41var react_1 = require("@emotion/react");
42var helpers_1 = require("./helpers");
43var grid = react_1.keyframes(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n 0% {transform: scale(1)}\n 50% {transform: scale(0.5); opacity: 0.7}\n 100% {transform: scale(1);opacity: 1}\n"], ["\n 0% {transform: scale(1)}\n 50% {transform: scale(0.5); opacity: 0.7}\n 100% {transform: scale(1);opacity: 1}\n"])));
44var random = function (top) { return Math.random() * top; };
45var Loader = /** @class */ (function (_super) {
46 __extends(Loader, _super);
47 function Loader() {
48 var _this = _super !== null && _super.apply(this, arguments) || this;
49 _this.style = function (rand) {
50 var _a = _this.props, color = _a.color, size = _a.size, margin = _a.margin, speedMultiplier = _a.speedMultiplier;
51 return react_1.css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n display: inline-block;\n background-color: ", ";\n width: ", ";\n height: ", ";\n margin: ", ";\n border-radius: 100%;\n animation-fill-mode: \"both\";\n animation: ", " ", "s ", "s infinite ease;\n "], ["\n display: inline-block;\n background-color: ", ";\n width: ", ";\n height: ", ";\n margin: ", ";\n border-radius: 100%;\n animation-fill-mode: \"both\";\n animation: ", " ", "s ", "s infinite ease;\n "])), color, helpers_1.cssValue(size), helpers_1.cssValue(size), helpers_1.cssValue(margin), grid, (rand / 100 + 0.6) / speedMultiplier, rand / 100 - 0.2);
52 };
53 _this.wrapper = function () {
54 var _a = _this.props, size = _a.size, margin = _a.margin;
55 var sizeWithUnit = helpers_1.parseLengthAndUnit(size);
56 var marginWithUnit = helpers_1.parseLengthAndUnit(margin);
57 var width = "" + (parseFloat(sizeWithUnit.value.toString()) * 3 + parseFloat(marginWithUnit.value.toString()) * 6) + sizeWithUnit.unit;
58 return react_1.css(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n width: ", ";\n font-size: 0;\n "], ["\n width: ", ";\n font-size: 0;\n "])), width);
59 };
60 return _this;
61 }
62 Loader.prototype.render = function () {
63 var _a = this.props, loading = _a.loading, css = _a.css;
64 return loading ? (react_1.jsx("span", { css: [this.wrapper(), css] },
65 react_1.jsx("span", { css: this.style(random(100)) }),
66 react_1.jsx("span", { css: this.style(random(100)) }),
67 react_1.jsx("span", { css: this.style(random(100)) }),
68 react_1.jsx("span", { css: this.style(random(100)) }),
69 react_1.jsx("span", { css: this.style(random(100)) }),
70 react_1.jsx("span", { css: this.style(random(100)) }),
71 react_1.jsx("span", { css: this.style(random(100)) }),
72 react_1.jsx("span", { css: this.style(random(100)) }),
73 react_1.jsx("span", { css: this.style(random(100)) }))) : null;
74 };
75 Loader.defaultProps = helpers_1.sizeMarginDefaults(15);
76 return Loader;
77}(React.PureComponent));
78exports.default = Loader;
79var templateObject_1, templateObject_2, templateObject_3;