@@ -3,6 +3,7 @@ import PropTypes from 'prop-types';
3
3
import cx from 'classnames' ;
4
4
import Link from 'rsg-components/Link' ;
5
5
import Styled from 'rsg-components/Styled' ;
6
+ import { hasInHash , getHash } from '../../utils/handleHash' ;
6
7
7
8
const styles = ( { color, fontFamily, fontSize, space, mq } ) => ( {
8
9
list : {
@@ -31,6 +32,9 @@ const styles = ({ color, fontFamily, fontSize, space, mq }) => ({
31
32
fontFamily : fontFamily . base ,
32
33
fontWeight : 'bold' ,
33
34
} ,
35
+ isSelected : {
36
+ fontWeight : 'bold' ,
37
+ } ,
34
38
} ) ;
35
39
36
40
export function ComponentsListRenderer ( { classes, items } ) {
@@ -40,23 +44,31 @@ export function ComponentsListRenderer({ classes, items }) {
40
44
return null ;
41
45
}
42
46
47
+ const windowHash = window . location . pathname + getHash ( window . location . hash ) ;
43
48
return (
44
49
< ul className = { classes . list } >
45
- { items . map ( ( { heading, visibleName, href, content, external } ) => (
46
- < li
47
- className = { cx ( classes . item , ( ! content || ! content . props . items . length ) && classes . isChild ) }
48
- key = { href }
49
- >
50
- < Link
51
- className = { cx ( heading && classes . heading ) }
52
- href = { href }
53
- target = { external ? '_blank' : undefined }
50
+ { items . map ( ( { heading, visibleName, href, content, external } ) => {
51
+ const isItemSelected = hasInHash ( windowHash , href ) ;
52
+ return (
53
+ < li
54
+ className = { cx (
55
+ classes . item ,
56
+ ( ! content || ! content . props . items . length ) && classes . isChild ,
57
+ isItemSelected && classes . isSelected
58
+ ) }
59
+ key = { href }
54
60
>
55
- { visibleName }
56
- </ Link >
57
- { content }
58
- </ li >
59
- ) ) }
61
+ < Link
62
+ className = { cx ( heading && classes . heading ) }
63
+ href = { href }
64
+ target = { external ? '_blank' : undefined }
65
+ >
66
+ { visibleName }
67
+ </ Link >
68
+ { content }
69
+ </ li >
70
+ ) ;
71
+ } ) }
60
72
</ ul >
61
73
) ;
62
74
}
0 commit comments