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.
@@ -6,6 +6,7 @@ import React from 'react';
6
6
  type Props = {
7
7
  filename: string;
8
8
  csv: string;
9
+ label?: string;
9
10
  id?: string;
10
11
  className?: string;
11
12
  ariaLabel?: string;
@@ -2,7 +2,10 @@
2
2
  * Generate a CSV file
3
3
  * @author Gabe Abrams
4
4
  * @param data list of row data in the form of json objects
5
- * @param columns list of columns to include in the csv
5
+ * @param columns list of columns to include in the csv where each column is an object with:
6
+ * - title: the column title
7
+ * - param: the key in the data object to use for this column
8
+ * - textIfUndefined: optional text to use if the value is undefined (defaults to empty string)
6
9
  * @returns multiline csv string
7
10
  */
8
11
  declare const genCSV: (data: {
@@ -10,5 +13,6 @@ declare const genCSV: (data: {
10
13
  }[], columns: {
11
14
  title: string;
12
15
  param: string;
16
+ textIfUndefined?: string;
13
17
  }[]) => string;
14
18
  export default genCSV;
package/dist/esm/index.js CHANGED
@@ -3902,7 +3902,10 @@ const escapeCellText = (text) => {
3902
3902
  * Generate a CSV file
3903
3903
  * @author Gabe Abrams
3904
3904
  * @param data list of row data in the form of json objects
3905
- * @param columns list of columns to include in the csv
3905
+ * @param columns list of columns to include in the csv where each column is an object with:
3906
+ * - title: the column title
3907
+ * - param: the key in the data object to use for this column
3908
+ * - textIfUndefined: optional text to use if the value is undefined (defaults to empty string)
3906
3909
  * @returns multiline csv string
3907
3910
  */
3908
3911
  const genCSV = (data, columns) => {
@@ -3918,16 +3921,20 @@ const genCSV = (data, columns) => {
3918
3921
  csv += '\n';
3919
3922
  csv += (columns
3920
3923
  .map((column) => {
3924
+ var _a;
3921
3925
  let contents;
3922
3926
  const cell = datum[column.param];
3923
3927
  if (typeof cell === 'string'
3924
- || typeof cell === 'number') {
3928
+ || typeof cell === 'number'
3929
+ || typeof cell === 'boolean') {
3925
3930
  contents = String(cell);
3926
3931
  }
3927
- else if (typeof cell === 'undefined'
3928
- || cell === null) {
3932
+ else if (cell === null) {
3929
3933
  contents = '';
3930
3934
  }
3935
+ else if (typeof cell === 'undefined') {
3936
+ contents = ((_a = column.textIfUndefined) !== null && _a !== void 0 ? _a : '');
3937
+ }
3931
3938
  else if (typeof cell === 'object') {
3932
3939
  contents = JSON.stringify(cell);
3933
3940
  }
@@ -3955,7 +3962,7 @@ const CSVDownloadButton = (props) => {
3955
3962
  /*------------------------------------------------------------------------*/
3956
3963
  /* -------------- Props ------------- */
3957
3964
  // Destructure all props
3958
- const { filename, csv, id, className, ariaLabel, style, onClick, children, } = props;
3965
+ const { filename, csv, id, className, ariaLabel, style, onClick, children, label = 'Download CSV', } = props;
3959
3966
  /*------------------------------------------------------------------------*/
3960
3967
  /* ------------------------------- Render ------------------------------- */
3961
3968
  /*------------------------------------------------------------------------*/
@@ -3969,7 +3976,7 @@ const CSVDownloadButton = (props) => {
3969
3976
  !children && (React__default.createElement(React__default.Fragment, null,
3970
3977
  React__default.createElement(FontAwesomeIcon, { icon: faCloudDownloadAlt }),
3971
3978
  ' ',
3972
- "Download CSV")),
3979
+ label)),
3973
3980
  children));
3974
3981
  };
3975
3982