UNPKG

28.9 kBJavaScriptView Raw
1'use strict';
2
3exports.__esModule = true;
4exports.default = undefined;
5
6var _extends2 = require('babel-runtime/helpers/extends');
7
8var _extends3 = _interopRequireDefault(_extends2);
9
10var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
11
12var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
13
14var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
15
16var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
17
18var _inherits2 = require('babel-runtime/helpers/inherits');
19
20var _inherits3 = _interopRequireDefault(_inherits2);
21
22var _class, _temp;
23
24var _react = require('react');
25
26var _react2 = _interopRequireDefault(_react);
27
28var _propTypes = require('prop-types');
29
30var _propTypes2 = _interopRequireDefault(_propTypes);
31
32var _select = require('../select');
33
34var _select2 = _interopRequireDefault(_select);
35
36var _cascader = require('../cascader');
37
38var _cascader2 = _interopRequireDefault(_cascader);
39
40var _menu = require('../menu');
41
42var _menu2 = _interopRequireDefault(_menu);
43
44var _util = require('../util');
45
46function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
47
48var bindCtx = _util.func.bindCtx;
49var pickOthers = _util.obj.pickOthers;
50var getStyle = _util.dom.getStyle;
51
52/**
53 * CascaderSelect
54 */
55
56var CascaderSelect = (_temp = _class = function (_Component) {
57 (0, _inherits3.default)(CascaderSelect, _Component);
58
59 function CascaderSelect(props, context) {
60 (0, _classCallCheck3.default)(this, CascaderSelect);
61
62 var _this = (0, _possibleConstructorReturn3.default)(this, _Component.call(this, props, context));
63
64 _this.state = {
65 value: _this.normalizeValue('value' in props ? props.value : props.defaultValue),
66 searchValue: '',
67 visible: typeof props.visible === 'undefined' ? props.defaultVisible : props.visible
68 };
69
70 bindCtx(_this, ['handleVisibleChange', 'handleAfterOpen', 'handleChange', 'handleClear', 'handleRemove', 'handleSearch', 'getPopup', 'saveSelectRef', 'saveCascaderRef', 'handleKeyDown']);
71 return _this;
72 }
73
74 CascaderSelect.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
75 var st = {};
76
77 if ('value' in nextProps) {
78 st.value = this.normalizeValue(nextProps.value);
79 }
80 if ('visible' in nextProps) {
81 st.visible = nextProps.visible;
82 }
83
84 if (Object.keys(st).length) {
85 this.setState(st);
86 }
87 };
88
89 CascaderSelect.prototype.normalizeValue = function normalizeValue(value) {
90 if (value) {
91 if (Array.isArray(value)) {
92 return value;
93 }
94
95 return [value];
96 }
97
98 return [];
99 };
100
101 CascaderSelect.prototype.updateCache = function updateCache(dataSource) {
102 var _this2 = this;
103
104 this._v2n = {};
105 this._p2n = {};
106 var loop = function loop(data) {
107 var prefix = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '0';
108 return data.forEach(function (item, index) {
109 var value = item.value,
110 children = item.children;
111
112 var pos = prefix + '-' + index;
113 _this2._v2n[value] = _this2._p2n[pos] = (0, _extends3.default)({}, item, { pos: pos });
114
115 if (children && children.length) {
116 loop(children, pos);
117 }
118 });
119 };
120
121 loop(dataSource);
122 };
123
124 CascaderSelect.prototype.flatValue = function flatValue(value) {
125 var _this3 = this;
126
127 var getDepth = function getDepth(v) {
128 var pos = _this3.getPos(v);
129 if (!pos) {
130 return 0;
131 }
132 return pos.split('-').length;
133 };
134 var newValue = value.slice(0).sort(function (prev, next) {
135 return getDepth(prev) - getDepth(next);
136 });
137
138 for (var i = 0; i < newValue.length; i++) {
139 for (var j = 0; j < newValue.length; j++) {
140 if (i !== j && this.isDescendantOrSelf(this.getPos(newValue[i]), this.getPos(newValue[j]))) {
141 newValue.splice(j, 1);
142 j--;
143 }
144 }
145 }
146
147 return newValue;
148 };
149
150 CascaderSelect.prototype.isDescendantOrSelf = function isDescendantOrSelf(currentPos, targetPos) {
151 if (!currentPos || !targetPos) {
152 return false;
153 }
154
155 var currentNums = currentPos.split('-');
156 var targetNums = targetPos.split('-');
157
158 return currentNums.length <= targetNums.length && currentNums.every(function (num, index) {
159 return num === targetNums[index];
160 });
161 };
162
163 CascaderSelect.prototype.getValue = function getValue(pos) {
164 return this._p2n[pos] ? this._p2n[pos].value : null;
165 };
166
167 CascaderSelect.prototype.getPos = function getPos(value) {
168 return this._v2n[value] ? this._v2n[value].pos : null;
169 };
170
171 CascaderSelect.prototype.getData = function getData(value) {
172 var _this4 = this;
173
174 return value.map(function (v) {
175 return _this4._v2n[v];
176 });
177 };
178
179 CascaderSelect.prototype.getLabelPath = function getLabelPath(data) {
180 var _this5 = this;
181
182 var nums = data.pos.split('-');
183 return nums.slice(1).reduce(function (ret, num, index) {
184 var p = nums.slice(0, index + 2).join('-');
185 ret.push(_this5._p2n[p].label);
186 return ret;
187 }, []);
188 };
189
190 CascaderSelect.prototype.getSignleData = function getSignleData(value) {
191 if (!value.length) {
192 return null;
193 }
194
195 if (Array.isArray(value)) value = value[0];
196
197 var data = this._v2n[value];
198 if (!data) {
199 return {
200 value: value
201 };
202 }
203
204 var labelPath = this.getLabelPath(data);
205 var displayRender = this.props.displayRender || function (labels) {
206 return labels.join(' / ');
207 };
208
209 return (0, _extends3.default)({}, data, {
210 label: displayRender(labelPath, data)
211 });
212 };
213
214 CascaderSelect.prototype.getMultipleData = function getMultipleData(value) {
215 var _this6 = this;
216
217 if (!value.length) {
218 return null;
219 }
220
221 var _props = this.props,
222 checkStrictly = _props.checkStrictly,
223 canOnlyCheckLeaf = _props.canOnlyCheckLeaf,
224 displayRender = _props.displayRender;
225
226 var data = (checkStrictly || canOnlyCheckLeaf ? value : this.flatValue(value)).map(function (v) {
227 return _this6._v2n[v] || { value: v };
228 });
229
230 if (displayRender) {
231 data = data.map(function (item) {
232 if (!item.pos) {
233 return item;
234 }
235 var labelPath = _this6.getLabelPath(item);
236
237 return (0, _extends3.default)({}, item, {
238 label: displayRender(labelPath, item)
239 });
240 });
241 }
242
243 return data;
244 };
245
246 CascaderSelect.prototype.getIndeterminate = function getIndeterminate(value) {
247 var _this7 = this;
248
249 var indeterminate = [];
250
251 var positions = value.map(this.getPos.bind(this));
252 positions.forEach(function (pos) {
253 if (!pos) {
254 return false;
255 }
256 var nums = pos.split('-');
257 for (var i = nums.length; i > 2; i--) {
258 var parentPos = nums.slice(0, i - 1).join('-');
259 var parentValue = _this7.getValue(parentPos);
260 if (indeterminate.indexOf(parentValue) === -1) {
261 indeterminate.push(parentValue);
262 }
263 }
264 });
265
266 return indeterminate;
267 };
268
269 CascaderSelect.prototype.saveSelectRef = function saveSelectRef(ref) {
270 this.select = ref;
271 };
272
273 CascaderSelect.prototype.saveCascaderRef = function saveCascaderRef(ref) {
274 this.cascader = ref;
275 };
276
277 CascaderSelect.prototype.completeValue = function completeValue(value) {
278 var newValue = [];
279
280 var flatValue = this.flatValue(value).reverse();
281 var ps = Object.keys(this._p2n);
282 for (var i = 0; i < ps.length; i++) {
283 for (var j = 0; j < flatValue.length; j++) {
284 var v = flatValue[j];
285 if (this.isDescendantOrSelf(this.getPos(v), ps[i])) {
286 newValue.push(this.getValue(ps[i]));
287 ps.splice(i, 1);
288 i--;
289 break;
290 }
291 }
292 }
293
294 return newValue;
295 };
296
297 CascaderSelect.prototype.isLeaf = function isLeaf(data) {
298 return !(data.children && data.children.length || !!this.props.loadData && !data.isLeaf);
299 };
300
301 CascaderSelect.prototype.handleVisibleChange = function handleVisibleChange(visible, type) {
302 if (!('visible' in this.props)) {
303 this.setState({
304 visible: visible
305 });
306 }
307
308 if (['fromCascader', 'keyboard'].indexOf(type) !== -1 && !visible) {
309 this.select.focusInput();
310 }
311
312 this.props.onVisibleChange(visible, type);
313 };
314
315 CascaderSelect.prototype.handleKeyDown = function handleKeyDown(e) {
316 var onKeyDown = this.props.onKeyDown;
317 var visible = this.state.visible;
318
319
320 if (onKeyDown) {
321 onKeyDown(e);
322 }
323
324 if (!visible) {
325 return;
326 }
327
328 switch (e.keyCode) {
329 case _util.KEYCODE.UP:
330 case _util.KEYCODE.DOWN:
331 this.cascader.setFocusValue();
332 e.preventDefault();
333 break;
334 default:
335 break;
336 }
337 };
338
339 CascaderSelect.prototype.getPopup = function getPopup(ref) {
340 this.popup = ref;
341 if (typeof this.props.popupProps.ref === 'function') {
342 this.props.popupProps.ref(ref);
343 }
344 };
345
346 CascaderSelect.prototype.handleAfterOpen = function handleAfterOpen() {
347 if (!this.popup) {
348 return;
349 }
350
351 var _props2 = this.props,
352 prefix = _props2.prefix,
353 popupProps = _props2.popupProps;
354
355 var dropDownNode = this.popup.getInstance().overlay.getInstance().getContentNode();
356 var cascaderNode = dropDownNode.querySelector('.' + prefix + 'cascader');
357 if (cascaderNode) {
358 this.cascaderHeight = getStyle(cascaderNode, 'height');
359 }
360
361 if (typeof popupProps.afterOpen === 'function') {
362 popupProps.afterOpen();
363 }
364 };
365
366 CascaderSelect.prototype.handleChange = function handleChange(value, data, extra) {
367 var _props3 = this.props,
368 multiple = _props3.multiple,
369 changeOnSelect = _props3.changeOnSelect,
370 onChange = _props3.onChange;
371 var _state = this.state,
372 visible = _state.visible,
373 searchValue = _state.searchValue;
374
375
376 var st = {};
377 if (!multiple && (!changeOnSelect || this.isLeaf(data) || !!searchValue)) {
378 this.handleVisibleChange(!visible, 'fromCascader');
379 }
380 if (!('value' in this.props)) {
381 st.value = value;
382 }
383 if (!multiple && searchValue) {
384 st.searchValue = '';
385 }
386 if (Object.keys(st).length) {
387 this.setState(st);
388 }
389
390 if (onChange) {
391 onChange(value, data, extra);
392 }
393 };
394
395 CascaderSelect.prototype.handleClear = function handleClear() {
396 // 单选时点击清空按钮
397 var _props4 = this.props,
398 hasClear = _props4.hasClear,
399 multiple = _props4.multiple,
400 treeCheckable = _props4.treeCheckable;
401
402 if (hasClear && (!multiple || !treeCheckable)) {
403 if (!('value' in this.props)) {
404 this.setState({
405 value: []
406 });
407 }
408
409 this.props.onChange(null, null);
410 }
411 };
412
413 CascaderSelect.prototype.handleRemove = function handleRemove(currentData) {
414 var currentValue = currentData.value;
415
416 var value = void 0;
417
418 var _props5 = this.props,
419 multiple = _props5.multiple,
420 checkStrictly = _props5.checkStrictly,
421 onChange = _props5.onChange;
422
423 if (multiple) {
424 value = [].concat(this.state.value);
425 value.splice(value.indexOf(currentValue), 1);
426
427 if (this.props.onChange) {
428 var data = this.getData(value);
429 var checked = false;
430
431 if (checkStrictly) {
432 this.props.onChange(value, data, {
433 checked: checked,
434 currentData: currentData,
435 checkedData: data
436 });
437 } else {
438 var checkedValue = this.completeValue(value);
439 var checkedData = this.getData(checkedValue);
440 var indeterminateValue = this.getIndeterminate(value);
441 var indeterminateData = this.getData(indeterminateValue);
442 this.props.onChange(value, data, {
443 checked: checked,
444 currentData: currentData,
445 checkedData: checkedData,
446 indeterminateData: indeterminateData
447 });
448 }
449 }
450 } else {
451 value = [];
452 onChange(null, null);
453 }
454
455 if (!('value' in this.props)) {
456 this.setState({
457 value: value
458 });
459 }
460 };
461
462 CascaderSelect.prototype.handleSearch = function handleSearch(searchValue) {
463 this.setState({
464 searchValue: searchValue
465 });
466 };
467
468 CascaderSelect.prototype.getPath = function getPath(pos) {
469 var items = [];
470
471 var nums = pos.split('-');
472 if (nums === 2) {
473 items.push(this._p2n[pos]);
474 } else {
475 for (var i = 1; i < nums.length; i++) {
476 var p = nums.slice(0, i + 1).join('-');
477 items.push(this._p2n[p]);
478 }
479 }
480
481 return items;
482 };
483
484 CascaderSelect.prototype.filterItems = function filterItems() {
485 var _this8 = this;
486
487 var _props6 = this.props,
488 multiple = _props6.multiple,
489 changeOnSelect = _props6.changeOnSelect,
490 canOnlyCheckLeaf = _props6.canOnlyCheckLeaf,
491 filter = _props6.filter;
492 var searchValue = this.state.searchValue;
493
494 var items = Object.keys(this._p2n).map(function (p) {
495 return _this8._p2n[p];
496 });
497 if (!multiple && !changeOnSelect || multiple && canOnlyCheckLeaf) {
498 items = items.filter(function (item) {
499 return !item.children || !item.children.length;
500 });
501 }
502
503 return items.map(function (item) {
504 return _this8.getPath(item.pos);
505 }).filter(function (path) {
506 return filter(searchValue, path);
507 });
508 };
509
510 CascaderSelect.prototype.renderNotFound = function renderNotFound() {
511 var _props7 = this.props,
512 prefix = _props7.prefix,
513 notFoundContent = _props7.notFoundContent;
514
515
516 return _react2.default.createElement(
517 _menu2.default,
518 { className: prefix + 'cascader-select-not-found' },
519 _react2.default.createElement(
520 _menu2.default.Item,
521 null,
522 notFoundContent
523 )
524 );
525 };
526
527 CascaderSelect.prototype.renderCascader = function renderCascader() {
528 var dataSource = this.props.dataSource;
529
530 if (dataSource.length === 0) {
531 return this.renderNotFound();
532 }
533
534 var searchValue = this.state.searchValue;
535
536 var filteredPaths = [];
537 if (searchValue) {
538 filteredPaths = this.filterItems();
539 if (filteredPaths.length === 0) {
540 return this.renderNotFound();
541 }
542 }
543
544 var _props8 = this.props,
545 multiple = _props8.multiple,
546 useVirtual = _props8.useVirtual,
547 changeOnSelect = _props8.changeOnSelect,
548 checkStrictly = _props8.checkStrictly,
549 canOnlyCheckLeaf = _props8.canOnlyCheckLeaf,
550 defaultExpandedValue = _props8.defaultExpandedValue,
551 expandTriggerType = _props8.expandTriggerType,
552 onExpand = _props8.onExpand,
553 listStyle = _props8.listStyle,
554 listClassName = _props8.listClassName,
555 loadData = _props8.loadData,
556 showSearch = _props8.showSearch,
557 resultRender = _props8.resultRender,
558 readOnly = _props8.readOnly,
559 itemRender = _props8.itemRender;
560 var value = this.state.value;
561
562
563 var props = {
564 dataSource: dataSource,
565 value: value,
566 multiple: multiple,
567 useVirtual: useVirtual,
568 canOnlySelectLeaf: !changeOnSelect,
569 checkStrictly: checkStrictly,
570 canOnlyCheckLeaf: canOnlyCheckLeaf,
571 defaultExpandedValue: defaultExpandedValue,
572 expandTriggerType: expandTriggerType,
573 ref: this.saveCascaderRef,
574 onExpand: onExpand,
575 listStyle: listStyle,
576 listClassName: listClassName,
577 loadData: loadData,
578 itemRender: itemRender
579 };
580 if (!readOnly) {
581 props.onChange = this.handleChange;
582 }
583 if (showSearch) {
584 props.searchValue = searchValue;
585 props.filteredPaths = filteredPaths;
586 props.resultRender = resultRender;
587 props.filteredListStyle = { height: this.cascaderHeight };
588 }
589
590 return _react2.default.createElement(_cascader2.default, props);
591 };
592
593 CascaderSelect.prototype.renderPopupContent = function renderPopupContent() {
594 var _props9 = this.props,
595 prefix = _props9.prefix,
596 header = _props9.header,
597 footer = _props9.footer;
598
599 return _react2.default.createElement(
600 'div',
601 { className: prefix + 'cascader-select-dropdown' },
602 header,
603 this.renderCascader(),
604 footer
605 );
606 };
607
608 CascaderSelect.prototype.render = function render() {
609 var _props10 = this.props,
610 prefix = _props10.prefix,
611 size = _props10.size,
612 hasArrow = _props10.hasArrow,
613 hasBorder = _props10.hasBorder,
614 hasClear = _props10.hasClear,
615 label = _props10.label,
616 readOnly = _props10.readOnly,
617 placeholder = _props10.placeholder,
618 dataSource = _props10.dataSource,
619 disabled = _props10.disabled,
620 multiple = _props10.multiple,
621 className = _props10.className,
622 showSearch = _props10.showSearch,
623 popupStyle = _props10.popupStyle,
624 popupClassName = _props10.popupClassName,
625 popupContainer = _props10.popupContainer,
626 popupProps = _props10.popupProps;
627 var _state2 = this.state,
628 value = _state2.value,
629 searchValue = _state2.searchValue,
630 visible = _state2.visible;
631
632 var others = pickOthers(Object.keys(CascaderSelect.propTypes), this.props);
633 var popupContent = this.renderPopupContent();
634
635 this.updateCache(dataSource);
636
637 var props = {
638 prefix: prefix,
639 className: className,
640 size: size,
641 placeholder: placeholder,
642 disabled: disabled,
643 hasArrow: hasArrow,
644 hasBorder: hasBorder,
645 hasClear: hasClear,
646 label: label,
647 readOnly: readOnly,
648 ref: this.saveSelectRef,
649 autoWidth: false,
650 mode: multiple ? 'multiple' : 'single',
651 value: multiple ? this.getMultipleData(value) : this.getSignleData(value),
652 onChange: this.handleClear,
653 onRemove: this.handleRemove,
654 visible: visible,
655 onVisibleChange: this.handleVisibleChange,
656 showSearch: showSearch,
657 searchValue: searchValue,
658 onSearch: this.handleSearch,
659 onKeyDown: this.handleKeyDown,
660 popupContent: popupContent,
661 popupStyle: popupStyle,
662 popupClassName: popupClassName,
663 popupContainer: popupContainer,
664 popupProps: popupProps
665 };
666
667 if (showSearch) {
668 props.popupProps = (0, _extends3.default)({}, popupProps, {
669 ref: this.getPopup,
670 afterOpen: this.handleAfterOpen
671 });
672 props.autoWidth = showSearch && !!searchValue;
673 }
674
675 return _react2.default.createElement(_select2.default, (0, _extends3.default)({}, props, others));
676 };
677
678 return CascaderSelect;
679}(_react.Component), _class.propTypes = {
680 prefix: _propTypes2.default.string,
681 pure: _propTypes2.default.bool,
682 className: _propTypes2.default.string,
683 /**
684 * 选择框大小
685 */
686 size: _propTypes2.default.oneOf(['small', 'medium', 'large']),
687 /**
688 * 选择框占位符
689 */
690 placeholder: _propTypes2.default.string,
691 /**
692 * 是否禁用
693 */
694 disabled: _propTypes2.default.bool,
695 /**
696 * 是否有下拉箭头
697 */
698 hasArrow: _propTypes2.default.bool,
699 /**
700 * 是否有边框
701 */
702 hasBorder: _propTypes2.default.bool,
703 /**
704 * 是否有清除按钮
705 */
706 hasClear: _propTypes2.default.bool,
707 /**
708 * 自定义内联 label
709 */
710 label: _propTypes2.default.node,
711 /**
712 * 是否只读,只读模式下可以展开弹层但不能选
713 */
714 readOnly: _propTypes2.default.bool,
715 /**
716 * 数据源,结构可参考下方说明
717 */
718 dataSource: _propTypes2.default.arrayOf(_propTypes2.default.object),
719 /**
720 * (非受控)默认值
721 */
722 defaultValue: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.arrayOf(_propTypes2.default.string)]),
723 /**
724 * (受控)当前值
725 */
726 value: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.arrayOf(_propTypes2.default.string)]),
727 /**
728 * 选中值改变时触发的回调函数
729 * @param {String|Array} value 选中的值,单选时返回单个值,多选时返回数组
730 * @param {Object|Array} data 选中的数据,包括 value 和 label,单选时返回单个值,多选时返回数组,父子节点选中关联时,同时选中,只返回父节点
731 * @param {Object} extra 额外参数
732 * @param {Array} extra.selectedPath 单选时选中的数据的路径
733 * @param {Boolean} extra.checked 多选时当前的操作是选中还是取消选中
734 * @param {Object} extra.currentData 多选时当前操作的数据
735 * @param {Array} extra.checkedData 多选时所有被选中的数据
736 * @param {Array} extra.indeterminateData 多选时半选的数据
737 */
738 onChange: _propTypes2.default.func,
739 /**
740 * 默认展开值,如果不设置,组件内部会根据 defaultValue/value 进行自动设置
741 */
742 defaultExpandedValue: _propTypes2.default.arrayOf(_propTypes2.default.string),
743 /**
744 * 展开触发的方式
745 */
746 expandTriggerType: _propTypes2.default.oneOf(['click', 'hover']),
747 onExpand: _propTypes2.default.func,
748 /**
749 * 是否开启虚拟滚动
750 */
751 useVirtual: _propTypes2.default.bool,
752 /**
753 * 是否多选
754 */
755 multiple: _propTypes2.default.bool,
756 /**
757 * 是否选中即发生改变, 该属性仅在单选模式下有效
758 */
759 changeOnSelect: _propTypes2.default.bool,
760 /**
761 * 是否只能勾选叶子项的checkbox,该属性仅在多选模式下有效
762 */
763 canOnlyCheckLeaf: _propTypes2.default.bool,
764 /**
765 * 父子节点是否选中不关联
766 */
767 checkStrictly: _propTypes2.default.bool,
768 /**
769 * 每列列表样式对象
770 */
771 listStyle: _propTypes2.default.object,
772 /**
773 * 每列列表类名
774 */
775 listClassName: _propTypes2.default.string,
776 /**
777 * 选择框单选时展示结果的自定义渲染函数
778 * @param {Array} label 选中路径的文本数组
779 * @return {ReactNode} 渲染在选择框中的内容
780 * @default 单选时:labelPath => labelPath.join(' / ');多选时:labelPath => labelPath[labelPath.length - 1]
781 */
782 displayRender: _propTypes2.default.func,
783 /**
784 * 渲染 item 内容的方法
785 * @param {Object} item 渲染节点的item
786 * @return {ReactNode} item node
787 */
788 itemRender: _propTypes2.default.func,
789 /**
790 * 是否显示搜索框
791 */
792 showSearch: _propTypes2.default.bool,
793 /**
794 * 自定义搜索函数
795 * @param {String} searchValue 搜索的关键字
796 * @param {Array} path 节点路径
797 * @return {Boolean} 是否匹配
798 * @default 根据路径所有节点的文本值模糊匹配
799 */
800 filter: _propTypes2.default.func,
801 /**
802 * 搜索结果自定义渲染函数
803 * @param {String} searchValue 搜索的关键字
804 * @param {Array} path 匹配到的节点路径
805 * @return {ReactNode} 渲染的内容
806 * @default 按照节点文本 a / b / c 的模式渲染
807 */
808 resultRender: _propTypes2.default.func,
809 /**
810 * 搜索结果列表是否和选择框等宽
811 */
812 resultAutoWidth: _propTypes2.default.bool,
813 /**
814 * 无数据时显示内容
815 */
816 notFoundContent: _propTypes2.default.node,
817 /**
818 * 异步加载数据函数
819 * @param {Object} data 当前点击异步加载的数据
820 */
821 loadData: _propTypes2.default.func,
822 /**
823 * 自定义下拉框头部
824 */
825 header: _propTypes2.default.node,
826 /**
827 * 自定义下拉框底部
828 */
829 footer: _propTypes2.default.node,
830 /**
831 * 初始下拉框是否显示
832 */
833 defaultVisible: _propTypes2.default.bool,
834 /**
835 * 当前下拉框是否显示
836 */
837 visible: _propTypes2.default.bool,
838 /**
839 * 下拉框显示或关闭时触发事件的回调函数
840 * @param {Boolean} visible 是否显示
841 * @param {String} type 触发显示关闭的操作类型
842 */
843 onVisibleChange: _propTypes2.default.func,
844 /**
845 * 下拉框自定义样式对象
846 */
847 popupStyle: _propTypes2.default.object,
848 /**
849 * 下拉框样式自定义类名
850 */
851 popupClassName: _propTypes2.default.string,
852 /**
853 * 下拉框挂载的容器节点
854 */
855 popupContainer: _propTypes2.default.oneOfType([_propTypes2.default.string, _propTypes2.default.func]),
856 /**
857 * 透传到 Popup 的属性对象
858 */
859 popupProps: _propTypes2.default.object
860}, _class.defaultProps = {
861 prefix: 'next-',
862 pure: false,
863 size: 'medium',
864 disabled: false,
865 hasArrow: true,
866 hasBorder: true,
867 hasClear: false,
868 dataSource: [],
869 defaultValue: null,
870 expandTriggerType: 'click',
871 onExpand: function onExpand() {},
872 useVirtual: false,
873 multiple: false,
874 changeOnSelect: false,
875 canOnlyCheckLeaf: false,
876 checkStrictly: false,
877 showSearch: false,
878 filter: function filter(searchValue, path) {
879 return path.some(function (item) {
880 return item.label.indexOf(searchValue) > -1;
881 });
882 },
883 resultRender: function resultRender(searchValue, path) {
884 var parts = [];
885 path.forEach(function (item, i) {
886 var others = item.label.split(searchValue);
887 others.forEach(function (other, j) {
888 if (other) {
889 parts.push(other);
890 }
891 if (j < others.length - 1) {
892 parts.push(_react2.default.createElement(
893 'em',
894 { key: i + '-' + j },
895 searchValue
896 ));
897 }
898 });
899 if (i < path.length - 1) {
900 parts.push(' / ');
901 }
902 });
903 return _react2.default.createElement(
904 'span',
905 null,
906 parts
907 );
908 },
909 resultAutoWidth: true,
910 notFoundContent: 'Not Found',
911 defaultVisible: false,
912 onVisibleChange: function onVisibleChange() {},
913 popupProps: {}
914}, _temp);
915CascaderSelect.displayName = 'CascaderSelect';
916exports.default = CascaderSelect;
917module.exports = exports['default'];
\No newline at end of file