ant-design-vue/components/_util/hooks/useConfigInject.ts

29 lines
952 B
TypeScript
Raw Normal View History

2021-05-12 21:06:53 +08:00
import { computed, ComputedRef, inject, UnwrapRef } from 'vue';
import {
ConfigProviderProps,
defaultConfigProvider,
Direction,
SizeType,
} from '../../config-provider';
2021-05-12 21:06:53 +08:00
export default (
name: string,
props: Record<any, any>,
): {
configProvider: UnwrapRef<ConfigProviderProps>;
prefixCls: ComputedRef<string>;
direction: ComputedRef<Direction>;
size: ComputedRef<SizeType>;
2021-05-24 18:09:11 +08:00
getTargetContainer: ComputedRef<() => HTMLElement>;
2021-05-12 21:06:53 +08:00
} => {
const configProvider = inject<UnwrapRef<ConfigProviderProps>>(
'configProvider',
defaultConfigProvider,
);
const prefixCls = computed(() => configProvider.getPrefixCls(name, props.prefixCls));
2021-05-12 21:06:53 +08:00
const direction = computed(() => configProvider.direction);
const size = computed(() => props.size || configProvider.componentSize);
2021-05-24 18:09:11 +08:00
const getTargetContainer = computed(() => props.getTargetContainer);
return { configProvider, prefixCls, direction, size, getTargetContainer };
};