UNPKG

elfen-component-spinner

Version:

react components for loader or spinner

91 lines (72 loc) 3.78 kB
'use strict'; 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 0%, 100% { transform: translateY(0); }\n 25% { transform: translateY(8px); }\n 75% { transform: translateY(-8px); }\n'], ['\n 0%, 100% { transform: translateY(0); }\n 25% { transform: translateY(8px); }\n 75% { transform: translateY(-8px); }\n']), _templateObject2 = _taggedTemplateLiteral(['\n width: ', ';\n height: ', ';\n animation-delay: -', 's;\n animation-duration: ', 's;\n animation-name: ', ';\n animation-iteration-count: infinite;\n transform-origin: center;\n'], ['\n width: ', ';\n height: ', ';\n animation-delay: -', 's;\n animation-duration: ', 's;\n animation-name: ', ';\n animation-iteration-count: infinite;\n transform-origin: center;\n']), _templateObject3 = _taggedTemplateLiteral(['\n width: ', ';\n height: ', ';\n'], ['\n width: ', ';\n height: ', ';\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 animationBounce = (0, _styledComponents.keyframes)(_templateObject); var Rect = _styledComponents2.default.rect(_templateObject2, function (props) { return typeof props.width === 'string' ? props.width : props.width + 'px'; }, function (props) { return typeof props.height === 'string' ? props.height : props.height + 'px'; }, function (props) { return props.duration / (props.total + 1) * (props.total - props.offset); }, function (props) { return props.duration; }, animationBounce); var Svg = _styledComponents2.default.svg(_templateObject3, function (props) { return typeof props.width === 'string' ? props.width : props.width + 'px'; }, function (props) { return typeof props.height === 'string' ? props.height : props.height + 'px'; }); var BounceLoading = function BounceLoading(_ref) { var duration = _ref.duration, count = _ref.count, color = _ref.color, fill = _ref.fill, barStyle = _ref.barStyle, barWidth = _ref.barWidth, barHeight = _ref.barHeight, gap = _ref.gap, rest = _objectWithoutProperties(_ref, ['duration', 'count', 'color', 'fill', 'barStyle', 'barWidth', 'barHeight', 'gap']); var viewWidth = (barWidth + gap) * count - gap; return _react2.default.createElement( Svg, _extends({ width: viewWidth, height: barHeight * 3 }, rest), (0, _lib.repeat)(count).map(function (_, i) { return _react2.default.createElement(Rect, { key: 'rect-' + i, style: barStyle, height: barHeight, width: barWidth, fill: color || fill, duration: duration, offset: i, total: count, x: (barWidth + gap) * i, y: barHeight }); }) ); }; BounceLoading.defaultProps = { gap: 6, count: 4, barWidth: 4, barHeight: 16, duration: 0.8 }; exports.default = BounceLoading;