UNPKG

fk-react-ui-components

Version:

Step 1 : Create a file in [ Seeds / Plants / Trees ] <br> Step 2 : It should export an Object with component name and story Component [Refer other components] <br> Step 3 : Story Component should return a react component <br> Step 3 : Created file should

42 lines (37 loc) 1 kB
import React from 'react'; import PropTypes from 'prop-types'; import { Flex } from '../Layout'; export default class Tree extends React.Component { constructor(props) { super(props); this.state = { currentLevel: 0 }; this.setCurrentLevel = this.setCurrentLevel.bind(this); } setCurrentLevel(level) { this.setState({ currentLevel: level }); } render() { let index = 0; const items = React.Children.map(this.props.children, child => { index += 1; return React.cloneElement(child, { level: index, setCurrentLevel: this.setCurrentLevel, currentLevel: this.state.currentLevel }); }); return React.createElement( Flex, { margin: '0px' }, items ); } } Tree.propTypes = { children: PropTypes.node.isRequired }; //# sourceMappingURL=Tree.js.map