@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.
193 lines (162 loc) • 7.42 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.default = exports.StyledSpinner = exports.StyledLoading = void 0;
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");
const getHeight = ({
type,
customSize
}) => {
const tokens = {
[_consts.default.BUTTON_LOADER]: "100%",
[_consts.default.SEARCH_LOADER]: "40px",
[_consts.default.BOX_LOADER]: "80px",
[_consts.default.PAGE_LOADER]: "120px",
[_consts.default.INLINE_LOADER]: "19px"
};
if (customSize) return `height: ${customSize}px`;
return (0, _styledComponents.css)(["", ":", ""], type === _consts.default.INLINE_LOADER ? "min-height" : "height", tokens[type]);
};
const getAlign = ({
type
}) => {
const tokens = {
[_consts.default.BUTTON_LOADER]: "center",
[_consts.default.SEARCH_LOADER]: "start",
[_consts.default.BOX_LOADER]: "center",
[_consts.default.PAGE_LOADER]: "center",
[_consts.default.INLINE_LOADER]: "center"
};
return tokens[type];
}; // Animations
const SpinnerAnimation = (0, _styledComponents.keyframes)(["100%{transform:rotate(360deg);}"]);
const 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);}"]);
const StyledLoading = (0, _styledComponents.default)(({
children,
className,
dataTest
}) => /*#__PURE__*/React.createElement("div", {
className: className,
"data-test": dataTest
}, children)).withConfig({
displayName: "Loading__StyledLoading",
componentId: "sc-199xidk-0"
})(["", ""], ({
type,
theme,
customSize
}) => (0, _styledComponents.css)(["position:", ";top:", ";", ":", ";width:", ";", ";padding:", ";display:", ";flex-direction:", ";justify-content:", ";align-items:center;overflow:hidden;box-sizing:border-box;"], type === _consts.default.BUTTON_LOADER && "absolute", type === _consts.default.BUTTON_LOADER && "0", _rtl.left, type === _consts.default.BUTTON_LOADER && "0", type === _consts.default.BUTTON_LOADER && "100%", getHeight, type !== _consts.default.INLINE_LOADER && !customSize && theme.orbit.paddingLoading, type === _consts.default.INLINE_LOADER ? "inline-flex" : "flex", 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
};
const StyledLoadingText = _styledComponents.default.div.withConfig({
displayName: "Loading__StyledLoadingText",
componentId: "sc-199xidk-1"
})(["font-family:", ";font-size:", ";color:", ";line-height:", ";margin-top:", ";margin-", ":", ";"], ({
theme
}) => theme.orbit.fontFamily, ({
theme
}) => theme.orbit.fontSizeTextNormal, ({
theme
}) => theme.orbit.colorTextLoading, ({
theme
}) => theme.orbit.lineHeightTextNormal, ({
theme,
type
}) => type === _consts.default.PAGE_LOADER && theme.orbit.spaceMedium, _rtl.left, ({
theme,
type
}) => 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
};
const StyledSpinner = _styledComponents.default.svg.withConfig({
displayName: "Loading__StyledSpinner",
componentId: "sc-199xidk-2"
})(["", ";"], ({
customSize
}) => (0, _styledComponents.css)(["width:", ";height:", ";animation:", " 0.75s linear infinite;"], customSize ? `${customSize}px` : "40px", customSize ? `${customSize}px` : "40px", SpinnerAnimation)); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
exports.StyledSpinner = StyledSpinner;
StyledSpinner.defaultProps = {
theme: _defaultTheme.default
};
const StyledSpinnerCircle = _styledComponents.default.circle.withConfig({
displayName: "Loading__StyledSpinnerCircle",
componentId: "sc-199xidk-3"
})(["", ";"], ({
type,
theme,
customSize
}) => (0, _styledComponents.css)(["fill:transparent;stroke:", ";stroke-width:3px;stroke-linecap:round;stroke-dasharray:", ";stroke-dashoffset:", ";"], type === _consts.default.BUTTON_LOADER ? "currentColor" : theme.orbit.paletteCloudDarker, customSize ? `${customSize * 3 + 8}px` : "128px", customSize ? `${customSize + 24}px` : "64px")); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
StyledSpinnerCircle.defaultProps = {
theme: _defaultTheme.default
};
const StyledLoader = _styledComponents.default.div.withConfig({
displayName: "Loading__StyledLoader",
componentId: "sc-199xidk-4"
})(["display:flex;justify-content:center;align-items:center;"]);
const StyledLoaderCircle = _styledComponents.default.div.withConfig({
displayName: "Loading__StyledLoaderCircle",
componentId: "sc-199xidk-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, ({
theme
}) => theme.orbit.paletteCloudDarker, LoaderAnimation); // $FlowFixMe: https://github.com/flow-typed/flow-typed/issues/3653#issuecomment-568539198
StyledLoaderCircle.defaultProps = {
theme: _defaultTheme.default
};
const Loader = ({
type,
customSize
}) => {
const isCircledIcon = type === _consts.default.BOX_LOADER || type === _consts.default.SEARCH_LOADER || type === _consts.default.INLINE_LOADER;
if (customSize) {
return /*#__PURE__*/React.createElement(StyledSpinner, {
viewBox: `0 0 ${customSize} ${customSize}`,
customSize: customSize
}, /*#__PURE__*/React.createElement(StyledSpinnerCircle, {
cx: "50%",
cy: "50%",
r: customSize ? customSize / 2 - 2 : 18,
customSize: customSize
}));
}
if (isCircledIcon) return /*#__PURE__*/React.createElement(StyledLoader, null, /*#__PURE__*/React.createElement(StyledLoaderCircle, null), /*#__PURE__*/React.createElement(StyledLoaderCircle, null), /*#__PURE__*/React.createElement(StyledLoaderCircle, null));
return /*#__PURE__*/React.createElement(StyledSpinner, {
viewBox: "0 0 40 40"
}, /*#__PURE__*/React.createElement(StyledSpinnerCircle, {
cx: "50%",
cy: "50%",
r: "18",
type: type
}));
};
const Loading = ({
loading = false,
customSize,
type = _consts.default.PAGE_LOADER,
text,
children,
dataTest,
id
}) => {
return children && !loading ? children : /*#__PURE__*/React.createElement(StyledLoading, {
type: type,
dataTest: dataTest,
id: id,
customSize: customSize
}, /*#__PURE__*/React.createElement(Loader, {
type: type,
customSize: customSize
}), type !== _consts.default.BUTTON_LOADER && text && /*#__PURE__*/React.createElement(StyledLoadingText, {
type: type
}, text));
};
Loading.displayName = "Loading";
var _default = Loading;
exports.default = _default;