2023-05-26 16:42:26 +08:00
|
|
|
import * as React from 'react';
|
2023-09-11 17:28:04 +08:00
|
|
|
import type { ValidateMessages } from 'rc-field-form/lib/interface';
|
2023-01-03 09:56:47 +08:00
|
|
|
import type { Options } from 'scroll-into-view-if-needed';
|
2023-09-11 17:28:04 +08:00
|
|
|
|
|
|
|
import type { WarningContextProps } from '../_util/warning';
|
|
|
|
import type { ShowWaveEffect } from '../_util/wave/interface';
|
2023-06-29 16:43:11 +08:00
|
|
|
import type { BadgeProps } from '../badge';
|
2023-05-26 16:42:26 +08:00
|
|
|
import type { ButtonProps } from '../button';
|
2023-10-24 00:57:38 +08:00
|
|
|
import type { DrawerProps } from '../drawer';
|
2023-09-14 17:04:05 +08:00
|
|
|
import type { FlexProps } from '../flex/interface';
|
2022-05-26 17:14:05 +08:00
|
|
|
import type { RequiredMark } from '../form/Form';
|
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';
|
2023-10-24 00:57:38 +08:00
|
|
|
import type { ModalProps } from '../modal';
|
2023-06-02 15:03:29 +08:00
|
|
|
import type { SpaceProps } from '../space';
|
2023-09-11 17:28:04 +08:00
|
|
|
import type { TabsProps } from '../tabs';
|
2023-07-27 11:31:38 +08:00
|
|
|
import type { AliasToken, MappingAlgorithm, OverrideToken } from '../theme/interface';
|
2023-05-26 16:42:26 +08:00
|
|
|
import type { RenderEmptyHandler } from './defaultRenderEmpty';
|
2023-09-11 17:28:04 +08:00
|
|
|
import type { SizeType } from './SizeContext';
|
2019-10-21 12:01:33 +08:00
|
|
|
|
2022-02-18 14:17:32 +08:00
|
|
|
export const defaultIconPrefixCls = 'anticon';
|
|
|
|
|
2021-09-01 10:56:50 +08:00
|
|
|
export interface Theme {
|
|
|
|
primaryColor?: string;
|
|
|
|
infoColor?: string;
|
|
|
|
successColor?: string;
|
|
|
|
processingColor?: string;
|
|
|
|
errorColor?: string;
|
|
|
|
warningColor?: string;
|
|
|
|
}
|
|
|
|
|
2019-10-21 12:01:33 +08:00
|
|
|
export interface CSPConfig {
|
|
|
|
nonce?: string;
|
|
|
|
}
|
|
|
|
|
2020-11-03 16:22:18 +08:00
|
|
|
export type DirectionType = 'ltr' | 'rtl' | undefined;
|
|
|
|
|
2023-07-27 11:31:38 +08:00
|
|
|
type ComponentsConfig = {
|
|
|
|
[key in keyof OverrideToken]?: OverrideToken[key] & {
|
|
|
|
algorithm?: boolean | MappingAlgorithm | MappingAlgorithm[];
|
|
|
|
};
|
|
|
|
};
|
2022-08-16 21:06:25 +08:00
|
|
|
|
2022-03-24 18:44:42 +08:00
|
|
|
export interface ThemeConfig {
|
2022-09-15 21:26:04 +08:00
|
|
|
token?: Partial<AliasToken>;
|
2023-07-27 11:31:38 +08:00
|
|
|
components?: ComponentsConfig;
|
2022-08-16 21:06:25 +08:00
|
|
|
algorithm?: MappingAlgorithm | MappingAlgorithm[];
|
2022-03-24 18:44:42 +08:00
|
|
|
hashed?: boolean;
|
2022-11-17 01:06:33 +08:00
|
|
|
inherit?: boolean;
|
2023-11-10 10:02:46 +08:00
|
|
|
cssVar?:
|
|
|
|
| {
|
|
|
|
/**
|
|
|
|
* Prefix for css variable, default to `antd`.
|
|
|
|
*/
|
|
|
|
prefix?: string;
|
|
|
|
/**
|
|
|
|
* Unique key for theme, should be set manually < react@18.
|
|
|
|
*/
|
|
|
|
key?: string;
|
|
|
|
}
|
|
|
|
| boolean;
|
2022-03-24 18:44:42 +08:00
|
|
|
}
|
|
|
|
|
2023-06-26 11:42:46 +08:00
|
|
|
export interface ComponentStyleConfig {
|
2023-05-26 16:42:26 +08:00
|
|
|
className?: string;
|
|
|
|
style?: React.CSSProperties;
|
2023-06-19 19:30:16 +08:00
|
|
|
}
|
|
|
|
|
2023-09-25 14:27:41 +08:00
|
|
|
export interface ModalConfig extends ComponentStyleConfig {
|
|
|
|
classNames?: ModalProps['classNames'];
|
|
|
|
styles?: ModalProps['styles'];
|
|
|
|
}
|
|
|
|
|
2023-06-29 16:43:11 +08:00
|
|
|
export interface BadgeConfig extends ComponentStyleConfig {
|
|
|
|
classNames?: BadgeProps['classNames'];
|
|
|
|
styles?: BadgeProps['styles'];
|
|
|
|
}
|
|
|
|
|
2023-06-26 11:42:46 +08:00
|
|
|
export interface ButtonConfig extends ComponentStyleConfig {
|
2023-05-26 16:42:26 +08:00
|
|
|
classNames?: ButtonProps['classNames'];
|
|
|
|
styles?: ButtonProps['styles'];
|
|
|
|
}
|
|
|
|
|
2023-09-25 20:37:37 +08:00
|
|
|
export interface DrawerConfig extends ComponentStyleConfig {
|
|
|
|
classNames?: DrawerProps['classNames'];
|
|
|
|
styles?: DrawerProps['styles'];
|
|
|
|
}
|
|
|
|
|
2023-09-14 17:04:05 +08:00
|
|
|
export interface FlexConfig extends ComponentStyleConfig {
|
|
|
|
vertical?: FlexProps['vertical'];
|
|
|
|
}
|
|
|
|
|
2023-04-07 10:17:00 +08:00
|
|
|
export type PopupOverflow = 'viewport' | 'scroll';
|
|
|
|
|
2023-07-25 16:29:47 +08:00
|
|
|
export interface WaveConfig {
|
|
|
|
disabled?: boolean;
|
|
|
|
showEffect?: ShowWaveEffect;
|
|
|
|
}
|
|
|
|
|
2019-10-21 12:01:33 +08:00
|
|
|
export interface ConfigConsumerProps {
|
2020-04-29 20:22:16 +08:00
|
|
|
getTargetContainer?: () => HTMLElement;
|
2021-10-09 10:24:41 +08:00
|
|
|
getPopupContainer?: (triggerNode?: HTMLElement) => HTMLElement;
|
2019-10-21 12:01:33 +08:00
|
|
|
rootPrefixCls?: string;
|
2022-02-27 22:17:17 +08:00
|
|
|
iconPrefixCls: string;
|
2020-08-03 11:41:08 +08:00
|
|
|
getPrefixCls: (suffixCls?: string, customizePrefixCls?: string) => string;
|
2022-05-16 16:34:42 +08:00
|
|
|
renderEmpty?: RenderEmptyHandler;
|
2019-10-21 12:01:33 +08:00
|
|
|
csp?: CSPConfig;
|
|
|
|
autoInsertSpaceInButton?: boolean;
|
2023-06-28 11:53:26 +08:00
|
|
|
input?: ComponentStyleConfig & {
|
2020-04-22 10:38:43 +08:00
|
|
|
autoComplete?: string;
|
2023-06-28 11:53:26 +08:00
|
|
|
classNames?: InputProps['classNames'];
|
|
|
|
styles?: InputProps['styles'];
|
2020-04-22 10:38:43 +08:00
|
|
|
};
|
2023-06-26 15:32:18 +08:00
|
|
|
pagination?: ComponentStyleConfig & { showSizeChanger?: boolean };
|
2019-10-21 12:01:33 +08:00
|
|
|
locale?: Locale;
|
|
|
|
pageHeader?: {
|
|
|
|
ghost: 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
|
|
|
popupMatchSelectWidth?: boolean;
|
2023-04-07 10:17:00 +08:00
|
|
|
popupOverflow?: PopupOverflow;
|
2023-06-28 14:13:14 +08:00
|
|
|
form?: ComponentStyleConfig & {
|
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;
|
2023-07-06 15:33:33 +08:00
|
|
|
validateMessages?: ValidateMessages;
|
2020-10-24 14:27:49 +08:00
|
|
|
};
|
2022-03-24 18:44:42 +08:00
|
|
|
theme?: ThemeConfig;
|
2023-06-27 17:12:36 +08:00
|
|
|
select?: ComponentStyleConfig & {
|
2022-12-14 10:22:17 +08:00
|
|
|
showSearch?: boolean;
|
|
|
|
};
|
2023-07-06 09:33:54 +08:00
|
|
|
alert?: ComponentStyleConfig;
|
2023-06-26 17:09:55 +08:00
|
|
|
anchor?: ComponentStyleConfig;
|
2023-05-26 16:42:26 +08:00
|
|
|
button?: ButtonConfig;
|
2023-06-26 11:42:46 +08:00
|
|
|
divider?: ComponentStyleConfig;
|
2023-09-25 20:37:37 +08:00
|
|
|
drawer?: DrawerConfig;
|
2023-07-06 09:38:21 +08:00
|
|
|
calendar?: ComponentStyleConfig;
|
2023-07-07 09:30:37 +08:00
|
|
|
carousel?: ComponentStyleConfig;
|
2023-06-27 17:13:27 +08:00
|
|
|
cascader?: ComponentStyleConfig;
|
2023-07-06 09:45:25 +08:00
|
|
|
collapse?: ComponentStyleConfig;
|
2023-06-26 11:42:46 +08:00
|
|
|
typography?: ComponentStyleConfig;
|
2023-07-05 18:00:46 +08:00
|
|
|
skeleton?: ComponentStyleConfig;
|
2023-06-26 11:42:46 +08:00
|
|
|
spin?: ComponentStyleConfig;
|
|
|
|
segmented?: ComponentStyleConfig;
|
|
|
|
steps?: ComponentStyleConfig;
|
2023-07-06 21:54:54 +08:00
|
|
|
statistic?: ComponentStyleConfig;
|
2023-06-26 11:42:46 +08:00
|
|
|
image?: ComponentStyleConfig;
|
2023-06-28 13:51:24 +08:00
|
|
|
layout?: ComponentStyleConfig;
|
2023-07-06 09:43:03 +08:00
|
|
|
list?: ComponentStyleConfig;
|
2023-06-27 10:51:23 +08:00
|
|
|
mentions?: ComponentStyleConfig;
|
2023-09-25 14:27:41 +08:00
|
|
|
modal?: ModalConfig;
|
2023-07-05 19:21:56 +08:00
|
|
|
progress?: ComponentStyleConfig;
|
2023-06-26 11:42:46 +08:00
|
|
|
result?: ComponentStyleConfig;
|
|
|
|
slider?: ComponentStyleConfig;
|
|
|
|
breadcrumb?: ComponentStyleConfig;
|
2023-07-05 19:48:33 +08:00
|
|
|
menu?: ComponentStyleConfig;
|
2023-06-26 11:42:46 +08:00
|
|
|
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-06 09:36:45 +08:00
|
|
|
transfer?: ComponentStyleConfig;
|
2023-07-03 10:27:31 +08:00
|
|
|
avatar?: ComponentStyleConfig;
|
2023-07-03 20:38:14 +08:00
|
|
|
message?: 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-08-30 21:28:45 +08:00
|
|
|
tabs?: ComponentStyleConfig & Pick<TabsProps, 'indicatorSize'>;
|
2023-07-06 10:27:39 +08:00
|
|
|
timeline?: ComponentStyleConfig;
|
2023-07-07 19:02:55 +08:00
|
|
|
timePicker?: ComponentStyleConfig;
|
2023-07-03 16:38:56 +08:00
|
|
|
upload?: ComponentStyleConfig;
|
2023-07-03 20:37:11 +08:00
|
|
|
notification?: ComponentStyleConfig;
|
2023-07-03 22:42:46 +08:00
|
|
|
tree?: ComponentStyleConfig;
|
2023-07-04 11:23:58 +08:00
|
|
|
colorPicker?: ComponentStyleConfig;
|
2023-07-07 19:02:55 +08:00
|
|
|
datePicker?: ComponentStyleConfig;
|
2023-10-24 00:57:38 +08:00
|
|
|
rangePicker?: ComponentStyleConfig;
|
2023-11-02 00:48:26 +08:00
|
|
|
dropdown?: ComponentStyleConfig;
|
2023-09-14 17:04:05 +08:00
|
|
|
flex?: FlexConfig;
|
2023-07-25 16:29:47 +08:00
|
|
|
wave?: WaveConfig;
|
2023-09-11 17:28:04 +08:00
|
|
|
warning?: WarningContextProps;
|
2019-10-21 12:01:33 +08:00
|
|
|
}
|
|
|
|
|
2021-01-09 15:22:08 +08:00
|
|
|
const defaultGetPrefixCls = (suffixCls?: string, customizePrefixCls?: string) => {
|
2023-06-20 14:35:05 +08:00
|
|
|
if (customizePrefixCls) {
|
|
|
|
return customizePrefixCls;
|
|
|
|
}
|
2021-01-09 15:22:08 +08:00
|
|
|
return suffixCls ? `ant-${suffixCls}` : 'ant';
|
|
|
|
};
|
|
|
|
|
2022-11-29 19:48:53 +08:00
|
|
|
// zombieJ: 🚨 Do not pass `defaultRenderEmpty` here since it will cause circular dependency.
|
2019-10-30 16:28:28 +08:00
|
|
|
export const ConfigContext = React.createContext<ConfigConsumerProps>({
|
2019-10-21 12:01:33 +08:00
|
|
|
// We provide a default function for Context without provider
|
2021-01-09 15:22:08 +08:00
|
|
|
getPrefixCls: defaultGetPrefixCls,
|
2022-02-18 14:17:32 +08:00
|
|
|
iconPrefixCls: defaultIconPrefixCls,
|
2019-10-21 12:01:33 +08:00
|
|
|
});
|
|
|
|
|
2022-12-25 22:54:56 +08:00
|
|
|
export const { Consumer: ConfigConsumer } = ConfigContext;
|