1
1
import * as React from 'react' ;
2
+ import DisplayName from '../helpers/DisplayName' ;
2
3
import { DivAttributes } from '../helpers/types' ;
3
4
import { assertValidHtmlId , nextUuid } from '../helpers/uuid' ;
4
5
import {
@@ -9,23 +10,35 @@ import {
9
10
} from './ItemContext' ;
10
11
11
12
type Props = DivAttributes & {
12
- className ?: string ;
13
13
uuid ?: UUID ;
14
14
activeClassName ?: string ;
15
15
dangerouslySetExpanded ?: boolean ;
16
16
} ;
17
17
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 ;
26
37
const { expanded } = itemContext ;
27
38
const cx = expanded && activeClassName ? activeClassName : className ;
28
39
40
+ console . log ( { rest } ) ;
41
+
29
42
return (
30
43
< div
31
44
data-accordion-component = "AccordionItem"
@@ -35,18 +48,26 @@ const AccordionItem = ({
35
48
) ;
36
49
} ;
37
50
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 ;
41
57
42
- return (
43
- < ItemProvider
44
- uuid = { uuid }
45
- dangerouslySetExpanded = { dangerouslySetExpanded }
46
- >
47
- < ItemConsumer > { renderChildren } </ ItemConsumer >
48
- </ ItemProvider >
49
- ) ;
50
- } ;
58
+ assertValidHtmlId ( uuid ) ;
51
59
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