UNPKG

yantd

Version:

React component library

54 lines (53 loc) 1.85 kB
import React from "react"; import { ConfigContext, ConfigConsumer } from "./context"; export { ConfigContext, ConfigConsumer }; export var configConsumerProps = [ 'getTargetContainer', 'getPopupContainer', 'rootPrefixCls', 'getPrefixCls', 'renderEmpty', 'csp', 'autoInsertSpaceInButton', 'locale', 'pageHeader', ]; export var defaultPrefixCls = 'yant'; var globalPrefixCls; function getGlobalPrefixCls() { return globalPrefixCls || defaultPrefixCls; } var ConfigProvider = function (props) { return (React.createElement(ConfigContext.Provider, { value: { getPrefixCls: globalConfig().getPrefixCls } }, props.children)); }; var setGlobalConfig = function (params) { if (params.prefixCls !== undefined) { globalPrefixCls = params.prefixCls; } }; export var globalConfig = function () { return ({ getPrefixCls: function (suffixCls, customizePrefixCls) { if (customizePrefixCls) return customizePrefixCls; return suffixCls ? getGlobalPrefixCls() + "-" + suffixCls : getGlobalPrefixCls(); }, getRootPrefixCls: function (rootPrefixCls, customizePrefixCls) { // Customize rootPrefixCls is first priority if (rootPrefixCls) { return rootPrefixCls; } // If Global prefixCls provided, use this if (globalPrefixCls) { return globalPrefixCls; } // [Legacy] If customize prefixCls provided, we cut it to get the prefixCls if (customizePrefixCls && customizePrefixCls.includes('-')) { return customizePrefixCls.replace(/^(.*)-[^-]*$/, '$1'); } // Fallback to default prefixCls return getGlobalPrefixCls(); }, }); }; ConfigProvider.ConfigContext = ConfigContext; ConfigProvider.config = setGlobalConfig; export default ConfigProvider;