@@ -10,94 +10,104 @@ import isItemActive from 'utils/isItemActive';
10
10
import MetaTitle from '../MetaTitle' ;
11
11
import ChevronSvg from '../ChevronSvg' ;
12
12
13
- const Section = ( {
14
- activeItemId,
15
- createLink,
16
- isActive,
17
- isScrollSync,
18
- location,
19
- onLinkClick,
20
- onSectionTitleClick,
21
- section,
22
- } ) => (
23
- < div >
24
- < button
25
- css = { {
26
- cursor : 'pointer' ,
27
- backgroundColor : 'transparent' ,
28
- border : 0 ,
29
- marginTop : 10 ,
30
- } }
31
- onClick = { onSectionTitleClick } >
32
- < MetaTitle
33
- cssProps = { {
34
- [ media . greaterThan ( 'small' ) ] : {
35
- color : isActive ? colors . text : colors . subtle ,
36
-
37
- ':hover' : {
38
- color : colors . text ,
39
- } ,
40
- } ,
41
- } } >
42
- { section . title }
43
- < ChevronSvg
44
- cssProps = { {
45
- marginLeft : 7 ,
46
- transform : isActive ? 'rotateX(180deg)' : 'rotateX(0deg)' ,
47
- transition : 'transform 0.2s ease' ,
48
-
49
- [ media . lessThan ( 'small' ) ] : {
50
- display : 'none' ,
51
- } ,
13
+ class Section extends React . Component {
14
+ state = { uid : ( '' + Math . random ( ) ) . replace ( / \D / g, '' ) } ;
15
+ render ( ) {
16
+ const {
17
+ activeItemId,
18
+ createLink,
19
+ isActive,
20
+ isScrollSync,
21
+ location,
22
+ onLinkClick,
23
+ onSectionTitleClick,
24
+ section,
25
+ } = this . props ;
26
+ const uid = 'section_' + this . state . uid ;
27
+ return (
28
+ < div >
29
+ < button
30
+ aria-expanded = { isActive }
31
+ aria-controls = { uid }
32
+ css = { {
33
+ cursor : 'pointer' ,
34
+ backgroundColor : 'transparent' ,
35
+ border : 0 ,
36
+ marginTop : 10 ,
52
37
} }
53
- />
54
- </ MetaTitle >
55
- </ button >
56
- < ul
57
- css = { {
58
- marginBottom : 10 ,
38
+ onClick = { onSectionTitleClick } >
39
+ < MetaTitle
40
+ cssProps = { {
41
+ [ media . greaterThan ( 'small' ) ] : {
42
+ color : isActive ? colors . text : colors . subtle ,
43
+
44
+ ':hover' : {
45
+ color : colors . text ,
46
+ } ,
47
+ } ,
48
+ } } >
49
+ { section . title }
50
+ < ChevronSvg
51
+ cssProps = { {
52
+ marginLeft : 7 ,
53
+ transform : isActive ? 'rotateX(180deg)' : 'rotateX(0deg)' ,
54
+ transition : 'transform 0.2s ease' ,
59
55
60
- [ media . greaterThan ( 'small' ) ] : {
61
- display : isActive ? 'block' : 'none' ,
62
- } ,
63
- } } >
64
- { section . items . map ( item => (
65
- < li
66
- key = { item . id }
56
+ [ media . lessThan ( 'small' ) ] : {
57
+ display : 'none' ,
58
+ } ,
59
+ } }
60
+ />
61
+ </ MetaTitle >
62
+ </ button >
63
+ < ul
64
+ id = { uid }
67
65
css = { {
68
- marginTop : 5 ,
66
+ marginBottom : 10 ,
67
+
68
+ [ media . greaterThan ( 'small' ) ] : {
69
+ display : isActive ? 'block' : 'none' ,
70
+ } ,
69
71
} } >
70
- { createLink ( {
71
- isActive : isScrollSync
72
- ? activeItemId === item . id
73
- : isItemActive ( location , item ) ,
74
- item,
75
- location,
76
- onLinkClick,
77
- section,
78
- } ) }
72
+ { section . items . map ( item => (
73
+ < li
74
+ key = { item . id }
75
+ css = { {
76
+ marginTop : 5 ,
77
+ } } >
78
+ { createLink ( {
79
+ isActive : isScrollSync
80
+ ? activeItemId === item . id
81
+ : isItemActive ( location , item ) ,
82
+ item,
83
+ location,
84
+ onLinkClick,
85
+ section,
86
+ } ) }
79
87
80
- { item . subitems && (
81
- < ul css = { { marginLeft : 20 } } >
82
- { item . subitems . map ( subitem => (
83
- < li key = { subitem . id } >
84
- { createLink ( {
85
- isActive : isScrollSync
86
- ? activeItemId === subitem . id
87
- : isItemActive ( location , subitem ) ,
88
- item : subitem ,
89
- location,
90
- onLinkClick,
91
- section,
92
- } ) }
93
- </ li >
94
- ) ) }
95
- </ ul >
96
- ) }
97
- </ li >
98
- ) ) }
99
- </ ul >
100
- </ div >
101
- ) ;
88
+ { item . subitems && (
89
+ < ul css = { { marginLeft : 20 } } >
90
+ { item . subitems . map ( subitem => (
91
+ < li key = { subitem . id } >
92
+ { createLink ( {
93
+ isActive : isScrollSync
94
+ ? activeItemId === subitem . id
95
+ : isItemActive ( location , subitem ) ,
96
+ item : subitem ,
97
+ location,
98
+ onLinkClick,
99
+ section,
100
+ } ) }
101
+ </ li >
102
+ ) ) }
103
+ </ ul >
104
+ ) }
105
+ </ li >
106
+ ) ) }
107
+ </ ul >
108
+ </ div >
109
+ ) ;
110
+ }
111
+ }
102
112
103
113
export default Section ;
0 commit comments