UNPKG

wix-style-react

Version:
185 lines (159 loc) • 6.85 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 { st, classes } from './ListItemSection.st.css'; import Divider from '../Divider'; import Text from '../Text'; import TextButton from '../TextButton'; import { dataHooks } from './constants'; import { isString } from '../utils/StringUtils'; export var TYPES = { WHITESPACE: 'whitespace', DIVIDER: 'divider', TITLE: 'title', SUBHEADER: 'subheader' }; /** ListItemSection description */ var ListItemSection = /*#__PURE__*/function (_React$PureComponent) { _inherits(ListItemSection, _React$PureComponent); var _super = _createSuper(ListItemSection); function ListItemSection() { var _this; _classCallCheck(this, ListItemSection); 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), "state", {}); _defineProperty(_assertThisInitialized(_this), "_renderDivisionElements", function (children) { var _this$props = _this.props, dataHook = _this$props.dataHook, type = _this$props.type; return /*#__PURE__*/React.createElement("div", { className: st(classes.root, _defineProperty({}, type, true)), "data-hook": dataHook, onClick: function onClick(e) { return e.stopPropagation(); }, children: children }); }); _defineProperty(_assertThisInitialized(_this), "_renderSuffix", function () { var _this$props2 = _this.props, suffix = _this$props2.suffix, onClick = _this$props2.onClick, ellipsis = _this$props2.ellipsis; return isString(suffix) ? /*#__PURE__*/React.createElement("div", { className: classes.suffixWrapper }, /*#__PURE__*/React.createElement(TextButton, { ellipsis: ellipsis, dataHook: dataHooks.SUFFIX, size: "tiny", onClick: onClick, className: classes.suffix }, suffix)) : /*#__PURE__*/React.createElement("div", { "data-hook": dataHooks.SUFFIX, className: classes.suffixWrapper, onClick: onClick }, suffix); }); _defineProperty(_assertThisInitialized(_this), "_renderTitle", function () { var _this$props3 = _this.props, dataHook = _this$props3.dataHook, className = _this$props3.className, type = _this$props3.type, title = _this$props3.title, suffix = _this$props3.suffix, ellipsis = _this$props3.ellipsis; return /*#__PURE__*/React.createElement("div", { className: st(classes.root, { subheader: type === TYPES.SUBHEADER, ellipsis: ellipsis, suffix: !!suffix }, className), "data-hook": dataHook }, /*#__PURE__*/React.createElement("div", { className: classes.titleWrapper }, /*#__PURE__*/React.createElement(Text, { dataHook: dataHooks.TITLE, tagName: "div", size: "small", className: classes.title, ellipsis: ellipsis, enterDelay: 300 }, title)), suffix && _this._renderSuffix()); }); return _this; } _createClass(ListItemSection, [{ key: "render", value: function render() { var type = this.props.type; if (type === TYPES.WHITESPACE) return this._renderDivisionElements(); if (type === TYPES.DIVIDER) return this._renderDivisionElements( /*#__PURE__*/React.createElement(Divider, null)); return this._renderTitle(); } }]); return ListItemSection; }(React.PureComponent); _defineProperty(ListItemSection, "displayName", 'ListItemSection'); _defineProperty(ListItemSection, "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, /** A list item section can be * * `title` - Acts as a title for following list items. * * `subheader` - Acts as separator between list items for differentiation. * * `whitespace` - Adds some padding between list items. * * `divider` - Same as whitespace, but with a line. */ type: PropTypes.oneOf(Object.values(TYPES)), /** Text of the list item */ title: PropTypes.string, /** Suffix node. Renders TextButton for a string otherwise the node itself.*/ suffix: PropTypes.node, /** If true, long text won't break into more than one line and will be terminated with an ellipsis */ ellipsis: PropTypes.bool, /** A callback function called when suffix is clicked */ onClick: PropTypes.func }); _defineProperty(ListItemSection, "defaultProps", { type: TYPES.TITLE, ellipsis: false, dataHook: 'list-item-section' }); export default ListItemSection; export var listItemSectionBuilder = function listItemSectionBuilder(_ref) { var id = _ref.id, className = _ref.className, dataHook = _ref.dataHook, type = _ref.type, title = _ref.title, suffix = _ref.suffix, ellipsis = _ref.ellipsis; return { id: id, overrideOptionStyle: true, disabled: true, value: function value(props) { return /*#__PURE__*/React.createElement(ListItemSection, _extends({ className: className, dataHook: dataHook, type: type, title: title, suffix: suffix, ellipsis: ellipsis }, props)); } }; };