import { Component, createRef } from 'react'; import { WithTreeInjectedProps } from '../Gesture/withTreeGesture'; type TreeItemType = { id: string; isOpened: boolean; name: string; children?: TreeItemType[]; }; type TreeItemProps = Pick & { children: any; item: TreeItemType; level: number; posinset: number; }; class TreeItem extends Component { ref = createRef(); render() { return ( // eslint-disable-next-line jsx-a11y/no-static-element-interactions
  • { if (this.ref.current) { this.props.onKeyDown(e, this.ref.current, this.props.item); } }} ref={this.ref} aria-level={this.props.level} aria-posinset={this.props.posinset} > {this.props.item.name} {this.props.item.isOpened ? this.props.children : null}
  • ); } } type TreeProps = Pick & { items: TreeItemType[]; level: number; }; function Tree(props: TreeProps) { return (
      {props.items.map((item, index) => ( {item.children && ( )} ))}
    ); } Tree.displayName = 'Tree'; Tree.defaultProps = { items: [], level: 0, }; export default Tree;