-
Notifications
You must be signed in to change notification settings - Fork 4k
Expand file tree
/
Copy pathAccordionPanel.js
More file actions
63 lines (52 loc) · 1.62 KB
/
AccordionPanel.js
File metadata and controls
63 lines (52 loc) · 1.62 KB
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
54
55
56
57
58
59
60
61
62
63
import _ from 'lodash'
import PropTypes from 'prop-types'
import React, { Component } from 'react'
import { createShorthandFactory, customPropTypes } from '../../lib'
import AccordionTitle from './AccordionTitle'
import AccordionContent from './AccordionContent'
/**
* A panel sub-component for Accordion component.
*/
class AccordionPanel extends Component {
handleTitleOverrides = (predefinedProps) => ({
onClick: (e, titleProps) => {
predefinedProps.onClick?.(e, titleProps)
this.props.onTitleClick?.(e, titleProps)
},
})
render() {
const { active, content, index, title } = this.props
return (
<>
{AccordionTitle.create(title, {
autoGenerateKey: false,
defaultProps: { active, index },
overrideProps: this.handleTitleOverrides,
})}
{AccordionContent.create(content, {
autoGenerateKey: false,
defaultProps: { active },
})}
</>
)
}
}
AccordionPanel.propTypes = {
/** Whether or not the title is in the open state. */
active: PropTypes.bool,
/** A shorthand for Accordion.Content. */
content: customPropTypes.itemShorthand,
/** A panel index. */
index: PropTypes.oneOfType([PropTypes.number, PropTypes.string]),
/**
* Called when a panel title is clicked.
*
* @param {SyntheticEvent} event - React's original SyntheticEvent.
* @param {object} data - All item props.
*/
onTitleClick: PropTypes.func,
/** A shorthand for Accordion.Title. */
title: customPropTypes.itemShorthand,
}
AccordionPanel.create = createShorthandFactory(AccordionPanel, null)
export default AccordionPanel