UNPKG

1.56 kBJavaScriptView Raw
1import React, {Component, PureComponent} from 'react';
2import PropTypes from 'prop-types';
3import classNames from 'classnames';
4
5import Link, {linkHOC} from '../link/link';
6import dataTests from '../global/data-tests';
7
8import styles from './list.css';
9
10/**
11 * @constructor
12 * @extends {ReactComponent}
13 */
14export default class ListLink extends PureComponent {
15 static propTypes = {
16 ...Link.propTypes,
17 description: PropTypes.string,
18 label: PropTypes.oneOfType([
19 PropTypes.element,
20 PropTypes.string
21 ]),
22 rgItemType: PropTypes.number,
23 scrolling: PropTypes.bool,
24 url: PropTypes.string,
25 LinkComponent: PropTypes.oneOfType([
26 PropTypes.instanceOf(Component),
27 PropTypes.func,
28 PropTypes.string
29 ]),
30 onCheckboxChange: PropTypes.func,
31 compact: PropTypes.bool
32 };
33
34 render() {
35 const {scrolling, 'data-test': dataTest, className, label, hover, description, rgItemType, url, onCheckboxChange, disabled, LinkComponent, compact, ...restProps} = this.props; // eslint-disable-line no-unused-vars, max-len
36 const classes = classNames(styles.item, className, {
37 [styles.actionLink]: !disabled,
38 [styles.compact]: compact,
39 [styles.scrolling]: scrolling
40 });
41
42 const Comp = LinkComponent ? linkHOC(LinkComponent) : Link;
43
44 return (
45 <Comp
46 pseudo={!this.props.href}
47 {...restProps}
48 hover={hover && !disabled}
49 className={classes}
50 data-test={dataTests('ring-list-link', dataTest)}
51 >
52 {label}
53 </Comp>
54 );
55 }
56}