UNPKG

3.48 kBJavaScriptView Raw
1'use strict';
2
3exports.__esModule = true;
4
5var _extends2 = require('babel-runtime/helpers/extends');
6
7var _extends3 = _interopRequireDefault(_extends2);
8
9exports.default = getContextProps;
10
11var _zhCn = require('../locale/zh-cn.js');
12
13var _zhCn2 = _interopRequireDefault(_zhCn);
14
15var _util = require('../util');
16
17function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
19/**
20 *
21 * @param {Object|Boolean} input
22 * @returns {Object} typeof obj.open === 'boolean'
23 */
24var parseBoundary = function parseBoundary(input) {
25 var obj = void 0;
26 if (input === undefined || input === null) {
27 return {};
28 } else if (typeof input === 'boolean') {
29 obj = { open: input };
30 } else {
31 obj = (0, _extends3.default)({ open: true }, input);
32 }
33
34 return obj;
35};
36
37function getContextProps(props, context, displayName) {
38 var prefix = props.prefix,
39 locale = props.locale,
40 defaultPropsConfig = props.defaultPropsConfig,
41 pure = props.pure,
42 rtl = props.rtl,
43 device = props.device,
44 popupContainer = props.popupContainer,
45 errorBoundary = props.errorBoundary;
46 var nextPrefix = context.nextPrefix,
47 nextLocale = context.nextLocale,
48 nextDefaultPropsConfig = context.nextDefaultPropsConfig,
49 nextPure = context.nextPure,
50 nextWarning = context.nextWarning,
51 nextRtl = context.nextRtl,
52 nextDevice = context.nextDevice,
53 nextPopupContainer = context.nextPopupContainer,
54 nextErrorBoundary = context.nextErrorBoundary;
55
56
57 var newPrefix = prefix || nextPrefix;
58
59 var localeFromContext = void 0;
60 var newDisplayName = displayName;
61
62 switch (displayName) {
63 case 'DatePicker2':
64 newDisplayName = 'DatePicker';
65 break;
66 case 'Calendar2':
67 newDisplayName = 'Calendar';
68 break;
69 case 'TimePicker2':
70 newDisplayName = 'TimePicker';
71 break;
72 default:
73 break;
74 }
75
76 if (nextLocale) {
77 localeFromContext = nextLocale[newDisplayName];
78 if (localeFromContext) {
79 localeFromContext.momentLocale = nextLocale.momentLocale;
80 }
81 }
82
83 var newLocale = void 0;
84 if (locale) {
85 newLocale = _util.obj.deepMerge({}, _zhCn2.default[newDisplayName], localeFromContext, locale);
86 } else if (localeFromContext) {
87 newLocale = _util.obj.deepMerge({}, _zhCn2.default[newDisplayName], localeFromContext);
88 }
89
90 var newPure = typeof pure === 'boolean' ? pure : nextPure;
91 var newRtl = typeof rtl === 'boolean' ? rtl : nextRtl;
92
93 // ProtoType of [nextE|e]rrorBoundary can be one of [boolean, object]
94 // but typeof newErrorBoundary === 'object'
95 // newErrorBoundary should always have the key 'open', which indicates ErrorBoundary on or off
96 var newErrorBoundary = (0, _extends3.default)({}, parseBoundary(nextErrorBoundary), parseBoundary(errorBoundary));
97
98 if (!('open' in newErrorBoundary)) {
99 newErrorBoundary.open = false;
100 }
101
102 return {
103 prefix: newPrefix,
104 locale: newLocale,
105 pure: newPure,
106 rtl: newRtl,
107 warning: nextWarning,
108 defaultPropsConfig: nextDefaultPropsConfig || {},
109 device: device || nextDevice || undefined,
110 popupContainer: popupContainer || nextPopupContainer,
111 errorBoundary: newErrorBoundary
112 };
113}
114module.exports = exports['default'];
\No newline at end of file