UNPKG

wix-style-react

Version:
180 lines (159 loc) • 6.21 kB
var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _class, _temp; function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } import React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import WixComponent from '../BaseComponents/WixComponent'; import Arc from './Arc'; import css from './Loader.scss'; import Tooltip from '../Tooltip'; import FormFieldError from '../new-icons/system/FormFieldError'; import FormFieldErrorSmall from '../new-icons/system/FormFieldErrorSmall'; import ToggleOn from '../new-icons/system/ToggleOn'; import CircleLoaderCheck from '../new-icons/system/CircleLoaderCheck'; import CircleLoaderCheckSmall from '../new-icons/system/CircleLoaderCheckSmall'; import Heading from '../Heading'; 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: React.createElement(ToggleOn, null), small: React.createElement(CircleLoaderCheckSmall, null), medium: React.createElement(CircleLoaderCheck, null), large: React.createElement(CircleLoaderCheck, null) }; var sizeToErrorIcon = { tiny: React.createElement(FormFieldError, null), small: React.createElement(FormFieldErrorSmall, null), medium: React.createElement(FormFieldError, null), large: React.createElement(FormFieldError, null) }; var Loader = (_temp = _class = function (_WixComponent) { _inherits(Loader, _WixComponent); function Loader() { _classCallCheck(this, Loader); return _possibleConstructorReturn(this, (Loader.__proto__ || Object.getPrototypeOf(Loader)).apply(this, arguments)); } _createClass(Loader, [{ key: 'render', value: function render() { var _props = this.props, size = _props.size, color = _props.color, text = _props.text, status = _props.status, statusMessage = _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 = React.createElement( 'div', { className: css.arcsContainer, style: { width: sizeInPx + 'px', height: sizeInPx + 'px' } }, React.createElement(Arc, { angle: lightArcAngle, className: css.lightArc, strokeWidth: strokeWidth, viewBoxSize: sizeInPx }), React.createElement(Arc, { angle: darkArcAngle, className: css.darkArc, strokeWidth: strokeWidth, viewBoxSize: sizeInPx }), status !== 'loading' && React.createElement( 'div', { className: css.statusIndicator }, status === 'success' && successIcon, status === 'error' && errorIcon ) ); return React.createElement( 'div', { className: classNames(css.loaderContainer, css[size], css[color], css[status]) }, statusMessage ? React.createElement( Tooltip, { dataHook: 'loader-tooltip', placement: 'top', textAlign: 'center', alignment: 'center', content: statusMessage, theme: 'dark' }, loader ) : loader, shouldShowText && text && React.createElement( 'div', { className: css.text }, React.createElement( Heading, { appearance: 'H6', dataHook: 'loader-text' }, this.props.text ) ) ); } }]); return Loader; }(WixComponent), _class.displayName = 'Loader', _class.propTypes = { /** 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 tolltip **/ statusMessage: PropTypes.string }, _class.defaultProps = { size: 'medium', color: 'blue', status: 'loading' }, _temp); export { Loader as default };