import { CascaderItemSelectionState, ICascaderItem } from '../types'; import Tag from './Tag'; import Pop from '../../pop'; import { getPathValue, getPathLabel } from '../path-fns'; import { simplify } from '../simplify'; export interface ICascaderTagsProps { list: Array; // 节点选中信息 selectionMap: Map; simplifyPaths: boolean; onRemove(node: ICascaderItem): void; renderValue?: (path: ICascaderItem[]) => React.ReactNode; collapse: boolean; } const renderTagCollapsedTrigger = function (length) { return ( +{length} ); }; function CascaderTagList(props: ICascaderTagsProps) { const { list, renderValue, selectionMap, simplifyPaths, onRemove, collapse } = props; const paths = simplifyPaths ? simplify(list, selectionMap) : list; const renderPaths = collapse ? paths.slice(0, 1) : paths; const renderCollapsePaths = paths.slice(1); return ( <> {renderPaths.map(path => { const removeCallback = (e: React.MouseEvent) => { e.stopPropagation(); // 即移除最后一级叶子节点的选中状态 onRemove(path[path.length - 1]); }; return ( ); })} {collapse && renderCollapsePaths.length > 0 && (
{renderCollapsePaths .map(item => { return getPathLabel(item); }) .join('、')}
} > {renderTagCollapsedTrigger(renderCollapsePaths.length)}
)} ); } export default CascaderTagList;