UNPKG

@perfma/heaven

Version:

An UI Framework base [Ant Design V4](https://ant.design/components/overview-cn/) for React.

55 lines (44 loc) 4 kB
var _excluded = ["type", "disabled", "maxLength", "icon", "className", "prefixCls", "children"]; function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; } function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; } function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } import React from 'react'; import { Tag, Tooltip, ConfigProvider } from 'antd'; import { PlusOutlined } from '@ant-design/icons'; import classnames from 'classnames'; import './index.less'; var CheckableTag = Tag.CheckableTag; var ConfigContext = ConfigProvider.ConfigContext; var ProTag = function ProTag(_ref) { var _children, _classnames; var _ref$type = _ref.type, type = _ref$type === void 0 ? 'default' : _ref$type, disabled = _ref.disabled, _ref$maxLength = _ref.maxLength, maxLength = _ref$maxLength === void 0 ? 0 : _ref$maxLength, icon = _ref.icon, className = _ref.className, prefixCls = _ref.prefixCls, children = _ref.children, resetProps = _objectWithoutProperties(_ref, _excluded); var _React$useContext = React.useContext(ConfigContext), getPrefixCls = _React$useContext.getPrefixCls; var consutomPrefixCls = getPrefixCls('tag', prefixCls); var disabledPrefixCls = getPrefixCls('tag-disabled', prefixCls); var addIcon = type === 'add' ? /*#__PURE__*/React.createElement(PlusOutlined, null) : null; children = children || (type === 'add' ? 'New Tag' : null); var isTooLong = typeof children === 'string' && maxLength > 0 && children.length > maxLength; var shortChildren = isTooLong ? "".concat((_children = children) === null || _children === void 0 ? void 0 : _children.slice(0, maxLength), "...") : children; var TagElem = /*#__PURE__*/React.createElement(Tag, _objectSpread(_objectSpread({}, resetProps), {}, { icon: icon || addIcon, className: classnames((_classnames = {}, _defineProperty(_classnames, "".concat(className), !!className), _defineProperty(_classnames, "".concat(consutomPrefixCls, "-").concat(type), !!type), _defineProperty(_classnames, disabledPrefixCls, disabled), _classnames)) }), shortChildren); return isTooLong ? /*#__PURE__*/React.createElement(Tooltip, { title: children }, TagElem) : TagElem; }; ProTag.displayName = 'Tag'; ProTag.CheckableTag = CheckableTag; export default ProTag;