dce-reactkit 4.1.2 → 4.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.js +13 -6
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/components/CSVDownloadButton.d.ts +1 -0
- package/dist/cjs/types/helpers/genCSV.d.ts +5 -1
- package/dist/esm/index.js +13 -6
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/types/components/CSVDownloadButton.d.ts +1 -0
- package/dist/esm/types/helpers/genCSV.d.ts +5 -1
- package/dist/index.d.ts +6 -1
- package/package.json +1 -1
- package/src/components/CSVDownloadButton.tsx +4 -1
- package/src/helpers/genCSV.test.ts +18 -4
- package/src/helpers/genCSV.ts +12 -5
package/dist/cjs/index.js
CHANGED
|
@@ -3929,7 +3929,10 @@ const escapeCellText = (text) => {
|
|
|
3929
3929
|
* Generate a CSV file
|
|
3930
3930
|
* @author Gabe Abrams
|
|
3931
3931
|
* @param data list of row data in the form of json objects
|
|
3932
|
-
* @param columns list of columns to include in the csv
|
|
3932
|
+
* @param columns list of columns to include in the csv where each column is an object with:
|
|
3933
|
+
* - title: the column title
|
|
3934
|
+
* - param: the key in the data object to use for this column
|
|
3935
|
+
* - textIfUndefined: optional text to use if the value is undefined (defaults to empty string)
|
|
3933
3936
|
* @returns multiline csv string
|
|
3934
3937
|
*/
|
|
3935
3938
|
const genCSV = (data, columns) => {
|
|
@@ -3945,16 +3948,20 @@ const genCSV = (data, columns) => {
|
|
|
3945
3948
|
csv += '\n';
|
|
3946
3949
|
csv += (columns
|
|
3947
3950
|
.map((column) => {
|
|
3951
|
+
var _a;
|
|
3948
3952
|
let contents;
|
|
3949
3953
|
const cell = datum[column.param];
|
|
3950
3954
|
if (typeof cell === 'string'
|
|
3951
|
-
|| typeof cell === 'number'
|
|
3955
|
+
|| typeof cell === 'number'
|
|
3956
|
+
|| typeof cell === 'boolean') {
|
|
3952
3957
|
contents = String(cell);
|
|
3953
3958
|
}
|
|
3954
|
-
else if (
|
|
3955
|
-
|| cell === null) {
|
|
3959
|
+
else if (cell === null) {
|
|
3956
3960
|
contents = '';
|
|
3957
3961
|
}
|
|
3962
|
+
else if (typeof cell === 'undefined') {
|
|
3963
|
+
contents = ((_a = column.textIfUndefined) !== null && _a !== void 0 ? _a : '');
|
|
3964
|
+
}
|
|
3958
3965
|
else if (typeof cell === 'object') {
|
|
3959
3966
|
contents = JSON.stringify(cell);
|
|
3960
3967
|
}
|
|
@@ -3982,7 +3989,7 @@ const CSVDownloadButton = (props) => {
|
|
|
3982
3989
|
/*------------------------------------------------------------------------*/
|
|
3983
3990
|
/* -------------- Props ------------- */
|
|
3984
3991
|
// Destructure all props
|
|
3985
|
-
const { filename, csv, id, className, ariaLabel, style, onClick, children, } = props;
|
|
3992
|
+
const { filename, csv, id, className, ariaLabel, style, onClick, children, label = 'Download CSV', } = props;
|
|
3986
3993
|
/*------------------------------------------------------------------------*/
|
|
3987
3994
|
/* ------------------------------- Render ------------------------------- */
|
|
3988
3995
|
/*------------------------------------------------------------------------*/
|
|
@@ -3996,7 +4003,7 @@ const CSVDownloadButton = (props) => {
|
|
|
3996
4003
|
!children && (React__default["default"].createElement(React__default["default"].Fragment, null,
|
|
3997
4004
|
React__default["default"].createElement(reactFontawesome.FontAwesomeIcon, { icon: freeSolidSvgIcons.faCloudDownloadAlt }),
|
|
3998
4005
|
' ',
|
|
3999
|
-
|
|
4006
|
+
label)),
|
|
4000
4007
|
children));
|
|
4001
4008
|
};
|
|
4002
4009
|
|