-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathSelectedOption.js
More file actions
44 lines (43 loc) · 1.12 KB
/
SelectedOption.js
File metadata and controls
44 lines (43 loc) · 1.12 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
import React, { isValidElement, cloneElement } from 'react';
export default function SelectedOption(props) {
let {
option,
optionLabelPath,
selectedOptionComponent,
showOptionClose,
onCloseClick,
select,
} = props;
let value = null;
let SelectedOptionComponent = selectedOptionComponent;
if (isValidElement(SelectedOptionComponent)) {
return cloneElement(SelectedOptionComponent, props);
}
if (SelectedOptionComponent) {
return <SelectedOptionComponent {...props} />;
}
if (typeof option === 'object') {
if (optionLabelPath) {
value = option[optionLabelPath];
}
}
if (typeof option === 'string') {
value = option;
}
return (
<li className="PowerSelectMultiple__SelectedOption">
<span className="PowerSelectMultiple__SelectedOption__Label">{value}</span>
{showOptionClose ? (
<span
className="PowerSelectMultiple__SelectedOption__Close"
onClick={event => {
event.stopPropagation();
onCloseClick({ option, select });
}}
>
×
</span>
) : null}
</li>
);
}