1 | import { __rest } from "tslib";
|
2 | import * as React from 'react';
|
3 | import { css } from '@patternfly/react-styles';
|
4 | import styles from '@patternfly/react-styles/css/components/SimpleList/simple-list';
|
5 | import { SimpleListContext } from './SimpleList';
|
6 | export class SimpleListItem extends React.Component {
|
7 | constructor() {
|
8 | super(...arguments);
|
9 | this.ref = React.createRef();
|
10 | }
|
11 | render() {
|
12 | const _a = this.props, { children, isCurrent, isActive, className, component: Component, componentClassName, componentProps, onClick, type, href,
|
13 |
|
14 | itemId } = _a, props = __rest(_a, ["children", "isCurrent", "isActive", "className", "component", "componentClassName", "componentProps", "onClick", "type", "href", "itemId"]);
|
15 | return (React.createElement(SimpleListContext.Consumer, null, ({ currentRef, updateCurrentRef, isControlled }) => {
|
16 | const isButton = Component === 'button';
|
17 | const isCurrentItem = this.ref && currentRef && isControlled ? currentRef.current === this.ref.current : isActive || isCurrent;
|
18 | const additionalComponentProps = isButton
|
19 | ? {
|
20 | type
|
21 | }
|
22 | : {
|
23 | tabIndex: 0,
|
24 | href
|
25 | };
|
26 | return (React.createElement("li", Object.assign({ className: css(className) }, props),
|
27 | React.createElement(Component, Object.assign({ className: css(styles.simpleListItemLink, isCurrentItem && styles.modifiers.current, componentClassName), onClick: (evt) => {
|
28 | onClick(evt);
|
29 | updateCurrentRef(this.ref, this.props);
|
30 | }, ref: this.ref }, componentProps, additionalComponentProps), children)));
|
31 | }));
|
32 | }
|
33 | }
|
34 | SimpleListItem.displayName = 'SimpleListItem';
|
35 | SimpleListItem.defaultProps = {
|
36 | children: null,
|
37 | className: '',
|
38 | isActive: false,
|
39 | isCurrent: false,
|
40 | component: 'button',
|
41 | componentClassName: '',
|
42 | type: 'button',
|
43 | href: '',
|
44 | onClick: () => { }
|
45 | };
|
46 |
|
\ | No newline at end of file |