@itwin/core-react
Version:
A react component library of iTwin.js UI general purpose components
58 lines • 2.58 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
* @module Expandable
*/
import classnames from "classnames";
import * as React from "react";
/** ExpandableList React component is a container for ExpandableBlock components.
* @public
* @deprecated in 4.12.0. Use a custom container and manage {@link https://itwinui.bentley.com/docs/expandableblock expandable block} state manually.
*/
export class ExpandableList extends React.PureComponent {
// eslint-disable-next-line @typescript-eslint/no-deprecated
constructor(props) {
super(props);
// set active block
this._handleBlockToggle = (index, onToggle) => {
let activeBlock = index;
if (this.props.singleIsCollapsible && index === this.state.activeBlock)
activeBlock = -1;
this.setState({ activeBlock });
if (onToggle) {
onToggle(activeBlock === index); // fire the ExpandableBlock onToggle
}
};
this.state = { activeBlock: this.props.defaultActiveBlock };
}
renderBlocks() {
return React.Children.map(this.props.children, (child, i) => {
return React.cloneElement(child, {
key: i,
isExpanded: this.props.singleExpandOnly
? i === this.state.activeBlock
: child.props.isExpanded,
onToggle: this._handleBlockToggle.bind(this, i, child.props.onToggle),
});
});
}
/** @internal */
// eslint-disable-next-line @typescript-eslint/no-deprecated
componentDidUpdate(prevProps) {
if (this.props.defaultActiveBlock !== prevProps.defaultActiveBlock &&
this.props.defaultActiveBlock !== this.state.activeBlock) {
this.setState((_, props) => ({ activeBlock: props.defaultActiveBlock }));
}
}
render() {
return (React.createElement("div", { className: classnames("uicore-expandable-blocks-list", this.props.className), style: this.props.style }, this.renderBlocks()));
}
}
// eslint-disable-next-line @typescript-eslint/no-deprecated
ExpandableList.defaultProps = {
singleExpandOnly: false,
defaultActiveBlock: 0,
};
//# sourceMappingURL=ExpandableList.js.map