Skip to content

Commit 4320118

Browse files
authored
Merge branch 'master' into master
2 parents 5c17153 + 7f19d79 commit 4320118

File tree

5 files changed

+57
-8
lines changed

5 files changed

+57
-8
lines changed

docs/customization/plugin-api.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ const MyWrapSelectorsPlugin = function(system) {
293293

294294
Wrap Components allow you to override a component registered within the system.
295295

296-
Wrap Components are function factories with the signature `(OriginalComponent, system) => props => ReactElement`.
296+
Wrap Components are function factories with the signature `(OriginalComponent, system) => props => ReactElement`. If you'd prefer to provide a React component class, `(OriginalComponent, system) => ReactClass` works as well.
297297

298298
```javascript
299299
const MyWrapBuiltinComponentPlugin = function(system) {
@@ -310,9 +310,12 @@ const MyWrapBuiltinComponentPlugin = function(system) {
310310
}
311311
```
312312

313+
Here's another example that includes a code sample of a component that will be wrapped:
314+
313315
```javascript
314-
// Overriding a component from a plugin
316+
///// Overriding a component from a plugin
315317

318+
// Here's our normal, unmodified component.
316319
const MyNumberDisplayPlugin = function(system) {
317320
return {
318321
components: {
@@ -321,13 +324,15 @@ const MyNumberDisplayPlugin = function(system) {
321324
}
322325
}
323326

327+
// Here's a component wrapper defined as a function.
324328
const MyWrapComponentPlugin = function(system) {
325329
return {
326330
wrapComponents: {
327331
NumberDisplay: (Original, system) => (props) => {
328332
if(props.number > 10) {
329333
return <div>
330334
<h3>Warning! Big number ahead.</h3>
335+
<OriginalComponent {...props} />
331336
</div>
332337
} else {
333338
return <Original {...props} />
@@ -336,8 +341,30 @@ const MyWrapComponentPlugin = function(system) {
336341
}
337342
}
338343
}
344+
345+
// Alternatively, here's the same component wrapper defined as a class.
346+
const MyWrapComponentPlugin = function(system) {
347+
return {
348+
wrapComponents: {
349+
NumberDisplay: (Original, system) => class WrappedNumberDisplay extends React.component {
350+
render() {
351+
if(props.number > 10) {
352+
return <div>
353+
<h3>Warning! Big number ahead.</h3>
354+
<OriginalComponent {...props} />
355+
</div>
356+
} else {
357+
return <Original {...props} />
358+
}
359+
}
360+
}
361+
}
362+
}
363+
}
339364
```
340365

366+
367+
341368
##### fn
342369

343370
The fn interface allows you to add helper functions to the system for use elsewhere.

docs/usage/installation.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const ui = SwaggerUIBundle({
4949
presets: [
5050
SwaggerUIBundle.presets.apis,
5151
SwaggerUIBundle.SwaggerUIStandalonePreset
52-
]
52+
],
5353
layout: "StandaloneLayout"
5454
})
5555
```
@@ -86,7 +86,7 @@ This will serve Swagger UI at `/swagger` instead of `/`.
8686
You can embed Swagger-UI's code directly in your HTML by using unkpg's interface:
8787

8888
```html
89-
<script src="//unpkg.com/swagger-ui-dist@3/swagger-ui-bundle.js">
89+
<script src="//unpkg.com/swagger-ui-dist@3/swagger-ui-bundle.js"></script>
9090
<!-- `SwaggerUIBundle` is now available on the page -->
9191
```
9292

src/core/components/layouts/base.jsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,18 @@ export default class BaseLayout extends React.Component {
6161
const isSpecEmpty = !specSelectors.specStr()
6262

6363
if(isSpecEmpty) {
64-
return <h4>No spec provided.</h4>
64+
let loadingMessage
65+
if(isLoading) {
66+
loadingMessage = <div className="loading"></div>
67+
} else {
68+
loadingMessage = <h4>No API definition provided.</h4>
69+
}
70+
71+
return <div className="swagger-ui">
72+
<div className="loading-container">
73+
{loadingMessage}
74+
</div>
75+
</div>
6576
}
6677

6778
return (

src/standalone/layout.jsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
2+
13
import React from "react"
24
import PropTypes from "prop-types"
35

@@ -32,17 +34,21 @@ export default class StandaloneLayout extends React.Component {
3234
{ Topbar ? <Topbar /> : null }
3335
{ loadingStatus === "loading" &&
3436
<div className="info">
35-
<h4 className="title">Loading...</h4>
37+
<div className="loading-container">
38+
<div className="loading"></div>
39+
</div>
3640
</div>
3741
}
3842
{ loadingStatus === "failed" &&
3943
<div className="info">
40-
<h4 className="title">Failed to load spec.</h4>
44+
<div className="loading-container">
45+
<h4 className="title">Failed to load API definition.</h4>
46+
</div>
4147
</div>
4248
}
4349
{ loadingStatus === "failedConfig" &&
4450
<div className="info" style={{ maxWidth: "880px", marginLeft: "auto", marginRight: "auto", textAlign: "center" }}>
45-
<h4 className="title">Failed to load config.</h4>
51+
<h4 className="title">Failed to load remote configuration.</h4>
4652
</div>
4753
}
4854
{ !loadingStatus || loadingStatus === "success" && <BaseLayout /> }

src/style/_layout.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,11 @@
653653
.loading-container
654654
{
655655
padding: 40px 0 60px;
656+
margin-top: 1em;
657+
min-height: 1px;
658+
display: flex;
659+
justify-content: center;
660+
656661
.loading
657662
{
658663
position: relative;

0 commit comments

Comments
 (0)