index.js
5.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
"use strict";
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
Object.defineProperty(exports, "ConfigConsumer", {
enumerable: true,
get: function get() {
return _context.ConfigConsumer;
}
});
Object.defineProperty(exports, "ConfigContext", {
enumerable: true,
get: function get() {
return _context.ConfigContext;
}
});
exports["default"] = exports.configConsumerProps = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var React = _interopRequireWildcard(require("react"));
var _rcFieldForm = require("rc-field-form");
var _localeProvider = _interopRequireWildcard(require("../locale-provider"));
var _LocaleReceiver = _interopRequireDefault(require("../locale-provider/LocaleReceiver"));
var _context = require("./context");
var _SizeContext = require("./SizeContext");
var _message = _interopRequireDefault(require("../message"));
var _notification = _interopRequireDefault(require("../notification"));
// TODO: remove this lint
// SFC has specified a displayName, but not worked.
/* eslint-disable react/display-name */
var configConsumerProps = ['getTargetContainer', 'getPopupContainer', 'rootPrefixCls', 'getPrefixCls', 'renderEmpty', 'csp', 'autoInsertSpaceInButton', 'locale', 'pageHeader'];
exports.configConsumerProps = configConsumerProps;
var ConfigProvider = function ConfigProvider(props) {
React.useEffect(function () {
if (props.direction) {
_message["default"].config({
rtl: props.direction === 'rtl'
});
_notification["default"].config({
rtl: props.direction === 'rtl'
});
}
}, [props.direction]);
var getPrefixClsWrapper = function getPrefixClsWrapper(context) {
return function (suffixCls, customizePrefixCls) {
var prefixCls = props.prefixCls;
if (customizePrefixCls) return customizePrefixCls;
var mergedPrefixCls = prefixCls || context.getPrefixCls('');
return suffixCls ? "".concat(mergedPrefixCls, "-").concat(suffixCls) : mergedPrefixCls;
};
};
var renderProvider = function renderProvider(context, legacyLocale) {
var children = props.children,
getTargetContainer = props.getTargetContainer,
getPopupContainer = props.getPopupContainer,
renderEmpty = props.renderEmpty,
csp = props.csp,
autoInsertSpaceInButton = props.autoInsertSpaceInButton,
form = props.form,
input = props.input,
locale = props.locale,
pageHeader = props.pageHeader,
componentSize = props.componentSize,
direction = props.direction,
space = props.space,
virtual = props.virtual,
dropdownMatchSelectWidth = props.dropdownMatchSelectWidth;
var config = (0, _extends2["default"])((0, _extends2["default"])({}, context), {
getPrefixCls: getPrefixClsWrapper(context),
csp: csp,
autoInsertSpaceInButton: autoInsertSpaceInButton,
locale: locale || legacyLocale,
direction: direction,
space: space,
virtual: virtual,
dropdownMatchSelectWidth: dropdownMatchSelectWidth
});
if (getTargetContainer) {
config.getTargetContainer = getTargetContainer;
}
if (getPopupContainer) {
config.getPopupContainer = getPopupContainer;
}
if (renderEmpty) {
config.renderEmpty = renderEmpty;
}
if (pageHeader) {
config.pageHeader = pageHeader;
}
if (input) {
config.input = input;
}
if (form) {
config.form = form;
}
var childNode = children; // Additional Form provider
var validateMessages = {};
if (locale && locale.Form && locale.Form.defaultValidateMessages) {
validateMessages = locale.Form.defaultValidateMessages;
}
if (form && form.validateMessages) {
validateMessages = (0, _extends2["default"])((0, _extends2["default"])({}, validateMessages), form.validateMessages);
}
if (Object.keys(validateMessages).length > 0) {
childNode = /*#__PURE__*/React.createElement(_rcFieldForm.FormProvider, {
validateMessages: validateMessages
}, children);
}
var childrenWithLocale = locale === undefined ? childNode : /*#__PURE__*/React.createElement(_localeProvider["default"], {
locale: locale || legacyLocale,
_ANT_MARK__: _localeProvider.ANT_MARK
}, childNode);
return /*#__PURE__*/React.createElement(_SizeContext.SizeContextProvider, {
size: componentSize
}, /*#__PURE__*/React.createElement(_context.ConfigContext.Provider, {
value: config
}, childrenWithLocale));
};
return /*#__PURE__*/React.createElement(_LocaleReceiver["default"], null, function (_, __, legacyLocale) {
return /*#__PURE__*/React.createElement(_context.ConfigConsumer, null, function (context) {
return renderProvider(context, legacyLocale);
});
});
};
/** @private internal usage. do not use in your production */
ConfigProvider.ConfigContext = _context.ConfigContext;
var _default = ConfigProvider;
exports["default"] = _default;