diff --git a/README.md b/README.md index d1921a5..7a9dc73 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Property | Type | Description **id** | *string* | ID attribute of button element. **className** | *string* | Class attribute of button element. **buttonText** | *string* | Button text. - +**children** | *element* | Child elements to render instead of the button text. ## Example diff --git a/package.json b/package.json index 3d6892f..1b42d3a 100644 --- a/package.json +++ b/package.json @@ -1,13 +1,13 @@ { "name": "react-html-table-to-excel", - "version": "2.0.0", + "version": "3.0.0", "description": "Small react component for converting and downloading HTML table to Excel file", "main": "index.js", "scripts": { "build": "./node_modules/.bin/babel ./src/ReactHTMLTableToExcel.jsx -o index.js", "prepublish": "npm run build", - "client:test": "NODE_ENV=test jest", - "client:test:watch": "NODE_ENV=test jest --watch" + "client:test": "jest", + "client:test:watch": "jest --watch" }, "repository": { "type": "git", @@ -39,7 +39,7 @@ ] }, "peerDependencies": { - "react": "^15.x.x" + "react": "^16.x.x" }, "devDependencies": { "babel-cli": "^6.24.1", @@ -48,20 +48,21 @@ "babel-preset-react": "^6.24.1", "babel-preset-stage-0": "^6.24.1", "chai": "^3.5.0", - "chai-enzyme": "^0.6.1", - "enzyme": "^2.8.2", - "eslint": "^3.19.0", - "eslint-config-airbnb": "^14.1.0", + "chai-enzyme": "^1.0.0-beta.1", + "enzyme": "^3.11.0", + "enzyme-adapter-react-16": "^1.15.6", + "eslint": "^8.18.0", + "eslint-config-airbnb": "^19.0.4", "eslint-plugin-import": "^2.2.0", - "eslint-plugin-jsx-a11y": "^5.0.1", - "eslint-plugin-react": "^7.0.0", - "jest": "^20.0.1", - "react": "^15.5.4", - "react-dom": "^15.5.4", - "react-test-renderer": "^15.5.4", + "eslint-plugin-jsx-a11y": "^6.6.0", + "eslint-plugin-react": "^7.30.1", + "jest": "^20.0.4", + "react": "^16.14.0", + "react-dom": "^16.14.0", + "react-test-renderer": "^16.14.0", "sinon": "^2.2.0" }, "dependencies": { - "prop-types": "^15.5.10" + "prop-types": "^15.8.1" } } \ No newline at end of file diff --git a/src/ReactHTMLTableToExcel.jsx b/src/ReactHTMLTableToExcel.jsx index 4d66866..271ef50 100644 --- a/src/ReactHTMLTableToExcel.jsx +++ b/src/ReactHTMLTableToExcel.jsx @@ -5,6 +5,7 @@ import PropTypes from 'prop-types'; const propTypes = { table: PropTypes.string.isRequired, filename: PropTypes.string.isRequired, + filetype: PropTypes.string, sheet: PropTypes.string.isRequired, id: PropTypes.string, className: PropTypes.string, @@ -50,7 +51,9 @@ class ReactHTMLTableToExcel extends Component { const table = document.getElementById(this.props.table).outerHTML; const sheet = String(this.props.sheet); - const filename = `${String(this.props.filename)}.xlsx`; + const filetype = String((this.props.filetype)?(this.props.filetype === 'xlsx'?'xlsx':'xls'):'xls') + const filename = `${String(this.props.filename) + '.' + filetype}`; + const uri = 'data:application/vnd.ms-excel;base64,'; const template = @@ -101,7 +104,7 @@ class ReactHTMLTableToExcel extends Component { type="button" onClick={this.handleDownload} > - {this.props.buttonText} + {this.props.children ? this.props.children : this.props.buttonText} ); } diff --git a/test/index.test.js b/test/index.test.js index 734604e..d1e4c97 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -1,10 +1,14 @@ import React from 'react'; import chai, { expect } from 'chai'; import chaiEnzyme from 'chai-enzyme'; +import { configure } from 'enzyme'; +import Adapter from 'enzyme-adapter-react-16'; import { shallow } from 'enzyme'; import sinon from 'sinon'; import ReactHTMLTableToExcel from '../src/ReactHTMLTableToExcel'; +configure({ adapter: new Adapter() }); + chai.use(chaiEnzyme()); const props = {