feat: new option disableSearch

This commit is contained in:
Roman Hotsiy 2018-07-17 11:07:34 +03:00
parent fec4605115
commit d4ab5adc17
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
4 changed files with 27 additions and 16 deletions

View File

@ -220,6 +220,7 @@ You can use all of the following options with standalone version on <redoc> 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

View File

@ -42,12 +42,15 @@ export class Redoc extends React.Component<RedocProps> {
<RedocWrap className="redoc-wrap">
<StickyResponsiveSidebar menu={menu} className="menu-content">
<ApiLogo info={spec.info} />
<SearchBox
search={search}
marker={marker}
getItemById={menu.getItemById}
onActivate={menu.activateAndScroll}
/>
{(!options.disableSearch && (
<SearchBox
search={search!}
marker={marker}
getItemById={menu.getItemById}
onActivate={menu.activateAndScroll}
/>
)) ||
null}
<SideMenu menu={menu} />
</StickyResponsiveSidebar>
<ApiContentWrap className="api-content">

View File

@ -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<string>;
search?: SearchStore<string>;
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,
};
}

View File

@ -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);
}