UNPKG

@kiwicom/orbit-components

Version:

<div align="center"> <a href="https://orbit.kiwi" target="_blank"> <img alt="orbit-components" src="https://orbit.kiwi/wp-content/uploads/2018/08/orbit-components.png" srcset="https://orbit.kiwi/wp-content/uploads/2018/08/orbit-components@2x.png 2x"

172 lines (143 loc) 7.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.StyledSpinner = undefined; var _react = require("react"); var React = _interopRequireWildcard(_react); var _styledComponents = require("styled-components"); var _styledComponents2 = _interopRequireDefault(_styledComponents); var _defaultTokens = require("../defaultTokens"); var _defaultTokens2 = _interopRequireDefault(_defaultTokens); var _consts = require("./consts"); var _consts2 = _interopRequireDefault(_consts); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } // Animations var SpinnerAnimation = (0, _styledComponents.keyframes)(["100%{transform:rotate(360deg);}"]); var LoaderAnimation = (0, _styledComponents.keyframes)(["0%{opacity:.3;transform:translateY(0px);}20%{opacity:1;transform:translateY(-3px);}40%{opacity:.3;transform:translateY(0px);}100%{opacity:.3;transform:translateY(0px);}"]); var StyledLoading = (0, _styledComponents2.default)(function (_ref) { var children = _ref.children, className = _ref.className, dataTest = _ref.dataTest; return React.createElement( "div", { className: className, "data-test": dataTest }, children ); }).withConfig({ displayName: "Loading__StyledLoading" })(["position:", ";left:", ";width:", ";height:", ";padding:0 ", ";display:flex;flex-direction:", ";justify-content:", ";align-items:center;overflow:hidden;box-sizing:border-box;"], function (_ref2) { var type = _ref2.type; return type === _consts2.default.BUTTON_LOADER && "absolute"; }, function (_ref3) { var type = _ref3.type; return type === _consts2.default.BUTTON_LOADER && "0"; }, function (_ref4) { var type = _ref4.type; return type === _consts2.default.BUTTON_LOADER && "100%"; }, function (_ref5) { var tokens = _ref5.tokens, type = _ref5.type; return tokens.heightLoadingContainer[type]; }, function (_ref6) { var theme = _ref6.theme; return theme.orbit.spaceSmall; }, function (_ref7) { var type = _ref7.type; return type === _consts2.default.PAGE_LOADER ? "column" : "row"; }, function (_ref8) { var tokens = _ref8.tokens, type = _ref8.type; return tokens.alignLoadingContainer[type]; }); StyledLoading.defaultProps = { theme: _defaultTokens2.default }; var StyledLoadingText = _styledComponents2.default.div.withConfig({ displayName: "Loading__StyledLoadingText" })(["font-family:", ";font-size:", ";color:", ";line-height:", ";margin-top:", ";margin-left:", ";"], function (_ref9) { var theme = _ref9.theme; return theme.orbit.fontFamily; }, function (_ref10) { var theme = _ref10.theme; return theme.orbit.fontSizeTextNormal; }, function (_ref11) { var theme = _ref11.theme; return theme.orbit.paletteInkLighter; }, function (_ref12) { var theme = _ref12.theme; return theme.orbit.lineHeightText; }, function (_ref13) { var theme = _ref13.theme, type = _ref13.type; return type === _consts2.default.PAGE_LOADER && theme.orbit.spaceMedium; }, function (_ref14) { var theme = _ref14.theme, type = _ref14.type; return type !== _consts2.default.PAGE_LOADER && theme.orbit.spaceSmall; }); StyledLoadingText.defaultProps = { theme: _defaultTokens2.default }; var StyledSpinner = exports.StyledSpinner = _styledComponents2.default.svg.withConfig({ displayName: "Loading__StyledSpinner" })(["width:40px;height:40px;animation:", " 0.75s linear infinite;"], SpinnerAnimation); var StyledSpinnerCircle = _styledComponents2.default.circle.withConfig({ displayName: "Loading__StyledSpinnerCircle" })(["fill:transparent;stroke:", ";stroke-width:3px;stroke-linecap:round;stroke-dasharray:128px;stroke-dashoffset:64px;"], function (_ref15) { var theme = _ref15.theme, type = _ref15.type; return type === _consts2.default.BUTTON_LOADER ? "currentColor" : theme.orbit.paletteInkLighter; }); StyledSpinnerCircle.defaultProps = { theme: _defaultTokens2.default }; var StyledLoader = _styledComponents2.default.div.withConfig({ displayName: "Loading__StyledLoader" })(["display:flex;justify-content:center;align-items:center;"]); var StyledLoaderCircle = _styledComponents2.default.div.withConfig({ displayName: "Loading__StyledLoaderCircle" })(["width:8px;height:8px;border-radius:50%;margin-right:6px;background:", ";animation:", " 1.25s infinite ease-in-out;&:nth-child(2){animation-delay:0.1s;}&:nth-child(3){animation-delay:0.2s;margin:0;}"], function (_ref16) { var theme = _ref16.theme; return theme.orbit.paletteInkLighter; }, LoaderAnimation); StyledLoaderCircle.defaultProps = { theme: _defaultTokens2.default }; var Loading = function Loading(props) { var _alignLoadingContaine, _heightLoadingContain; var _props$loading = props.loading, loading = _props$loading === undefined ? false : _props$loading, _props$type = props.type, type = _props$type === undefined ? _consts2.default.PAGE_LOADER : _props$type, text = props.text, children = props.children, dataTest = props.dataTest; var tokens = { alignLoadingContainer: (_alignLoadingContaine = {}, _defineProperty(_alignLoadingContaine, _consts2.default.BUTTON_LOADER, "center"), _defineProperty(_alignLoadingContaine, _consts2.default.SEARCH_LOADER, "start"), _defineProperty(_alignLoadingContaine, _consts2.default.BOX_LOADER, "center"), _defineProperty(_alignLoadingContaine, _consts2.default.PAGE_LOADER, "center"), _alignLoadingContaine), heightLoadingContainer: (_heightLoadingContain = {}, _defineProperty(_heightLoadingContain, _consts2.default.BUTTON_LOADER, "100%"), _defineProperty(_heightLoadingContain, _consts2.default.SEARCH_LOADER, "40px"), _defineProperty(_heightLoadingContain, _consts2.default.BOX_LOADER, "80px"), _defineProperty(_heightLoadingContain, _consts2.default.PAGE_LOADER, "120px"), _heightLoadingContain) }; return children && !loading ? children : React.createElement( StyledLoading, { tokens: tokens, type: type, dataTest: dataTest }, type === _consts2.default.BOX_LOADER || type === _consts2.default.SEARCH_LOADER ? React.createElement( StyledLoader, null, React.createElement(StyledLoaderCircle, null), React.createElement(StyledLoaderCircle, null), React.createElement(StyledLoaderCircle, null) ) : React.createElement( StyledSpinner, { viewBox: "0 0 40 40" }, React.createElement(StyledSpinnerCircle, { cx: "50%", cy: "50%", r: "18", type: type }) ), type !== _consts2.default.BUTTON_LOADER && React.createElement( StyledLoadingText, { type: type }, text ) ); }; exports.default = Loading;