2023-01-27 16:00:17 +08:00
|
|
|
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 = () => {
|
2023-02-21 23:11:05 +08:00
|
|
|
return inject(SizeContextKey, ref(undefined as SizeType));
|
2023-01-27 16:00:17 +08:00
|
|
|
};
|
|
|
|
export const useProviderSize = (size: Ref<SizeType>) => {
|
|
|
|
const parentSize = useInjectSize();
|
|
|
|
provide(
|
|
|
|
SizeContextKey,
|
|
|
|
computed(() => size.value || parentSize.value),
|
|
|
|
);
|
|
|
|
return size;
|
|
|
|
};
|