import cx from 'classnames'; import { Component } from 'react'; import Popover from '../../popover'; import { ICascaderItem, CascaderSearchClickHandler, CascaderItemSelectionState, } from '../types'; import { II18nLocaleCascader } from '../../i18n'; import { Checkbox } from '../../checkbox'; import BlockLoading from '../../loading/BlockLoading'; import { getNodeKey } from '../node-fns'; import { getPathValue } from '../path-fns'; const withPopover = Popover.withPopover; export interface ISearchContentProps { // injected by withPopover popover: Popover; multiple: boolean; onOptionToggle: (path: ICascaderItem[], checked: boolean) => void; onOptionClick: CascaderSearchClickHandler; isSearching: boolean; keyword: string; searchList: Array; highlight: (keyword: string, path: ICascaderItem[]) => React.ReactNode; i18n: II18nLocaleCascader; selectionMap: Map; } class SearchContent extends Component { closePopup = () => this.props.popover?.close(); onOptionClick(path: ICascaderItem[]) { const { onOptionClick } = this.props; onOptionClick(path, this.closePopup); } renderSearchingOrEmpty() { const { isSearching, i18n } = this.props; return (
{isSearching ? ( ) : ( i18n.searchEmpty )}
); } renderPanels() { const { searchList, multiple, highlight, keyword, selectionMap } = this.props; return (
    {searchList.map(path => { const leafNode = path[path.length - 1]; const searchItemCls = cx('zent-cascader-v2--search-item', { 'zent-cascader-v2--search-item--multiple': multiple, }); let checkState: CascaderItemSelectionState | undefined; if (multiple) { checkState = selectionMap.get(getNodeKey(leafNode)); } return (
  • this.onOptionClick(path) } > {multiple && ( this.props.onOptionToggle(path, e.target.checked) } checked={checkState === 'on'} disabled={leafNode.disabled} /> )} {highlight(keyword, path)}
  • ); })}
); } render() { const { isSearching, searchList } = this.props; return (
{isSearching || !searchList.length ? this.renderSearchingOrEmpty() : this.renderPanels()}
); } } export default withPopover(SearchContent);