diff --git a/package.json b/package.json index a0ce4a62..5d77ce43 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "getbase": "^2.8.2", "ieee754": "^1.1.8", "immutable": "^3.x.x", + "js-file-download": "^0.4.1", "js-yaml": "^3.5.5", "lodash": "4.17.5", "matcher": "^0.1.2", diff --git a/src/core/components/highlight-code.jsx b/src/core/components/highlight-code.jsx index e0c3c461..22ed061e 100644 --- a/src/core/components/highlight-code.jsx +++ b/src/core/components/highlight-code.jsx @@ -1,11 +1,13 @@ import React, { Component } from "react" import PropTypes from "prop-types" import { highlight } from "core/utils" +import saveAs from "js-file-download" export default class HighlightCode extends Component { static propTypes = { value: PropTypes.string.isRequired, - className: PropTypes.string + className: PropTypes.string, + downloadable: PropTypes.bool } componentDidMount() { @@ -20,10 +22,46 @@ export default class HighlightCode extends Component { this.el = c } + downloadText = () => { + saveAs(this.props.value, "response.txt") + } + + 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 + let { value, className, downloadable } = this.props className = className || "" - return
{ value }
+ return (
+
+ {value}
+
+