ant-design-vue/components/config-provider/hooks/useConfigInject.ts

58 lines
2.1 KiB
TypeScript
Raw Normal View History

2023-01-27 16:00:17 +08:00
import { computed, inject } from 'vue';
import { defaultConfigProvider, configProviderKey } from '../context';
export default (name: string, props: Record<any, any>) => {
const configProvider = inject(configProviderKey, {
...defaultConfigProvider,
renderEmpty: () => null,
});
const prefixCls = computed(() => configProvider.getPrefixCls(name, props.prefixCls));
const direction = computed(() => props.direction ?? configProvider.direction?.value);
2023-01-27 16:00:17 +08:00
const iconPrefixCls = computed(() => props.iconPrefixCls ?? configProvider.iconPrefixCls.value);
const rootPrefixCls = computed(() => configProvider.getPrefixCls());
const autoInsertSpaceInButton = computed(() => configProvider.autoInsertSpaceInButton?.value);
2023-01-27 16:00:17 +08:00
const renderEmpty = configProvider.renderEmpty;
const space = configProvider.space;
const pageHeader = configProvider.pageHeader;
const form = configProvider.form;
const getTargetContainer = configProvider.getTargetContainer;
const getPopupContainer = configProvider.getPopupContainer;
const dropdownMatchSelectWidth = computed<boolean | number>(
() => props.dropdownMatchSelectWidth ?? configProvider.dropdownMatchSelectWidth?.value,
2023-01-27 16:00:17 +08:00
);
const virtual = computed(
() =>
(props.virtual === undefined
? configProvider.virtual?.value !== false
2023-01-27 16:00:17 +08:00
: props.virtual !== false) && dropdownMatchSelectWidth.value !== false,
);
const size = computed(() => props.size || configProvider.componentSize?.value);
2023-01-27 16:00:17 +08:00
const autocomplete = computed(
() => props.autocomplete ?? configProvider.input?.value?.autocomplete,
2023-01-27 16:00:17 +08:00
);
const disabled = computed(() => props.disabled || configProvider.componentDisabled?.value);
2023-01-27 16:00:17 +08:00
const csp = computed(() => props.csp ?? configProvider.csp);
return {
configProvider,
prefixCls,
direction,
size,
getTargetContainer,
getPopupContainer,
space,
pageHeader,
form,
autoInsertSpaceInButton,
renderEmpty,
virtual,
dropdownMatchSelectWidth,
rootPrefixCls,
getPrefixCls: configProvider.getPrefixCls,
autocomplete,
csp,
iconPrefixCls,
disabled,
2023-02-20 10:28:16 +08:00
select: configProvider.select,
2023-01-27 16:00:17 +08:00
};
};