spinners-react
Version:
Lightweight SVG/CSS spinners for React
127 lines (108 loc) • 6.53 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react')) :
typeof define === 'function' && define.amd ? define(['exports', 'react'], factory) :
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.SpinnersReact = {}, global.React));
})(this, (function (exports, React) { 'use strict';
/******************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
var e = new Error(message);
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
};
var defaultProps$1 = {
speed: 100,
still: false,
thickness: 100,
};
var secondaryColorDefaultProps = __assign(__assign({}, defaultProps$1), { secondaryColor: 'rgba(0,0,0,0.44)' });
var defaultProps = {
color: '#38ad48',
enabled: true,
size: 50,
style: {},
};
var normalizeSize = function (size) { return (parseFloat(size.toString()).toString() === size.toString()
? "".concat(size, "px")
: size.toString()); };
var withSharedProps = function (Component) {
function Wrapper(props) {
var _a = props.color, color = _a === void 0 ? defaultProps.color : _a, _b = props.enabled, enabled = _b === void 0 ? defaultProps.enabled : _b, _c = props.size, size = _c === void 0 ? defaultProps.size : _c, _d = props.style, style = _d === void 0 ? defaultProps.style : _d, otherProps = __rest(props, ["color", "enabled", "size", "style"]);
var componentProps = __assign(__assign({}, otherProps), { style: __assign({ color: color, overflow: 'visible', width: normalizeSize(size) }, style) });
if (!enabled)
return null;
return React.createElement(Component, __assign({}, componentProps));
}
return Wrapper;
};
function styleInject(css, ref) {
if ( ref === void 0 ) ref = {};
var insertAt = ref.insertAt;
if (typeof document === 'undefined') { return; }
var head = document.head || document.getElementsByTagName('head')[0];
var style = document.createElement('style');
style.type = 'text/css';
if (insertAt === 'top') {
if (head.firstChild) {
head.insertBefore(style, head.firstChild);
} else {
head.appendChild(style);
}
} else {
head.appendChild(style);
}
if (style.styleSheet) {
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
}
var css_248z = "@keyframes spinners-react-infinity{0%{stroke-dasharray:1,347;stroke-dashoffset:75}25%,75%{stroke-dasharray:17,330}50%{stroke-dasharray:1,347}to{stroke-dasharray:1,347;stroke-dashoffset:423}}";
styleInject(css_248z);
function Component(_a) {
var _b = _a.secondaryColor, secondaryColor = _b === void 0 ? secondaryColorDefaultProps.secondaryColor : _b, _c = _a.speed, speed = _c === void 0 ? secondaryColorDefaultProps.speed : _c, _d = _a.still, still = _d === void 0 ? secondaryColorDefaultProps.still : _d, _e = _a.thickness, thickness = _e === void 0 ? secondaryColorDefaultProps.thickness : _e, svgProps = __rest(_a, ["secondaryColor", "speed", "still", "thickness"]);
var strokeWidth = 7 * (thickness / 100);
var dashStyle = !still
? { animation: "spinners-react-infinity ".concat(140 / speed, "s linear infinite") }
: {};
return (React.createElement("svg", __assign({ fill: "none", viewBox: "0 0 131 55" }, svgProps),
React.createElement("defs", null,
React.createElement("path", { d: "M46.57 45.5138C36.346 55.4954 19.8919 55.4954 9.66794 45.5138C-0.55598 35.5321 -0.55598 19.4678 9.66794 9.48624C19.8919 -0.495412 36.346 -0.495412 46.57 9.48624L84.4303 45.5138C94.6543 55.4954 111.108 55.4954 121.332 45.5138C131.556 35.5321 131.556 19.4678 121.332 9.48624C111.108 -0.495412 94.6543 -0.495412 84.4303 9.48624L46.57 45.5138Z", id: "spinners-react-infinity-path" })),
React.createElement("use", { stroke: secondaryColor, strokeWidth: strokeWidth, xlinkHref: "#spinners-react-infinity-path" }),
React.createElement("use", { fill: "none", stroke: "currentColor", strokeDasharray: "1, 347", strokeDashoffset: "75", strokeLinecap: "round", strokeWidth: strokeWidth, style: dashStyle, xlinkHref: "#spinners-react-infinity-path" })));
}
var SpinnerInfinity = withSharedProps(Component);
exports.SpinnerInfinity = SpinnerInfinity;
}));
//# sourceMappingURL=SpinnerInfinity.js.map