1
1
import * as React from 'react' ;
2
- import DisplayName from '../helpers/DisplayName' ;
3
2
import { DivAttributes } from '../helpers/types' ;
4
3
import { assertValidHtmlId , nextUuid } from '../helpers/uuid' ;
5
4
import {
@@ -10,24 +9,20 @@ import {
10
9
} from './ItemContext' ;
11
10
12
11
type Props = DivAttributes & {
12
+ className ?: string ;
13
13
uuid ?: UUID ;
14
14
activeClassName ?: string ;
15
15
dangerouslySetExpanded ?: boolean ;
16
16
} ;
17
17
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 => {
31
26
const { expanded } = itemContext ;
32
27
const cx = expanded && activeClassName ? activeClassName : className ;
33
28
@@ -40,24 +35,18 @@ export default class AccordionItem extends React.Component<Props> {
40
35
) ;
41
36
} ;
42
37
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
+ }
49
41
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
+ } ;
53
51
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