UNPKG

wix-style-react

Version:
124 lines (101 loc) 5.4 kB
import _extends from "@babel/runtime/helpers/extends"; import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized"; 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 { WixStyleReactContext } from '../WixStyleReactProvider/context'; import StatisticsItem from './StatisticsItem'; import { st, classes } from './StatisticsWidget.st.css'; var StatisticsWidget = /*#__PURE__*/function (_React$PureComponent) { _inherits(StatisticsWidget, _React$PureComponent); var _super = _createSuper(StatisticsWidget); function StatisticsWidget() { var _this; _classCallCheck(this, StatisticsWidget); for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } _this = _super.call.apply(_super, [this].concat(args)); _defineProperty(_assertThisInitialized(_this), "_renderStat", function (stat, key) { var _this$props = _this.props, size = _this$props.size, alignItems = _this$props.alignItems, isLoading = _this$props.isLoading; return /*#__PURE__*/React.createElement(StatisticsItem, _extends({}, stat, { isLoading: isLoading, key: key, size: size, alignItems: alignItems })); }); return _this; } _createClass(StatisticsWidget, [{ key: "render", value: function render() { var _this2 = this; var _this$props2 = this.props, dataHook = _this$props2.dataHook, size = _this$props2.size; var items = this.props.items; items = items || []; if (items.length > 5) { // eslint-disable-next-line console.warn("".concat(items.length, " items were passed in items array. StatisticsWidget will display only the first 5.")); } var firstFive = items.slice(0, 5); return /*#__PURE__*/React.createElement(WixStyleReactContext.Consumer, null, function (_ref) { var reducedSpacingAndImprovedLayout = _ref.reducedSpacingAndImprovedLayout; return /*#__PURE__*/React.createElement("div", { className: st(classes.root, { size: size, reducedSpacingAndImprovedLayout: reducedSpacingAndImprovedLayout }), "data-hook": dataHook }, firstFive.map(_this2._renderStat)); }); } }]); return StatisticsWidget; }(React.PureComponent); _defineProperty(StatisticsWidget, "displayName", 'StatisticsWidget'); _defineProperty(StatisticsWidget, "propTypes", { /** Applied as data-hook HTML attribute that can be used to create driver in testing */ dataHook: PropTypes.string, /** Displayed value size (default: large) */ size: PropTypes.oneOf(['tiny', 'large']), /** Alignment of inner items (default: center) */ alignItems: PropTypes.oneOf(['start', 'center', 'end']), /** Show loader instead of values for all statistic items (default: undefined) */ isLoading: PropTypes.bool, /** * Array of statistic items * * `value` - Value of the statistic. Displayed as big text in the first row. * * `valueInShort` - Short version of value. Will be applied when there is no space for long value. If not specified, part of the value will be hidden with ellipsis * * `description` - Description of the statistic. Displayed in the second row. * * `descriptionInfo` - More info about the description. Displayed as an info icon with this text inside a tooltip * * `percentage` - Change in percents. Positive number - arrow up, negative - arrow down. * * `invertedPercentage` - When set to true renders positive percentage in red and negative in green. * * `onClick` - Callback to be executed on click (also on Enter/Space key press) * * `isLoading` - Shows a loader instead of value. * * `children` - Node to render on bottom of section. */ items: PropTypes.arrayOf(PropTypes.shape({ value: PropTypes.string, valueInShort: PropTypes.string, description: PropTypes.string, descriptionInfo: PropTypes.string, percentage: PropTypes.number, invertedPercentage: PropTypes.bool, onClick: PropTypes.func, children: PropTypes.node })) }); export default StatisticsWidget;