UNPKG

spinners-react

Version:

Lightweight SVG/CSS spinners for React

330 lines (295 loc) 19.7 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, }; 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 (!css || 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$8 = "@keyframes spinners-react-circular{0%{stroke-dashoffset:306}50%{stroke-dasharray:40,134}to{stroke-dasharray:1,174;stroke-dashoffset:132}}"; styleInject(css_248z$8); function Component$8(_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 = 4 * (thickness / 100); var circleStyle = !still ? { animation: "spinners-react-circular ".concat(140 / speed, "s linear infinite") } : {}; return (React.createElement("svg", __assign({ fill: "none" }, svgProps, { viewBox: "0 0 66 66" }), React.createElement("circle", { cx: "33", cy: "33", fill: "none", r: "28", stroke: secondaryColor, strokeWidth: strokeWidth }), React.createElement("circle", { cx: "33", cy: "33", fill: "none", r: "28", stroke: "currentColor", strokeDasharray: "1, 174", strokeDashoffset: "306", strokeLinecap: "round", strokeWidth: strokeWidth, style: circleStyle }))); } var SpinnerCircular = withSharedProps(Component$8); var css_248z$7 = "@keyframes spinners-react-circular-fixed{0%{stroke-dashoffset:325}to{stroke-dashoffset:151}}"; styleInject(css_248z$7); function Component$7(_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 = 4 * (thickness / 100); var circleStyle = !still ? { animation: "spinners-react-circular-fixed ".concat(140 / speed, "s linear infinite") } : {}; return (React.createElement("svg", __assign({ fill: "none" }, svgProps, { viewBox: "0 0 66 66" }), React.createElement("circle", { cx: "33", cy: "33", fill: "none", r: "28", stroke: secondaryColor, strokeWidth: strokeWidth }), React.createElement("circle", { cx: "33", cy: "33", fill: "none", r: "28", stroke: "currentColor", strokeDasharray: "40, 134", strokeDashoffset: "325", strokeLinecap: "round", strokeWidth: strokeWidth, style: circleStyle }))); } var SpinnerCircularFixed = withSharedProps(Component$7); var css_248z$6 = "@keyframes spinners-react-circular-split{0%{stroke-dashoffset:1;stroke-dasharray:5,170}10%{stroke-dashoffset:13;stroke-dasharray:30,145}13%{stroke-dashoffset:-11;stroke-dasharray:5,145}50%{stroke-dasharray:5,0,5,165;stroke-dashoffset:-82}51%{stroke-dasharray:2,0,2,139;stroke-dashoffset:-85}61%{stroke-dasharray:15,0,15,165;stroke-dashoffset:-72}64%{stroke-dasharray:5,20,5,145;stroke-dashoffset:-72}}"; styleInject(css_248z$6); function Component$6(_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 = 4 * (thickness / 100); var circleStyle = !still ? { animation: "spinners-react-circular-split ".concat(140 / speed, "s linear infinite") } : {}; return (React.createElement("svg", __assign({ fill: "none" }, svgProps, { viewBox: "0 0 66 66" }), React.createElement("circle", { cx: "33", cy: "33", fill: "none", r: "28", stroke: secondaryColor, strokeWidth: strokeWidth }), React.createElement("circle", { cx: "33", cy: "33", fill: "none", r: "28", stroke: "currentColor", strokeDasharray: "5, 170", strokeDashoffset: "1", strokeLinecap: "round", strokeWidth: strokeWidth, style: circleStyle, transform: "rotate(-90 33 33)" }))); } var SpinnerCircularSplit = withSharedProps(Component$6); var css_248z$5 = "@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$5); function Component$5(_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$5); var css_248z$4 = "@keyframes spinners-react-dotted-center{0%,15%,85%,to{transform:scale(0)}40%,50%{transform:scale(1)}84%{transform:scale(.45)}}@keyframes spinners-react-dotted-shrink{50%{transform:translate(0)}}"; styleInject(css_248z$4); var coords$1 = [ { x: 22, y: -20 }, { x: 29, y: 0 }, { x: 22, y: 20 }, { x: 0, y: 30 }, { x: -23, y: 20 }, { x: -30, y: 0 }, { x: -23, y: -20 }, { x: 0, y: -30 }, ]; function Component$4(_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"]); var duration = 200 / speed; var generateCircleStyle = function (i) { return (!still ? { animation: "spinners-react-dotted-shrink ".concat(duration, "s cubic-bezier(0, 0.9, 0, 0.9) ").concat((duration / 20) * i, "s infinite") } : {}); }; var centerStyle = !still ? { animation: "spinners-react-dotted-center ".concat(duration, "s ease-out infinite"), transformOrigin: 'center', } : { display: 'none' }; return (React.createElement("svg", __assign({ fill: "none", viewBox: "0 0 66 66" }, svgProps), coords$1.map(function (c, i) { return (React.createElement("circle", { key: "".concat(c.x, "-").concat(c.y), cx: "33", cy: "33", fill: "currentColor", r: 3 * (thickness / 100), style: __assign({ transform: "translate(".concat(c.x, "px, ").concat(c.y, "px)") }, generateCircleStyle(i)) })); }), React.createElement("circle", { cx: "33", cy: "33", fill: "currentColor", r: 6 * (thickness / 100), style: centerStyle }))); } var SpinnerDotted = withSharedProps(Component$4); var css_248z$3 = "@keyframes spinners-react-round{27%,73%{r:2px;stroke-width:4}}"; styleInject(css_248z$3); function Component$3(_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"]); var strokeWidth = 3 * (thickness / 100); var circleStyle = { animation: "spinners-react-round ".concat(140 / speed, "s ease-in-out infinite"), transformOrigin: 'center', }; if (still) circleStyle.animation = 'none'; return (React.createElement("svg", __assign({ fill: "none" }, svgProps, { viewBox: "0 0 66 66" }), React.createElement("circle", { cx: "33", cy: "33", fill: "none", r: 28, stroke: "currentColor", strokeWidth: strokeWidth, style: circleStyle }))); } var SpinnerRound = withSharedProps(Component$3); var css_248z$2 = "@keyframes spinners-react-round-outlined{35%,65%{r:2px;stroke-width:4}}"; styleInject(css_248z$2); var animations$1 = [ { r: 2, }, { name: 'spinners-react-round-outlined', r: 14, }, { name: 'spinners-react-round-outlined', r: 28, }, ]; function Component$2(_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"]); var strokeWidth = 3 * (thickness / 100); return (React.createElement("svg", __assign({ fill: "none" }, svgProps, { viewBox: "0 0 66 66" }), animations$1.map(function (animation, i) { return (React.createElement("circle", { key: "spinner-round-outlined-r".concat(animation.r), cx: "33", cy: "33", fill: "none", r: animation.r, stroke: "currentColor", strokeWidth: i ? strokeWidth : 4, style: animation.name && !still ? { animation: "".concat(animation.name, " ").concat(140 / speed, "s ease-in-out infinite") } : {} })); }))); } var SpinnerRoundOutlined = withSharedProps(Component$2); var css_248z$1 = "@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$1); 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$1(_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$1); var css_248z = "@keyframes spinners-react-diamond{25%{transform:translate(30px,-30px)}50%{transform:translate(60px)}75%{transform:translate(30px,30px)}}"; styleInject(css_248z); var coords = [ { x: 3, y: 48 }, { x: 18, y: 33 }, { x: 18, y: 48 }, { x: 18, y: 63 }, { x: 33, y: 48 }, // ------------- { x: 33, y: 18 }, { x: 33, y: 33 }, { x: 33, y: 63 }, { x: 33, y: 78 }, { x: 48, y: 3 }, { x: 48, y: 18 }, { x: 48, y: 33 }, { x: 48, y: 48 }, { x: 48, y: 63 }, { x: 48, y: 78 }, { x: 48, y: 93 }, { x: 63, y: 18 }, { x: 63, y: 33 }, { x: 63, y: 48 }, { x: 63, y: 63 }, { x: 63, y: 78 }, { x: 78, y: 33 }, { x: 78, y: 48 }, { x: 78, y: 63 }, { x: 93, y: 48 }, ]; 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 diamondStyle = { animation: "spinners-react-diamond ".concat(140 / speed, "s steps(2, end) infinite"), }; if (still) diamondStyle.animation = 'none'; return (React.createElement("svg", __assign({ fill: "currentColor" }, svgProps, { viewBox: "0 0 96 96" }), coords.map(function (c) { return (React.createElement("circle", { key: "".concat(c.x, "-").concat(c.y), cx: c.x, cy: c.y, fill: secondaryColor, r: 2.5 * (thickness / 100) })); }), React.createElement("g", { style: diamondStyle }, coords.filter(function (c, i) { return i < 5; }).map(function (c) { return (React.createElement("circle", { key: "h-".concat(c.x, "-").concat(c.y), cx: c.x, cy: c.y, r: 3.5 * (thickness / 100) })); })))); } var SpinnerRomb = withSharedProps(Component); var SpinnerDiamond = withSharedProps(Component); exports.Component = Component$4; exports.SpinnerCircular = SpinnerCircular; exports.SpinnerCircularFixed = SpinnerCircularFixed; exports.SpinnerCircularSplit = SpinnerCircularSplit; exports.SpinnerDiamond = SpinnerDiamond; exports.SpinnerDotted = SpinnerDotted; exports.SpinnerInfinity = SpinnerInfinity; exports.SpinnerRomb = SpinnerRomb; exports.SpinnerRound = SpinnerRound; exports.SpinnerRoundFilled = SpinnerRoundFilled; exports.SpinnerRoundOutlined = SpinnerRoundOutlined; })); //# sourceMappingURL=index.js.map