From 7922090eaa36c726cc6525bcf9521c32569819b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=8C=E8=B4=A7=E6=9C=BA=E5=99=A8=E4=BA=BA?= Date: Tue, 8 Oct 2019 14:45:17 +0800 Subject: [PATCH] fix: TreeShaking (#19115) --- components/config-provider/context.ts | 30 ++++++++++++++++++++++++ components/config-provider/index.tsx | 33 +++------------------------ 2 files changed, 33 insertions(+), 30 deletions(-) create mode 100644 components/config-provider/context.ts diff --git a/components/config-provider/context.ts b/components/config-provider/context.ts new file mode 100644 index 0000000000..37f2426ccc --- /dev/null +++ b/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({ + // 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; diff --git a/components/config-provider/index.tsx b/components/config-provider/index.tsx index 721f68a49c..92a30c37fd 100644 --- a/components/config-provider/index.tsx +++ b/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({ - // 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 { getPrefixCls = (suffixCls: string, customizePrefixCls?: string) => { const { prefixCls = 'ant' } = this.props;