UNPKG

1.75 kBJavaScriptView Raw
1import { __rest } from "tslib";
2import * as React from 'react';
3import { css } from '@patternfly/react-styles';
4import styles from '@patternfly/react-styles/css/components/SimpleList/simple-list';
5import { SimpleListGroup } from './SimpleListGroup';
6export const SimpleListContext = React.createContext({});
7export class SimpleList extends React.Component {
8 constructor() {
9 super(...arguments);
10 this.state = {
11 currentRef: null
12 };
13 this.handleCurrentUpdate = (newCurrentRef, itemProps) => {
14 this.setState({ currentRef: newCurrentRef });
15 const { onSelect } = this.props;
16 onSelect && onSelect(newCurrentRef, itemProps);
17 };
18 }
19 render() {
20 // eslint-disable-next-line @typescript-eslint/no-unused-vars
21 const _a = this.props, { children, className, onSelect, isControlled } = _a, props = __rest(_a, ["children", "className", "onSelect", "isControlled"]);
22 let isGrouped = false;
23 if (children) {
24 isGrouped = React.Children.toArray(children)[0].type === SimpleListGroup;
25 }
26 return (React.createElement(SimpleListContext.Provider, { value: {
27 currentRef: this.state.currentRef,
28 updateCurrentRef: this.handleCurrentUpdate,
29 isControlled
30 } },
31 React.createElement("div", Object.assign({ className: css(styles.simpleList, className) }, props),
32 isGrouped && children,
33 !isGrouped && React.createElement("ul", null, children))));
34 }
35}
36SimpleList.displayName = 'SimpleList';
37SimpleList.defaultProps = {
38 children: null,
39 className: '',
40 isControlled: true
41};
42//# sourceMappingURL=SimpleList.js.map
\No newline at end of file