11import * as React from 'react' ;
2+ import DisplayName from '../helpers/DisplayName' ;
23import { DivAttributes } from '../helpers/types' ;
34import { assertValidHtmlId , nextUuid } from '../helpers/uuid' ;
45import {
@@ -9,23 +10,35 @@ import {
910} from './ItemContext' ;
1011
1112type Props = DivAttributes & {
12- className ?: string ;
1313 uuid ?: UUID ;
1414 activeClassName ?: string ;
1515 dangerouslySetExpanded ?: boolean ;
1616} ;
1717
18- const AccordionItem = ( {
19- uuid = nextUuid ( ) ,
20- className = 'accordion__item' ,
21- activeClassName,
22- dangerouslySetExpanded,
23- ...rest
24- } : Props ) : JSX . Element => {
25- const renderChildren = ( itemContext : ItemContext ) : JSX . Element => {
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 {
31+ uuid,
32+ className,
33+ activeClassName,
34+ dangerouslySetExpanded,
35+ ...rest
36+ } = this . props ;
2637 const { expanded } = itemContext ;
2738 const cx = expanded && activeClassName ? activeClassName : className ;
2839
40+ console . log ( { rest } ) ;
41+
2942 return (
3043 < div
3144 data-accordion-component = "AccordionItem"
@@ -35,18 +48,26 @@ const AccordionItem = ({
3548 ) ;
3649 } ;
3750
38- if ( rest . id ) {
39- assertValidHtmlId ( rest . id ) ;
40- }
51+ render ( ) : JSX . Element {
52+ const {
53+ uuid = this . instanceUuid ,
54+ dangerouslySetExpanded,
55+ ...rest
56+ } = this . props ;
4157
42- return (
43- < ItemProvider
44- uuid = { uuid }
45- dangerouslySetExpanded = { dangerouslySetExpanded }
46- >
47- < ItemConsumer > { renderChildren } </ ItemConsumer >
48- </ ItemProvider >
49- ) ;
50- } ;
58+ assertValidHtmlId ( uuid ) ;
5159
52- export default AccordionItem ;
60+ if ( rest . id ) {
61+ assertValidHtmlId ( rest . id ) ;
62+ }
63+ `` ;
64+ return (
65+ < ItemProvider
66+ uuid = { uuid }
67+ dangerouslySetExpanded = { dangerouslySetExpanded }
68+ >
69+ < ItemConsumer > { this . renderChildren } </ ItemConsumer >
70+ </ ItemProvider >
71+ ) ;
72+ }
73+ }
0 commit comments