@kiwicom/orbit-components
Version:
Orbit-components is a React component library which provides developers with the easiest possible way of building Kiwi.com’s products.
177 lines (147 loc) • 7.93 kB
JavaScript
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = exports.StyledSpinner = exports.StyledLoading = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var React = _interopRequireWildcard(require("react"));
var _styledComponents = _interopRequireWildcard(require("styled-components"));
var _defaultTheme = _interopRequireDefault(require("../defaultTheme"));
var _consts = _interopRequireDefault(require("./consts"));
var _rtl = require("../utils/rtl");
var getHeight = function getHeight(_ref) {
var _tokens;
var type = _ref.type;
var tokens = (_tokens = {}, (0, _defineProperty2.default)(_tokens, _consts.default.BUTTON_LOADER, "100%"), (0, _defineProperty2.default)(_tokens, _consts.default.SEARCH_LOADER, "40px"), (0, _defineProperty2.default)(_tokens, _consts.default.BOX_LOADER, "80px"), (0, _defineProperty2.default)(_tokens, _consts.default.PAGE_LOADER, "120px"), (0, _defineProperty2.default)(_tokens, _consts.default.INLINE_LOADER, "19px"), _tokens);
return (0, _styledComponents.css)(["", ":", ""], type === _consts.default.INLINE_LOADER ? "min-height" : "height", tokens[type]);
};
var getAlign = function getAlign(_ref2) {
var _tokens2;
var type = _ref2.type;
var tokens = (_tokens2 = {}, (0, _defineProperty2.default)(_tokens2, _consts.default.BUTTON_LOADER, "center"), (0, _defineProperty2.default)(_tokens2, _consts.default.SEARCH_LOADER, "start"), (0, _defineProperty2.default)(_tokens2, _consts.default.BOX_LOADER, "center"), (0, _defineProperty2.default)(_tokens2, _consts.default.PAGE_LOADER, "center"), (0, _defineProperty2.default)(_tokens2, _consts.default.INLINE_LOADER, "center"), _tokens2);
return tokens[type];
}; // 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, _styledComponents.default)(function (_ref3) {
var children = _ref3.children,
className = _ref3.className,
dataTest = _ref3.dataTest;
return /*#__PURE__*/React.createElement("div", {
className: className,
"data-test": dataTest
}, children);
}).withConfig({
displayName: "Loading__StyledLoading",
componentId: "sc-1psg3na-0"
})(["position:", ";top:", ";", ":", ";width:", ";", ";padding:", ";display:", ";flex-direction:", ";justify-content:", ";align-items:center;overflow:hidden;box-sizing:border-box;"], function (_ref4) {
var type = _ref4.type;
return type === _consts.default.BUTTON_LOADER && "absolute";
}, function (_ref5) {
var type = _ref5.type;
return type === _consts.default.BUTTON_LOADER && "0";
}, _rtl.left, function (_ref6) {
var type = _ref6.type;
return type === _consts.default.BUTTON_LOADER && "0";
}, function (_ref7) {
var type = _ref7.type;
return type === _consts.default.BUTTON_LOADER && "100%";
}, getHeight, function (_ref8) {
var theme = _ref8.theme,
type = _ref8.type;
return type !== _consts.default.INLINE_LOADER && theme.orbit.paddingLoading;
}, function (_ref9) {
var type = _ref9.type;
return type === _consts.default.INLINE_LOADER ? "inline-flex" : "flex";
}, function (_ref10) {
var type = _ref10.type;
return type === _consts.default.PAGE_LOADER ? "column" : "row";
}, getAlign); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
exports.StyledLoading = StyledLoading;
StyledLoading.defaultProps = {
theme: _defaultTheme.default
};
var StyledLoadingText = _styledComponents.default.div.withConfig({
displayName: "Loading__StyledLoadingText",
componentId: "sc-1psg3na-1"
})(["font-family:", ";font-size:", ";color:", ";line-height:", ";margin-top:", ";margin-", ":", ";"], function (_ref11) {
var theme = _ref11.theme;
return theme.orbit.fontFamily;
}, function (_ref12) {
var theme = _ref12.theme;
return theme.orbit.fontSizeTextNormal;
}, function (_ref13) {
var theme = _ref13.theme;
return theme.orbit.colorTextLoading;
}, function (_ref14) {
var theme = _ref14.theme;
return theme.orbit.lineHeightTextNormal;
}, function (_ref15) {
var theme = _ref15.theme,
type = _ref15.type;
return type === _consts.default.PAGE_LOADER && theme.orbit.spaceMedium;
}, _rtl.left, function (_ref16) {
var theme = _ref16.theme,
type = _ref16.type;
return type !== _consts.default.PAGE_LOADER && theme.orbit.spaceSmall;
}); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
StyledLoadingText.defaultProps = {
theme: _defaultTheme.default
};
var StyledSpinner = _styledComponents.default.svg.withConfig({
displayName: "Loading__StyledSpinner",
componentId: "sc-1psg3na-2"
})(["width:40px;height:40px;animation:", " 0.75s linear infinite;"], SpinnerAnimation);
exports.StyledSpinner = StyledSpinner;
var StyledSpinnerCircle = _styledComponents.default.circle.withConfig({
displayName: "Loading__StyledSpinnerCircle",
componentId: "sc-1psg3na-3"
})(["fill:transparent;stroke:", ";stroke-width:3px;stroke-linecap:round;stroke-dasharray:128px;stroke-dashoffset:64px;"], function (_ref17) {
var theme = _ref17.theme,
type = _ref17.type;
return type === _consts.default.BUTTON_LOADER ? "currentColor" : theme.orbit.paletteCloudDarker;
}); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
StyledSpinnerCircle.defaultProps = {
theme: _defaultTheme.default
};
var StyledLoader = _styledComponents.default.div.withConfig({
displayName: "Loading__StyledLoader",
componentId: "sc-1psg3na-4"
})(["display:flex;justify-content:center;align-items:center;"]);
var StyledLoaderCircle = _styledComponents.default.div.withConfig({
displayName: "Loading__StyledLoaderCircle",
componentId: "sc-1psg3na-5"
})(["width:8px;height:8px;border-radius:50%;margin-", ":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;}"], _rtl.right, function (_ref18) {
var theme = _ref18.theme;
return theme.orbit.paletteCloudDarker;
}, LoaderAnimation); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
StyledLoaderCircle.defaultProps = {
theme: _defaultTheme.default
};
var Loading = function Loading(props) {
var _props$loading = props.loading,
loading = _props$loading === void 0 ? false : _props$loading,
_props$type = props.type,
type = _props$type === void 0 ? _consts.default.PAGE_LOADER : _props$type,
text = props.text,
children = props.children,
dataTest = props.dataTest;
return children && !loading ? children : /*#__PURE__*/React.createElement(StyledLoading, {
type: type,
dataTest: dataTest
}, type === _consts.default.BOX_LOADER || type === _consts.default.SEARCH_LOADER || type === _consts.default.INLINE_LOADER ? /*#__PURE__*/React.createElement(StyledLoader, null, /*#__PURE__*/React.createElement(StyledLoaderCircle, null), /*#__PURE__*/React.createElement(StyledLoaderCircle, null), /*#__PURE__*/React.createElement(StyledLoaderCircle, null)) : /*#__PURE__*/React.createElement(StyledSpinner, {
viewBox: "0 0 40 40"
}, /*#__PURE__*/React.createElement(StyledSpinnerCircle, {
cx: "50%",
cy: "50%",
r: "18",
type: type
})), type !== _consts.default.BUTTON_LOADER && /*#__PURE__*/React.createElement(StyledLoadingText, {
type: type
}, text));
};
Loading.displayName = "Loading";
var _default = Loading;
exports.default = _default;