UNPKG

@flatbiz/antd

Version:
97 lines (93 loc) 2.89 kB
/*! @flatjs/forge MIT @flatbiz/antd */ import { useMemo, Fragment } from 'react'; import { Tag } from 'antd'; import { toArray, isUndefinedOrNull, valueIsEqual } from '@flatbiz/utils'; import { jsx } from 'react/jsx-runtime'; /** * 在列表数据中通过value匹配数据,以Tag形式展示 * @deprecated 已过期,请使用 TagListRender 组件 * @param props * @returns * ``` * 1. forceMatch: 是否强制匹配(默认值false) * - false: 匹配不到显示value值, * - true:匹配不到不显示 * 2. value 与 dataList中label、value任一相等,都可匹配 * * 用法1: * <TagListSelect * dataList=[{ label: '启用', value: 1 }] * colorMap={{ 1:'red', 2: 'blue'}} * value={1} /> * => * <Tag color={'red'}>启用</Tag> * * 用法2 * <TagListSelect * dataList=[{ label: '启用', value: 1. color: 'red' }] * value="启用" /> * => * <Tag color={'red'}>启用</Tag> * ``` */ var TagListSelect = function TagListSelect(props) { var valueList = toArray(props.value); var tagList = useMemo(function () { if (isUndefinedOrNull(props.value)) { return []; } return valueList.map(function (value) { var _props$dataList; var target = (_props$dataList = props.dataList) === null || _props$dataList === void 0 ? void 0 : _props$dataList.find(function (item) { return valueIsEqual(item.value, value) || item.label === value; }); if (target) { var _props$colorMap; return { label: target.label || target.value, color: ((_props$colorMap = props.colorMap) === null || _props$colorMap === void 0 ? void 0 : _props$colorMap[String(target.value)]) || target.color, value: value }; } if (props.forceMatch) { return undefined; } return { label: "".concat(value), color: undefined, value: value }; }).filter(Boolean); }, [props.colorMap, props.dataList, props.forceMatch, props.value, valueList]); if (tagList.length === 0) { return /*#__PURE__*/jsx(Fragment, { children: props.value }); } var hasColor = tagList.find(function (item) { return !!(item !== null && item !== void 0 && item.color); }); if (hasColor) { return /*#__PURE__*/jsx(Fragment, { children: tagList.map(function (item, index) { return /*#__PURE__*/jsx(Tag, { color: item.color, style: index === tagList.length - 1 ? { margin: '0' } : undefined, children: item.label }, index); }) }); } return /*#__PURE__*/jsx(Fragment, { children: tagList.map(function (item) { return item.label; }).join(',') }); }; TagListSelect.defaultProps = { forceMatch: false }; export { TagListSelect as T }; //# sourceMappingURL=tag-list-select-C8_X2SS-.js.map