forked from alibaba-fusion/next
-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-context-props.jsx
94 lines (83 loc) · 2.6 KB
/
get-context-props.jsx
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
import zhCN from '../locale/zh-cn.js';
import { obj } from '../util';
/**
*
* @param {Object|Boolean} input
* @returns {Object} typeof obj.open === 'boolean'
*/
const parseBoundary = input => {
let obj;
if (input === undefined || input === null) {
return {};
} else if (typeof input === 'boolean') {
obj = { open: input };
} else {
obj = { open: true, ...input };
}
return obj;
};
export default function getContextProps(props, context, displayName) {
const { prefix, locale, defaultPropsConfig, pure, rtl, device, popupContainer, errorBoundary } = props;
const {
nextPrefix,
nextLocale,
nextDefaultPropsConfig,
nextPure,
nextWarning,
nextRtl,
nextDevice,
nextPopupContainer,
nextErrorBoundary,
} = context;
const newPrefix = prefix || nextPrefix;
let localeFromContext;
let newDisplayName = displayName;
switch (displayName) {
case 'DatePicker2':
newDisplayName = 'DatePicker';
break;
case 'Calendar2':
newDisplayName = 'Calendar';
break;
case 'TimePicker2':
newDisplayName = 'TimePicker';
break;
default:
break;
}
if (nextLocale) {
localeFromContext = nextLocale[newDisplayName];
if (localeFromContext) {
localeFromContext.momentLocale = nextLocale.momentLocale;
}
}
let newLocale;
if (locale) {
newLocale = obj.deepMerge({}, zhCN[newDisplayName], localeFromContext, locale);
} else if (localeFromContext) {
newLocale = obj.deepMerge({}, zhCN[newDisplayName], localeFromContext);
}
const newPure = typeof pure === 'boolean' ? pure : nextPure;
const newRtl = typeof rtl === 'boolean' ? rtl : nextRtl;
// ProtoType of [nextE|e]rrorBoundary can be one of [boolean, object]
// but typeof newErrorBoundary === 'object'
// newErrorBoundary should always have the key 'open', which indicates ErrorBoundary on or off
const newErrorBoundary = {
...parseBoundary(nextErrorBoundary),
...parseBoundary(errorBoundary),
};
if (!('open' in newErrorBoundary)) {
newErrorBoundary.open = false;
}
return {
prefix: newPrefix,
locale: newLocale,
pure: newPure,
rtl: newRtl,
warning: nextWarning,
defaultPropsConfig: nextDefaultPropsConfig || {},
device: device || nextDevice || undefined,
popupContainer: popupContainer || nextPopupContainer,
errorBoundary: newErrorBoundary,
};
}