@@ -8,6 +8,29 @@ import Error from 'rsg-components/Error';
8
8
import { HOMEPAGE } from '../../../scripts/consts' ;
9
9
import { DisplayModes } from '../../consts' ;
10
10
11
+ /**
12
+ * This function will return true, if the sidebar should be visible and false otherwise.
13
+ *
14
+ * These sorted conditions (highest precedence first) define the visibility
15
+ * state of the sidebar.
16
+ *
17
+ * - Sidebar is hidden for isolated example views
18
+ * - Sidebar is always visible when pagePerSection
19
+ * - Sidebar is hidden when showSidebar is set to false
20
+ * - Sidebar is visible when showSidebar is set to true for non-isolated views
21
+ *
22
+ * @param {boolean } displayMode
23
+ * @param {boolean } showSidebar
24
+ * @param {boolean } pagePerSection
25
+ * @returns {boolean }
26
+ */
27
+ function hasSidebar ( displayMode , showSidebar , pagePerSection = false ) {
28
+ return (
29
+ ( pagePerSection && displayMode !== DisplayModes . example ) ||
30
+ ( showSidebar && displayMode === DisplayModes . all )
31
+ ) ;
32
+ }
33
+
11
34
export default class StyleGuide extends Component {
12
35
static propTypes = {
13
36
codeRevision : PropTypes . number . isRequired ,
@@ -17,6 +40,8 @@ export default class StyleGuide extends Component {
17
40
welcomeScreen : PropTypes . bool ,
18
41
patterns : PropTypes . array ,
19
42
displayMode : PropTypes . string ,
43
+ allSections : PropTypes . array . isRequired ,
44
+ pagePerSection : PropTypes . bool ,
20
45
} ;
21
46
22
47
static childContextTypes = {
@@ -52,7 +77,15 @@ export default class StyleGuide extends Component {
52
77
}
53
78
54
79
render ( ) {
55
- const { config, sections, welcomeScreen, patterns, displayMode } = this . props ;
80
+ const {
81
+ config,
82
+ sections,
83
+ welcomeScreen,
84
+ patterns,
85
+ displayMode,
86
+ allSections,
87
+ pagePerSection,
88
+ } = this . props ;
56
89
57
90
if ( this . state . error ) {
58
91
return < Error error = { this . state . error } info = { this . state . info } /> ;
@@ -66,8 +99,8 @@ export default class StyleGuide extends Component {
66
99
< StyleGuideRenderer
67
100
title = { config . title }
68
101
homepageUrl = { HOMEPAGE }
69
- toc = { < TableOfContents sections = { sections } /> }
70
- hasSidebar = { config . showSidebar && displayMode === DisplayModes . all }
102
+ toc = { < TableOfContents sections = { allSections } useIsolatedLinks = { pagePerSection } /> }
103
+ hasSidebar = { hasSidebar ( displayMode , config . showSidebar , pagePerSection ) }
71
104
>
72
105
< Sections sections = { sections } depth = { 1 } />
73
106
</ StyleGuideRenderer >
0 commit comments