UNPKG

elfen-component-spinner

Version:

react components for loader or spinner

97 lines (78 loc) 3.41 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _templateObject = _taggedTemplateLiteral(['\n 50% { opacity: .3; }\n 100% { opacity: 1; }\n'], ['\n 50% { opacity: .3; }\n 100% { opacity: 1; }\n']), _templateObject2 = _taggedTemplateLiteral(['\n transform: rotate(', 'deg);\n animation: ', ' linear infinite both;\n animation-delay: ', 's;\n animation-duration: ', 's;\n transform-origin: center;\n'], ['\n transform: rotate(', 'deg);\n animation: ', ' linear infinite both;\n animation-delay: ', 's;\n animation-duration: ', 's;\n transform-origin: center;\n']), _templateObject3 = _taggedTemplateLiteral(['\n width: ', 'px;\n height: ', 'px;\n'], ['\n width: ', 'px;\n height: ', 'px;\n']); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _styledComponents = require('styled-components'); var _styledComponents2 = _interopRequireDefault(_styledComponents); var _lib = require('../lib'); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } function _taggedTemplateLiteral(strings, raw) { return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); } var animationFade = (0, _styledComponents.keyframes)(_templateObject); var Rect = _styledComponents2.default.rect(_templateObject2, function (props) { return 90 + props.angle; }, animationFade, function (props) { return props.duration * 0.8 / props.total * props.offset; }, function (props) { return props.duration; }); var Svg = _styledComponents2.default.svg(_templateObject3, function (props) { return props.width; }, function (props) { return props.height; }); var SpinLoading = function SpinLoading(_ref) { var size = _ref.size, barStyle = _ref.barStyle, barWidth = _ref.barWidth, barHeight = _ref.barHeight, count = _ref.count, duration = _ref.duration, color = _ref.color, fill = _ref.fill, borderRadius = _ref.borderRadius, rest = _objectWithoutProperties(_ref, ['size', 'barStyle', 'barWidth', 'barHeight', 'count', 'duration', 'color', 'fill', 'borderRadius']); var radius = size / 2 - barHeight / 2; return _react2.default.createElement( Svg, { width: size, height: size }, (0, _lib.repeat)(count).map(function (_, i) { var angle = 360 / count * i; /* (barWidth + borderRadius) / 2 is used to fix the excursion caused by thickness */ var x = Math.cos(Math.PI * angle / 180) * radius + radius + (barWidth + borderRadius) / 2; var y = Math.sin(Math.PI * angle / 180) * radius + radius; return _react2.default.createElement(Rect, { key: 'r-' + i, style: barStyle, fill: color || fill, width: barWidth, height: barHeight, x: x, y: y, rx: borderRadius, ry: borderRadius, duration: duration, offset: i, total: count, angle: angle }); }) ); }; SpinLoading.defaultProps = { size: 40, count: 8, barWidth: 4, duration: 1, barHeight: 10, borderRadius: 1 }; exports.default = SpinLoading;