UNPKG

2.47 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.SimpleListItem = void 0;
4const tslib_1 = require("tslib");
5const React = tslib_1.__importStar(require("react"));
6const react_styles_1 = require("@patternfly/react-styles");
7const simple_list_1 = tslib_1.__importDefault(require("@patternfly/react-styles/css/components/SimpleList/simple-list"));
8const SimpleList_1 = require("./SimpleList");
9class SimpleListItem extends React.Component {
10 constructor() {
11 super(...arguments);
12 this.ref = React.createRef();
13 }
14 render() {
15 const _a = this.props, { children, isCurrent, isActive, className, component: Component, componentClassName, componentProps, onClick, type, href,
16 // eslint-disable-next-line @typescript-eslint/no-unused-vars
17 itemId } = _a, props = tslib_1.__rest(_a, ["children", "isCurrent", "isActive", "className", "component", "componentClassName", "componentProps", "onClick", "type", "href", "itemId"]);
18 return (React.createElement(SimpleList_1.SimpleListContext.Consumer, null, ({ currentRef, updateCurrentRef, isControlled }) => {
19 const isButton = Component === 'button';
20 const isCurrentItem = this.ref && currentRef && isControlled ? currentRef.current === this.ref.current : isActive || isCurrent;
21 const additionalComponentProps = isButton
22 ? {
23 type
24 }
25 : {
26 tabIndex: 0,
27 href
28 };
29 return (React.createElement("li", Object.assign({ className: react_styles_1.css(className) }, props),
30 React.createElement(Component, Object.assign({ className: react_styles_1.css(simple_list_1.default.simpleListItemLink, isCurrentItem && simple_list_1.default.modifiers.current, componentClassName), onClick: (evt) => {
31 onClick(evt);
32 updateCurrentRef(this.ref, this.props);
33 }, ref: this.ref }, componentProps, additionalComponentProps), children)));
34 }));
35 }
36}
37exports.SimpleListItem = SimpleListItem;
38SimpleListItem.displayName = 'SimpleListItem';
39SimpleListItem.defaultProps = {
40 children: null,
41 className: '',
42 isActive: false,
43 isCurrent: false,
44 component: 'button',
45 componentClassName: '',
46 type: 'button',
47 href: '',
48 onClick: () => { }
49};
50//# sourceMappingURL=SimpleListItem.js.map
\No newline at end of file