diff --git a/README.md b/README.md index 3169a0da..98d1c39a 100644 --- a/README.md +++ b/README.md @@ -220,6 +220,7 @@ You can use all of the following options with standalone version on tag * `hideLoading` - do not show loading animation. Useful for small docs * `nativeScrollbars` - use native scrollbar for sidemenu instead of perfect-scroll (scrolling performance optimization for big specs) * `hideDownloadButton` - do not show "Download" spec button. **THIS DOESN'T MAKE YOUR SPEC PRIVATE**, it just hides the button. +* `disableSearch` - disable search indexing and search box * `theme` - ReDoc theme. Not documented yet. For details check source code: [theme.ts](https://github.com/Rebilly/ReDoc/blob/master/src/theme.ts) ## Advanced usage of standalone version diff --git a/src/components/Redoc/Redoc.tsx b/src/components/Redoc/Redoc.tsx index 9fd74360..25d4a50a 100644 --- a/src/components/Redoc/Redoc.tsx +++ b/src/components/Redoc/Redoc.tsx @@ -42,12 +42,15 @@ export class Redoc extends React.Component { - + {(!options.disableSearch && ( + + )) || + null} diff --git a/src/services/AppStore.ts b/src/services/AppStore.ts index 6c5b006e..27603752 100644 --- a/src/services/AppStore.ts +++ b/src/services/AppStore.ts @@ -41,7 +41,9 @@ export class AppStore { const inst = new AppStore(state.spec.data, state.spec.url, state.options, false); inst.menu.activeItemIdx = state.menu.activeItemIdx || 0; inst.menu.activate(inst.menu.flatItems[inst.menu.activeItemIdx]); - inst.search.load(state.searchIndex); + if (!inst.options.disableSearch) { + inst.search!.load(state.searchIndex); + } return inst; } @@ -49,7 +51,7 @@ export class AppStore { spec: SpecStore; rawOptions: RedocRawOptions; options: RedocNormalizedOptions; - search: SearchStore; + search?: SearchStore; marker = new MarkerService(); private scroll: ScrollService; @@ -71,14 +73,16 @@ export class AppStore { this.spec = new SpecStore(spec, specUrl, this.options); this.menu = new MenuStore(this.spec, this.scroll); - this.search = new SearchStore(); - if (createSearchIndex) { - this.search.indexItems(this.menu.items); - } + if (!this.options.disableSearch) { + this.search = new SearchStore(); + if (createSearchIndex) { + this.search.indexItems(this.menu.items); + } - this.disposer = observe(this.menu, 'activeItemIdx', change => { - this.updateMarkOnMenu(change.newValue as number); - }); + this.disposer = observe(this.menu, 'activeItemIdx', change => { + this.updateMarkOnMenu(change.newValue as number); + }); + } } onDidMount() { @@ -128,7 +132,7 @@ export class AppStore { url: this.spec.parser.specUrl, data: this.spec.parser.spec, }, - searchIndex: await this.search.toJS(), + searchIndex: this.search ? await this.search.toJS() : undefined, options: this.rawOptions, }; } diff --git a/src/services/RedocNormalizedOptions.ts b/src/services/RedocNormalizedOptions.ts index f5f65505..8c3e0462 100644 --- a/src/services/RedocNormalizedOptions.ts +++ b/src/services/RedocNormalizedOptions.ts @@ -14,6 +14,7 @@ export interface RedocRawOptions { untrustedSpec?: boolean | string; hideLoading?: boolean | string; hideDownloadButton?: boolean | string; + disableSearch?: boolean | string; unstable_ignoreMimeParameters?: boolean; } @@ -93,6 +94,7 @@ export class RedocNormalizedOptions { pathInMiddlePanel: boolean; untrustedSpec: boolean; hideDownloadButton: boolean; + disableSearch: boolean; /* tslint:disable-next-line */ unstable_ignoreMimeParameters: boolean; @@ -115,6 +117,7 @@ export class RedocNormalizedOptions { this.pathInMiddlePanel = argValueToBoolean(raw.pathInMiddlePanel); this.untrustedSpec = argValueToBoolean(raw.untrustedSpec); this.hideDownloadButton = argValueToBoolean(raw.hideDownloadButton); + this.disableSearch = argValueToBoolean(raw.disableSearch); this.unstable_ignoreMimeParameters = argValueToBoolean(raw.unstable_ignoreMimeParameters); }