forked from vueComponent/ant-design-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTabContext.ts
34 lines (28 loc) · 968 Bytes
/
TabContext.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
import type { Tab } from './interface';
import type { PropType, InjectionKey, Ref } from 'vue';
import { provide, inject, defineComponent, toRefs, ref } from 'vue';
export interface TabContextProps {
tabs: Ref<Tab[]>;
prefixCls: Ref<string>;
}
const TabsContextKey: InjectionKey<TabContextProps> = Symbol('tabsContextKey');
export const useProvideTabs = (props: TabContextProps) => {
provide(TabsContextKey, props);
};
export const useInjectTabs = () => {
return inject(TabsContextKey, { tabs: ref([]), prefixCls: ref() });
};
const TabsContextProvider = defineComponent({
compatConfig: { MODE: 3 },
name: 'TabsContextProvider',
inheritAttrs: false,
props: {
tabs: { type: Object as PropType<TabContextProps['tabs']>, default: undefined },
prefixCls: { type: String, default: undefined },
},
setup(props, { slots }) {
useProvideTabs(toRefs(props));
return () => slots.default?.();
},
});
export default TabsContextProvider;