1 | import { __rest } from "tslib";
|
2 | import * as React from 'react';
|
3 | import styles from '@patternfly/react-styles/css/components/ContextSelector/context-selector';
|
4 | import { css } from '@patternfly/react-styles';
|
5 | import { ContextSelectorContext } from './contextSelectorConstants';
|
6 | export class ContextSelectorItem extends React.Component {
|
7 | constructor() {
|
8 | super(...arguments);
|
9 | this.ref = React.createRef();
|
10 | }
|
11 | componentDidMount() {
|
12 |
|
13 | this.props.sendRef(this.props.index, this.ref.current);
|
14 | }
|
15 | render() {
|
16 |
|
17 | const _a = this.props, { className, children, onClick, isDisabled, index, sendRef, href } = _a, props = __rest(_a, ["className", "children", "onClick", "isDisabled", "index", "sendRef", "href"]);
|
18 | const Component = href ? 'a' : 'button';
|
19 | const isDisabledLink = href && isDisabled;
|
20 | return (React.createElement(ContextSelectorContext.Consumer, null, ({ onSelect }) => (React.createElement("li", { role: "none" },
|
21 | React.createElement(Component, Object.assign({ className: css(styles.contextSelectorMenuListItem, isDisabledLink && styles.modifiers.disabled, className), ref: this.ref, onClick: event => {
|
22 | if (!isDisabled) {
|
23 | onClick(event);
|
24 | onSelect(event, children);
|
25 | }
|
26 | }, disabled: isDisabled && !href, href: href }, (isDisabledLink && { 'aria-disabled': true, tabIndex: -1 }), props), children)))));
|
27 | }
|
28 | }
|
29 | ContextSelectorItem.displayName = 'ContextSelectorItem';
|
30 | ContextSelectorItem.defaultProps = {
|
31 | children: null,
|
32 | className: '',
|
33 | isDisabled: false,
|
34 | onClick: () => undefined,
|
35 | index: undefined,
|
36 | sendRef: () => { },
|
37 | href: null
|
38 | };
|
39 |
|
\ | No newline at end of file |