UNPKG

1.9 kBJavaScriptView Raw
1import { __rest } from "tslib";
2import * as React from 'react';
3import styles from '@patternfly/react-styles/css/components/ContextSelector/context-selector';
4import { css } from '@patternfly/react-styles';
5import { ContextSelectorContext } from './contextSelectorConstants';
6export class ContextSelectorItem extends React.Component {
7 constructor() {
8 super(...arguments);
9 this.ref = React.createRef();
10 }
11 componentDidMount() {
12 /* eslint-disable-next-line */
13 this.props.sendRef(this.props.index, this.ref.current);
14 }
15 render() {
16 // eslint-disable-next-line @typescript-eslint/no-unused-vars
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}
29ContextSelectorItem.displayName = 'ContextSelectorItem';
30ContextSelectorItem.defaultProps = {
31 children: null,
32 className: '',
33 isDisabled: false,
34 onClick: () => undefined,
35 index: undefined,
36 sendRef: () => { },
37 href: null
38};
39//# sourceMappingURL=ContextSelectorItem.js.map
\No newline at end of file