feat: Add feature to specify href for logo explicitly (#645)

Closes https://github.com/Rebilly/ReDoc/issues/627
This commit is contained in:
TATSUNO Yasuhiro 2018-11-27 18:27:10 +09:00 committed by Roman Hotsiy
parent 5e6f6fff03
commit 87fd7d7fdd
2 changed files with 6 additions and 1 deletions

View File

@ -96,6 +96,7 @@ The information about API logo
| url | string | The URL pointing to the spec logo. MUST be in the format of a URL. It SHOULD be an absolute URL so your API definition is usable from any location
| backgroundColor | string | background color to be used. MUST be RGB color in [hexadecimal format] (https://en.wikipedia.org/wiki/Web_colors#Hex_triplet)
| altText | string | Text to use for alt tag on the logo. Defaults to 'logo' if nothing is provided.
| href | string | The URL pointing to the contact page. Default to 'info.contact.url' field of the OAS.
###### x-logo example

View File

@ -11,6 +11,8 @@ export class ApiLogo extends React.Component<{ info: OpenAPIInfo }> {
if (!logoInfo || !logoInfo.url) {
return null;
}
const logoHref = logoInfo.href || (info.contact && info.contact.url);
// Use the english word logo if no alt text is provided
const altText = logoInfo.altText ? logoInfo.altText : 'logo';
@ -24,7 +26,9 @@ export class ApiLogo extends React.Component<{ info: OpenAPIInfo }> {
);
return (
<LogoWrap>
{info.contact && info.contact.url ? LinkWrap(info.contact.url)(logo) : logo}{' '}
{
logoHref ? LinkWrap(logoHref)(logo) : logo
}
</LogoWrap>
);
}