-
Notifications
You must be signed in to change notification settings - Fork 196
/
Copy pathwarningPropsUtil.ts
51 lines (44 loc) · 1.56 KB
/
warningPropsUtil.ts
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
import warning from '@rc-component/util/lib/warning';
import type { TreeSelectProps } from '../TreeSelect';
import { toArray } from './valueUtil';
function warningProps(props: TreeSelectProps & { searchPlaceholder?: string }) {
const {
searchPlaceholder,
treeCheckStrictly,
treeCheckable,
labelInValue,
value,
multiple,
showCheckedStrategy,
maxCount,
} = props;
warning(!searchPlaceholder, '`searchPlaceholder` has been removed.');
if (treeCheckStrictly && labelInValue === false) {
warning(false, '`treeCheckStrictly` will force set `labelInValue` to `true`.');
}
if (labelInValue || treeCheckStrictly) {
warning(
toArray(value).every(val => val && typeof val === 'object' && 'value' in val),
'Invalid prop `value` supplied to `TreeSelect`. You should use { label: string, value: string | number } or [{ label: string, value: string | number }] instead.',
);
}
if (treeCheckStrictly || multiple || treeCheckable) {
warning(
!value || Array.isArray(value),
'`value` should be an array when `TreeSelect` is checkable or multiple.',
);
} else {
warning(!Array.isArray(value), '`value` should not be array when `TreeSelect` is single mode.');
}
if (
maxCount &&
((showCheckedStrategy === 'SHOW_ALL' && !treeCheckStrictly) ||
showCheckedStrategy === 'SHOW_PARENT')
) {
warning(
false,
'`maxCount` not work with `showCheckedStrategy=SHOW_ALL` (when `treeCheckStrictly=false`) or `showCheckedStrategy=SHOW_PARENT`.',
);
}
}
export default warningProps;