UNPKG

wix-style-react

Version:
169 lines (151 loc) • 6.1 kB
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _inherits from "@babel/runtime/helpers/inherits"; import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn"; import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf"; import _defineProperty from "@babel/runtime/helpers/defineProperty"; function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } import React from 'react'; import PropTypes from 'prop-types'; import FormFieldError from 'wix-ui-icons-common/system/FormFieldError'; import FormFieldErrorSmall from 'wix-ui-icons-common/system/FormFieldErrorSmall'; import ToggleOn from 'wix-ui-icons-common/system/ToggleOn'; import CircleLoaderCheck from 'wix-ui-icons-common/system/CircleLoaderCheck'; import CircleLoaderCheckSmall from 'wix-ui-icons-common/system/CircleLoaderCheckSmall'; import Arc from './Arc'; import Heading from '../Heading'; import Tooltip from '../Tooltip'; import { st, classes } from './Loader.st.css'; var arcsAngles = { tiny: { light: 216, dark: 144 }, small: { light: 216, dark: 144 }, medium: { light: 108, dark: 108 }, large: { light: 180, dark: 180 } }; var strokeWidths = { tiny: 3, small: 4, medium: 4, large: 4 }; var sizesInPx = { tiny: 18, small: 30, medium: 54, large: 102 }; var FULL_CIRCLE_ANGLE = 359; var sizeToSuccessIcon = { tiny: /*#__PURE__*/React.createElement(ToggleOn, null), small: /*#__PURE__*/React.createElement(CircleLoaderCheckSmall, null), medium: /*#__PURE__*/React.createElement(CircleLoaderCheck, null), large: /*#__PURE__*/React.createElement(CircleLoaderCheck, null) }; var sizeToErrorIcon = { tiny: /*#__PURE__*/React.createElement(FormFieldError, null), small: /*#__PURE__*/React.createElement(FormFieldErrorSmall, null), medium: /*#__PURE__*/React.createElement(FormFieldError, null), large: /*#__PURE__*/React.createElement(FormFieldError, null) }; var Loader = /*#__PURE__*/function (_React$PureComponent) { _inherits(Loader, _React$PureComponent); var _super = _createSuper(Loader); function Loader() { _classCallCheck(this, Loader); return _super.apply(this, arguments); } _createClass(Loader, [{ key: "render", value: function render() { var _this$props = this.props, dataHook = _this$props.dataHook, size = _this$props.size, color = _this$props.color, text = _this$props.text, status = _this$props.status, statusMessage = _this$props.statusMessage; var sizeInPx = sizesInPx[size]; var shouldShowFullCircle = status !== 'loading'; var lightArcAngle = !shouldShowFullCircle ? arcsAngles[size].light : FULL_CIRCLE_ANGLE; var darkArcAngle = !shouldShowFullCircle ? arcsAngles[size].dark : FULL_CIRCLE_ANGLE; var shouldShowText = size !== 'tiny'; var successIcon = sizeToSuccessIcon[size]; var errorIcon = sizeToErrorIcon[size]; var strokeWidth = strokeWidths[size]; var loader = /*#__PURE__*/React.createElement("div", { className: classes.arcsContainer, style: { width: "".concat(sizeInPx, "px"), height: "".concat(sizeInPx, "px") } }, /*#__PURE__*/React.createElement(Arc, { angle: lightArcAngle, className: classes.lightArc, strokeWidth: strokeWidth, viewBoxSize: sizeInPx }), /*#__PURE__*/React.createElement(Arc, { angle: darkArcAngle, className: classes.darkArc, strokeWidth: strokeWidth, viewBoxSize: sizeInPx }), status !== 'loading' && /*#__PURE__*/React.createElement("div", { className: classes.statusIndicator }, status === 'success' && successIcon, status === 'error' && errorIcon)); return /*#__PURE__*/React.createElement("div", { className: st(classes.root, { size: size, color: color, status: status }), "data-hook": dataHook, "data-size": size, "data-color": color, "data-status": status }, statusMessage ? /*#__PURE__*/React.createElement(Tooltip, { content: statusMessage, appendTo: "window", dataHook: "loader-tooltip" }, loader) : loader, shouldShowText && text && /*#__PURE__*/React.createElement("div", { className: classes.text }, /*#__PURE__*/React.createElement(Heading, { appearance: "H6", dataHook: "loader-text" }, this.props.text))); } }]); return Loader; }(React.PureComponent); _defineProperty(Loader, "displayName", 'Loader'); _defineProperty(Loader, "propTypes", { /** Applied as data-hook HTML attribute that can be used in the tests */ dataHook: PropTypes.string, /** The size of the loader */ size: PropTypes.oneOf(['tiny', 'small', 'medium', 'large']), /** The color of the loader */ color: PropTypes.oneOf(['blue', 'white']), /** Node (usually text) to be shown below the loader */ text: PropTypes.node, /** The status of the loader */ status: PropTypes.oneOf(['loading', 'success', 'error']), /** Text to be shown in the tooltip **/ statusMessage: PropTypes.string }); _defineProperty(Loader, "defaultProps", { size: 'medium', color: 'blue', status: 'loading' }); export default Loader;