UNPKG

tntd

Version:

tntd是基于 TNT Design 设计体系的 React UI 组件库,主要用于研发企业级中后台产品。

237 lines (234 loc) 9.99 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var _exportNames = { TagColors: true, Tag: true }; exports.TagColors = exports.Tag = void 0; var _react = _interopRequireWildcard(require("react")); var _configProvider = require("../config-provider"); var _tag = _interopRequireWildcard(require("antd/lib/tag")); Object.keys(_tag).forEach(function (key) { if (key === "default" || key === "__esModule") return; if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; if (key in exports && exports[key] === _tag[key]) return; Object.defineProperty(exports, key, { enumerable: true, get: function get() { return _tag[key]; } }); }); var _classnames = _interopRequireDefault(require("classnames")); var _ellipsis = _interopRequireDefault(require("../ellipsis")); var _icon = _interopRequireDefault(require("../icon")); function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; } function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; } 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(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : 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); } var __rest = void 0 && (void 0).__rest || function (s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; }; /* * @Author: 周泽飞 zefei.zhou@tongdun.net * @Date: 2024-03-04 19:15:22 * @LastEditors: 周泽飞 zefei.zhou@tongdun.net * @LastEditTime: 2024-03-11 10:10:31 * @FilePath: /tntd/packages/tntd/src/tag/tag.tsx * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ var TagColors; (function (TagColors) { TagColors["grey"] = "grey"; TagColors["rose"] = "rose"; TagColors["lightblue"] = "lightblue"; TagColors["bluegrey"] = "bluegrey"; TagColors["purplegrey"] = "purplegrey"; TagColors["lightpurple"] = "lightpurple"; TagColors["lightgreen"] = "lightgreen"; TagColors["tnt-pink"] = "tnt-pink"; TagColors["tnt-orange"] = "tnt-orange"; TagColors["tnt-purple"] = "tnt-purple"; })(TagColors || (exports.TagColors = TagColors = {})); // 内置的状态 var statusMap = { success: { icon: 'check-circle', color: 'green' }, info: { icon: 'info-circle', color: 'blue' }, error: { icon: 'close-circle', color: 'red' }, warning: { icon: 'info-circle', color: 'orange' } }; var getDisplayEllipsisOptions = function getDisplayEllipsisOptions(props, prefixCls) { var _a; var _ref = props || {}, ellipsisOptions = _ref.ellipsisOptions, addonContent = _ref.addonContent, addonType = _ref.addonType, addonPosition = _ref.addonPosition, children = _ref.children; var options = Object.assign({}, ellipsisOptions); var addonContentInfo = null; if (addonContent) { addonContentInfo = addonContent; } else if (addonType && statusMap[addonType]) { addonContentInfo = _react["default"].createElement(_icon["default"], { type: (_a = statusMap[addonType]) === null || _a === void 0 ? void 0 : _a.icon }); } if (addonContentInfo) { addonContentInfo = _react["default"].createElement("span", { className: "".concat(prefixCls, "-addon") }, addonContentInfo); if (addonPosition === 'prefix') { options.prefix = addonContentInfo; } if (addonPosition === 'suffix') { options.suffix = addonContentInfo; } if (options.Popover === true) { options.content = children; } else { options.title = children; } options.contentInfo = addonContentInfo; } return options; }; var Tag = exports.Tag = (0, _react.forwardRef)(function (props, ref) { var _a; var className = props.className, _props$border = props.border, border = _props$border === void 0 ? true : _props$border, size = props.size, addonType = props.addonType, addonContent = props.addonContent, _props$addonPosition = props.addonPosition, addonPosition = _props$addonPosition === void 0 ? 'prefix' : _props$addonPosition, ellipsisOptions = props.ellipsisOptions, children = props.children, restProps = __rest(props, ["className", "border", "size", "addonType", "addonContent", "addonPosition", "ellipsisOptions", "children"]); var _ref2 = props || {}, color = _ref2.color; if (!color && addonType) { color = (_a = statusMap[addonType]) === null || _a === void 0 ? void 0 : _a.color; } return _react["default"].createElement(_configProvider.ConfigConsumer, null, function (_ref3) { var getPrefixCls = _ref3.getPrefixCls; var _a, _b, _c, _d, _e; var prefixCls = getPrefixCls('tag'); var displayEllipsisOptions = getDisplayEllipsisOptions({ ellipsisOptions: ellipsisOptions, addonContent: addonContent, addonType: addonType, addonPosition: addonPosition, children: children }, prefixCls); // 只有一个icon时 padding距离存在差异 var onlyIcon = _react["default"].isValidElement(children) && _react["default"].Children.only(children) && (children === null || children === void 0 ? void 0 : children.type) instanceof Function && ((_c = (_b = (_a = children === null || children === void 0 ? void 0 : children.type) === null || _a === void 0 ? void 0 : _a.name) === null || _b === void 0 ? void 0 : _b.toLowerCase) === null || _c === void 0 ? void 0 : _c.call(_b)) === 'icon'; // 前缀是图片 只处理一层节点下是图片的,否则就用户自定义样式 var addonIsImg = _react["default"].isValidElement(addonContent) && (addonContent === null || addonContent === void 0 ? void 0 : addonContent.type) && typeof (addonContent === null || addonContent === void 0 ? void 0 : addonContent.type) === 'string' && ((_e = (_d = addonContent === null || addonContent === void 0 ? void 0 : addonContent.type) === null || _d === void 0 ? void 0 : _d.toLowerCase) === null || _e === void 0 ? void 0 : _e.call(_d)) === 'img'; return _react["default"].createElement(_tag["default"], Object.assign({ className: (0, _classnames["default"])(_defineProperty({}, "".concat(prefixCls, "-").concat(color), color && !!TagColors[color]), 'tnt-tag', "".concat(prefixCls, "-").concat(size || 'middle'), _defineProperty({}, "".concat(prefixCls, "-no-border"), !border), _defineProperty({}, "".concat(prefixCls, "-only-child"), !children || onlyIcon), _defineProperty({}, "".concat(prefixCls, "-addon-img"), !!addonIsImg), className || '') }, restProps, { color: !TagColors[color] ? color : '', ref: ref }), !addonContent && !addonType && !ellipsisOptions && children, (!!addonContent || !!addonType || !!ellipsisOptions) && _react["default"].createElement("span", { className: "".concat(prefixCls, "-addon-wrap") }, !!children && _react["default"].createElement(_ellipsis["default"], Object.assign({}, displayEllipsisOptions), children), !children && (displayEllipsisOptions === null || displayEllipsisOptions === void 0 ? void 0 : displayEllipsisOptions.contentInfo))); }); }); Tag.CheckableTag = (0, _react.forwardRef)(function (props, ref) { // 默认没有border var _a = props || {}, onChange = _a.onChange, disabled = _a.disabled, _a$border = _a.border, border = _a$border === void 0 ? false : _a$border, className = _a.className, rest = __rest(_a, ["onChange", "disabled", "border", "className"]); return _react["default"].createElement(_configProvider.ConfigConsumer, null, function (_ref4) { var getPrefixCls = _ref4.getPrefixCls; var prefixCls = getPrefixCls('tag-checkable'); return _react["default"].createElement(_tag["default"].CheckableTag, Object.assign({}, !disabled && { onChange: onChange }, { className: (0, _classnames["default"])('tnt-tag', _defineProperty(_defineProperty({}, "".concat(prefixCls, "-disabled"), disabled), "".concat(prefixCls, "-border"), !!border)) }, rest, { ref: ref })); }); });