1 | import invariant from 'invariant';
|
2 | import getStringLabelKey from './getStringLabelKey';
|
3 | import hasOwnProperty from './hasOwnProperty';
|
4 | import { isFunction, isString } from './nodash';
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | function getOptionLabel(option, labelKey) {
|
12 |
|
13 | if (!isString(option) && (hasOwnProperty(option, 'paginationOption') || hasOwnProperty(option, 'customOption'))) {
|
14 | return option[getStringLabelKey(labelKey)];
|
15 | }
|
16 |
|
17 | var optionLabel;
|
18 |
|
19 | if (isFunction(labelKey)) {
|
20 | optionLabel = labelKey(option);
|
21 | } else if (isString(option)) {
|
22 | optionLabel = option;
|
23 | } else {
|
24 |
|
25 | optionLabel = option[labelKey];
|
26 | }
|
27 |
|
28 | !isString(optionLabel) ? process.env.NODE_ENV !== "production" ? invariant(false, 'One or more options does not have a valid label string. Check the ' + '`labelKey` prop to ensure that it matches the correct option key and ' + 'provides a string for filtering and display.') : invariant(false) : void 0;
|
29 | return optionLabel;
|
30 | }
|
31 |
|
32 | export default getOptionLabel; |
\ | No newline at end of file |