2021-06-26 01:35:40 +00:00
|
|
|
import type { RequiredMark } from '../../form/Form';
|
2021-12-16 09:20:18 +00:00
|
|
|
import type { ComputedRef, UnwrapRef } from 'vue';
|
2021-06-26 01:35:40 +00:00
|
|
|
import { computed, inject } from 'vue';
|
2022-01-23 06:48:27 +00:00
|
|
|
import type { ConfigProviderProps, CSPConfig, Direction, SizeType } from '../../config-provider';
|
2021-06-26 01:35:40 +00:00
|
|
|
import { defaultConfigProvider } from '../../config-provider';
|
2021-12-16 09:20:18 +00:00
|
|
|
import type { VueNode } from '../type';
|
2021-03-16 04:54:22 +00:00
|
|
|
|
2021-05-12 13:06:53 +00:00
|
|
|
export default (
|
|
|
|
name: string,
|
|
|
|
props: Record<any, any>,
|
|
|
|
): {
|
|
|
|
configProvider: UnwrapRef<ConfigProviderProps>;
|
|
|
|
prefixCls: ComputedRef<string>;
|
2021-09-25 08:51:32 +00:00
|
|
|
rootPrefixCls: ComputedRef<string>;
|
2021-05-12 13:06:53 +00:00
|
|
|
direction: ComputedRef<Direction>;
|
|
|
|
size: ComputedRef<SizeType>;
|
2021-05-24 10:09:11 +00:00
|
|
|
getTargetContainer: ComputedRef<() => HTMLElement>;
|
2021-05-26 09:31:16 +00:00
|
|
|
space: ComputedRef<{ size: SizeType | number }>;
|
2021-05-26 15:14:00 +00:00
|
|
|
pageHeader: ComputedRef<{ ghost: boolean }>;
|
2021-05-28 09:31:15 +00:00
|
|
|
form?: ComputedRef<{
|
|
|
|
requiredMark?: RequiredMark;
|
|
|
|
}>;
|
2021-09-25 08:51:32 +00:00
|
|
|
autoInsertSpaceInButton: ComputedRef<boolean>;
|
2021-12-16 09:20:18 +00:00
|
|
|
renderEmpty?: ComputedRef<(componentName?: string) => VueNode>;
|
2021-09-25 08:51:32 +00:00
|
|
|
virtual: ComputedRef<boolean>;
|
|
|
|
dropdownMatchSelectWidth: ComputedRef<boolean | number>;
|
|
|
|
getPopupContainer: ComputedRef<ConfigProviderProps['getPopupContainer']>;
|
2021-12-14 15:50:22 +00:00
|
|
|
getPrefixCls: ConfigProviderProps['getPrefixCls'];
|
|
|
|
autocomplete: ComputedRef<string>;
|
2022-01-23 06:48:27 +00:00
|
|
|
csp: ComputedRef<CSPConfig>;
|
2021-05-12 13:06:53 +00:00
|
|
|
} => {
|
|
|
|
const configProvider = inject<UnwrapRef<ConfigProviderProps>>(
|
|
|
|
'configProvider',
|
|
|
|
defaultConfigProvider,
|
|
|
|
);
|
2021-03-16 04:54:22 +00:00
|
|
|
const prefixCls = computed(() => configProvider.getPrefixCls(name, props.prefixCls));
|
2021-09-25 08:51:32 +00:00
|
|
|
const direction = computed(() => props.direction ?? configProvider.direction);
|
|
|
|
const rootPrefixCls = computed(() => configProvider.getPrefixCls());
|
2021-06-30 02:03:17 +00:00
|
|
|
const autoInsertSpaceInButton = computed(() => configProvider.autoInsertSpaceInButton);
|
2021-06-23 06:44:21 +00:00
|
|
|
const renderEmpty = computed(() => configProvider.renderEmpty);
|
2021-05-26 09:31:16 +00:00
|
|
|
const space = computed(() => configProvider.space);
|
2021-05-26 15:14:00 +00:00
|
|
|
const pageHeader = computed(() => configProvider.pageHeader);
|
2021-05-28 09:31:15 +00:00
|
|
|
const form = computed(() => configProvider.form);
|
2021-09-25 08:51:32 +00:00
|
|
|
const getTargetContainer = computed(
|
|
|
|
() => props.getTargetContainer || configProvider.getTargetContainer,
|
|
|
|
);
|
|
|
|
const getPopupContainer = computed(
|
|
|
|
() => props.getPopupContainer || configProvider.getPopupContainer,
|
|
|
|
);
|
|
|
|
const virtual = computed(() => props.virtual ?? configProvider.virtual);
|
|
|
|
const dropdownMatchSelectWidth = computed<boolean | number>(
|
|
|
|
() => props.dropdownMatchSelectWidth ?? configProvider.dropdownMatchSelectWidth,
|
|
|
|
);
|
2021-05-12 13:06:53 +00:00
|
|
|
const size = computed(() => props.size || configProvider.componentSize);
|
2021-12-14 15:50:22 +00:00
|
|
|
const autocomplete = computed(() => props.autocomplete || configProvider.input?.autocomplete);
|
2022-01-23 06:48:27 +00:00
|
|
|
const csp = computed(() => configProvider.csp);
|
2021-05-28 09:31:15 +00:00
|
|
|
return {
|
|
|
|
configProvider,
|
|
|
|
prefixCls,
|
|
|
|
direction,
|
|
|
|
size,
|
|
|
|
getTargetContainer,
|
2021-09-25 08:51:32 +00:00
|
|
|
getPopupContainer,
|
2021-05-28 09:31:15 +00:00
|
|
|
space,
|
|
|
|
pageHeader,
|
|
|
|
form,
|
2021-06-30 02:03:17 +00:00
|
|
|
autoInsertSpaceInButton,
|
2021-06-23 06:44:21 +00:00
|
|
|
renderEmpty,
|
2021-09-25 08:51:32 +00:00
|
|
|
virtual,
|
|
|
|
dropdownMatchSelectWidth,
|
|
|
|
rootPrefixCls,
|
2021-12-14 15:50:22 +00:00
|
|
|
getPrefixCls: configProvider.getPrefixCls,
|
|
|
|
autocomplete,
|
2022-01-23 06:48:27 +00:00
|
|
|
csp,
|
2021-05-28 09:31:15 +00:00
|
|
|
};
|
2021-03-16 04:54:22 +00:00
|
|
|
};
|