elfen-component-spinner
Version:
react components for loader or spinner
92 lines (71 loc) • 3.89 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
var _templateObject = _taggedTemplateLiteral(['\n to {\n transform: rotate(360deg);\n }\n'], ['\n to {\n transform: rotate(360deg);\n }\n']),
_templateObject2 = _taggedTemplateLiteral(['\n 0% {\n stroke-dasharray: 1, 200;\n stroke-dashoffset: 0;\n }\n 50% {\n stroke-dasharray: 89, 200;\n stroke-dashoffset: -35;\n }\n 100% {\n stroke-dasharray: 89, 200;\n stroke-dashoffset: -124;\n }\n'], ['\n 0% {\n stroke-dasharray: 1, 200;\n stroke-dashoffset: 0;\n }\n 50% {\n stroke-dasharray: 89, 200;\n stroke-dashoffset: -35;\n }\n 100% {\n stroke-dasharray: 89, 200;\n stroke-dashoffset: -124;\n }\n']),
_templateObject3 = _taggedTemplateLiteral(['\n transform-origin: center;\n animation: ', ' ', 's infinite;\n'], ['\n transform-origin: center;\n animation: ', ' ', 's infinite;\n']),
_templateObject4 = _taggedTemplateLiteral(['\n width: ', ';\n animation: ', ' linear infinite;\n animation-duration: ', 's;\n'], ['\n width: ', ';\n animation: ', ' linear infinite;\n animation-duration: ', 's;\n']);
var _react = require('react');
var _react2 = _interopRequireDefault(_react);
var _styledComponents = require('styled-components');
var _styledComponents2 = _interopRequireDefault(_styledComponents);
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) } })); }
/*
* hard to find the law of google style circular loading
* set 50 x 50 as basic viewbox size. scale viewbox when use.
*
* from: https://codepen.io/jczimm/pen/vEBpoL
*/
var CIRCLE_RADIUS = 50 / 2;
var VIEW_BOX = '0 0 ' + CIRCLE_RADIUS * 2 + ' ' + CIRCLE_RADIUS * 2;
var animationRotate = (0, _styledComponents.keyframes)(_templateObject);
var animationDash = (0, _styledComponents.keyframes)(_templateObject2);
var Circle = _styledComponents2.default.circle(_templateObject3, animationDash, function (props) {
return props.duration;
});
var Svg = _styledComponents2.default.svg(_templateObject4, function (props) {
return typeof props.viewBoxSize === 'string' ? props.viewBoxSize : props.viewBoxSize + 'px';
}, animationRotate, function (props) {
return props.duration * 4 / 3;
});
var CircularLoading = function CircularLoading(_ref) {
var duration = _ref.duration,
color = _ref.color,
stroke = _ref.stroke,
strokeWidth = _ref.strokeWidth,
linecap = _ref.linecap,
size = _ref.size,
rest = _objectWithoutProperties(_ref, ['duration', 'color', 'stroke', 'strokeWidth', 'linecap', 'size']);
var radius = size / 2 - strokeWidth;
return _react2.default.createElement(
Svg,
_extends({}, rest, {
viewBox: VIEW_BOX,
duration: duration,
viewBoxSize: size
}),
_react2.default.createElement(Circle, {
duration: duration,
fill: 'none',
stroke: color || stroke,
strokeWidth: strokeWidth,
strokeLinecap: linecap,
cx: CIRCLE_RADIUS,
cy: CIRCLE_RADIUS,
r: CIRCLE_RADIUS - strokeWidth
})
);
};
CircularLoading.defaultProps = {
size: 40,
stroke: '#4197ff',
color: '#4197ff',
strokeWidth: 5,
duration: 1,
linecap: 'round'
};
exports.default = CircularLoading;