Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions docs/redoc-vendor-extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,13 @@ Extends the OpenAPI [Info Object](https://redocly.com/docs/openapi-visual-refere
The information about API logo

#### Fixed fields

| Field Name | Type | Description |
| :-------------- | :------: | :---------- |
| 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. |
| 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. |
| hrefTarget | string | The target of the generated anchor tag. |


#### x-logo example
Expand Down
3 changes: 2 additions & 1 deletion src/components/ApiLogo/ApiLogo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ export class ApiLogo extends React.Component<{ info: OpenAPIInfo }> {
}

const logoHref = logoInfo.href || (info.contact && info.contact.url);
const logoHrefTarget = logoInfo.hrefTarget;

// Use the english word logo if no alt text is provided
const altText = logoInfo.altText ? logoInfo.altText : 'logo';

const logo = <LogoImgEl src={logoInfo.url} alt={altText} />;
return (
<LogoWrap style={{ backgroundColor: logoInfo.backgroundColor }}>
{logoHref ? LinkWrap(logoHref)(logo) : logo}
{logoHref ? LinkWrap({ url: logoHref, target: logoHrefTarget })(logo) : logo}
</LogoWrap>
);
}
Expand Down
11 changes: 9 additions & 2 deletions src/components/ApiLogo/styled.elements.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,12 @@ const Link = styled.a`
display: inline-block;
`;

// eslint-disable-next-line react/display-name
export const LinkWrap = url => Component => <Link href={url}>{Component}</Link>;
export const LinkWrap =
({ url, target }) =>
// eslint-disable-next-line react/display-name
Component =>
(
<Link href={url} target={target}>
{Component}
</Link>
);