UNPKG

wix-style-react

Version:
124 lines (104 loc) 4.86 kB
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 { st, classes } from './CounterBadge.st.css'; import Caption from '../Text/Caption'; import Text from '../Text/Text'; import { dataHooks } from './constants'; var MAX_NUMBER = 100; /** CounterBadge */ var CounterBadge = /*#__PURE__*/function (_React$PureComponent) { _inherits(CounterBadge, _React$PureComponent); var _super = _createSuper(CounterBadge); function CounterBadge() { var _this; _classCallCheck(this, CounterBadge); 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), "_renderNumberContent", function (n) { return n < MAX_NUMBER ? n : /*#__PURE__*/React.createElement("div", { className: classes.numberContent }, MAX_NUMBER - 1, /*#__PURE__*/React.createElement("svg", { xmlns: "http://www.w3.org/2000/svg", width: "5", height: "5", viewBox: "0 0 5 5" }, /*#__PURE__*/React.createElement("path", { fill: "currentColor", d: "M3,0 L3,2 L5,2 L5,3 L3,3 L3,5 L2,5 L2,3 L0,3 L0,2 L2,2 L2,0 L3,0 Z" }))); }); _defineProperty(_assertThisInitialized(_this), "_renderCounterBadgeContent", function (size, content) { return size === 'small' ? /*#__PURE__*/React.createElement(Caption, { caption: "c1", light: true, dataHook: dataHooks.content, className: classes.caption }, content) : /*#__PURE__*/React.createElement(Text, { dataHook: dataHooks.content, size: "tiny", weight: "bold", light: true, className: classes.text }, content); }); return _this; } _createClass(CounterBadge, [{ key: "render", value: function render() { var _this$props = this.props, dataHook = _this$props.dataHook, size = _this$props.size, skin = _this$props.skin, children = _this$props.children, className = _this$props.className, showShadow = _this$props.showShadow; var custom = isNaN(children); var longNumber = !custom && Number(children) >= MAX_NUMBER; var content = custom ? children : this._renderNumberContent(Number(children)); return /*#__PURE__*/React.createElement("div", { className: st(classes.root, { skin: skin, custom: custom, size: size, longNumber: longNumber, showShadow: showShadow }, className), "data-hook": dataHook }, this._renderCounterBadgeContent(size, content)); } }]); return CounterBadge; }(React.PureComponent); CounterBadge.displayName = 'CounterBadge'; CounterBadge.propTypes = { /** Applied as data-hook HTML attribute that can be used in the tests */ dataHook: PropTypes.string, /** A css class to be applied to the component's root element */ className: PropTypes.string, /** Any element to be rendered inside */ children: PropTypes.node, /** The component's look and feel */ skin: PropTypes.oneOf(['general', 'standard', 'neutralStandard', 'danger', 'warning', 'urgent', 'success', 'light']), /** The component's size. Can be small or medium */ size: PropTypes.oneOf(['small', 'medium']), /** Makes the card have a box-shadow style */ showShadow: PropTypes.bool }; CounterBadge.defaultProps = { skin: 'general', size: 'small', showShadow: false }; export default CounterBadge;