import cx from 'classnames'; import { Component, createRef, CSSProperties } from 'react'; import { CascaderItemSelectionState, ICascaderItem } from '../types'; import { ISearchInputImperativeHandlers, SearchInput } from './Search'; import Tags, { ICascaderTagsProps } from './Tags'; import { BaseTrigger, ICascaderBaseTriggerProps } from './BaseTrigger'; interface ITagsTriggerProps extends ICascaderBaseTriggerProps { onRemove: (node: ICascaderItem) => void; // 节点选中信息 selectionMap: Map; renderTags?: ( props: Pick ) => React.ReactNode; simplifyPaths: boolean; maxLine: number | null; lineHeight: number; } export class TagsTrigger extends Component { static defaultProps = { selectedPaths: [], }; searchInputRef = createRef(); onKeywordChange: React.ChangeEventHandler = e => { this.props.onKeywordChange(e.target.value); }; focus() { this.searchInputRef.current?.focus(); } renderTagsContent() { const { selectedPaths, renderValue, onRemove, selectionMap, simplifyPaths, maxLine, lineHeight, } = this.props; const tagEl = ( ); const maxHeightStyle: CSSProperties = {}; if (maxLine > 1) { maxHeightStyle.maxHeight = maxLine * lineHeight + 'px'; maxHeightStyle.overflowY = 'auto'; return (
{tagEl}
); } return tagEl; } render() { const { className, visible, clearable, selectedPaths, keyword, disabled, i18n, searchable, placeholder, onClick, onClear, onKeywordChange, renderValue, renderTags, onRemove, maxLine, } = this.props; const showTags = selectedPaths.length > 0; const showSearch = visible && searchable; return ( {showTags && // Allow customize rendering of tag list (typeof renderTags === 'function' ? renderTags({ list: selectedPaths, renderValue, onRemove, }) : this.renderTagsContent())} {showSearch && ( )} ); } }