@@ -6,6 +6,8 @@ import { Motion, spring } from 'react-motion'
66import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
77import { faCaretRight } from '@fortawesome/free-solid-svg-icons'
88import { trackElementHeight } from '../../util/trackHeight'
9+ import GatsbyLink from 'gatsby-link'
10+ import { Location } from '@reach/router'
911
1012const ChildrenList = styled . ul `
1113 height: calc(var(--open-ratio) * var(--calculated-height) * 1px);
@@ -19,6 +21,13 @@ const ListItem = styled.li`
1921 padding: 0.5rem;
2022`
2123
24+ const NavigationLink = styled ( GatsbyLink ) `
25+ ${ props => props . active == "t" && `
26+ background-color: #ffccc6;
27+ width: 100%;
28+ ` }
29+ `
30+
2231const ItemTitleWrapper = styled . div `
2332 display: flex;
2433 align-items: center;
@@ -68,42 +77,53 @@ export default class TreeViewItem extends React.Component {
6877 render ( ) {
6978 return (
7079 < React . Fragment >
71- < Motion
72- style = { { openRatio : spring ( this . state . childrenVisible ? 1 : 0 ) } }
73- >
74- { ( { openRatio } ) => (
75- < React . Fragment >
76- < ItemTitleWrapper
77- className = { `nav-item-${ this . props . item . name
78- . toLowerCase ( )
79- . replace ( / / g, '-' ) } `}
80- >
81- { this . props . item . children && (
82- < StyledIcon
83- style = { { '--open-ratio' : `${ openRatio } ` } }
84- icon = { faCaretRight }
85- size = "1x"
86- />
87- ) }
88- < a href = { this . props . item . href } >
89- < ListItem onClick = { this . onClick } >
90- { this . props . item . name }
91- </ ListItem >
92- </ a >
93- </ ItemTitleWrapper >
94- { this . props . item . children && (
95- < ChildrenList
96- innerRef = { this . childrenListRef }
97- style = { { '--open-ratio' : `${ openRatio } ` } }
98- >
99- { this . props . item . children . map ( i => (
100- < TreeViewItem key = { i . name } item = { i } />
101- ) ) }
102- </ ChildrenList >
80+ < Location >
81+ { ( { navigate, location } ) => (
82+ < Motion
83+ style = { {
84+ openRatio : spring ( this . state . childrenVisible ? 1 : 0 ) ,
85+ } }
86+ >
87+ { ( { openRatio } ) => (
88+ < React . Fragment >
89+ < ItemTitleWrapper
90+ className = { `nav-item-${ this . props . item . name
91+ . toLowerCase ( )
92+ . replace ( / / g, '-' ) } `}
93+ >
94+ { this . props . item . children && (
95+ < StyledIcon
96+ style = { { '--open-ratio' : `${ openRatio } ` } }
97+ icon = { faCaretRight }
98+ size = "1x"
99+ />
100+ ) }
101+ < NavigationLink
102+ to = { this . props . item . href }
103+ active = {
104+ this . props . item . href == location . pathname ? 't' : 'f'
105+ }
106+ >
107+ < ListItem onClick = { this . onClick } >
108+ { this . props . item . name }
109+ </ ListItem >
110+ </ NavigationLink >
111+ </ ItemTitleWrapper >
112+ { this . props . item . children && (
113+ < ChildrenList
114+ innerRef = { this . childrenListRef }
115+ style = { { '--open-ratio' : `${ openRatio } ` } }
116+ >
117+ { this . props . item . children . map ( i => (
118+ < TreeViewItem key = { i . name } item = { i } />
119+ ) ) }
120+ </ ChildrenList >
121+ ) }
122+ </ React . Fragment >
103123 ) }
104- </ React . Fragment >
124+ </ Motion >
105125 ) }
106- </ Motion >
126+ </ Location >
107127 </ React . Fragment >
108128 )
109129 }
0 commit comments