UNPKG

wix-style-react

Version:
65 lines 3.08 kB
import React from 'react'; import PropTypes from 'prop-types'; import StatisticsItem from './StatisticsItem'; import { st, classes } from './StatisticsWidget.st.css'; import { SIZES } from './constants'; class StatisticsWidget extends React.PureComponent { constructor() { super(...arguments); this._renderStat = (stat, key) => { const { size, alignItems, isLoading } = this.props; return (React.createElement(StatisticsItem, { ...stat, isLoading: isLoading, key: key, size: size, alignItems: alignItems })); }; } render() { const { dataHook, size } = this.props; let { items } = this.props; items = items || []; if (items.length > 5) { // eslint-disable-next-line console.warn(`${items.length} items were passed in items array. StatisticsWidget will display only the first 5.`); } const firstFive = items.slice(0, 5); return (React.createElement("div", { className: st(classes.root, { size, }), "data-hook": dataHook }, firstFive.map(this._renderStat))); } } StatisticsWidget.displayName = 'StatisticsWidget'; StatisticsWidget.defaultProps = { size: SIZES.tiny, }; 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; //# sourceMappingURL=StatisticsWidget.js.map