nillud-data-table 1.0.5 → 1.0.6

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/README.md CHANGED
@@ -40,6 +40,9 @@ const data = [{ name: 'Иван' }]
40
40
  import { DataTable } from 'nillud-data-table'
41
41
  import 'nillud-data-table/styles.css'
42
42
 
43
+ import ExportExcel from 'nillud-data-table/export/ExportExcel';
44
+ import WordExport from 'nillud-data-table/export/WordExport';
45
+
43
46
  const columns = [{ field: 'name', title: 'Имя' }]
44
47
  const data = [{ name: 'Иван' }]
45
48
 
@@ -55,6 +58,8 @@ const data = [{ name: 'Иван' }]
55
58
  scrollHeight={410}
56
59
  excelBtn
57
60
  wordBtn
61
+ WordExportComponent={WordExport}
62
+ ExportExcelComponent={ExportExcel}
58
63
  downloadSectionLeftSideContent={<button className='base-button' onClick={() => setCanvas(true)}>OffCanvas</button>}
59
64
  excelCustomColumns={[
60
65
  {
@@ -440,6 +445,17 @@ npm i exceljs
440
445
  yarn add exceljs
441
446
  ```
442
447
 
448
+ ```tsx
449
+ import ExportExcel from 'nillud-data-table/export/ExportExcel';
450
+
451
+ <DataTable>
452
+ ...
453
+ excelBtn
454
+ ExportExcelComponent={ExportExcel}
455
+ ...
456
+ </DataTable>
457
+ ```
458
+
443
459
  ### wordBtn
444
460
 
445
461
  Необязательный параметр. Тип **boolean**, по умолчанию **false**. При значении **true** над таблицей с правой стороны появляется кнопка экспорта Word, которая по умолчанию принимает в себя исходный массив **tableData**
@@ -452,6 +468,17 @@ npm i docx file-saver
452
468
  yarn add docx file-saver
453
469
  ```
454
470
 
471
+ ```tsx
472
+ import WordExport from 'nillud-data-table/export/WordExport';
473
+
474
+ <DataTable>
475
+ ...
476
+ wordBtn
477
+ WordExportComponent={WordExport}
478
+ ...
479
+ </DataTable>
480
+ ```
481
+
455
482
  ### wordOptions
456
483
 
457
484
  Необязательный параметр. Используется вместе с **wordBtn**. Принимает в себя объект
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import React, { ReactElement } from 'react';
1
+ import React$1, { ReactElement } from 'react';
2
2
 
3
3
  type TableElement = {
4
4
  [key: string]: string | number;
@@ -46,12 +46,25 @@ type TableProps = {
46
46
  groupBy?: string | null;
47
47
  isTitles?: boolean;
48
48
  wordOptions?: ExportOptions;
49
+ WordExportComponent?: React.ComponentType<{
50
+ wordData: TableData;
51
+ columns: Array<Column>;
52
+ title: string;
53
+ options?: ExportOptions;
54
+ exportCustomColumns?: TableProps["exportCustomColumns"];
55
+ }>;
56
+ ExportExcelComponent?: React.ComponentType<{
57
+ excelData: TableData;
58
+ columns: Array<Column>;
59
+ title: string;
60
+ exportCustomColumns?: TableProps["exportCustomColumns"];
61
+ }>;
49
62
  };
50
63
  type DataTableRef = {
51
64
  getData: () => TableData;
52
65
  getCurrentData: () => TableData;
53
66
  };
54
67
 
55
- declare const DataTable: React.ForwardRefExoticComponent<TableProps & React.RefAttributes<DataTableRef>>;
68
+ declare const DataTable: React$1.ForwardRefExoticComponent<TableProps & React$1.RefAttributes<DataTableRef>>;
56
69
 
57
70
  export { type Column, DataTable, type TableElement, type TableProps };
package/dist/index.js CHANGED
@@ -393,228 +393,25 @@ function useDebouncedEffect(callback, deps, delay) {
393
393
  }, [...deps, delay]);
394
394
  }
395
395
 
396
- // utils/exportUtils/ExportHelpers.ts
397
- function prepareExportRows(columns, data) {
398
- return data.map(
399
- (row) => columns.map((col) => {
400
- const value = row[col.field];
401
- return typeof col.exportCustomCell !== "undefined" ? col.exportCustomCell(String(value), row) : String(value != null ? value : "");
402
- })
403
- );
404
- }
405
- function prepareExportHeaders(columns) {
406
- return columns.map((col) => col.title);
407
- }
408
-
409
- // components/export/WordExport.tsx
410
- import { jsx as jsx13 } from "react/jsx-runtime";
411
- var WordExport = ({
412
- wordData,
396
+ // components/ExportSection.tsx
397
+ import { Fragment as Fragment2, jsx as jsx13, jsxs as jsxs5 } from "react/jsx-runtime";
398
+ var ExportSection = ({
399
+ wordBtn,
400
+ excelBtn,
401
+ downloadSectionLeftSideContent,
402
+ tableData,
413
403
  columns,
414
- title,
415
- options = {
416
- fontSize: 20,
417
- boldHeaders: false,
418
- autoLandscape: false,
419
- maxColumnsBeforeLandscape: 5
420
- }
421
- // exportCustomColumns
404
+ tableName,
405
+ exportCustomColumns,
406
+ wordOptions,
407
+ WordExportComponent,
408
+ ExportExcelComponent
422
409
  }) => {
423
- const createNewWord = async () => {
424
- const {
425
- AlignmentType,
426
- Document,
427
- Packer,
428
- PageOrientation,
429
- // PageOrientation,
430
- Paragraph,
431
- Table,
432
- TableCell,
433
- TableRow,
434
- TextRun,
435
- VerticalAlign,
436
- WidthType
437
- } = await import("docx");
438
- const { saveAs } = await import("file-saver");
439
- const {
440
- fontSize = 0,
441
- boldHeaders = true,
442
- autoLandscape = true,
443
- maxColumnsBeforeLandscape = 5
444
- } = options;
445
- const isLandscape = autoLandscape && columns.length > maxColumnsBeforeLandscape;
446
- const headerCells = prepareExportHeaders(columns).map((header) => new TableCell({
447
- children: [new Paragraph({
448
- children: [new TextRun({
449
- text: header,
450
- size: fontSize,
451
- bold: boldHeaders
452
- })],
453
- alignment: AlignmentType.CENTER
454
- })],
455
- verticalAlign: VerticalAlign.CENTER
456
- }));
457
- const tableHeaderRow = new TableRow({ children: headerCells });
458
- const rows = prepareExportRows(columns, wordData).map((cells) => {
459
- const rowCells = cells.map(
460
- (value) => new TableCell({
461
- children: [new Paragraph({
462
- children: [new TextRun({
463
- text: value,
464
- size: fontSize
465
- })],
466
- alignment: AlignmentType.CENTER
467
- })],
468
- verticalAlign: VerticalAlign.CENTER
469
- })
470
- );
471
- return new TableRow({ children: rowCells });
472
- });
473
- const table = new Table({
474
- rows: [tableHeaderRow, ...rows],
475
- width: { size: 11e3, type: WidthType.DXA },
476
- indent: { size: -1e3, type: WidthType.DXA }
477
- });
478
- const doc = new Document({
479
- sections: [{
480
- children: [table, new Paragraph({ text: "" })],
481
- properties: isLandscape ? { page: { size: { orientation: PageOrientation.LANDSCAPE } } } : {}
482
- }]
483
- });
484
- Packer.toBlob(doc).then((blob) => {
485
- saveAs(blob, `${title}.docx`);
486
- });
487
- };
488
- return /* @__PURE__ */ jsx13("button", { className: `ndt-buttonExport ndt-Word}`, onClick: createNewWord, children: "\u0421\u043A\u0430\u0447\u0430\u0442\u044C Word" });
489
- };
490
- var WordExport_default = WordExport;
491
-
492
- // utils/exportUtils/exportUtils.ts
493
- var generateExcelColumns = (columns, exportCustomColumns) => {
494
- let excelColumns = columns.map((column) => ({
495
- header: column.title,
496
- key: column.field,
497
- width: 20
498
- }));
499
- if (exportCustomColumns) {
500
- exportCustomColumns.forEach((custom) => {
501
- excelColumns = excelColumns.map(
502
- (col) => col.key === custom.key ? { ...col, ...custom } : col
503
- );
504
- });
505
- }
506
- return excelColumns;
507
- };
508
- var applyHeaderStyles = (row, columnCount) => {
509
- row.height = 40;
510
- row.font = { size: 12, bold: true };
511
- row.alignment = { vertical: "middle", horizontal: "center" };
512
- for (let i = 1; i <= columnCount; i++) {
513
- const cell = row.getCell(i);
514
- cell.alignment = { wrapText: true, vertical: "middle", horizontal: "center" };
515
- cell.border = {
516
- top: { style: "thin" },
517
- left: { style: "thin" },
518
- bottom: { style: "thin" },
519
- right: { style: "thin" }
520
- };
521
- }
522
- };
523
- var applyRowStyles = (row, columnCount) => {
524
- row.height = 40;
525
- row.font = { size: 12 };
526
- row.alignment = { vertical: "middle", horizontal: "center" };
527
- for (let i = 1; i <= columnCount; i++) {
528
- const cell = row.getCell(i);
529
- cell.alignment = { wrapText: true, vertical: "middle", horizontal: "center" };
530
- cell.border = {
531
- top: { style: "thin" },
532
- left: { style: "thin" },
533
- bottom: { style: "thin" },
534
- right: { style: "thin" }
535
- };
536
- }
537
- };
538
- var generateExcelDataRows = (columns, data) => {
539
- return data.map((element) => {
540
- const rowData = {};
541
- columns.forEach((col) => {
542
- const value = element[col.field];
543
- rowData[col.field] = typeof col.exportCustomCell !== "undefined" ? col.exportCustomCell(String(value), element) : value != null ? value : "";
544
- });
545
- return rowData;
546
- });
547
- };
548
- var setColumnAutoWidths = (sheet) => {
549
- var _a;
550
- (_a = sheet.columns) == null ? void 0 : _a.forEach((column) => {
551
- var _a2;
552
- let maxLength = 10;
553
- (_a2 = column.eachCell) == null ? void 0 : _a2.call(column, { includeEmpty: true }, (cell) => {
554
- const cellValue = cell.value ? String(cell.value) : "";
555
- maxLength = Math.max(maxLength, cellValue.length + 5);
556
- });
557
- column.width = maxLength;
558
- });
559
- };
560
-
561
- // components/export/ExportExcel.tsx
562
- import { jsx as jsx14 } from "react/jsx-runtime";
563
- var ExportExcel = ({ columns, excelData, title, exportCustomColumns }) => {
564
- const exportExcel = async () => {
565
- const ExcelJS = await import("exceljs");
566
- const workbook = new ExcelJS.Workbook();
567
- const sheet = workbook.addWorksheet(title, {
568
- pageSetup: {
569
- fitToPage: true,
570
- fitToHeight: 2,
571
- fitToWidth: 1,
572
- orientation: "landscape"
573
- },
574
- headerFooter: {
575
- oddFooter: "\u0421\u0442\u0440\u0430\u043D\u0438\u0446\u0430 &P \u0438\u0437 &N",
576
- evenFooter: "\u0421\u0442\u0440\u0430\u043D\u0438\u0446\u0430 &P \u0438\u0437 &N"
577
- }
578
- });
579
- const excelColumns = generateExcelColumns(columns, exportCustomColumns);
580
- sheet.columns = excelColumns;
581
- const headerRow = sheet.getRow(1);
582
- applyHeaderStyles(headerRow, sheet.columns.length);
583
- const dataRows = generateExcelDataRows(columns, excelData);
584
- dataRows.forEach((data) => {
585
- const row = sheet.addRow(data);
586
- applyRowStyles(row, sheet.columns.length);
587
- });
588
- setColumnAutoWidths(sheet);
589
- if (excelData.length > 15) {
590
- sheet.pageSetup.fitToHeight = Math.floor(excelData.length / 15);
591
- } else {
592
- sheet.pageSetup.fitToHeight = 1;
593
- }
594
- workbook.xlsx.writeBuffer().then((data) => {
595
- const blob = new Blob([data], {
596
- type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
597
- });
598
- const url = window.URL.createObjectURL(blob);
599
- const anchor = document.createElement("a");
600
- anchor.href = url;
601
- anchor.download = `${title}.xlsx`;
602
- anchor.click();
603
- window.URL.revokeObjectURL(url);
604
- });
605
- };
606
- return /* @__PURE__ */ jsx14("button", { className: `ndt-buttonExport ndt-Excel`, onClick: exportExcel, children: "\u0421\u043A\u0430\u0447\u0430\u0442\u044C Excel" });
607
- };
608
- var ExportExcel_default = ExportExcel;
609
-
610
- // components/ExportSection.tsx
611
- import { Fragment as Fragment2, jsx as jsx15, jsxs as jsxs5 } from "react/jsx-runtime";
612
- var ExportSection = ({ wordBtn, excelBtn, downloadSectionLeftSideContent, tableData, columns, tableName, exportCustomColumns, wordOptions }) => {
613
- return /* @__PURE__ */ jsx15(Fragment2, { children: /* @__PURE__ */ jsxs5("div", { className: "ndt-download-section", children: [
614
- /* @__PURE__ */ jsx15("div", { className: "ndt-download-content", children: (wordBtn || excelBtn) && downloadSectionLeftSideContent !== null && downloadSectionLeftSideContent }),
410
+ return /* @__PURE__ */ jsx13(Fragment2, { children: /* @__PURE__ */ jsxs5("div", { className: "ndt-download-section", children: [
411
+ /* @__PURE__ */ jsx13("div", { className: "ndt-download-content", children: (wordBtn || excelBtn) && downloadSectionLeftSideContent !== null && downloadSectionLeftSideContent }),
615
412
  /* @__PURE__ */ jsxs5("div", { className: "ndt-download-buttons", children: [
616
- wordBtn && /* @__PURE__ */ jsx15(
617
- WordExport_default,
413
+ wordBtn && WordExportComponent && /* @__PURE__ */ jsx13(
414
+ WordExportComponent,
618
415
  {
619
416
  wordData: tableData,
620
417
  columns,
@@ -623,8 +420,8 @@ var ExportSection = ({ wordBtn, excelBtn, downloadSectionLeftSideContent, tableD
623
420
  options: wordOptions
624
421
  }
625
422
  ),
626
- excelBtn && /* @__PURE__ */ jsx15(
627
- ExportExcel_default,
423
+ excelBtn && ExportExcelComponent && /* @__PURE__ */ jsx13(
424
+ ExportExcelComponent,
628
425
  {
629
426
  excelData: tableData,
630
427
  columns,
@@ -638,7 +435,7 @@ var ExportSection = ({ wordBtn, excelBtn, downloadSectionLeftSideContent, tableD
638
435
  var ExportSection_default = ExportSection;
639
436
 
640
437
  // components/DataTable.tsx
641
- import { jsx as jsx16, jsxs as jsxs6 } from "react/jsx-runtime";
438
+ import { jsx as jsx14, jsxs as jsxs6 } from "react/jsx-runtime";
642
439
  var DataTable = forwardRef(({
643
440
  tableData,
644
441
  columns,
@@ -656,7 +453,9 @@ var DataTable = forwardRef(({
656
453
  headerGroup = null,
657
454
  groupBy = null,
658
455
  isTitles = false,
659
- wordOptions
456
+ wordOptions,
457
+ WordExportComponent,
458
+ ExportExcelComponent
660
459
  }, ref) => {
661
460
  const [filters, setFilters] = useState({});
662
461
  const [sortBy, setSortBy] = useState({ col: "", type: "asc" });
@@ -733,7 +532,7 @@ var DataTable = forwardRef(({
733
532
  getCurrentData: () => displayData
734
533
  }), [processedData, displayData]);
735
534
  return /* @__PURE__ */ jsxs6("div", { className: "ndt-table-container", children: [
736
- (wordBtn || excelBtn) && /* @__PURE__ */ jsx16(
535
+ (wordBtn || excelBtn) && /* @__PURE__ */ jsx14(
737
536
  ExportSection_default,
738
537
  {
739
538
  wordBtn,
@@ -743,11 +542,13 @@ var DataTable = forwardRef(({
743
542
  columns,
744
543
  tableName,
745
544
  exportCustomColumns,
746
- wordOptions
545
+ wordOptions,
546
+ WordExportComponent,
547
+ ExportExcelComponent
747
548
  }
748
549
  ),
749
550
  /* @__PURE__ */ jsxs6("div", { className: "ndt-table", children: [
750
- /* @__PURE__ */ jsx16(
551
+ /* @__PURE__ */ jsx14(
751
552
  TableHeader_default,
752
553
  {
753
554
  columns,
@@ -759,7 +560,7 @@ var DataTable = forwardRef(({
759
560
  headerGroup
760
561
  }
761
562
  ),
762
- loading ? loadingElement !== null ? loadingElement : /* @__PURE__ */ jsx16("span", { style: { marginLeft: 10, fontWeight: "bold" }, children: "\u0417\u0430\u0433\u0440\u0443\u0437\u043A\u0430 \u0434\u0430\u043D\u043D\u044B\u0445..." }) : /* @__PURE__ */ jsx16(
563
+ loading ? loadingElement !== null ? loadingElement : /* @__PURE__ */ jsx14("span", { style: { marginLeft: 10, fontWeight: "bold" }, children: "\u0417\u0430\u0433\u0440\u0443\u0437\u043A\u0430 \u0434\u0430\u043D\u043D\u044B\u0445..." }) : /* @__PURE__ */ jsx14(
763
564
  TableBody_default,
764
565
  {
765
566
  tableData: displayData,
@@ -773,7 +574,7 @@ var DataTable = forwardRef(({
773
574
  isTitles
774
575
  }
775
576
  ),
776
- isFooter && /* @__PURE__ */ jsx16(
577
+ isFooter && /* @__PURE__ */ jsx14(
777
578
  TableFooter_default,
778
579
  {
779
580
  paginationCounts,
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "nillud-data-table",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "type": "module",
5
- "main": "./dist/index.cjs",
5
+ "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
8
8
  "style": "./dist/styles.css",
@@ -13,6 +13,8 @@
13
13
  ".": {
14
14
  "import": "./dist/index.js"
15
15
  },
16
+ "./export/ExportExcel": "./dist/components/export/ExportExcel.js",
17
+ "./export/WordExport": "./dist/components/export/WordExport.js",
16
18
  "./types": "./dist/index.d.ts",
17
19
  "./styles.css": "./dist/styles.css"
18
20
  },
@@ -35,4 +37,4 @@
35
37
  "build": "tsup && npm run build:styles",
36
38
  "build:styles": "node build-styles.js"
37
39
  }
38
- }
40
+ }