UNPKG

7.66 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 fade = react_1.keyframes(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n 50% {opacity: 0.3}\n 100% {opacity: 1}\n"], ["\n 50% {opacity: 0.3}\n 100% {opacity: 1}\n"])));
44var Loader = /** @class */ (function (_super) {
45 __extends(Loader, _super);
46 function Loader() {
47 var _this = _super !== null && _super.apply(this, arguments) || this;
48 _this.radius = function () {
49 var margin = _this.props.margin;
50 var value = helpers_1.parseLengthAndUnit(margin).value;
51 return value + 18;
52 };
53 _this.quarter = function () {
54 return _this.radius() / 2 + _this.radius() / 5.5;
55 };
56 _this.style = function (i) {
57 var _a = _this.props, height = _a.height, width = _a.width, margin = _a.margin, color = _a.color, radius = _a.radius, speedMultiplier = _a.speedMultiplier;
58 return react_1.css(templateObject_2 || (templateObject_2 = __makeTemplateObject(["\n position: absolute;\n width: ", ";\n height: ", ";\n margin: ", ";\n background-color: ", ";\n border-radius: ", ";\n transition: 2s;\n animation-fill-mode: \"both\";\n animation: ", " ", "s ", "s infinite ease-in-out;\n "], ["\n position: absolute;\n width: ", ";\n height: ", ";\n margin: ", ";\n background-color: ", ";\n border-radius: ", ";\n transition: 2s;\n animation-fill-mode: \"both\";\n animation: ", " ", "s ", "s infinite ease-in-out;\n "])), helpers_1.cssValue(width), helpers_1.cssValue(height), helpers_1.cssValue(margin), color, helpers_1.cssValue(radius), fade, 1.2 / speedMultiplier, i * 0.12);
59 };
60 _this.wrapper = function () {
61 return react_1.css(templateObject_3 || (templateObject_3 = __makeTemplateObject(["\n position: relative;\n font-size: 0;\n top: ", "px;\n left: ", "px;\n width: ", "px;\n height: ", "px;\n "], ["\n position: relative;\n font-size: 0;\n top: ", "px;\n left: ", "px;\n width: ", "px;\n height: ", "px;\n "])), _this.radius(), _this.radius(), _this.radius() * 3, _this.radius() * 3);
62 };
63 _this.a = function () { return react_1.css(templateObject_4 || (templateObject_4 = __makeTemplateObject(["\n ", ";\n top: ", "px;\n left: 0;\n "], ["\n ", ";\n top: ", "px;\n left: 0;\n "])), _this.style(1), _this.radius()); };
64 _this.b = function () { return react_1.css(templateObject_5 || (templateObject_5 = __makeTemplateObject(["\n ", ";\n top: ", "px;\n left: ", "px;\n transform: rotate(-45deg);\n "], ["\n ", ";\n top: ", "px;\n left: ", "px;\n transform: rotate(-45deg);\n "])), _this.style(2), _this.quarter(), _this.quarter()); };
65 _this.c = function () { return react_1.css(templateObject_6 || (templateObject_6 = __makeTemplateObject(["\n ", ";\n top: 0;\n left: ", "px;\n transform: rotate(90deg);\n "], ["\n ", ";\n top: 0;\n left: ", "px;\n transform: rotate(90deg);\n "])), _this.style(3), _this.radius()); };
66 _this.d = function () { return react_1.css(templateObject_7 || (templateObject_7 = __makeTemplateObject(["\n ", ";\n top: ", "px;\n left: ", "px;\n transform: rotate(45deg);\n "], ["\n ", ";\n top: ", "px;\n left: ", "px;\n transform: rotate(45deg);\n "])), _this.style(4), -_this.quarter(), _this.quarter()); };
67 _this.e = function () { return react_1.css(templateObject_8 || (templateObject_8 = __makeTemplateObject(["\n ", ";\n top: ", "px;\n left: 0;\n "], ["\n ", ";\n top: ", "px;\n left: 0;\n "])), _this.style(5), -_this.radius()); };
68 _this.f = function () { return react_1.css(templateObject_9 || (templateObject_9 = __makeTemplateObject(["\n ", ";\n top: ", "px;\n left: ", "px;\n transform: rotate(-45deg);\n "], ["\n ", ";\n top: ", "px;\n left: ", "px;\n transform: rotate(-45deg);\n "])), _this.style(6), -_this.quarter(), -_this.quarter()); };
69 _this.g = function () { return react_1.css(templateObject_10 || (templateObject_10 = __makeTemplateObject(["\n ", ";\n top: 0;\n left: ", "px;\n transform: rotate(90deg);\n "], ["\n ", ";\n top: 0;\n left: ", "px;\n transform: rotate(90deg);\n "])), _this.style(7), -_this.radius()); };
70 _this.h = function () { return react_1.css(templateObject_11 || (templateObject_11 = __makeTemplateObject(["\n ", ";\n top: ", "px;\n left: ", "px;\n transform: rotate(45deg);\n "], ["\n ", ";\n top: ", "px;\n left: ", "px;\n transform: rotate(45deg);\n "])), _this.style(8), _this.quarter(), -_this.quarter()); };
71 return _this;
72 }
73 Loader.prototype.render = function () {
74 var _a = this.props, loading = _a.loading, css = _a.css;
75 return loading ? (react_1.jsx("span", { css: [this.wrapper(), css] },
76 react_1.jsx("span", { css: this.a() }),
77 react_1.jsx("span", { css: this.b() }),
78 react_1.jsx("span", { css: this.c() }),
79 react_1.jsx("span", { css: this.d() }),
80 react_1.jsx("span", { css: this.e() }),
81 react_1.jsx("span", { css: this.f() }),
82 react_1.jsx("span", { css: this.g() }),
83 react_1.jsx("span", { css: this.h() }))) : null;
84 };
85 Loader.defaultProps = helpers_1.heightWidthRadiusDefaults(15, 5, 2);
86 return Loader;
87}(React.PureComponent));
88exports.default = Loader;
89var templateObject_1, templateObject_2, templateObject_3, templateObject_4, templateObject_5, templateObject_6, templateObject_7, templateObject_8, templateObject_9, templateObject_10, templateObject_11;