2022-07-04 11:00:19 +08:00
|
|
|
import { createTheme } from '@ant-design/cssinjs';
|
2021-01-26 16:18:13 +08:00
|
|
|
import IconContext from '@ant-design/icons/lib/components/Context';
|
2022-05-07 14:31:54 +08:00
|
|
|
import type { ValidateMessages } from 'rc-field-form/lib/interface';
|
2021-01-13 17:05:05 +08:00
|
|
|
import useMemo from 'rc-util/lib/hooks/useMemo';
|
2023-05-25 19:58:07 +08:00
|
|
|
import { merge } from 'rc-util/lib/utils/set';
|
2022-11-18 09:55:42 +08:00
|
|
|
import type { ReactElement } from 'react';
|
2023-05-06 15:49:37 +08:00
|
|
|
import * as React from 'react';
|
2023-01-03 09:56:47 +08:00
|
|
|
import type { Options } from 'scroll-into-view-if-needed';
|
2023-04-04 17:17:36 +08:00
|
|
|
import warning from '../_util/warning';
|
2022-05-24 19:48:44 +08:00
|
|
|
import type { RequiredMark } from '../form/Form';
|
2023-06-15 10:26:56 +08:00
|
|
|
import ValidateMessagesContext from '../form/validateMessagesContext';
|
2023-06-28 11:53:26 +08:00
|
|
|
import type { InputProps } from '../input';
|
2022-12-09 15:04:08 +08:00
|
|
|
import type { Locale } from '../locale';
|
|
|
|
import LocaleProvider, { ANT_MARK } from '../locale';
|
2023-02-22 18:18:26 +08:00
|
|
|
import type { LocaleContextProps } from '../locale/context';
|
|
|
|
import LocaleContext from '../locale/context';
|
2022-10-26 14:38:54 +08:00
|
|
|
import defaultLocale from '../locale/en_US';
|
2023-06-02 15:03:29 +08:00
|
|
|
import type { SpaceProps } from '../space';
|
2022-11-23 20:22:38 +08:00
|
|
|
import { DesignTokenContext } from '../theme/internal';
|
2022-06-27 14:25:59 +08:00
|
|
|
import defaultSeedToken from '../theme/themes/seed';
|
2023-04-07 10:17:00 +08:00
|
|
|
import type {
|
2023-06-29 16:43:11 +08:00
|
|
|
BadgeConfig,
|
2023-05-26 16:42:26 +08:00
|
|
|
ButtonConfig,
|
2023-06-26 11:42:46 +08:00
|
|
|
ComponentStyleConfig,
|
2023-04-07 10:17:00 +08:00
|
|
|
ConfigConsumerProps,
|
|
|
|
CSPConfig,
|
|
|
|
DirectionType,
|
|
|
|
PopupOverflow,
|
|
|
|
Theme,
|
|
|
|
ThemeConfig,
|
|
|
|
} from './context';
|
2022-03-24 18:44:42 +08:00
|
|
|
import { ConfigConsumer, ConfigContext, defaultIconPrefixCls } from './context';
|
2021-09-01 10:56:50 +08:00
|
|
|
import { registerTheme } from './cssVariables';
|
2022-11-09 12:28:04 +08:00
|
|
|
import type { RenderEmptyHandler } from './defaultRenderEmpty';
|
2022-05-25 14:57:58 +08:00
|
|
|
import { DisabledContextProvider } from './DisabledContext';
|
2023-02-23 15:05:18 +08:00
|
|
|
import useConfig from './hooks/useConfig';
|
2022-03-24 18:44:42 +08:00
|
|
|
import useTheme from './hooks/useTheme';
|
2023-04-23 15:42:36 +08:00
|
|
|
import MotionWrapper from './MotionWrapper';
|
2022-05-24 19:48:44 +08:00
|
|
|
import type { SizeType } from './SizeContext';
|
|
|
|
import SizeContext, { SizeContextProvider } from './SizeContext';
|
2022-11-18 09:55:42 +08:00
|
|
|
import useStyle from './style';
|
2018-12-26 16:01:00 +08:00
|
|
|
|
2023-03-10 14:12:49 +08:00
|
|
|
/**
|
2023-06-19 19:30:16 +08:00
|
|
|
* Since too many feedback using static method like `Modal.confirm` not getting theme, we record the
|
|
|
|
* theme register info here to help developer get warning info.
|
2023-03-10 14:12:49 +08:00
|
|
|
*/
|
|
|
|
let existThemeConfig = false;
|
|
|
|
|
|
|
|
export const warnContext: (componentName: string) => void =
|
|
|
|
process.env.NODE_ENV !== 'production'
|
|
|
|
? (componentName: string) => {
|
|
|
|
warning(
|
|
|
|
!existThemeConfig,
|
|
|
|
componentName,
|
|
|
|
`Static function can not consume context like dynamic theme. Please use 'App' component instead.`,
|
|
|
|
);
|
|
|
|
}
|
2023-06-07 21:59:21 +08:00
|
|
|
: /* istanbul ignore next */
|
2023-03-10 14:12:49 +08:00
|
|
|
null!;
|
|
|
|
|
2020-11-03 16:22:18 +08:00
|
|
|
export {
|
|
|
|
ConfigConsumer,
|
2023-06-07 21:59:21 +08:00
|
|
|
ConfigContext,
|
|
|
|
defaultIconPrefixCls,
|
|
|
|
type ConfigConsumerProps,
|
2022-11-09 12:28:04 +08:00
|
|
|
type CSPConfig,
|
|
|
|
type DirectionType,
|
2023-06-07 21:59:21 +08:00
|
|
|
type RenderEmptyHandler,
|
2023-01-23 19:24:05 +08:00
|
|
|
type ThemeConfig,
|
2020-11-03 16:22:18 +08:00
|
|
|
};
|
2018-11-26 12:06:42 +08:00
|
|
|
|
2019-02-19 11:42:05 +08:00
|
|
|
export const configConsumerProps = [
|
2020-04-29 20:22:16 +08:00
|
|
|
'getTargetContainer',
|
2019-02-19 11:42:05 +08:00
|
|
|
'getPopupContainer',
|
|
|
|
'rootPrefixCls',
|
|
|
|
'getPrefixCls',
|
|
|
|
'renderEmpty',
|
|
|
|
'csp',
|
|
|
|
'autoInsertSpaceInButton',
|
2019-07-24 10:34:55 +08:00
|
|
|
'locale',
|
2019-10-15 11:46:12 +08:00
|
|
|
'pageHeader',
|
2019-02-19 11:42:05 +08:00
|
|
|
];
|
|
|
|
|
2021-01-19 17:33:05 +08:00
|
|
|
// These props is used by `useContext` directly in sub component
|
|
|
|
const PASSED_PROPS: Exclude<keyof ConfigConsumerProps, 'rootPrefixCls' | 'getPrefixCls'>[] = [
|
|
|
|
'getTargetContainer',
|
|
|
|
'getPopupContainer',
|
|
|
|
'renderEmpty',
|
|
|
|
'pageHeader',
|
|
|
|
'input',
|
2022-05-26 17:14:05 +08:00
|
|
|
'pagination',
|
2021-01-19 17:33:05 +08:00
|
|
|
'form',
|
2022-12-14 10:22:17 +08:00
|
|
|
'select',
|
2023-05-26 16:42:26 +08:00
|
|
|
'button',
|
2021-01-19 17:33:05 +08:00
|
|
|
];
|
|
|
|
|
2019-03-16 09:48:21 +08:00
|
|
|
export interface ConfigProviderProps {
|
2022-10-06 18:53:06 +08:00
|
|
|
getTargetContainer?: () => HTMLElement | Window;
|
2021-10-09 10:24:41 +08:00
|
|
|
getPopupContainer?: (triggerNode?: HTMLElement) => HTMLElement;
|
2018-12-05 19:12:18 +08:00
|
|
|
prefixCls?: string;
|
2021-01-19 17:33:05 +08:00
|
|
|
iconPrefixCls?: string;
|
2018-12-05 19:12:18 +08:00
|
|
|
children?: React.ReactNode;
|
2018-12-26 16:01:00 +08:00
|
|
|
renderEmpty?: RenderEmptyHandler;
|
2019-01-09 20:15:37 +08:00
|
|
|
csp?: CSPConfig;
|
2019-01-10 11:47:11 +08:00
|
|
|
autoInsertSpaceInButton?: boolean;
|
2023-06-28 14:13:14 +08:00
|
|
|
form?: ComponentStyleConfig & {
|
2019-07-03 20:14:39 +08:00
|
|
|
validateMessages?: ValidateMessages;
|
2020-10-24 14:27:49 +08:00
|
|
|
requiredMark?: RequiredMark;
|
2021-11-11 17:51:33 +08:00
|
|
|
colon?: boolean;
|
2023-01-03 09:56:47 +08:00
|
|
|
scrollToFirstError?: Options | boolean;
|
2019-07-03 20:14:39 +08:00
|
|
|
};
|
2023-06-28 11:53:26 +08:00
|
|
|
input?: ComponentStyleConfig & {
|
|
|
|
classNames?: InputProps['classNames'];
|
|
|
|
styles?: InputProps['styles'];
|
2020-04-22 10:38:43 +08:00
|
|
|
autoComplete?: string;
|
|
|
|
};
|
2023-06-27 17:12:36 +08:00
|
|
|
select?: ComponentStyleConfig & {
|
2022-12-14 10:22:17 +08:00
|
|
|
showSearch?: boolean;
|
|
|
|
};
|
2023-06-26 15:32:18 +08:00
|
|
|
pagination?: ComponentStyleConfig & { showSizeChanger?: boolean };
|
2019-07-24 10:34:55 +08:00
|
|
|
locale?: Locale;
|
2019-10-15 11:46:12 +08:00
|
|
|
pageHeader?: {
|
|
|
|
ghost: boolean;
|
|
|
|
};
|
2020-01-03 13:38:16 +08:00
|
|
|
componentSize?: SizeType;
|
2022-05-25 14:57:58 +08:00
|
|
|
componentDisabled?: boolean;
|
2020-11-03 16:22:18 +08:00
|
|
|
direction?: DirectionType;
|
2020-03-22 11:38:02 +08:00
|
|
|
space?: {
|
|
|
|
size?: SizeType | number;
|
2023-06-02 15:03:29 +08:00
|
|
|
className?: SpaceProps['className'];
|
|
|
|
classNames?: SpaceProps['classNames'];
|
|
|
|
style?: SpaceProps['style'];
|
|
|
|
styles?: SpaceProps['styles'];
|
2020-03-22 11:38:02 +08:00
|
|
|
};
|
2020-05-05 15:00:43 +08:00
|
|
|
virtual?: boolean;
|
2023-04-04 17:17:36 +08:00
|
|
|
/** @deprecated Please use `popupMatchSelectWidth` instead */
|
2020-05-05 15:00:43 +08:00
|
|
|
dropdownMatchSelectWidth?: boolean;
|
2023-04-04 17:17:36 +08:00
|
|
|
popupMatchSelectWidth?: boolean;
|
2023-04-07 10:17:00 +08:00
|
|
|
popupOverflow?: PopupOverflow;
|
2022-03-24 18:44:42 +08:00
|
|
|
theme?: ThemeConfig;
|
2023-06-26 17:09:55 +08:00
|
|
|
anchor?: ComponentStyleConfig;
|
2023-05-26 16:42:26 +08:00
|
|
|
button?: ButtonConfig;
|
2023-06-27 17:13:27 +08:00
|
|
|
cascader?: ComponentStyleConfig;
|
2023-06-26 11:42:46 +08:00
|
|
|
divider?: ComponentStyleConfig;
|
|
|
|
typography?: ComponentStyleConfig;
|
|
|
|
spin?: ComponentStyleConfig;
|
|
|
|
segmented?: ComponentStyleConfig;
|
|
|
|
steps?: ComponentStyleConfig;
|
|
|
|
image?: ComponentStyleConfig;
|
2023-06-28 13:51:24 +08:00
|
|
|
layout?: ComponentStyleConfig;
|
2023-06-27 10:51:23 +08:00
|
|
|
mentions?: ComponentStyleConfig;
|
2023-06-27 17:14:08 +08:00
|
|
|
modal?: ComponentStyleConfig;
|
2023-06-26 11:42:46 +08:00
|
|
|
result?: ComponentStyleConfig;
|
|
|
|
slider?: ComponentStyleConfig;
|
|
|
|
breadcrumb?: ComponentStyleConfig;
|
|
|
|
checkbox?: ComponentStyleConfig;
|
2023-06-26 14:38:02 +08:00
|
|
|
descriptions?: ComponentStyleConfig;
|
2023-06-26 17:10:26 +08:00
|
|
|
empty?: ComponentStyleConfig;
|
2023-06-29 16:43:11 +08:00
|
|
|
badge?: BadgeConfig;
|
2023-06-26 19:07:57 +08:00
|
|
|
radio?: ComponentStyleConfig;
|
2023-06-29 19:30:34 +08:00
|
|
|
rate?: ComponentStyleConfig;
|
2023-06-30 11:29:39 +08:00
|
|
|
switch?: ComponentStyleConfig;
|
2023-07-03 10:27:31 +08:00
|
|
|
avatar?: ComponentStyleConfig;
|
2023-06-30 17:19:27 +08:00
|
|
|
tag?: ComponentStyleConfig;
|
2023-06-30 20:42:43 +08:00
|
|
|
table?: ComponentStyleConfig;
|
2023-07-03 10:25:55 +08:00
|
|
|
card?: ComponentStyleConfig;
|
2023-07-03 13:38:38 +08:00
|
|
|
tabs?: ComponentStyleConfig;
|
2023-07-03 16:38:56 +08:00
|
|
|
upload?: ComponentStyleConfig;
|
2018-12-05 19:12:18 +08:00
|
|
|
}
|
|
|
|
|
2021-01-12 10:40:15 +08:00
|
|
|
interface ProviderChildrenProps extends ConfigProviderProps {
|
|
|
|
parentContext: ConfigConsumerProps;
|
|
|
|
legacyLocale: Locale;
|
|
|
|
}
|
2021-01-09 15:22:08 +08:00
|
|
|
|
2021-02-09 21:49:15 +08:00
|
|
|
export const defaultPrefixCls = 'ant';
|
2021-03-02 11:53:12 +08:00
|
|
|
let globalPrefixCls: string;
|
2021-06-09 15:36:59 +08:00
|
|
|
let globalIconPrefixCls: string;
|
2023-05-18 23:53:34 +08:00
|
|
|
let globalTheme: ThemeConfig;
|
2021-02-09 21:49:15 +08:00
|
|
|
|
2021-09-01 10:56:50 +08:00
|
|
|
function getGlobalPrefixCls() {
|
|
|
|
return globalPrefixCls || defaultPrefixCls;
|
|
|
|
}
|
|
|
|
|
|
|
|
function getGlobalIconPrefixCls() {
|
|
|
|
return globalIconPrefixCls || defaultIconPrefixCls;
|
|
|
|
}
|
|
|
|
|
2023-05-18 23:53:34 +08:00
|
|
|
function isLegacyTheme(theme: Theme | ThemeConfig): theme is Theme {
|
|
|
|
return Object.keys(theme).some((key) => key.endsWith('Color'));
|
|
|
|
}
|
|
|
|
|
2021-06-09 15:36:59 +08:00
|
|
|
const setGlobalConfig = ({
|
|
|
|
prefixCls,
|
|
|
|
iconPrefixCls,
|
2021-09-01 10:56:50 +08:00
|
|
|
theme,
|
2023-05-18 23:53:34 +08:00
|
|
|
}: Pick<ConfigProviderProps, 'prefixCls' | 'iconPrefixCls'> & { theme?: Theme | ThemeConfig }) => {
|
2021-06-09 15:36:59 +08:00
|
|
|
if (prefixCls !== undefined) {
|
|
|
|
globalPrefixCls = prefixCls;
|
|
|
|
}
|
|
|
|
if (iconPrefixCls !== undefined) {
|
|
|
|
globalIconPrefixCls = iconPrefixCls;
|
2021-02-09 21:49:15 +08:00
|
|
|
}
|
|
|
|
|
2021-09-01 10:56:50 +08:00
|
|
|
if (theme) {
|
2023-05-18 23:53:34 +08:00
|
|
|
if (isLegacyTheme(theme)) {
|
|
|
|
warning(
|
|
|
|
false,
|
|
|
|
'ConfigProvider',
|
|
|
|
'`config` of css variable theme is not work in v5. Please use new `theme` config instead.',
|
|
|
|
);
|
|
|
|
registerTheme(getGlobalPrefixCls(), theme);
|
|
|
|
} else {
|
|
|
|
globalTheme = theme;
|
|
|
|
}
|
2021-09-01 10:56:50 +08:00
|
|
|
}
|
|
|
|
};
|
2021-06-09 15:36:59 +08:00
|
|
|
|
2021-02-09 21:49:15 +08:00
|
|
|
export const globalConfig = () => ({
|
|
|
|
getPrefixCls: (suffixCls?: string, customizePrefixCls?: string) => {
|
2023-06-29 16:43:11 +08:00
|
|
|
if (customizePrefixCls) {
|
|
|
|
return customizePrefixCls;
|
|
|
|
}
|
2021-03-02 11:53:12 +08:00
|
|
|
return suffixCls ? `${getGlobalPrefixCls()}-${suffixCls}` : getGlobalPrefixCls();
|
|
|
|
},
|
2021-06-09 15:36:59 +08:00
|
|
|
getIconPrefixCls: getGlobalIconPrefixCls,
|
2022-05-11 14:26:18 +08:00
|
|
|
getRootPrefixCls: () => {
|
2021-03-02 11:53:12 +08:00
|
|
|
// If Global prefixCls provided, use this
|
|
|
|
if (globalPrefixCls) {
|
|
|
|
return globalPrefixCls;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fallback to default prefixCls
|
|
|
|
return getGlobalPrefixCls();
|
2021-02-09 21:49:15 +08:00
|
|
|
},
|
2023-05-18 23:53:34 +08:00
|
|
|
getTheme: () => globalTheme,
|
2021-02-09 21:49:15 +08:00
|
|
|
});
|
|
|
|
|
2022-11-18 09:55:42 +08:00
|
|
|
const ProviderChildren: React.FC<ProviderChildrenProps> = (props) => {
|
2021-01-12 10:40:15 +08:00
|
|
|
const {
|
|
|
|
children,
|
2022-09-06 10:13:18 +08:00
|
|
|
csp: customCsp,
|
2021-01-12 10:40:15 +08:00
|
|
|
autoInsertSpaceInButton,
|
2023-06-26 17:09:55 +08:00
|
|
|
anchor,
|
2021-01-12 10:40:15 +08:00
|
|
|
form,
|
|
|
|
locale,
|
|
|
|
componentSize,
|
|
|
|
direction,
|
|
|
|
space,
|
|
|
|
virtual,
|
|
|
|
dropdownMatchSelectWidth,
|
2023-04-04 17:17:36 +08:00
|
|
|
popupMatchSelectWidth,
|
2023-04-07 10:17:00 +08:00
|
|
|
popupOverflow,
|
2021-01-12 10:40:15 +08:00
|
|
|
legacyLocale,
|
|
|
|
parentContext,
|
2022-09-06 10:13:18 +08:00
|
|
|
iconPrefixCls: customIconPrefixCls,
|
2022-03-24 18:44:42 +08:00
|
|
|
theme,
|
2022-05-25 14:57:58 +08:00
|
|
|
componentDisabled,
|
2023-06-25 09:32:53 +08:00
|
|
|
segmented,
|
2023-06-20 19:34:45 +08:00
|
|
|
spin,
|
2023-06-27 17:13:27 +08:00
|
|
|
cascader,
|
2023-06-20 14:35:05 +08:00
|
|
|
typography,
|
2023-06-26 11:42:46 +08:00
|
|
|
checkbox,
|
2023-06-26 14:38:02 +08:00
|
|
|
descriptions,
|
2023-06-19 19:30:16 +08:00
|
|
|
divider,
|
2023-06-25 11:42:31 +08:00
|
|
|
steps,
|
2023-06-25 14:46:13 +08:00
|
|
|
image,
|
2023-06-28 13:51:24 +08:00
|
|
|
layout,
|
2023-06-27 10:51:23 +08:00
|
|
|
mentions,
|
2023-06-27 17:14:08 +08:00
|
|
|
modal,
|
2023-06-25 16:20:39 +08:00
|
|
|
result,
|
2023-06-25 17:28:00 +08:00
|
|
|
slider,
|
2023-06-25 18:28:57 +08:00
|
|
|
breadcrumb,
|
2023-06-26 15:32:18 +08:00
|
|
|
pagination,
|
2023-06-28 11:53:26 +08:00
|
|
|
input,
|
2023-06-26 17:10:26 +08:00
|
|
|
empty,
|
2023-06-29 16:43:11 +08:00
|
|
|
badge,
|
2023-06-26 19:07:57 +08:00
|
|
|
radio,
|
2023-06-29 19:30:34 +08:00
|
|
|
rate,
|
2023-06-30 11:29:39 +08:00
|
|
|
switch: SWITCH,
|
2023-07-03 10:27:31 +08:00
|
|
|
avatar,
|
2023-06-30 17:19:27 +08:00
|
|
|
tag,
|
2023-06-30 20:42:43 +08:00
|
|
|
table,
|
2023-07-03 10:25:55 +08:00
|
|
|
card,
|
2023-07-03 13:38:38 +08:00
|
|
|
tabs,
|
2023-07-03 16:38:56 +08:00
|
|
|
upload,
|
2021-01-12 10:40:15 +08:00
|
|
|
} = props;
|
2020-04-29 23:18:22 +08:00
|
|
|
|
2023-04-04 17:17:36 +08:00
|
|
|
// =================================== Warning ===================================
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
|
|
warning(
|
|
|
|
dropdownMatchSelectWidth === undefined,
|
|
|
|
'ConfigProvider',
|
|
|
|
'`dropdownMatchSelectWidth` is deprecated. Please use `popupMatchSelectWidth` instead.',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// =================================== Context ===================================
|
2021-01-13 13:02:56 +08:00
|
|
|
const getPrefixCls = React.useCallback(
|
|
|
|
(suffixCls: string, customizePrefixCls?: string) => {
|
|
|
|
const { prefixCls } = props;
|
2018-12-05 19:12:18 +08:00
|
|
|
|
2023-06-20 14:35:05 +08:00
|
|
|
if (customizePrefixCls) {
|
|
|
|
return customizePrefixCls;
|
|
|
|
}
|
2018-12-05 19:12:18 +08:00
|
|
|
|
2021-01-13 13:02:56 +08:00
|
|
|
const mergedPrefixCls = prefixCls || parentContext.getPrefixCls('');
|
2020-04-21 11:16:33 +08:00
|
|
|
|
2021-01-13 13:02:56 +08:00
|
|
|
return suffixCls ? `${mergedPrefixCls}-${suffixCls}` : mergedPrefixCls;
|
|
|
|
},
|
2021-05-24 11:46:12 +08:00
|
|
|
[parentContext.getPrefixCls, props.prefixCls],
|
2021-01-13 13:02:56 +08:00
|
|
|
);
|
2018-12-05 19:12:18 +08:00
|
|
|
|
2022-09-06 10:13:18 +08:00
|
|
|
const iconPrefixCls = customIconPrefixCls || parentContext.iconPrefixCls || defaultIconPrefixCls;
|
2022-11-18 09:55:42 +08:00
|
|
|
const shouldWrapSSR = iconPrefixCls !== parentContext.iconPrefixCls;
|
2022-09-06 10:13:18 +08:00
|
|
|
const csp = customCsp || parentContext.csp;
|
|
|
|
|
2023-03-27 23:00:56 +08:00
|
|
|
const wrapSSR = useStyle(iconPrefixCls, csp);
|
2022-11-18 09:55:42 +08:00
|
|
|
|
2022-03-24 18:44:42 +08:00
|
|
|
const mergedTheme = useTheme(theme, parentContext.theme);
|
|
|
|
|
2023-03-10 14:12:49 +08:00
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
|
|
existThemeConfig = existThemeConfig || !!mergedTheme;
|
|
|
|
}
|
|
|
|
|
2022-12-13 13:57:17 +08:00
|
|
|
const baseConfig = {
|
2021-01-15 23:11:11 +08:00
|
|
|
csp,
|
|
|
|
autoInsertSpaceInButton,
|
2023-06-26 17:09:55 +08:00
|
|
|
anchor,
|
2021-01-15 23:11:11 +08:00
|
|
|
locale: locale || legacyLocale,
|
|
|
|
direction,
|
|
|
|
space,
|
|
|
|
virtual,
|
2023-04-04 17:17:36 +08:00
|
|
|
popupMatchSelectWidth: popupMatchSelectWidth ?? dropdownMatchSelectWidth,
|
2023-04-07 10:17:00 +08:00
|
|
|
popupOverflow,
|
2021-01-15 23:11:11 +08:00
|
|
|
getPrefixCls,
|
2022-09-06 10:13:18 +08:00
|
|
|
iconPrefixCls,
|
2022-03-24 18:44:42 +08:00
|
|
|
theme: mergedTheme,
|
2023-06-25 09:32:53 +08:00
|
|
|
segmented,
|
2023-06-20 19:34:45 +08:00
|
|
|
spin,
|
2023-06-27 17:13:27 +08:00
|
|
|
cascader,
|
2023-06-20 14:35:05 +08:00
|
|
|
typography,
|
2023-06-26 11:42:46 +08:00
|
|
|
checkbox,
|
2023-06-26 14:38:02 +08:00
|
|
|
descriptions,
|
2023-06-19 19:30:16 +08:00
|
|
|
divider,
|
2023-06-25 11:42:31 +08:00
|
|
|
steps,
|
2023-06-25 14:46:13 +08:00
|
|
|
image,
|
2023-06-28 11:53:26 +08:00
|
|
|
input,
|
2023-06-28 13:51:24 +08:00
|
|
|
layout,
|
2023-06-27 10:51:23 +08:00
|
|
|
mentions,
|
2023-06-27 17:14:08 +08:00
|
|
|
modal,
|
2023-06-25 16:20:39 +08:00
|
|
|
result,
|
2023-06-25 17:28:00 +08:00
|
|
|
slider,
|
2023-06-25 18:28:57 +08:00
|
|
|
breadcrumb,
|
2023-06-26 15:32:18 +08:00
|
|
|
pagination,
|
2023-06-26 17:10:26 +08:00
|
|
|
empty,
|
2023-06-29 16:43:11 +08:00
|
|
|
badge,
|
2023-06-26 19:07:57 +08:00
|
|
|
radio,
|
2023-06-29 19:30:34 +08:00
|
|
|
rate,
|
2023-06-30 11:29:39 +08:00
|
|
|
switch: SWITCH,
|
2023-07-03 10:27:31 +08:00
|
|
|
avatar,
|
2023-06-30 17:19:27 +08:00
|
|
|
tag,
|
2023-06-30 20:42:43 +08:00
|
|
|
table,
|
2023-07-03 10:25:55 +08:00
|
|
|
card,
|
2023-07-03 13:38:38 +08:00
|
|
|
tabs,
|
2023-07-03 16:38:56 +08:00
|
|
|
upload,
|
2021-01-12 10:40:15 +08:00
|
|
|
};
|
2020-04-18 13:18:51 +08:00
|
|
|
|
2022-12-13 13:57:17 +08:00
|
|
|
const config = {
|
|
|
|
...parentContext,
|
|
|
|
};
|
|
|
|
|
|
|
|
Object.keys(baseConfig).forEach((key: keyof typeof baseConfig) => {
|
|
|
|
if (baseConfig[key] !== undefined) {
|
|
|
|
(config as any)[key] = baseConfig[key];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-01-19 17:33:05 +08:00
|
|
|
// Pass the props used by `useContext` directly with child component.
|
|
|
|
// These props should merged into `config`.
|
2022-11-18 09:55:42 +08:00
|
|
|
PASSED_PROPS.forEach((propName) => {
|
2022-10-06 18:53:06 +08:00
|
|
|
const propValue = props[propName];
|
2021-01-19 17:33:05 +08:00
|
|
|
if (propValue) {
|
|
|
|
(config as any)[propName] = propValue;
|
|
|
|
}
|
|
|
|
});
|
2021-01-12 21:02:53 +08:00
|
|
|
|
2021-01-12 10:40:15 +08:00
|
|
|
// https://github.com/ant-design/ant-design/issues/27617
|
2021-01-13 17:05:05 +08:00
|
|
|
const memoedConfig = useMemo(
|
2021-01-13 13:02:56 +08:00
|
|
|
() => config,
|
2021-01-13 17:05:05 +08:00
|
|
|
config,
|
2022-10-06 18:53:06 +08:00
|
|
|
(prevConfig, currentConfig) => {
|
|
|
|
const prevKeys = Object.keys(prevConfig) as Array<keyof typeof config>;
|
|
|
|
const currentKeys = Object.keys(currentConfig) as Array<keyof typeof config>;
|
2021-01-13 17:05:05 +08:00
|
|
|
return (
|
|
|
|
prevKeys.length !== currentKeys.length ||
|
2022-11-18 09:55:42 +08:00
|
|
|
prevKeys.some((key) => prevConfig[key] !== currentConfig[key])
|
2021-01-13 17:05:05 +08:00
|
|
|
);
|
|
|
|
},
|
2021-01-12 21:02:53 +08:00
|
|
|
);
|
2021-01-12 10:40:15 +08:00
|
|
|
|
2021-08-04 13:45:35 +08:00
|
|
|
const memoIconContextValue = React.useMemo(
|
|
|
|
() => ({ prefixCls: iconPrefixCls, csp }),
|
2022-03-08 14:01:53 +08:00
|
|
|
[iconPrefixCls, csp],
|
2021-08-04 13:45:35 +08:00
|
|
|
);
|
2021-01-26 16:18:13 +08:00
|
|
|
|
2022-11-18 09:55:42 +08:00
|
|
|
let childNode = shouldWrapSSR ? wrapSSR(children as ReactElement) : children;
|
2021-01-12 10:40:15 +08:00
|
|
|
|
2023-02-24 18:22:48 +08:00
|
|
|
const validateMessages = React.useMemo(
|
|
|
|
() =>
|
2023-05-25 19:58:07 +08:00
|
|
|
merge(
|
2023-02-24 18:22:48 +08:00
|
|
|
defaultLocale.Form?.defaultValidateMessages || {},
|
|
|
|
memoedConfig.locale?.Form?.defaultValidateMessages || {},
|
|
|
|
form?.validateMessages || {},
|
|
|
|
),
|
|
|
|
[memoedConfig, form?.validateMessages],
|
|
|
|
);
|
2021-01-12 10:40:15 +08:00
|
|
|
|
|
|
|
if (Object.keys(validateMessages).length > 0) {
|
2023-05-25 19:58:07 +08:00
|
|
|
childNode = (
|
|
|
|
<ValidateMessagesContext.Provider value={validateMessages}>
|
|
|
|
{children}
|
|
|
|
</ValidateMessagesContext.Provider>
|
|
|
|
);
|
2021-01-12 10:40:15 +08:00
|
|
|
}
|
|
|
|
|
2021-01-19 17:33:05 +08:00
|
|
|
if (locale) {
|
|
|
|
childNode = (
|
2021-01-12 21:02:53 +08:00
|
|
|
<LocaleProvider locale={locale} _ANT_MARK__={ANT_MARK}>
|
2021-01-12 10:40:15 +08:00
|
|
|
{childNode}
|
|
|
|
</LocaleProvider>
|
|
|
|
);
|
2021-01-19 17:33:05 +08:00
|
|
|
}
|
2020-04-18 13:18:51 +08:00
|
|
|
|
2022-03-08 14:01:53 +08:00
|
|
|
if (iconPrefixCls || csp) {
|
2021-01-26 16:18:13 +08:00
|
|
|
childNode = (
|
|
|
|
<IconContext.Provider value={memoIconContextValue}>{childNode}</IconContext.Provider>
|
|
|
|
);
|
2021-01-19 17:33:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (componentSize) {
|
|
|
|
childNode = <SizeContextProvider size={componentSize}>{childNode}</SizeContextProvider>;
|
|
|
|
}
|
|
|
|
|
2023-04-23 15:42:36 +08:00
|
|
|
// =================================== Motion ===================================
|
|
|
|
childNode = <MotionWrapper>{childNode}</MotionWrapper>;
|
|
|
|
|
2022-02-18 14:17:32 +08:00
|
|
|
// ================================ Dynamic theme ================================
|
2022-06-29 20:34:00 +08:00
|
|
|
const memoTheme = React.useMemo(() => {
|
|
|
|
const { algorithm, token, ...rest } = mergedTheme || {};
|
2022-08-16 21:06:25 +08:00
|
|
|
const themeObj =
|
|
|
|
algorithm && (!Array.isArray(algorithm) || algorithm.length > 0)
|
|
|
|
? createTheme(algorithm)
|
|
|
|
: undefined;
|
2022-06-29 20:34:00 +08:00
|
|
|
|
|
|
|
return {
|
|
|
|
...rest,
|
|
|
|
theme: themeObj,
|
2022-03-24 18:44:42 +08:00
|
|
|
|
2022-02-18 14:17:32 +08:00
|
|
|
token: {
|
2022-03-21 16:48:25 +08:00
|
|
|
...defaultSeedToken,
|
2022-06-29 20:34:00 +08:00
|
|
|
...token,
|
2022-02-18 14:17:32 +08:00
|
|
|
},
|
2022-06-29 20:34:00 +08:00
|
|
|
};
|
|
|
|
}, [mergedTheme]);
|
2022-03-03 14:55:19 +08:00
|
|
|
|
2022-03-24 18:44:42 +08:00
|
|
|
if (theme) {
|
2022-02-18 14:17:32 +08:00
|
|
|
childNode = (
|
|
|
|
<DesignTokenContext.Provider value={memoTheme}>{childNode}</DesignTokenContext.Provider>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// =================================== Render ===================================
|
2022-05-25 14:57:58 +08:00
|
|
|
if (componentDisabled !== undefined) {
|
|
|
|
childNode = (
|
|
|
|
<DisabledContextProvider disabled={componentDisabled}>{childNode}</DisabledContextProvider>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-01-19 17:33:05 +08:00
|
|
|
return <ConfigContext.Provider value={memoedConfig}>{childNode}</ConfigContext.Provider>;
|
2021-01-12 10:40:15 +08:00
|
|
|
};
|
2019-07-03 20:14:39 +08:00
|
|
|
|
2021-01-12 10:40:15 +08:00
|
|
|
const ConfigProvider: React.FC<ConfigProviderProps> & {
|
2022-02-18 14:17:32 +08:00
|
|
|
/** @private internal Usage. do not use in your production */
|
2021-01-12 10:40:15 +08:00
|
|
|
ConfigContext: typeof ConfigContext;
|
2023-02-14 17:39:35 +08:00
|
|
|
/** @deprecated Please use `ConfigProvider.useConfig().componentSize` instead */
|
2021-01-24 23:24:06 +08:00
|
|
|
SizeContext: typeof SizeContext;
|
2021-02-09 21:49:15 +08:00
|
|
|
config: typeof setGlobalConfig;
|
2023-02-14 17:39:35 +08:00
|
|
|
useConfig: typeof useConfig;
|
2023-02-22 18:18:26 +08:00
|
|
|
} = (props) => {
|
|
|
|
const context = React.useContext<ConfigConsumerProps>(ConfigContext);
|
|
|
|
const antLocale = React.useContext<LocaleContextProps | undefined>(LocaleContext);
|
|
|
|
return <ProviderChildren parentContext={context} legacyLocale={antLocale!} {...props} />;
|
|
|
|
};
|
2018-11-26 12:06:42 +08:00
|
|
|
|
2020-09-11 21:24:26 +08:00
|
|
|
ConfigProvider.ConfigContext = ConfigContext;
|
2021-01-24 23:24:06 +08:00
|
|
|
ConfigProvider.SizeContext = SizeContext;
|
2021-02-09 21:49:15 +08:00
|
|
|
ConfigProvider.config = setGlobalConfig;
|
2023-02-14 17:39:35 +08:00
|
|
|
ConfigProvider.useConfig = useConfig;
|
|
|
|
|
|
|
|
Object.defineProperty(ConfigProvider, 'SizeContext', {
|
|
|
|
get: () => {
|
|
|
|
warning(
|
|
|
|
false,
|
|
|
|
'ConfigProvider',
|
|
|
|
'ConfigProvider.SizeContext is deprecated. Please use `ConfigProvider.useConfig().componentSize` instead.',
|
|
|
|
);
|
|
|
|
return SizeContext;
|
|
|
|
},
|
|
|
|
});
|
2021-01-24 23:24:06 +08:00
|
|
|
|
2023-01-08 21:30:41 +08:00
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
|
|
|
ConfigProvider.displayName = 'ConfigProvider';
|
|
|
|
}
|
|
|
|
|
2018-12-07 20:02:01 +08:00
|
|
|
export default ConfigProvider;
|