diff --git a/index.js b/index.js index 27bb0f1..15efc89 100644 --- a/index.js +++ b/index.js @@ -29,13 +29,15 @@ var propTypes = { sheet: _propTypes2.default.string.isRequired, id: _propTypes2.default.string, className: _propTypes2.default.string, - buttonText: _propTypes2.default.string + buttonText: _propTypes2.default.string, + autoDownload: _propTypes2.default.bool }; var defaultProps = { id: 'button-download-as-xls', className: 'button-download', - buttonText: 'Download' + buttonText: 'Download', + autoDownload: false }; var ReactHTMLTableToExcel = function (_Component) { @@ -51,6 +53,11 @@ var ReactHTMLTableToExcel = function (_Component) { } _createClass(ReactHTMLTableToExcel, [{ + key: 'componentDidMount', + value: function componentDidMount() { + if (this.props.autoDownload) this.handleDownload(); + } + }, { key: 'handleDownload', value: function handleDownload() { if (!document) { @@ -104,6 +111,7 @@ var ReactHTMLTableToExcel = function (_Component) { }, { key: 'render', value: function render() { + if (this.props.autoDownload) return null; return _react2.default.createElement( 'button', { diff --git a/src/ReactHTMLTableToExcel.jsx b/src/ReactHTMLTableToExcel.jsx index fd32011..cd6545a 100644 --- a/src/ReactHTMLTableToExcel.jsx +++ b/src/ReactHTMLTableToExcel.jsx @@ -9,12 +9,14 @@ const propTypes = { id: PropTypes.string, className: PropTypes.string, buttonText: PropTypes.string, + autoDownload: PropTypes.bool, }; const defaultProps = { id: 'button-download-as-xls', className: 'button-download', buttonText: 'Download', + autoDownload: false, }; class ReactHTMLTableToExcel extends Component { @@ -23,6 +25,10 @@ class ReactHTMLTableToExcel extends Component { this.handleDownload = this.handleDownload.bind(this); } + componentDidMount() { + if (this.props.autoDownload) this.handleDownload(); + } + static base64(s) { return window.btoa(unescape(encodeURIComponent(s))); } @@ -94,6 +100,7 @@ class ReactHTMLTableToExcel extends Component { } render() { + if (this.props.autoDownload) return null; return (