mirror of
https://gitee.com/ant-design-vue/ant-design-vue.git
synced 2024-12-02 03:58:05 +08:00
17 lines
547 B
TypeScript
17 lines
547 B
TypeScript
import type { InjectionKey, Ref } from 'vue';
|
|
import { computed, inject, ref, provide } from 'vue';
|
|
export type SizeType = 'small' | 'middle' | 'large' | undefined;
|
|
const SizeContextKey: InjectionKey<Ref<SizeType>> = Symbol('SizeContextKey');
|
|
|
|
export const useInjectSize = () => {
|
|
return inject(SizeContextKey, ref(undefined as SizeType));
|
|
};
|
|
export const useProviderSize = (size: Ref<SizeType>) => {
|
|
const parentSize = useInjectSize();
|
|
provide(
|
|
SizeContextKey,
|
|
computed(() => size.value || parentSize.value),
|
|
);
|
|
return size;
|
|
};
|