Skip to content

Commit

Permalink
feat: provide Topbar Logo as a wrappable component (#7521)
Browse files Browse the repository at this point in the history
* docs(logo): added logo replace docs

Co-authored-by: Tim Lai <[email protected]>
  • Loading branch information
mathis-m and tim-lai authored Jul 18, 2022
1 parent 0d5227b commit 878e848
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
15 changes: 15 additions & 0 deletions docs/customization/plug-points.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,21 @@ const MultiplePhraseFilterPlugin = function() {
}
}
```
### Logo component
While using the Standalone Preset the SwaggerUI logo is rendered in the Top Bar.
The logo can be exchanged by replacing the `Logo` component via the plugin api:

```jsx
import React from "react";
const MyLogoPlugin = {
components: {
Logo: () => (
<img alt="My Logo" height="40" src="data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNTM3IiBoZWlnaHQ9IjEzNCIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KCiA8Zz4KICA8dGl0bGU+TGF5ZXIgMTwvdGl0bGU+CiAgPHRleHQgdHJhbnNmb3JtPSJtYXRyaXgoMy40Nzc2OSAwIDAgMy4yNjA2NyAtNjczLjEyOCAtNjkxLjk5MykiIHN0cm9rZT0iIzAwMCIgZm9udC1zdHlsZT0ibm9ybWFsIiBmb250LXdlaWdodD0ibm9ybWFsIiB4bWw6c3BhY2U9InByZXNlcnZlIiB0ZXh0LWFuY2hvcj0ic3RhcnQiIGZvbnQtZmFtaWx5PSInT3BlbiBTYW5zIEV4dHJhQm9sZCciIGZvbnQtc2l6ZT0iMjQiIGlkPSJzdmdfMSIgeT0iMjQxLjIyMTkyIiB4PSIxOTYuOTY5MjEiIHN0cm9rZS13aWR0aD0iMCIgZmlsbD0iIzYyYTAzZiI+TXkgTG9nbzwvdGV4dD4KICA8cGF0aCBpZD0ic3ZnXzIiIGQ9Im0zOTUuNjAyNSw1MS4xODM1OWw1My44Nzc3MSwwbDE2LjY0ODYzLC01MS4xODM1OGwxNi42NDg2NCw1MS4xODM1OGw1My44Nzc3LDBsLTQzLjU4NzksMzEuNjMyODNsMTYuNjQ5NDksNTEuMTgzNThsLTQzLjU4NzkyLC0zMS42MzM2OWwtNDMuNTg3OTEsMzEuNjMzNjlsMTYuNjQ5NDksLTUxLjE4MzU4bC00My41ODc5MiwtMzEuNjMyODN6IiBzdHJva2Utd2lkdGg9IjAiIHN0cm9rZT0iIzAwMCIgZmlsbD0iIzYyYTAzZiIvPgogPC9nPgo8L3N2Zz4="/>
)
}
}
```


### JSON Schema components
In swagger there are so called JSON Schema components. These are used to render inputs for parameters and components of request bodies with `application/x-www-form-urlencoded` or `multipart/*` media-type.
Expand Down
4 changes: 3 additions & 1 deletion src/plugins/topbar/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import Topbar from "./topbar"
import Logo from "./logo"

export default function () {
return {
components: {
Topbar
Topbar,
Logo
}
}
}
8 changes: 8 additions & 0 deletions src/plugins/topbar/logo.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from "react"
import SwaggerUILogo from "./logo_small.svg"

export const Logo = () => (
<img height="40" src={ SwaggerUILogo } alt="Swagger UI"/>
)

export default Logo
4 changes: 2 additions & 2 deletions src/plugins/topbar/topbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React, { cloneElement } from "react"
import PropTypes from "prop-types"

//import "./topbar.less"
import Logo from "./logo_small.svg"
import {parseSearch, serializeSearch} from "../../core/utils"

export default class Topbar extends React.Component {
Expand Down Expand Up @@ -113,6 +112,7 @@ export default class Topbar extends React.Component {
let { getComponent, specSelectors, getConfigs } = this.props
const Button = getComponent("Button")
const Link = getComponent("Link")
const Logo = getComponent("Logo")

let isLoading = specSelectors.loadingStatus() === "loading"
let isFailed = specSelectors.loadingStatus() === "failed"
Expand Down Expand Up @@ -150,7 +150,7 @@ export default class Topbar extends React.Component {
<div className="wrapper">
<div className="topbar-wrapper">
<Link>
<img height="40" src={ Logo } alt="Swagger UI"/>
<Logo/>
</Link>
<form className="download-url-wrapper" onSubmit={formOnSubmit}>
{control.map((el, i) => cloneElement(el, { key: i }))}
Expand Down

0 comments on commit 878e848

Please sign in to comment.