Guest User

Untitled

a guest
Feb 18th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.81 KB | None | 0 0
  1. export const data = [
  2. {
  3. id: 1,
  4. icon: <FontAwesomeIcon className='i' icon={faHeartbeat} />,
  5. title: 'SAFETY',
  6. children: [
  7. {title: 'Reporting', children: [
  8. {id: 11, title: 'I-21 Injury Reporting', url: '/safety/report'},
  9. {id: 12, title: 'ASAP Reporting', url: '/safety/asap-report'},
  10. {id: 13, title: 'General ASAP Information', url: '/safety/general'},
  11. {id: 14, title: 'Flight Attendant Incident Report', url: '/safety/flight-attendant-incident'},
  12. ]},
  13. {title: 'Agriculture and Customs', children: [
  14. {id: 15, title: 'Product Safety Data Search', url: '/safety/data-search'}]},
  15. {id: 16, title: 'Known Crewmember', url: '/safety/known-cremember'},
  16. {id: 17, title: 'Product Safety Data Search', url: '/safety/data-search'},
  17. ],
  18. },
  19. ]
  20.  
  21. class NestedNav extends Component {
  22. constructor(props) {
  23. super(props)
  24. this.state = {
  25. selected: '',
  26. nestSelect: '',
  27. children: [],
  28. active: '',
  29. }
  30. }
  31.  
  32. handleClick = (title) => {
  33. this.setState({
  34. selected: '',
  35. nestSelect: '',
  36. children: [],
  37. active: '',
  38. })
  39. }
  40.  
  41. render() {
  42.  
  43. const {data, parentClass, nestedParentClass} = this.props
  44. const renderedChildElements = this.state.children
  45. const active = this.state.active === 'true' ? 'true' : ''
  46.  
  47. const mappedChildren = (child, title) => {
  48. let childElement
  49. if(child) {
  50. childElement = child.map((child, i) => <li
  51. key={i}
  52. id={child.id}
  53. className={nestedParentClass + (this.state.nestSelect === child.title ? 'nest-selected' : '')}
  54. url={child.url}><Link to={'/'}>{child.title}</Link>
  55. {child.children ?
  56. <FontAwesomeIcon
  57. onClick={() => mappedChildren(child.children, this.state.select)}
  58. className='i button'
  59. icon={faArrowCircleDown} /> : null}
  60. </li>)
  61. this.setState({
  62. selected: title,
  63. children: childElement,
  64. active: 'true',
  65. })
  66. }
  67. return ''
  68. }
  69.  
  70. const navListItems = data.map((collection, i) => <li
  71. key={i}
  72. id={collection.id}
  73. className={parentClass + (this.state.selected === collection.title ? 'selected' : '')}
  74. url={collection.url}><i onClick={this.handleClick}>{collection.icon}</i><Link to={'/'}><span>{collection.title}</span></Link>
  75. {collection.children ?
  76. <FontAwesomeIcon
  77. onClick={() => mappedChildren(collection.children, collection.title)}
  78. className='i button'
  79. icon={faArrowCircleRight} /> : null}
  80. </li>)
  81.  
  82. return (
  83. <div className={'nested-nav'}>
  84. <div className={'container-two-' + active}>
  85. <h2>{this.state.selected}</h2>
  86. {this.state.children}
  87. </div>
  88. <div className='container-one'>{navListItems}</div>
  89. </div>
  90. )
  91. }
  92. }
  93. export default NestedNav
Add Comment
Please, Sign In to add comment