feat: add hideDownloadButton option

This commit is contained in:
Roman Hotsiy 2018-03-07 17:21:17 +02:00
parent 0658b8ea67
commit 8dbe938195
No known key found for this signature in database
GPG Key ID: 5CB7B3ACABA57CB0
4 changed files with 14 additions and 5 deletions

View File

@ -13,6 +13,7 @@ export interface RedocRawOptions {
pathInMiddlePanel?: boolean | string;
untrustedSpec?: boolean | string;
hideLoading?: boolean | string;
hideDownloadButton?: boolean | string;
}
function argValueToBoolean(val?: string | boolean): boolean {
@ -89,6 +90,7 @@ export class RedocNormalizedOptions {
nativeScrollbars: boolean;
pathInMiddlePanel: boolean;
untrustedSpec: boolean;
hideDownloadButton: boolean;
constructor(raw: RedocRawOptions) {
this.theme = mergeObjects({} as any, defaultTheme, raw.theme || {});
@ -100,5 +102,6 @@ export class RedocNormalizedOptions {
this.nativeScrollbars = argValueToBoolean(raw.nativeScrollbars);
this.pathInMiddlePanel = argValueToBoolean(raw.pathInMiddlePanel);
this.untrustedSpec = argValueToBoolean(raw.untrustedSpec);
this.hideDownloadButton = argValueToBoolean(raw.hideDownloadButton);
}
}

View File

@ -24,7 +24,7 @@ export class SpecStore {
@computed
get info(): ApiInfoModel {
return new ApiInfoModel(this.parser);
return new ApiInfoModel(this.parser, this.options);
}
@computed

View File

@ -1,6 +1,7 @@
import { OpenAPIContact, OpenAPIInfo, OpenAPILicense } from '../../types';
import { isBrowser } from '../../utils/';
import { OpenAPIParser } from '../OpenAPIParser';
import { RedocNormalizedOptions } from '../RedocNormalizedOptions';
export class ApiInfoModel implements OpenAPIInfo {
title: string;
@ -11,12 +12,18 @@ export class ApiInfoModel implements OpenAPIInfo {
contact?: OpenAPIContact;
license?: OpenAPILicense;
constructor(public parser: OpenAPIParser) {
constructor(private parser: OpenAPIParser, private options: RedocNormalizedOptions) {
Object.assign(this, parser.spec.info);
}
get downloadLink() {
if (!this.parser.specUrl && isBrowser && window.Blob && window.URL) {
if (this.options.hideDownloadButton) return undefined;
if (this.parser.specUrl) {
return this.parser.specUrl;
}
if (isBrowser && window.Blob && window.URL) {
const blob = new Blob([JSON.stringify(this.parser.spec, null, 2)], {
type: 'application/json',
});
@ -27,7 +34,6 @@ export class ApiInfoModel implements OpenAPIInfo {
new Buffer(JSON.stringify(this.parser.spec, null, 2)).toString('base64')
);
}
return this.parser.specUrl;
}
get downloadFileName(): string | undefined {

View File

@ -53,7 +53,7 @@ const theme = {
backgroundColor: '#fafafa',
},
logo: {
maxHeight: '120px',
maxHeight: '150px',
},
rightPanel: {
backgroundColor: '#263238',