-
Notifications
You must be signed in to change notification settings - Fork 138
/
QuickSelectShortcut.tsx
60 lines (52 loc) 路 1.64 KB
/
QuickSelectShortcut.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
/**
* @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 } from 'vue'
import { callEmit } from '@idux/cdk/utils'
import { IxIcon } from '@idux/components/icon'
import { proSearchContext } from '../../token'
import { quickSelectPanelShortcutProps } from '../../types'
export default defineComponent({
props: quickSelectPanelShortcutProps,
setup(props) {
const {
props: proSearchProps,
mergedPrefixCls,
convertStateToValue,
createSearchState,
updateSearchState,
getSearchStatesByFieldKey,
setActiveSegment,
} = inject(proSearchContext)!
const handleClick = () => {
const fieldKey = props.searchField.key
if (!props.searchField.multiple && getSearchStatesByFieldKey(fieldKey).length) {
return
}
const state = createSearchState(props.searchField.key)
if (state) {
updateSearchState(state.key)
callEmit(proSearchProps.onItemCreate, {
...convertStateToValue(state.key),
nameInput: props.searchField.label,
})
setActiveSegment({
itemKey: state.key,
name: state.segmentValues[0]?.name,
})
}
}
return () => {
const prefixCls = `${mergedPrefixCls.value}-quick-select-shortcut`
return (
<span class={prefixCls} onClick={handleClick}>
{props.searchField.icon && <IxIcon class={`${prefixCls}-icon`} name={props.searchField.icon} />}
{props.searchField.label}
</span>
)
}
},
})