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

27 lines
807 B
TypeScript
Raw Normal View History

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