-
Notifications
You must be signed in to change notification settings - Fork 138
/
CascaderPanel.tsx
110 lines (97 loc) 路 2.52 KB
/
CascaderPanel.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
/**
* @license
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/IDuxFE/idux/blob/main/LICENSE
*/
import { defineComponent, inject, onUnmounted, watch } from 'vue'
import { type VKey, callEmit } from '@idux/cdk/utils'
import { CascaderPanelProps, IxCascaderPanel } from '@idux/components/cascader'
import PanelFooter from './PanelFooter'
import { proSearchContext } from '../token'
import { proSearchCascaderPanelProps } from '../types'
export default defineComponent({
props: proSearchCascaderPanelProps,
setup(props) {
const { mergedPrefixCls, locale } = inject(proSearchContext)!
watch(
() => props.searchValue,
searchValue => {
callEmit(props.onSearch, searchValue ?? '')
},
)
onUnmounted(() => {
if (props.searchValue) {
callEmit(props.onSearch, '')
}
})
const changeSelected = (keys: VKey[] | VKey[] | VKey[][]) => {
callEmit(props.onChange, props.multiple ? keys : [keys])
}
const handleConfirm = () => {
callEmit(props.onConfirm)
}
const handleCancel = () => {
callEmit(props.onCancel)
}
const renderFooter = () => {
if (!props.multiple) {
return
}
return (
<PanelFooter
prefixCls={mergedPrefixCls.value}
locale={locale}
onConfirm={handleConfirm}
onCancel={handleCancel}
/>
)
}
return () => {
const prefixCls = `${mergedPrefixCls.value}-cascader-panel`
const {
dataSource,
disableData,
expandIcon,
expandTrigger,
fullPath,
loadChildren,
multiple,
searchValue,
searchFn,
separator,
strategy,
virtual,
onExpand,
onLoaded,
} = props
const panelProps = {
selectedKeys: props.value,
dataSource,
disableData,
childrenKey: 'children',
getKey: 'key',
expandIcon,
expandTrigger,
fullPath,
loadChildren,
labelKey: 'label',
multiple,
searchFn,
searchValue,
separator,
strategy,
virtual,
onExpand,
onLoaded,
'onUpdate:selectedKeys': changeSelected,
} as CascaderPanelProps
return (
<div class={prefixCls} tabindex={-1} onMousedown={evt => evt.preventDefault()}>
<IxCascaderPanel {...panelProps} />
{renderFooter()}
</div>
)
}
},
})