enhance: scrollable + downloadable HighlightCode (#4397)

* Auto hidding content that is longer than 600 characters long.

* Added basic downloading

Slightly broken

* Better downloading

now downloads file on button click

* Fix the angry linter

* Fix dist

* Removed collapsing, added scrolling.

* Code clean up.

* CSS fix.

* prevent HighlightCode from scrolling entire document

* center "Download" text in button

* `this.downloadJSON` -> `this.downloadText`

we're always saving as `.txt`, so JSON is a misnomer

* hide Download button behind option `downloadable` prop

* `file-saver` -> `js-file-download`
This commit is contained in:
Giancarlo Klemm Camilo
2018-04-12 18:18:49 -07:00
committed by kyle
parent 2bf2167a18
commit 2795518340
4 changed files with 72 additions and 7 deletions

View File

@@ -66,7 +66,7 @@ export default class ResponseBody extends React.Component {
body = "can't parse JSON. Raw result:\n\n" + content
}
bodyEl = <HighlightCode value={ body } />
bodyEl = <HighlightCode downloadable value={ body } />
// XML
} else if (/xml/i.test(contentType)) {
@@ -74,11 +74,11 @@ export default class ResponseBody extends React.Component {
textNodesOnSameLine: true,
indentor: " "
})
bodyEl = <HighlightCode value={ body } />
bodyEl = <HighlightCode downloadable value={ body } />
// HTML or Plain Text
} else if (lowerCase(contentType) === "text/html" || /text\/plain/.test(contentType)) {
bodyEl = <HighlightCode value={ content } />
bodyEl = <HighlightCode downloadable value={ content } />
// Image
} else if (/^image\//i.test(contentType)) {
@@ -92,7 +92,7 @@ export default class ResponseBody extends React.Component {
} else if (/^audio\//i.test(contentType)) {
bodyEl = <pre><audio controls><source src={ url } type={ contentType } /></audio></pre>
} else if (typeof content === "string") {
bodyEl = <HighlightCode value={ content } />
bodyEl = <HighlightCode downloadable value={ content } />
} else if ( content.size > 0 ) {
// We don't know the contentType, but there was some content returned
bodyEl = <div>Unknown response type</div>