Browse Source

fix: TreeShaking (#19115)

pull/19121/head
二货机器人 5 years ago
committed by GitHub
parent
commit
7922090eaa
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 30
      components/config-provider/context.ts
  2. 33
      components/config-provider/index.tsx

30
components/config-provider/context.ts

@ -0,0 +1,30 @@
import createReactContext from '@ant-design/create-react-context';
import defaultRenderEmpty, { RenderEmptyHandler } from './renderEmpty';
import { Locale } from '../locale-provider';
export interface CSPConfig {
nonce?: string;
}
export interface ConfigConsumerProps {
getPopupContainer?: (triggerNode: HTMLElement) => HTMLElement;
rootPrefixCls?: string;
getPrefixCls: (suffixCls: string, customizePrefixCls?: string) => string;
renderEmpty: RenderEmptyHandler;
csp?: CSPConfig;
autoInsertSpaceInButton?: boolean;
locale?: Locale;
}
export const ConfigContext = createReactContext<ConfigConsumerProps>({
// We provide a default function for Context without provider
getPrefixCls: (suffixCls: string, customizePrefixCls?: string) => {
if (customizePrefixCls) return customizePrefixCls;
return `ant-${suffixCls}`;
},
renderEmpty: defaultRenderEmpty,
});
export const ConfigConsumer = ConfigContext.Consumer;

33
components/config-provider/index.tsx

@ -2,27 +2,13 @@
// SFC has specified a displayName, but not worked.
/* eslint-disable react/display-name */
import * as React from 'react';
import createReactContext from '@ant-design/create-react-context';
import defaultRenderEmpty, { RenderEmptyHandler } from './renderEmpty';
import { RenderEmptyHandler } from './renderEmpty';
import LocaleProvider, { Locale, ANT_MARK } from '../locale-provider';
import LocaleReceiver from '../locale-provider/LocaleReceiver';
import { ConfigConsumer, ConfigContext, CSPConfig, ConfigConsumerProps } from './context';
export { RenderEmptyHandler };
export interface CSPConfig {
nonce?: string;
}
export interface ConfigConsumerProps {
getPopupContainer?: (triggerNode: HTMLElement) => HTMLElement;
rootPrefixCls?: string;
getPrefixCls: (suffixCls: string, customizePrefixCls?: string) => string;
renderEmpty: RenderEmptyHandler;
csp?: CSPConfig;
autoInsertSpaceInButton?: boolean;
locale?: Locale;
}
export { RenderEmptyHandler, ConfigConsumer, CSPConfig, ConfigConsumerProps };
export const configConsumerProps = [
'getPopupContainer',
@ -44,19 +30,6 @@ export interface ConfigProviderProps {
locale?: Locale;
}
const ConfigContext = createReactContext<ConfigConsumerProps>({
// We provide a default function for Context without provider
getPrefixCls: (suffixCls: string, customizePrefixCls?: string) => {
if (customizePrefixCls) return customizePrefixCls;
return `ant-${suffixCls}`;
},
renderEmpty: defaultRenderEmpty,
});
export const ConfigConsumer = ConfigContext.Consumer;
class ConfigProvider extends React.Component<ConfigProviderProps> {
getPrefixCls = (suffixCls: string, customizePrefixCls?: string) => {
const { prefixCls = 'ant' } = this.props;

Loading…
Cancel
Save