-
Notifications
You must be signed in to change notification settings - Fork 0
/
Accordion.js
53 lines (49 loc) · 1.44 KB
/
Accordion.js
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
52
53
import React from 'react'
import ChevronDown from 'react-feather/dist/icons/chevron-down'
import _kebabCase from 'lodash/kebabCase'
import './Accordion.css'
export default class Accordion extends React.Component {
static defaultProps = {
items: [],
className: ''
}
// use state to auto close but has issues mobile view. onClick={() => this.handleClick(index)}
// state = {
// activeItem: null
// }
//
// handleClick = index => {
// this.setState({
// activeItem: this.state.activeItem === index ? null : index
// })
// }
handleClick = event => event.target.classList.toggle('active')
render() {
const { items, className } = this.props
return (
<div className={`Accordion ${className}`}>
{!!items &&
items.map((item, index) => (
<div
className={`Accordion--item `}
key={`accordion-item-${_kebabCase(item.title) + '-' + index}`}
onClick={this.handleClick}
>
<h2 className="flex">
<span>{item.title}</span>
<ChevronDown />
</h2>
<div className={'description'}>
{item.description} <br />
{item.link && (
<div href={item.link} className="button">
{item.linkTitle}
</div>
)}
</div>
</div>
))}
</div>
)
}
}