Skip to content

Commit 031b896

Browse files
committed
refactor(AccordionItemPanel): move to function
1 parent 5a0b7da commit 031b896

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

src/components/AccordionItemPanel.tsx

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,31 @@
11
import * as React from 'react';
2-
import DisplayName from '../helpers/DisplayName';
32
import { DivAttributes } from '../helpers/types';
43
import { assertValidHtmlId } from '../helpers/uuid';
54
import { Consumer as ItemConsumer, ItemContext } from './ItemContext';
65

7-
type Props = DivAttributes;
6+
type Props = DivAttributes & { className?: string };
87

9-
const defaultProps = {
10-
className: 'accordion__panel',
11-
};
12-
13-
export default class AccordionItemPanel extends React.Component<Props> {
14-
static defaultProps: typeof defaultProps = defaultProps;
15-
16-
static displayName: DisplayName.AccordionItemPanel =
17-
DisplayName.AccordionItemPanel;
18-
19-
renderChildren = ({ panelAttributes }: ItemContext): JSX.Element => {
20-
if (this.props.id) {
21-
assertValidHtmlId(this.props.id);
8+
const AccordionItemPanel = ({
9+
className = 'accordion__panel',
10+
id,
11+
...rest
12+
}: Props) => {
13+
const renderChildren = ({ panelAttributes }: ItemContext): JSX.Element => {
14+
if (id) {
15+
assertValidHtmlId(id);
2216
}
2317

2418
return (
2519
<div
2620
data-accordion-component="AccordionItemPanel"
27-
{...this.props}
21+
className={className}
22+
{...rest}
2823
{...panelAttributes}
2924
/>
3025
);
3126
};
3227

33-
render(): JSX.Element {
34-
return <ItemConsumer>{this.renderChildren}</ItemConsumer>;
35-
}
36-
}
28+
return <ItemConsumer>{renderChildren}</ItemConsumer>;
29+
};
30+
31+
export default AccordionItemPanel;

0 commit comments

Comments
 (0)