-
Notifications
You must be signed in to change notification settings - Fork 37
/
SelectOption.js
45 lines (39 loc) · 1.14 KB
/
SelectOption.js
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
import React, { forwardRef } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import css from './MultiSelect.css';
const SelectOption = forwardRef((props, ref) => {
function getClassName() {
return classnames(
css.multiSelectOption,
{ [`${css.optionCursor}`]: props.isActive },
{ [`${css.optionSelected}`]: props.isSelected },
{ [`${css.optionDisabled}`]: props.isDisabled },
);
}
const {
children,
isSelected,
isActive, // eslint-disable-line
isDisabled, // eslint-disable-line
optionItem, // eslint-disable-line
...rest
} = props;
if (React.Children.count(children) !== 0) {
return (
<li role="option" ref={ref} key={props.id} className={getClassName()} {...rest} aria-selected={isSelected}>
{children}
<div>{isSelected ? '-' : '+'}</div>
</li>
);
}
return null;
});
SelectOption.propTypes = {
children: PropTypes.node,
id: PropTypes.string,
isActive: PropTypes.bool,
isDisabled: PropTypes.bool,
isSelected: PropTypes.bool,
};
export default SelectOption;