/
AccordionBody.tsx
93 lines (85 loc) · 2.47 KB
/
AccordionBody.tsx
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
import classNames from 'classnames';
import * as React from 'react';
import { useContext } from 'react';
import PropTypes from 'prop-types';
import { TransitionCallbacks } from '@restart/ui/types';
import { useBootstrapPrefix } from './ThemeProvider';
import AccordionCollapse from './AccordionCollapse';
import AccordionItemContext from './AccordionItemContext';
import { BsPrefixRefForwardingComponent, BsPrefixProps } from './helpers';
export interface AccordionBodyProps
extends BsPrefixProps,
TransitionCallbacks,
React.HTMLAttributes<HTMLElement> {}
const propTypes = {
/** Set a custom element for this component */
as: PropTypes.elementType,
/** @default 'accordion-body' */
bsPrefix: PropTypes.string,
/**
* Callback fired before the component expands
*/
onEnter: PropTypes.func,
/**
* Callback fired after the component starts to expand
*/
onEntering: PropTypes.func,
/**
* Callback fired after the component has expanded
*/
onEntered: PropTypes.func,
/**
* Callback fired before the component collapses
*/
onExit: PropTypes.func,
/**
* Callback fired after the component starts to collapse
*/
onExiting: PropTypes.func,
/**
* Callback fired after the component has collapsed
*/
onExited: PropTypes.func,
};
const AccordionBody: BsPrefixRefForwardingComponent<'div', AccordionBodyProps> =
React.forwardRef<HTMLElement, AccordionBodyProps>(
(
{
// Need to define the default "as" during prop destructuring to be compatible with styled-components github.com/react-bootstrap/react-bootstrap/issues/3595
as: Component = 'div',
bsPrefix,
className,
onEnter,
onEntering,
onEntered,
onExit,
onExiting,
onExited,
...props
},
ref,
) => {
bsPrefix = useBootstrapPrefix(bsPrefix, 'accordion-body');
const { eventKey } = useContext(AccordionItemContext);
return (
<AccordionCollapse
eventKey={eventKey}
onEnter={onEnter}
onEntering={onEntering}
onEntered={onEntered}
onExit={onExit}
onExiting={onExiting}
onExited={onExited}
>
<Component
ref={ref}
{...props}
className={classNames(className, bsPrefix)}
/>
</AccordionCollapse>
);
},
);
AccordionBody.propTypes = propTypes;
AccordionBody.displayName = 'AccordionBody';
export default AccordionBody;