ant-design/components/config-provider/context.ts

34 lines
955 B
TypeScript
Raw Normal View History

2019-10-08 15:04:00 +08:00
import { createContext } from 'react';
2019-10-08 14:45:17 +08:00
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;
pageHeader?: {
ghost: boolean;
};
2019-10-08 14:45:17 +08:00
}
2019-10-08 15:04:00 +08:00
export const ConfigContext = createContext<ConfigConsumerProps>({
2019-10-08 14:45:17 +08:00
// 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;