UNPKG

6.96 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 pacman = [
44 react_1.keyframes(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n 0% {transform: rotate(0deg)}\n 50% {transform: rotate(-44deg)}\n "], ["\n 0% {transform: rotate(0deg)}\n 50% {transform: rotate(-44deg)}\n "]))),
45 react_1.keyframes(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n 0% {transform: rotate(0deg)}\n 50% {transform: rotate(44deg)}\n "], ["\n 0% {transform: rotate(0deg)}\n 50% {transform: rotate(44deg)}\n "])))
46];
47var Loader = /** @class */ (function (_super) {
48 __extends(Loader, _super);
49 function Loader() {
50 var _this = _super !== null && _super.apply(this, arguments) || this;
51 _this.ball = function () {
52 var size = _this.props.size;
53 var _a = helpers_1.parseLengthAndUnit(size), value = _a.value, unit = _a.unit;
54 return react_1.keyframes(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n 75% {opacity: 0.7}\n 100% {transform: translate(", ", ", ")}\n "], ["\n 75% {opacity: 0.7}\n 100% {transform: translate(", ", ", ")}\n "])), "" + -4 * value + unit, "" + -value / 4 + unit);
55 };
56 _this.ballStyle = function (i) {
57 var _a = _this.props, color = _a.color, margin = _a.margin, size = _a.size, speedMultiplier = _a.speedMultiplier;
58 var _b = helpers_1.parseLengthAndUnit(size), value = _b.value, unit = _b.unit;
59 return react_1.css(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n width: ", ";\n height: ", ";\n background-color: ", ";\n margin: ", ";\n border-radius: 100%;\n transform: translate(0, ", ");\n position: absolute;\n top: ", ";\n left: ", ";\n animation: ", " ", "s ", "s infinite linear;\n animation-fill-mode: both;\n "], ["\n width: ", ";\n height: ", ";\n background-color: ", ";\n margin: ", ";\n border-radius: 100%;\n transform: translate(0, ", ");\n position: absolute;\n top: ", ";\n left: ", ";\n animation: ", " ", "s ", "s infinite linear;\n animation-fill-mode: both;\n "])), "" + value / 3 + unit, "" + value / 3 + unit, color, helpers_1.cssValue(margin), "" + -value / 4 + unit, "" + value + unit, "" + value * 4 + unit, _this.ball(), 1 / speedMultiplier, i * 0.25);
60 };
61 _this.s1 = function () {
62 return helpers_1.cssValue(_this.props.size) + " solid transparent";
63 };
64 _this.s2 = function () {
65 var color = _this.props.color;
66 return helpers_1.cssValue(_this.props.size) + " solid " + color;
67 };
68 _this.pacmanStyle = function (i) {
69 var _a = _this.props, size = _a.size, speedMultiplier = _a.speedMultiplier;
70 var s1 = _this.s1();
71 var s2 = _this.s2();
72 return react_1.css(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n width: 0;\n height: 0;\n border-right: ", ";\n border-top: ", ";\n border-left: ", ";\n border-bottom: ", ";\n border-radius: ", ";\n position: absolute;\n animation: ", " ", "s infinite ease-in-out;\n animation-fill-mode: both;\n "], ["\n width: 0;\n height: 0;\n border-right: ", ";\n border-top: ", ";\n border-left: ", ";\n border-bottom: ", ";\n border-radius: ", ";\n position: absolute;\n animation: ", " ", "s infinite ease-in-out;\n animation-fill-mode: both;\n "])), s1, i === 0 ? s1 : s2, s2, i === 0 ? s2 : s1, helpers_1.cssValue(size), pacman[i], 0.8 / speedMultiplier);
73 };
74 _this.wrapper = function () {
75 return react_1.css(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n position: relative;\n font-size: 0;\n height: ", ";\n width: ", ";\n "], ["\n position: relative;\n font-size: 0;\n height: ", ";\n width: ", ";\n "])), helpers_1.cssValue(_this.props.size), helpers_1.cssValue(_this.props.size));
76 };
77 _this.pac = function () { return _this.pacmanStyle(0); };
78 _this.man = function () { return _this.pacmanStyle(1); };
79 return _this;
80 }
81 Loader.prototype.render = function () {
82 var _a = this.props, loading = _a.loading, css = _a.css;
83 return loading ? (react_1.jsx("span", { css: [this.wrapper(), css] },
84 react_1.jsx("span", { css: this.pac() }),
85 react_1.jsx("span", { css: this.man() }),
86 react_1.jsx("span", { css: this.ballStyle(2) }),
87 react_1.jsx("span", { css: this.ballStyle(3) }),
88 react_1.jsx("span", { css: this.ballStyle(4) }),
89 react_1.jsx("span", { css: this.ballStyle(5) }))) : null;
90 };
91 Loader.defaultProps = helpers_1.sizeMarginDefaults(25);
92 return Loader;
93}(React.PureComponent));
94exports.default = Loader;
95var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6;