forked from vueComponent/ant-design-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSelectContext.ts
36 lines (31 loc) · 1.15 KB
/
SelectContext.ts
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
/**
* BaseSelect provide some parsed data into context.
* You can use this hooks to get them.
*/
import type { InjectionKey } from 'vue';
import { inject, provide } from 'vue';
import type { RawValueType, RenderNode } from './BaseSelect';
import type { FlattenOptionData } from './interface';
import type { BaseOptionType, FieldNames, OnActiveValue, OnInternalSelect } from './Select';
// Use any here since we do not get the type during compilation
export interface SelectContextProps {
options: BaseOptionType[];
flattenOptions: FlattenOptionData<BaseOptionType>[];
onActiveValue: OnActiveValue;
defaultActiveFirstOption?: boolean;
onSelect: OnInternalSelect;
menuItemSelectedIcon?: RenderNode;
rawValues: Set<RawValueType>;
fieldNames?: FieldNames;
virtual?: boolean;
listHeight?: number;
listItemHeight?: number;
childrenAsData?: boolean;
}
const SelectContextKey: InjectionKey<SelectContextProps> = Symbol('SelectContextKey');
export function useProvideSelectProps(props: SelectContextProps) {
return provide(SelectContextKey, props);
}
export default function useSelectProps() {
return inject(SelectContextKey, {} as SelectContextProps);
}