UNPKG

wix-style-react

Version:
138 lines (118 loc) 6.25 kB
import _extends from "@babel/runtime/helpers/extends"; import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties"; 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"; var _excluded = ["light", "size", "skin", "label", "className"]; var _sizeToSuccessIcon, _sizeToErrorIcon; 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 { CircularProgressBar as CoreCircularProgressBar } from "wix-ui-core/dist/es/src/components/circular-progress-bar"; import CircleLoaderCheck from 'wix-ui-icons-common/system/CircleLoaderCheck'; import CircleLoaderCheckSmall from 'wix-ui-icons-common/system/CircleLoaderCheckSmall'; import FormFieldError from 'wix-ui-icons-common/system/FormFieldError'; import FormFieldErrorSmall from 'wix-ui-icons-common/system/FormFieldErrorSmall'; import Tooltip from '../Tooltip'; import { ThemeProviderConsumerBackwardCompatible } from '../ThemeProvider/ThemeProviderConsumerBackwardCompatible'; import { st, classes } from './CircularProgressBar.st.css'; import PropTypes from 'prop-types'; import { dataHooks, Size, sizesMap } from './constants'; var sizeToSuccessIcon = (_sizeToSuccessIcon = {}, _defineProperty(_sizeToSuccessIcon, Size.small, CircleLoaderCheckSmall), _defineProperty(_sizeToSuccessIcon, Size.medium, CircleLoaderCheck), _defineProperty(_sizeToSuccessIcon, Size.large, CircleLoaderCheck), _sizeToSuccessIcon); var sizeToErrorIcon = (_sizeToErrorIcon = {}, _defineProperty(_sizeToErrorIcon, Size.small, /*#__PURE__*/React.createElement(FormFieldErrorSmall, null)), _defineProperty(_sizeToErrorIcon, Size.medium, /*#__PURE__*/React.createElement(FormFieldError, null)), _defineProperty(_sizeToErrorIcon, Size.large, /*#__PURE__*/React.createElement(FormFieldError, null)), _sizeToErrorIcon); var CircularProgressBar = /*#__PURE__*/function (_React$PureComponent) { _inherits(CircularProgressBar, _React$PureComponent); var _super = _createSuper(CircularProgressBar); function CircularProgressBar() { _classCallCheck(this, CircularProgressBar); return _super.apply(this, arguments); } _createClass(CircularProgressBar, [{ key: "_renderSuccessIcon", value: function _renderSuccessIcon(size) { return /*#__PURE__*/React.createElement(ThemeProviderConsumerBackwardCompatible, { defaultIcons: { CircularProgressBar: sizeToSuccessIcon } }, function (_ref) { var icons = _ref.icons; var IconToRender = icons.CircularProgressBar[size]; return /*#__PURE__*/React.createElement(IconToRender, null); }); } }, { key: "_renderProgressBar", value: function _renderProgressBar() { var _this$props = this.props, light = _this$props.light, size = _this$props.size, skin = _this$props.skin, label = _this$props.label, className = _this$props.className, otherProps = _objectWithoutProperties(_this$props, _excluded); return /*#__PURE__*/React.createElement(CoreCircularProgressBar, _extends({ className: st(classes.progressBar, { light: light, size: size, skin: skin }) }, otherProps, { label: label, "data-hook": dataHooks.circularProgressBar, size: sizesMap[size], "data-size": size, "data-skin": skin, successIcon: this._renderSuccessIcon(size), errorIcon: sizeToErrorIcon[size] })); } }, { key: "render", value: function render() { var _this$props2 = this.props, dataHook = _this$props2.dataHook, error = _this$props2.error, errorMessage = _this$props2.errorMessage, className = _this$props2.className; return /*#__PURE__*/React.createElement("div", { "data-hook": dataHook, className: st(classes.root, className) }, error && errorMessage ? /*#__PURE__*/React.createElement(Tooltip, { className: classes.tooltip, content: errorMessage, dataHook: dataHooks.tooltip }, this._renderProgressBar()) : this._renderProgressBar()); } }]); return CircularProgressBar; }(React.PureComponent); CircularProgressBar.displayName = 'CircularProgressBar'; CircularProgressBar.defaultProps = { size: 'medium', skin: 'standard' }; CircularProgressBar.propTypes = { /** Should be true if had failure during the progress */ error: PropTypes.bool, /** Label to display when an error happens */ errorLabel: PropTypes.string, /** Message to display when an error happens */ errorMessage: PropTypes.string, /** Use light theme instead of dark theme */ light: PropTypes.bool, /** Use to display a percentage progress */ showProgressIndication: PropTypes.bool, /** Use to display custom text in the progress bar */ label: PropTypes.string, /** Size of the bar */ size: PropTypes.string, /** Skin of the bar */ skin: PropTypes.oneOf(['standard', 'premium', 'success']), /** The number of the percentage progress */ value: PropTypes.oneOfType([PropTypes.string, PropTypes.number]), dataHook: PropTypes.string }; export default CircularProgressBar;