11import * as React from 'react' ;
2- import DisplayName from '../helpers/DisplayName' ;
32import { DivAttributes } from '../helpers/types' ;
43import { assertValidHtmlId , nextUuid } from '../helpers/uuid' ;
54import {
@@ -10,24 +9,20 @@ import {
109} from './ItemContext' ;
1110
1211type Props = DivAttributes & {
12+ className ?: string ;
1313 uuid ?: UUID ;
1414 activeClassName ?: string ;
1515 dangerouslySetExpanded ?: boolean ;
1616} ;
1717
18- const defaultProps = {
19- className : 'accordion__item' ,
20- } ;
21-
22- export default class AccordionItem extends React . Component < Props > {
23- static defaultProps : typeof defaultProps = defaultProps ;
24-
25- static displayName : DisplayName . AccordionItem = DisplayName . AccordionItem ;
26-
27- instanceUuid : UUID = nextUuid ( ) ;
28-
29- renderChildren = ( itemContext : ItemContext ) : JSX . Element => {
30- const { uuid, className, activeClassName, ...rest } = this . props ;
18+ const AccordionItem = ( {
19+ uuid = nextUuid ( ) ,
20+ className = 'accordion__item' ,
21+ activeClassName,
22+ dangerouslySetExpanded,
23+ ...rest
24+ } : Props ) => {
25+ const renderChildren = ( itemContext : ItemContext ) : JSX . Element => {
3126 const { expanded } = itemContext ;
3227 const cx = expanded && activeClassName ? activeClassName : className ;
3328
@@ -40,24 +35,18 @@ export default class AccordionItem extends React.Component<Props> {
4035 ) ;
4136 } ;
4237
43- render ( ) : JSX . Element {
44- const {
45- uuid = this . instanceUuid ,
46- dangerouslySetExpanded,
47- ...rest
48- } = this . props ;
38+ if ( rest . id ) {
39+ assertValidHtmlId ( rest . id ) ;
40+ }
4941
50- if ( rest . id ) {
51- assertValidHtmlId ( rest . id ) ;
52- }
42+ return (
43+ < ItemProvider
44+ uuid = { uuid }
45+ dangerouslySetExpanded = { dangerouslySetExpanded }
46+ >
47+ < ItemConsumer > { renderChildren } </ ItemConsumer >
48+ </ ItemProvider >
49+ ) ;
50+ } ;
5351
54- return (
55- < ItemProvider
56- uuid = { uuid }
57- dangerouslySetExpanded = { dangerouslySetExpanded }
58- >
59- < ItemConsumer > { this . renderChildren } </ ItemConsumer >
60- </ ItemProvider >
61- ) ;
62- }
63- }
52+ export default AccordionItem ;
0 commit comments