{name &&
diff --git a/src/rsg-components/Sections/Sections.js b/src/rsg-components/Sections/Sections.js
index fd2f54202..62ef846d1 100644
--- a/src/rsg-components/Sections/Sections.js
+++ b/src/rsg-components/Sections/Sections.js
@@ -6,7 +6,13 @@ import SectionsRenderer from 'rsg-components/Sections/SectionsRenderer';
export default function Sections({ sections }) {
return (
- {sections.map((section, idx) => )}
+ {sections.map((section, idx) => {
+ if (section.sections.length || section.components.length || section.content) {
+ return ;
+ }
+
+ return null;
+ })}
);
}
diff --git a/src/rsg-components/StyleGuide/StyleGuide.js b/src/rsg-components/StyleGuide/StyleGuide.js
index fadd6c47d..6e7f24a70 100644
--- a/src/rsg-components/StyleGuide/StyleGuide.js
+++ b/src/rsg-components/StyleGuide/StyleGuide.js
@@ -10,12 +10,13 @@ export default class StyleGuide extends Component {
static propTypes = {
codeKey: PropTypes.number.isRequired,
config: PropTypes.object.isRequired,
- sections: PropTypes.array.isRequired,
+ allSections: PropTypes.array.isRequired,
welcomeScreen: PropTypes.bool,
patterns: PropTypes.array,
isolatedComponent: PropTypes.bool,
isolatedExample: PropTypes.bool,
isolatedSection: PropTypes.bool,
+ listTypes: PropTypes.array,
};
static childContextTypes = {
@@ -30,6 +31,12 @@ export default class StyleGuide extends Component {
isolatedComponent: false,
};
+ state = {
+ searchTerm: '',
+ listMode: '',
+ filteredSections: [],
+ };
+
getChildContext() {
return {
codeKey: this.props.codeKey,
@@ -40,8 +47,41 @@ export default class StyleGuide extends Component {
};
}
+ componentWillMount() {
+ const { allSections, listTypes } = this.props;
+
+ this.setState({
+ listMode: listTypes[0], //eslint-disable-line
+ filteredSections: this.getSectionsFromList(listTypes[0], allSections),
+ });
+ }
+
+ getSectionsFromList(listMode, sections) {
+ const list = sections.length === 1
+ ? sections
+ : sections.filter(section => section.name === listMode)[0].sections;
+
+ return list;
+ }
+
+ updateSections(listMode) {
+ const { allSections } = this.props;
+ this.setState({
+ filteredSections: this.getSectionsFromList(listMode, allSections),
+ });
+ }
+
render() {
- const { config, sections, welcomeScreen, patterns, isolatedComponent } = this.props;
+ const {
+ config,
+ listTypes,
+ allSections,
+ welcomeScreen,
+ patterns,
+ isolatedComponent,
+ } = this.props;
+
+ const { searchTerm, listMode, filteredSections } = this.state;
if (welcomeScreen) {
return
;
@@ -51,10 +91,32 @@ export default class StyleGuide extends Component {
}
hasSidebar={config.showSidebar && !isolatedComponent}
+ listMode={this.state.listMode}
+ listTypes={listTypes}
+ onListToggle={listMode => {
+ this.setState(
+ {
+ searchTerm: '',
+ listMode,
+ },
+ this.updateSections(listMode)
+ );
+ }}
+ toc={
+
{
+ this.setState({
+ searchTerm,
+ filteredSections,
+ });
+ }}
+ />
+ }
>
-
+
);
}
diff --git a/src/rsg-components/StyleGuide/StyleGuideRenderer.js b/src/rsg-components/StyleGuide/StyleGuideRenderer.js
index cf5bfbe0c..b62b362df 100644
--- a/src/rsg-components/StyleGuide/StyleGuideRenderer.js
+++ b/src/rsg-components/StyleGuide/StyleGuideRenderer.js
@@ -1,6 +1,5 @@
import React from 'react';
import PropTypes from 'prop-types';
-import Logo from 'rsg-components/Logo';
import Markdown from 'rsg-components/Markdown';
import Styled from 'rsg-components/Styled';
import cx from 'classnames';
@@ -54,20 +53,75 @@ const styles = ({ color, fontFamily, fontSize, sidebarWidth, mq, space, maxWidth
},
});
-export function StyleGuideRenderer({ classes, title, homepageUrl, children, toc, hasSidebar }) {
+function renderListModeToggle(listMode, listTypes, onListToggle) {
+ return (
+
+ {listTypes.map((type, idx) => {
+ return (
+ - onListToggle(type)}
+ className={listMode === type ? 'active' : ''}
+ >
+ {type}
+
+ );
+ })}
+
+ );
+}
+
+export function StyleGuideRenderer(props) {
+ const {
+ listMode,
+ listTypes,
+ onListToggle,
+ classes,
+ title,
+ homepageUrl,
+ children,
+ toc,
+ hasSidebar,
+ } = props;
+
return (
-
- {children}
+
+ {' '}{children}
{hasSidebar &&
-
+
-
{title}
+
+ {renderListModeToggle(listMode, listTypes, onListToggle)}
{toc}
}
@@ -81,6 +135,9 @@ StyleGuideRenderer.propTypes = {
children: PropTypes.node.isRequired,
toc: PropTypes.node.isRequired,
hasSidebar: PropTypes.bool,
+ listMode: PropTypes.string,
+ listTypes: PropTypes.array,
+ onListToggle: PropTypes.func,
};
export default Styled(styles)(StyleGuideRenderer);
diff --git a/src/rsg-components/TableOfContents/TableOfContents.js b/src/rsg-components/TableOfContents/TableOfContents.js
index 698520eba..c0d1e68a9 100644
--- a/src/rsg-components/TableOfContents/TableOfContents.js
+++ b/src/rsg-components/TableOfContents/TableOfContents.js
@@ -1,17 +1,53 @@
import React, { Component } from 'react';
import PropTypes from 'prop-types';
-import { filterSectionsByName } from '../../utils/utils';
import ComponentsList from 'rsg-components/ComponentsList';
import TableOfContentsRenderer from 'rsg-components/TableOfContents/TableOfContentsRenderer';
+import { debounce } from 'lodash';
+import { filterSectionsByName } from '../../utils/utils';
export default class TableOfContents extends Component {
static propTypes = {
sections: PropTypes.array.isRequired,
+ searchTerm: PropTypes.string,
+ onSearchTermChange: PropTypes.func,
+ updateStyleguide: PropTypes.func,
};
+
state = {
- searchTerm: '',
+ TOCsearchTerm: '',
+ filteredSections: [],
};
+ componentWillMount() {
+ const { sections, searchTerm } = this.props;
+
+ this.filterSections(searchTerm, sections);
+ }
+
+ // Handles listMode update
+ componentWillReceiveProps(nextProps) {
+ const { sections, searchTerm } = nextProps;
+
+ this.filterSections(searchTerm, sections);
+ }
+
+ // Updates Styleguidist state
+ // using updateSections function passed as prop
+ updateStyleguide = debounce((searchTerm, filteredSections, updateStyleguide) => {
+ updateStyleguide(searchTerm, filteredSections);
+ }, 200);
+
+ filterSections(TOCsearchTerm, sections) {
+ // If there is only one section, we treat it as a root section
+ // In this case the name of the section won't be rendered and it won't get left padding
+ const firstLevel = sections.length === 1 ? sections[0].components : sections;
+ const filteredSections = filterSectionsByName(firstLevel, TOCsearchTerm);
+
+ this.setState({ TOCsearchTerm, filteredSections });
+
+ return filteredSections;
+ }
+
renderLevel(sections) {
const items = sections.map(section => {
const children = [...(section.sections || []), ...(section.components || [])];
@@ -20,27 +56,27 @@ export default class TableOfContents extends Component {
content: children.length > 0 && this.renderLevel(children),
});
});
+
return ;
}
renderSections() {
- const { searchTerm } = this.state;
- const { sections } = this.props;
+ const { filteredSections } = this.state;
- // If there is only one section, we treat it as a root section
- // In this case the name of the section won't be rendered and it won't get left padding
- const firstLevel = sections.length === 1 ? sections[0].components : sections;
- const filtered = filterSectionsByName(firstLevel, searchTerm);
-
- return this.renderLevel(filtered);
+ return this.renderLevel(filteredSections);
}
render() {
- const { searchTerm } = this.state;
+ const { sections, updateStyleguide } = this.props;
+ const { TOCsearchTerm } = this.state;
+
return (
this.setState({ searchTerm })}
+ searchTerm={TOCsearchTerm}
+ onSearchTermChange={TOCsearchTerm => {
+ const updatedSections = this.filterSections(TOCsearchTerm, sections);
+ this.updateStyleguide(TOCsearchTerm, updatedSections, updateStyleguide);
+ }}
>
{this.renderSections()}
diff --git a/src/rsg-components/TableOfContents/TableOfContentsRenderer.js b/src/rsg-components/TableOfContents/TableOfContentsRenderer.js
index 5c9e299c0..0fe2df384 100644
--- a/src/rsg-components/TableOfContents/TableOfContentsRenderer.js
+++ b/src/rsg-components/TableOfContents/TableOfContentsRenderer.js
@@ -1,4 +1,6 @@
import React from 'react';
+import { findDOMNode } from 'react-dom';
+import cx from 'classnames';
import PropTypes from 'prop-types';
import Styled from 'rsg-components/Styled';
@@ -26,14 +28,42 @@ const styles = ({ space, color, fontFamily, fontSize, borderRadius }) => ({
outline: 0,
},
},
+ tocFooter: {
+ color: '#fff',
+ paddingLeft: '1rem',
+ fontSize: 'small',
+ paddingBottom: '1rem',
+ },
+ link: {
+ color: '#fff',
+ fontSize: 'small',
+ },
});
-export function TableOfContentsRenderer({ classes, children, searchTerm, onSearchTermChange }) {
+function renderTOCFooter(classes) {
+ const year = new Date().getFullYear();
+
+ return (
+
+ );
+}
+
+export function TableOfContentsRenderer(props) {
+ const { classes, children, onSearchTermChange, searchTerm } = props;
+
+ /* eslint-disable react/no-find-dom-node */
return (
-
);
diff --git a/src/styles/jss-isolate/inherited.js b/src/styles/jss-isolate/inherited.js
index 18005edfb..f9f7bcd95 100644
--- a/src/styles/jss-isolate/inherited.js
+++ b/src/styles/jss-isolate/inherited.js
@@ -12,14 +12,12 @@ export default {
'cursor': 'auto',
'direction': 'initial',
'empty-cells': 'show',
- 'font': 'initial',
'font-size-adjust': 'none',
'font-family': 'initial',
'font-size': 'medium',
'font-style': 'normal',
'font-stretch': 'normal',
'font-variant': 'normal',
- 'font-weight': 'normal',
'letter-spacing': 'normal',
'line-height': 'normal',
'list-style-image': 'none',
diff --git a/src/styles/theme.js b/src/styles/theme.js
index aff6e99d5..48e0e70c5 100644
--- a/src/styles/theme.js
+++ b/src/styles/theme.js
@@ -22,7 +22,7 @@ export const color = {
baseBackground: '#fff',
errorBackground: '#c00',
codeBackground: '#f5f5f5',
- sidebarBackground: '#f5f5f5',
+ sidebarBackground: '#000',
};
export const fontFamily = {