UNPKG

@alifd/meet-react

Version:

Fusion Mobile React UI System Component

58 lines 3.96 kB
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } import React, { createElement, forwardRef, Fragment } from "react"; import classNames from 'classnames'; import { Text } from "@alifd/meet-react-component-one"; import View from '../view'; import { stopPropagation } from '../utils'; var Item = function Item(props, ref) { var _props$disabled = props.disabled, disabled = _props$disabled === void 0 ? false : _props$disabled, _props$prefix = props.prefix, prefix = _props$prefix === void 0 ? 'mt-' : _props$prefix, size = props.size, last = props.last, disabledAll = props.disabledAll, _onClick = props.onClick, index = props.index, count = props.count, maxNode = props.maxNode, separator = props.separator; var renderSeparator = function renderSeparator() { return separator ? /*#__PURE__*/React.createElement(View, { className: classNames(["".concat(prefix, "breadcrumb-item-icon-custom"), "".concat(prefix, "breadcrumb-item--font-").concat(size, "-size"), "".concat(prefix, "breadcrumb-item--margin-").concat(size, "-size"), _defineProperty({}, "".concat(prefix, "breadcrumb-item--arrow-disabled"), disabledAll)]) }, separator) : /*#__PURE__*/React.createElement(View, { className: classNames(["".concat(prefix, "breadcrumb-item-icon"), "".concat(prefix, "breadcrumb-item--arrow-").concat(size, "-size"), "".concat(prefix, "breadcrumb-item--margin-").concat(size, "-size"), _defineProperty({}, "".concat(prefix, "breadcrumb-item--arrow-disabled"), disabledAll)]) }); }; var renderFull = function renderFull() { return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(View, { className: classNames("".concat(prefix, "breadcrumb-item--action"), _defineProperty(_defineProperty({}, "".concat(prefix, "breadcrumb-item--action-disabled"), disabled || disabledAll), "".concat(prefix, "breadcrumb-item--action-active"), last)) }, props.children), last ? '' : renderSeparator()); }; var shouldHide = count > maxNode && index !== 0 && count - index >= maxNode - 1; if (shouldHide && index !== 1) { return null; } var renderItem = function renderItem() { if (shouldHide && index === 1) { return /*#__PURE__*/React.createElement(Fragment, null, /*#__PURE__*/React.createElement(Text, null, '...'), last ? '' : renderSeparator()); } return renderFull(); }; return /*#__PURE__*/React.createElement(View, { ref: ref, className: classNames(["".concat(prefix, "breadcrumb-item"), "".concat(prefix, "breadcrumb-item--font-").concat(size, "-size"), "".concat(prefix, "breadcrumb-item--space-").concat(size, "-size"), _defineProperty({}, "".concat(prefix, "breadcrumb-item--disabled"), disabled || disabledAll)]), onClick: function onClick(e) { if (disabled || disabledAll) { stopPropagation(e); } else { _onClick(index); } } }, renderItem()); }; Item.displayName = 'BreadCrumb.Item'; export default /*#__PURE__*/forwardRef(Item);