34 lines
1.6 KiB
JavaScript
34 lines
1.6 KiB
JavaScript
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
|
|
import * as React from 'react';
|
|
import defaultRenderEmpty from './renderEmpty';
|
|
export var ConfigContext = React.createContext({
|
|
// We provide a default function for Context without provider
|
|
getPrefixCls: function getPrefixCls(suffixCls, customizePrefixCls) {
|
|
if (customizePrefixCls) return customizePrefixCls;
|
|
return "ant-".concat(suffixCls);
|
|
},
|
|
renderEmpty: defaultRenderEmpty
|
|
});
|
|
export var ConfigConsumer = ConfigContext.Consumer;
|
|
export function withConfigConsumer(config) {
|
|
return function withConfigConsumerFunc(Component) {
|
|
// Wrap with ConfigConsumer. Since we need compatible with react 15, be care when using ref methods
|
|
var SFC = function SFC(props) {
|
|
return /*#__PURE__*/React.createElement(ConfigConsumer, null, function (configProps) {
|
|
var basicPrefixCls = config.prefixCls;
|
|
var getPrefixCls = configProps.getPrefixCls;
|
|
var customizePrefixCls = props.prefixCls;
|
|
var prefixCls = getPrefixCls(basicPrefixCls, customizePrefixCls);
|
|
return /*#__PURE__*/React.createElement(Component, _extends({}, configProps, props, {
|
|
prefixCls: prefixCls
|
|
}));
|
|
});
|
|
};
|
|
|
|
var cons = Component.constructor;
|
|
var name = cons && cons.displayName || Component.name || 'Component';
|
|
SFC.displayName = "withConfigConsumer(".concat(name, ")");
|
|
return SFC;
|
|
};
|
|
} |