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 { SimpleListGroup } from './SimpleListGroup';
|
6 | export const SimpleListContext = React.createContext({});
|
7 | export 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 |
|
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 | }
|
36 | SimpleList.displayName = 'SimpleList';
|
37 | SimpleList.defaultProps = {
|
38 | children: null,
|
39 | className: '',
|
40 | isControlled: true
|
41 | };
|
42 |
|
\ | No newline at end of file |