2023-05-26 16:42:26 +08:00
|
|
|
import * as React from 'react';
|
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';
|
2024-01-26 13:53:52 +08:00
|
|
|
import type { FormProps } 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';
|
2024-01-26 13:53:52 +08:00
|
|
|
import type { PaginationProps } from '../pagination';
|
|
|
|
import type { SelectProps } from '../select';
|
2023-06-02 15:03:29 +08:00
|
|
|
import type { SpaceProps } from '../space';
|
2024-01-30 13:57:49 +08:00
|
|
|
import type { TableProps } from '../table';
|
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';
|
2024-01-29 11:01:30 +08:00
|
|
|
import type { TourProps } from '../tour/interface';
|
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;
|
|
|
|
|
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?:
|
|
|
|
| {
|
|
|
|
/**
|
2024-01-09 21:02:14 +08:00
|
|
|
* Prefix for css variable, default to `ant`.
|
2023-11-10 10:02:46 +08:00
|
|
|
*/
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2024-01-30 13:57:49 +08:00
|
|
|
export interface TableConfig extends ComponentStyleConfig {
|
|
|
|
expandable?: {
|
|
|
|
expandIcon?: NonNullable<TableProps['expandable']>['expandIcon'];
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2024-01-29 11:01:30 +08:00
|
|
|
export type TourConfig = Pick<TourProps, 'closeIcon'>;
|
|
|
|
|
2024-01-26 13:53:52 +08:00
|
|
|
export type ModalConfig = ComponentStyleConfig & Pick<ModalProps, 'classNames' | 'styles'>;
|
2023-09-25 14:27:41 +08:00
|
|
|
|
2024-01-26 13:53:52 +08:00
|
|
|
export type BadgeConfig = ComponentStyleConfig & Pick<BadgeProps, 'classNames' | 'styles'>;
|
2023-06-29 16:43:11 +08:00
|
|
|
|
2024-01-26 13:53:52 +08:00
|
|
|
export type ButtonConfig = ComponentStyleConfig & Pick<ButtonProps, 'classNames' | 'styles'>;
|
2023-05-26 16:42:26 +08:00
|
|
|
|
2024-01-26 10:52:17 +08:00
|
|
|
export type DrawerConfig = ComponentStyleConfig &
|
|
|
|
Pick<DrawerProps, 'classNames' | 'styles' | 'closeIcon'>;
|
2023-09-25 20:37:37 +08:00
|
|
|
|
2024-01-26 13:53:52 +08:00
|
|
|
export type FlexConfig = ComponentStyleConfig & Pick<FlexProps, 'vertical'>;
|
2023-09-14 17:04:05 +08:00
|
|
|
|
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;
|
2024-01-26 13:53:52 +08:00
|
|
|
input?: ComponentStyleConfig & Pick<InputProps, 'autoComplete' | 'classNames' | 'styles'>;
|
|
|
|
pagination?: ComponentStyleConfig & Pick<PaginationProps, 'showSizeChanger'>;
|
2019-10-21 12:01:33 +08:00
|
|
|
locale?: Locale;
|
2020-11-03 16:22:18 +08:00
|
|
|
direction?: DirectionType;
|
2024-01-26 13:53:52 +08:00
|
|
|
space?: Pick<SpaceProps, 'size' | 'className' | 'classNames' | 'style' | 'styles'>;
|
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;
|
2024-01-26 13:53:52 +08:00
|
|
|
form?: ComponentStyleConfig &
|
|
|
|
Pick<FormProps, 'requiredMark' | 'colon' | 'scrollToFirstError' | 'validateMessages'>;
|
2022-03-24 18:44:42 +08:00
|
|
|
theme?: ThemeConfig;
|
2024-01-26 13:53:52 +08:00
|
|
|
select?: ComponentStyleConfig & Pick<SelectProps, 'showSearch'>;
|
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;
|
2024-01-30 13:57:49 +08:00
|
|
|
table?: TableConfig;
|
2023-07-03 10:25:55 +08:00
|
|
|
card?: ComponentStyleConfig;
|
2024-01-05 10:56:11 +08:00
|
|
|
tabs?: ComponentStyleConfig & Pick<TabsProps, 'indicator' | 'indicatorSize'>;
|
2023-07-06 10:27:39 +08:00
|
|
|
timeline?: ComponentStyleConfig;
|
2023-07-07 19:02:55 +08:00
|
|
|
timePicker?: ComponentStyleConfig;
|
2024-01-29 11:01:30 +08:00
|
|
|
tour?: TourConfig;
|
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;
|