summaryrefslogtreecommitdiff
path: root/animism-align/frontend/app/views/viewer/checklist/checklist.dropdown.js
blob: 58695e03fdc4d8d87a929d8802a880d01775cbf5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import React, { Component } from 'react'
import { connect } from 'react-redux'

import actions from 'app/actions'
import { ROMAN_NUMERALS } from 'app/constants'
import { Arrow } from '../nav/viewer.icons'

class ChecklistDropdown extends Component {
  state = {
    open: false,
  }
  handleOpen() {
    this.setState({ open: !this.state.open })
  }
  handleSelect(index) {
    this.props.onChange(index)
    this.setState({ open: false })
  }
  render() {
    const { sections, checklistSection } = this.props
    const { open } = this.state
    return (
      <div className="checklist-dropdown-column">
        <div className="checklist-dropdown-container">
          <div className="checklist-dropdown" onClick={() => this.handleOpen()}>
            {checklistSection === 'all' ? 'View All' : 'Section ' + ROMAN_NUMERALS[checklistSection]}
            <div className='arrow-box'>
              <Arrow type={open ? 'up' : 'down'} />
            </div>
          </div>
          <div
            className={open ? "checklist-dropdown-options open" : "checklist-dropdown-options"}
            style={{ height: open ? ((sections.length * 2) + 'rem') : 0 }}
          >
            {sections.map(section => (
              <div key={section.index} onClick={() => this.handleSelect(section.index)}>
                {'Section '}{ROMAN_NUMERALS[section.index]}
              </div>
            ))}
          </div>
        </div>
      </div>
    )
  }
}

const mapStateToProps = state => ({
  sections: state.viewer.sections,
})

export default connect(mapStateToProps)(ChecklistDropdown)