UNPKG

spinners-react

Version:

Lightweight SVG/CSS spinners for React

140 lines (121 loc) 6.19 kB
(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, }; __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-round-filled-outer{40%,60%{transform:scale(0)}}@keyframes spinners-react-round-filled-center{30%,70%{transform:scale(0)}}@keyframes spinners-react-round-filled-inner{20%,80%{transform:scale(0)}}"; styleInject(css_248z); var animations = [ { r: 4 }, { name: 'spinners-react-round-filled-inner', r: 12.66, }, { name: 'spinners-react-round-filled-center', r: 20.32, }, { name: 'spinners-react-round-filled-outer', r: 27.5, }, ]; function Component(_a) { var _b = _a.speed, speed = _b === void 0 ? defaultProps$1.speed : _b, _c = _a.still, still = _c === void 0 ? defaultProps$1.still : _c, _d = _a.thickness, thickness = _d === void 0 ? defaultProps$1.thickness : _d, svgProps = __rest(_a, ["speed", "still", "thickness"]); return (React.createElement("svg", __assign({ fill: "none" }, svgProps, { viewBox: "0 0 66 66" }), animations.map(function (animation) { return (React.createElement("circle", { key: animation.name || 'still', cx: "33", cy: "33", fill: "currentColor", r: animation.r * (animation.name ? (thickness / 100) : 1), style: { opacity: animation.name ? 0.25 : 1, transformOrigin: 'center', animation: (!animation.name || still) ? 'none' : "".concat(animation.name, " ").concat(140 / speed, "s ease-in-out infinite"), } })); }))); } var SpinnerRoundFilled = withSharedProps(Component); exports.SpinnerRoundFilled = SpinnerRoundFilled; })); //# sourceMappingURL=SpinnerRoundFilled.js.map