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