Compare commits

...

14 Commits

Author SHA1 Message Date
Kyle Shockey
1e2baeb91b this.downloadJSON -> this.downloadText
we're always saving as `.txt`, so JSON is a misnomer
2018-04-12 17:56:35 -07:00
Kyle Shockey
ac43ee5feb center "Download" text in button 2018-04-12 17:56:07 -07:00
Kyle Shockey
64b83738ce prevent HighlightCode from scrolling entire document 2018-04-12 17:52:27 -07:00
kyle
0cdd54c24d Merge branch 'master' into auto-hide-contents 2018-04-12 17:17:20 -07:00
giancarlokc
a3ef0d609f CSS fix. 2018-04-05 23:31:35 -07:00
giancarlokc
80e994ef79 Code clean up. 2018-04-05 23:21:00 -07:00
giancarlokc
115c5305ea Removed collapsing, added scrolling. 2018-04-05 23:16:46 -07:00
giancarlokc
cd065d674c Merge branch 'auto-hide-contents' of https://github.com/giancarlokc/swagger-ui into auto-hide-contents 2018-04-05 22:39:19 -07:00
giancarlokc
6f061d8de5 Fix dist 2018-04-05 22:38:43 -07:00
Giancarlo Klemm Camilo
11eb6ef002 Merge branch 'master' into auto-hide-contents 2018-04-05 22:38:11 -07:00
Graeme
177464e06f Fix the angry linter 2018-04-05 21:07:07 -07:00
Graeme
6173d3b966 Better downloading
now downloads file on button click
2018-04-05 20:51:12 -07:00
Graeme
485d04ff3c Added basic downloading
Slightly broken
2018-04-03 15:21:05 -07:00
giancarlokc
0b8dab2d5e Auto hidding content that is longer than 600 characters long. 2018-04-02 23:56:26 -07:00
3 changed files with 62 additions and 1 deletions

View File

@@ -116,6 +116,7 @@
"eslint-plugin-react": "^7.1.0",
"extract-text-webpack-plugin": "^2.1.2",
"file-loader": "0.11.2",
"file-saver": "^1.3.8",
"git-describe": "^4.0.1",
"imports-loader": "0.7.1",
"json-loader": "0.5.4",

View File

@@ -1,6 +1,7 @@
import React, { Component } from "react"
import PropTypes from "prop-types"
import { highlight } from "core/utils"
import { saveAs } from "file-saver"
export default class HighlightCode extends Component {
static propTypes = {
@@ -20,10 +21,43 @@ export default class HighlightCode extends Component {
this.el = c
}
downloadText = () => {
let fileToSave = new Blob([this.props.value], {type: "text/plain"})
saveAs(fileToSave, "response")
}
preventYScrollingBeyondElement = (e) => {
const target = e.target
var deltaY = e.nativeEvent.deltaY
var contentHeight = target.scrollHeight
var visibleHeight = target.offsetHeight
var scrollTop = target.scrollTop
const scrollOffset = visibleHeight + scrollTop
const isScrollingPastTop = scrollTop === 0 && deltaY < 0
const isScrollingPastBottom = scrollOffset >= contentHeight && deltaY > 0
if (isScrollingPastTop || isScrollingPastBottom) {
e.preventDefault()
}
}
render () {
let { value, className } = this.props
className = className || ""
return <pre ref={this.initializeComponent} className={className + " microlight"}>{ value }</pre>
return (
<div className="highlight-code">
<div className="download-contents" onClick={this.downloadText}>Download</div>
<pre
ref={this.initializeComponent}
onWheel={this.preventYScrollingBeyondElement}
className={className + " microlight"}>
{value}
</pre>
</div>
)
}
}

View File

@@ -626,6 +626,32 @@
}
}
.highlight-code {
position: relative;
> .microlight {
overflow-y: auto;
max-height: 400px;
}
}
.download-contents {
position: absolute;
bottom: 10px;
right: 10px;
cursor: pointer;
background: #7d8293;
text-align: center;
padding: 5px;
border-radius: 4px;
font-family: 'Titillium Web', sans-serif;
font-weight: 600;
color: white;
font-size: 14px;
height: 30px;
width: 75px;
}
.scheme-container
{
margin: 0 0 20px 0;