2023-02-20 11:04:25 +08:00
|
|
|
import { computed, h, inject } from 'vue';
|
2023-02-21 23:11:05 +08:00
|
|
|
import type { SizeType } from '../context';
|
2023-01-27 16:00:17 +08:00
|
|
|
import { defaultConfigProvider, configProviderKey } from '../context';
|
2023-02-21 23:11:05 +08:00
|
|
|
import { useInjectDisabled } from '../DisabledContext';
|
2023-02-20 11:04:25 +08:00
|
|
|
import { DefaultRenderEmpty } from '../renderEmpty';
|
2023-02-21 23:11:05 +08:00
|
|
|
import { useInjectSize } from '../SizeContext';
|
2023-01-27 16:00:17 +08:00
|
|
|
export default (name: string, props: Record<any, any>) => {
|
2023-02-21 23:11:05 +08:00
|
|
|
const sizeContext = useInjectSize();
|
|
|
|
const disabledContext = useInjectDisabled();
|
2023-01-27 16:00:17 +08:00
|
|
|
const configProvider = inject(configProviderKey, {
|
|
|
|
...defaultConfigProvider,
|
2023-02-20 11:04:25 +08:00
|
|
|
renderEmpty: (name?: string) => h(DefaultRenderEmpty, { componentName: name }),
|
2023-01-27 16:00:17 +08:00
|
|
|
});
|
|
|
|
const prefixCls = computed(() => configProvider.getPrefixCls(name, props.prefixCls));
|
2023-02-02 18:05:58 +08:00
|
|
|
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());
|
2023-02-02 18:05:58 +08:00
|
|
|
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;
|
2023-05-08 16:09:29 +08:00
|
|
|
const getTargetContainer = computed(
|
2023-05-08 16:39:33 +08:00
|
|
|
() => props.getTargetContainer ?? configProvider.getTargetContainer?.value,
|
2023-05-08 16:09:29 +08:00
|
|
|
);
|
|
|
|
const getPopupContainer = computed(
|
2023-05-08 16:39:33 +08:00
|
|
|
() => props.getPopupContainer ?? configProvider.getPopupContainer?.value,
|
2023-05-08 16:09:29 +08:00
|
|
|
);
|
2023-01-27 16:00:17 +08:00
|
|
|
|
|
|
|
const dropdownMatchSelectWidth = computed<boolean | number>(
|
2023-02-02 18:05:58 +08:00
|
|
|
() => props.dropdownMatchSelectWidth ?? configProvider.dropdownMatchSelectWidth?.value,
|
2023-01-27 16:00:17 +08:00
|
|
|
);
|
|
|
|
const virtual = computed(
|
|
|
|
() =>
|
|
|
|
(props.virtual === undefined
|
2023-02-02 18:05:58 +08:00
|
|
|
? configProvider.virtual?.value !== false
|
2023-01-27 16:00:17 +08:00
|
|
|
: props.virtual !== false) && dropdownMatchSelectWidth.value !== false,
|
|
|
|
);
|
2023-02-21 23:11:05 +08:00
|
|
|
const size = computed(() => (props.size as SizeType) || sizeContext.value);
|
2023-01-27 16:00:17 +08:00
|
|
|
const autocomplete = computed(
|
2023-02-02 18:05:58 +08:00
|
|
|
() => props.autocomplete ?? configProvider.input?.value?.autocomplete,
|
2023-01-27 16:00:17 +08:00
|
|
|
);
|
2023-02-21 23:11:05 +08:00
|
|
|
const disabled = computed<boolean>(() => props.disabled ?? disabledContext.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
|
|
|
};
|
|
|
|
};
|