Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update search functionality #443

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/rsg-components/StyleGuide/StyleGuide.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import StyleGuideRenderer from 'rsg-components/StyleGuide/StyleGuideRenderer';
import Sections from 'rsg-components/Sections';
import Welcome from 'rsg-components/Welcome';
import { HOMEPAGE } from '../../../scripts/consts';
import { filterSectionsByName } from '../../utils/utils';

export default class StyleGuide extends Component {
static propTypes = {
Expand Down Expand Up @@ -43,6 +44,9 @@ export default class StyleGuide extends Component {
render() {
const { config, sections, welcomeScreen, patterns, isolatedComponent } = this.props;

const { searchTerm } = this.state;
const filteredSections = (0, filterSectionsByName)(sections, searchTerm);

if (welcomeScreen) {
return <Welcome patterns={patterns} />;
}
Expand All @@ -51,10 +55,15 @@ export default class StyleGuide extends Component {
<StyleGuideRenderer
title={config.title}
homepageUrl={HOMEPAGE}
toc={<TableOfContents sections={sections} />}
hasSidebar={config.showSidebar && !isolatedComponent}
toc={
<TableOfContents
sections={filteredSections}
onSearchFoo={searchTerm => this.setState({ searchTerm })}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we rename this?

/>
}
>
<Sections sections={sections} />
<Sections sections={filteredSections} />
</StyleGuideRenderer>
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/rsg-components/TableOfContents/TableOfContents.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import TableOfContentsRenderer from 'rsg-components/TableOfContents/TableOfConte
export default class TableOfContents extends Component {
static propTypes = {
sections: PropTypes.array.isRequired,
onSearchFoo: PropTypes.func,
};
state = {
searchTerm: '',
Expand Down Expand Up @@ -40,7 +41,7 @@ export default class TableOfContents extends Component {
return (
<TableOfContentsRenderer
searchTerm={searchTerm}
onSearchTermChange={searchTerm => this.setState({ searchTerm })}
onSearchTermChange={this.props.onSearchFoo({ searchTerm })}
>
{this.renderSections()}
</TableOfContentsRenderer>
Expand Down