2022-08-16 21:06:25 +08:00
|
|
|
import type { DerivativeFunc } from '@ant-design/cssinjs';
|
2023-05-26 16:42:26 +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-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';
|
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-06-02 15:03:29 +08:00
|
|
|
import type { SpaceProps } from '../space';
|
2022-09-15 21:26:04 +08:00
|
|
|
import type { AliasToken, MapToken, OverrideToken, SeedToken } from '../theme/interface';
|
2022-05-07 14:31:54 +08:00
|
|
|
import type { SizeType } from './SizeContext';
|
2023-05-26 16:42:26 +08:00
|
|
|
import type { RenderEmptyHandler } from './defaultRenderEmpty';
|
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;
|
|
|
|
|
2022-08-16 21:06:25 +08:00
|
|
|
export type MappingAlgorithm = DerivativeFunc<SeedToken, MapToken>;
|
|
|
|
|
2022-03-24 18:44:42 +08:00
|
|
|
export interface ThemeConfig {
|
2022-09-15 21:26:04 +08:00
|
|
|
token?: Partial<AliasToken>;
|
|
|
|
components?: OverrideToken;
|
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;
|
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-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-04-07 10:17:00 +08:00
|
|
|
export type PopupOverflow = 'viewport' | 'scroll';
|
|
|
|
|
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;
|
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-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-06-27 17:13:27 +08:00
|
|
|
cascader?: ComponentStyleConfig;
|
2023-06-26 11:42:46 +08:00
|
|
|
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-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-07-03 13:38:38 +08:00
|
|
|
tabs?: ComponentStyleConfig;
|
2023-07-03 16:38:56 +08:00
|
|
|
upload?: ComponentStyleConfig;
|
2023-07-03 20:37:11 +08:00
|
|
|
notification?: ComponentStyleConfig;
|
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;
|