UNPKG

1.67 kBJavaScriptView Raw
1import React, {PureComponent} from 'react';
2import PropTypes from 'prop-types';
3import classNames from 'classnames';
4
5import dataTests from '../global/data-tests';
6
7import styles from './list.css';
8
9export default class ListCustom extends PureComponent {
10 static propTypes = {
11 scrolling: PropTypes.bool,
12 hover: PropTypes.bool,
13 className: PropTypes.string,
14 disabled: PropTypes.bool,
15 rgItemType: PropTypes.number,
16 tabIndex: PropTypes.number,
17 template: PropTypes.oneOfType([
18 PropTypes.func,
19 PropTypes.element,
20 PropTypes.string
21 ]),
22 onClick: PropTypes.func,
23 onMouseOver: PropTypes.func,
24 onMouseUp: PropTypes.func,
25 onCheckboxChange: PropTypes.func,
26 'data-test': PropTypes.string
27 };
28
29 static defaultProps = {
30 hover: false
31 };
32
33 render() {
34 const {scrolling, hover, className, disabled, template, rgItemType, tabIndex, onClick, onCheckboxChange, onMouseOver, onMouseUp, ...restProps} = this.props; // eslint-disable-line no-unused-vars, max-len
35 const classes = classNames(styles.item, className, {
36 [styles.action]: !disabled,
37 [styles.hover]: hover && !disabled,
38 [styles.scrolling]: scrolling
39 });
40
41
42 const dataTest = dataTests('ring-list-item-custom', {
43 'ring-list-item-action': !disabled
44 }, restProps['data-test']);
45
46 const content = (typeof template === 'function') ? template(this.props) : template;
47 return (
48 <span
49 tabIndex={tabIndex}
50 onClick={onClick}
51 onMouseOver={onMouseOver}
52 onMouseUp={onMouseUp}
53 className={classes}
54 data-test={dataTest}
55 >
56 {content}
57 </span>
58 );
59 }
60}