You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
17 lines
547 B
17 lines
547 B
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;
|
|
};
|