mirror of
https://github.com/Redocly/redoc.git
synced 2025-01-31 01:54:08 +03:00
feat: new option disableSearch
This commit is contained in:
parent
fec4605115
commit
d4ab5adc17
|
@ -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
|
||||
|
|
|
@ -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">
|
||||
|
|
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user