import PropTypes from '../../../../_util/vue-types' import { createRef } from '../../util' import generateSelector, { selectorPropTypes } from '../../Base/BaseSelector' import SearchInput from '../../SearchInput' import Selection from './Selection' import { getComponentFromProp } from '../../../../_util/props-util' import getTransitionProps from '../../../../_util/getTransitionProps' import BaseMixin from '../../../../_util/BaseMixin' const TREE_SELECT_EMPTY_VALUE_KEY = 'RC_TREE_SELECT_EMPTY_VALUE_KEY' const Selector = generateSelector('multiple') // export const multipleSelectorContextTypes = { // onMultipleSelectorRemove: PropTypes.func.isRequired, // } const MultipleSelector = { mixins: [BaseMixin], props: { ...selectorPropTypes(), ...SearchInput.props, selectorValueList: PropTypes.array, disabled: PropTypes.bool, searchValue: PropTypes.string, labelInValue: PropTypes.bool, maxTagCount: PropTypes.number, maxTagPlaceholder: PropTypes.any, // onChoiceAnimationLeave: PropTypes.func, }, inject: { vcTreeSelect: { default: {}}, }, created () { this.inputRef = createRef() }, methods: { onPlaceholderClick () { this.inputRef.current.focus() }, focus () { this.inputRef.current.focus() }, blur () { this.inputRef.current.blur() }, _renderPlaceholder () { const { prefixCls, placeholder, searchPlaceholder, searchValue, selectorValueList, } = this.$props const currentPlaceholder = placeholder || searchPlaceholder if (!currentPlaceholder) return null const hidden = searchValue || selectorValueList.length // [Legacy] Not remove the placeholder return ( ) }, onChoiceAnimationLeave (...args) { this.__emit('choiceAnimationLeave', ...args) }, renderSelection () { const { selectorValueList, choiceTransitionName, prefixCls, labelInValue, maxTagCount, } = this.$props const { vcTreeSelect: { onMultipleSelectorRemove }, $listeners, $slots } = this // Check if `maxTagCount` is set let myValueList = selectorValueList if (maxTagCount >= 0) { myValueList = selectorValueList.slice(0, maxTagCount) } // Selector node list const selectedValueNodes = myValueList.map(({ label, value }) => ( {$slots.default} )) // Rest node count if (maxTagCount >= 0 && maxTagCount < selectorValueList.length) { let content = `+ ${selectorValueList.length - maxTagCount} ...` const maxTagPlaceholder = getComponentFromProp(this, 'maxTagPlaceholder', {}, false) if (typeof maxTagPlaceholder === 'string') { content = maxTagPlaceholder } else if (typeof maxTagPlaceholder === 'function') { const restValueList = selectorValueList.slice(maxTagCount) content = maxTagPlaceholder( labelInValue ? restValueList : restValueList.map(({ value }) => value) ) } const restNodeSelect = ( {$slots.default} ) selectedValueNodes.push(restNodeSelect) } selectedValueNodes.push() const className = `${prefixCls}-selection__rendered` if (choiceTransitionName) { const transitionProps = getTransitionProps(choiceTransitionName, { tag: 'ul', afterLeave: this.onChoiceAnimationLeave, }) return ( {selectedValueNodes} ) } return ( ) }, }, render () { const { $listeners, $slots } = this return ( {$slots.default} ) }, } export default MultipleSelector