@omniumretail/component-library 1.1.7 → 1.1.9
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/bundle.js +1 -1
- package/dist/types/components/ExportTableData/ExportTableData.stories.d.ts +4 -0
- package/dist/types/components/ExportTableData/index.d.ts +9 -0
- package/dist/types/components/index.d.ts +1 -0
- package/package.json +3 -2
- package/src/components/ExportTableData/ExportTableData.stories.tsx +44 -0
- package/src/components/ExportTableData/index.tsx +34 -0
- package/src/components/Table/Table.stories.tsx +1 -1
- package/src/components/index.tsx +1 -0
- package/src/locales/en.json +53 -53
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
interface TableExportButtonProps {
|
|
2
|
+
data: Record<string, any>[];
|
|
3
|
+
fileName: string;
|
|
4
|
+
buttonText: string;
|
|
5
|
+
customClass?: string;
|
|
6
|
+
columnTranslations: Record<string, string>;
|
|
7
|
+
}
|
|
8
|
+
export declare const TableExportButton: (props: TableExportButtonProps) => import("react/jsx-runtime").JSX.Element;
|
|
9
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@omniumretail/component-library",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.09",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "dist/bundle.js",
|
|
6
6
|
"typings": "./dist/types/index",
|
|
@@ -63,7 +63,8 @@
|
|
|
63
63
|
"terser-webpack-plugin": "^5.2.5",
|
|
64
64
|
"typescript": "^4.9.3",
|
|
65
65
|
"url-loader": "^4.1.1",
|
|
66
|
-
"web-vitals": "^2.1.0"
|
|
66
|
+
"web-vitals": "^2.1.0",
|
|
67
|
+
"xlsx": "^0.18.5"
|
|
67
68
|
},
|
|
68
69
|
"scripts": {
|
|
69
70
|
"prepublish": "rm -rf ./dist && npm run build",
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Meta, Story } from '@storybook/react';
|
|
3
|
+
import { TableExportButton } from './index';
|
|
4
|
+
|
|
5
|
+
export default {
|
|
6
|
+
title: 'TableExportButton',
|
|
7
|
+
component: TableExportButton,
|
|
8
|
+
} as Meta;
|
|
9
|
+
|
|
10
|
+
const columnTranslations = {
|
|
11
|
+
id: 'ID',
|
|
12
|
+
name: 'Nome',
|
|
13
|
+
age: 'Idade',
|
|
14
|
+
occupation: 'Ocupação'
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const Template: Story<any> = (args) => <TableExportButton {...args} />;
|
|
18
|
+
|
|
19
|
+
export const ExportButton = Template.bind({});
|
|
20
|
+
ExportButton.args = {
|
|
21
|
+
data: [
|
|
22
|
+
{
|
|
23
|
+
id: 1,
|
|
24
|
+
name: 'John Doe',
|
|
25
|
+
age: 30,
|
|
26
|
+
occupation: 'Software Developer'
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
id: 2,
|
|
30
|
+
name: 'Jane Smith',
|
|
31
|
+
age: 28,
|
|
32
|
+
occupation: 'Data Scientist'
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
id: 3,
|
|
36
|
+
name: 'Michael Johnson',
|
|
37
|
+
age: 35,
|
|
38
|
+
occupation: 'Project Manager'
|
|
39
|
+
},
|
|
40
|
+
],
|
|
41
|
+
fileName: 'table_data',
|
|
42
|
+
buttonText: 'exportar',
|
|
43
|
+
columnTranslations: columnTranslations
|
|
44
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import * as XLSX from 'xlsx';
|
|
3
|
+
import { Button } from '../Button';
|
|
4
|
+
|
|
5
|
+
interface TableExportButtonProps {
|
|
6
|
+
data: Record<string, any>[];
|
|
7
|
+
fileName: string;
|
|
8
|
+
buttonText: string;
|
|
9
|
+
customClass?: string;
|
|
10
|
+
columnTranslations: Record<string, string>;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export const TableExportButton = (props: TableExportButtonProps) => {
|
|
14
|
+
const exportToXLS = () => {
|
|
15
|
+
const wb = XLSX.utils.book_new();
|
|
16
|
+
const ws = XLSX.utils.json_to_sheet(props.data);
|
|
17
|
+
|
|
18
|
+
// Aplicar estilos às células do cabeçalho
|
|
19
|
+
const headerKeys = Object.keys(props.columnTranslations);
|
|
20
|
+
headerKeys.forEach((key, index) => {
|
|
21
|
+
const cellAddress = XLSX.utils.encode_cell({ c: index, r: 0 });
|
|
22
|
+
ws[cellAddress].v = props.columnTranslations[key]; // Substituir o valor pela tradução
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');
|
|
26
|
+
XLSX.writeFile(wb, `${props.fileName}.xlsx`);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
return (
|
|
30
|
+
<Button onClick={exportToXLS} className={props.customClass}>
|
|
31
|
+
{props.buttonText}
|
|
32
|
+
</Button>
|
|
33
|
+
);
|
|
34
|
+
};
|
|
@@ -23,7 +23,7 @@ const Template: Story<TableCustomProps> = (args) => {
|
|
|
23
23
|
return <Table scroll={{y: 1000, x: 3000}} fixedColumns={[
|
|
24
24
|
{ dataIndex: 'name', side: 'left' },
|
|
25
25
|
{ dataIndex: 'mecanographicNumber', side: 'left' },
|
|
26
|
-
]} customColumnWidths={[{columnName: 'name', width: "
|
|
26
|
+
]} customColumnWidths={[{columnName: 'name', width: "2%"}]} columnsSortChange={handleSortByColumnChange} paginationInfo={setPageInfo} headingTranslationsKey={'tableHeadings'} rowSelectionInfo={setRowSelectionInfo} actionsArray={
|
|
27
27
|
[
|
|
28
28
|
{ key: '1', label: `${t('actions.one')}`, onClick: () => {
|
|
29
29
|
console.log('onClick');
|
package/src/components/index.tsx
CHANGED
package/src/locales/en.json
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"tableHeadings": {
|
|
3
|
-
"key": "
|
|
4
|
-
"name": "
|
|
5
|
-
"mecanographicNumber": "
|
|
6
|
-
"store": "
|
|
7
|
-
"role": "
|
|
8
|
-
"type": "
|
|
3
|
+
"key": "Key",
|
|
4
|
+
"name": "Name",
|
|
5
|
+
"mecanographicNumber": "Employee Code",
|
|
6
|
+
"store": "Store",
|
|
7
|
+
"role": "Role",
|
|
8
|
+
"type": "Type",
|
|
9
9
|
"id": "Id",
|
|
10
|
-
"action": "
|
|
10
|
+
"action": "Action"
|
|
11
11
|
},
|
|
12
12
|
"userInfoColumn": {
|
|
13
|
-
"Date": "
|
|
14
|
-
"Store": "
|
|
15
|
-
"Team": "
|
|
13
|
+
"Date": "Date",
|
|
14
|
+
"Store": "Store",
|
|
15
|
+
"Team": "Team",
|
|
16
16
|
"Supervisor": "Supervisor",
|
|
17
|
-
"TypeOfContract": "
|
|
18
|
-
"Nationality": "
|
|
19
|
-
"CivilStatus": "
|
|
20
|
-
"IdentificationDocument": "
|
|
21
|
-
"NTaxpayer": "
|
|
17
|
+
"TypeOfContract": "Type Of Contract",
|
|
18
|
+
"Nationality": "Nationality",
|
|
19
|
+
"CivilStatus": "Civil Status",
|
|
20
|
+
"IdentificationDocument": "Identification Document",
|
|
21
|
+
"NTaxpayer": "Taxpayer Number",
|
|
22
22
|
"NIB": "NIB",
|
|
23
|
-
"SocialSecurity": "
|
|
24
|
-
"NChildren": "
|
|
25
|
-
"Workload": "
|
|
26
|
-
"Description": "
|
|
27
|
-
"Comments": "
|
|
23
|
+
"SocialSecurity": "Social Security",
|
|
24
|
+
"NChildren": "Number of Children",
|
|
25
|
+
"Workload": "Workload",
|
|
26
|
+
"Description": "Description",
|
|
27
|
+
"Comments": "Comments"
|
|
28
28
|
},
|
|
29
29
|
"navigation": {
|
|
30
|
-
"back": "
|
|
31
|
-
"logout": "
|
|
32
|
-
"home": "
|
|
30
|
+
"back": "Back",
|
|
31
|
+
"logout": "Logout",
|
|
32
|
+
"home": "Home"
|
|
33
33
|
},
|
|
34
34
|
"actions": {
|
|
35
35
|
"one": "one",
|
|
@@ -37,52 +37,52 @@
|
|
|
37
37
|
},
|
|
38
38
|
"components": {
|
|
39
39
|
"category": {
|
|
40
|
-
"addQuestion": "
|
|
41
|
-
"placeholderInfo": "
|
|
42
|
-
"errorInfo": "
|
|
43
|
-
"placeholderQuestion": "
|
|
44
|
-
"errorQuestion": "
|
|
45
|
-
"placeholderGrade": "
|
|
46
|
-
"errorGrade": "
|
|
47
|
-
"newCategory": "
|
|
40
|
+
"addQuestion": "Add Question",
|
|
41
|
+
"placeholderInfo": "Placeholder Info",
|
|
42
|
+
"errorInfo": "Error Info",
|
|
43
|
+
"placeholderQuestion": "Question",
|
|
44
|
+
"errorQuestion": "Error/Missing Question",
|
|
45
|
+
"placeholderGrade": "Grade",
|
|
46
|
+
"errorGrade": "Error/Missing Grade",
|
|
47
|
+
"newCategory": "New Category"
|
|
48
48
|
},
|
|
49
49
|
"categorySidBar": {
|
|
50
|
-
"addCategory": "
|
|
51
|
-
"removeCategory": "
|
|
50
|
+
"addCategory": "Add Category",
|
|
51
|
+
"removeCategory": "Remove Category"
|
|
52
52
|
},
|
|
53
53
|
"categoryContent": {
|
|
54
|
-
"message": "
|
|
55
|
-
"categoryName": "
|
|
56
|
-
"categoryNameError": "
|
|
57
|
-
"weighting": "
|
|
58
|
-
"openAnswer": "
|
|
59
|
-
"answerOption": "
|
|
60
|
-
"answers": "
|
|
54
|
+
"message": "Please select a category in the sidebar",
|
|
55
|
+
"categoryName": "Category Name",
|
|
56
|
+
"categoryNameError": "Category Name Error/Missing",
|
|
57
|
+
"weighting": "Weighting",
|
|
58
|
+
"openAnswer": "Open Answer",
|
|
59
|
+
"answerOption": "Answer Option",
|
|
60
|
+
"answers": "Answers"
|
|
61
61
|
},
|
|
62
62
|
"categoryResponse": {
|
|
63
|
-
"notApplicable": "
|
|
64
|
-
"answer": "
|
|
63
|
+
"notApplicable": "Not Applicable",
|
|
64
|
+
"answer": "Answer"
|
|
65
65
|
},
|
|
66
66
|
"categoryReadOnly": {
|
|
67
|
-
"categories": "
|
|
68
|
-
"categoryAverage": "
|
|
69
|
-
"userResponse": "
|
|
70
|
-
"supervisorResponse": "
|
|
67
|
+
"categories": "Categories",
|
|
68
|
+
"categoryAverage": "Category Average",
|
|
69
|
+
"userResponse": "User Response:",
|
|
70
|
+
"supervisorResponse": "Supervisor Response:"
|
|
71
71
|
},
|
|
72
72
|
"analyticsBar": {
|
|
73
|
-
"desc": "
|
|
74
|
-
"asc": "
|
|
73
|
+
"desc": "Descending",
|
|
74
|
+
"asc": "Ascending"
|
|
75
75
|
},
|
|
76
76
|
"tag": {
|
|
77
|
-
"search": "
|
|
78
|
-
"advancedFields": "
|
|
77
|
+
"search": "Search",
|
|
78
|
+
"advancedFields": "Advanced Filters"
|
|
79
79
|
},
|
|
80
80
|
"table": {
|
|
81
|
-
"selectAll": "
|
|
82
|
-
"deselectAll": "
|
|
81
|
+
"selectAll": "Select All",
|
|
82
|
+
"deselectAll": "Deselect All"
|
|
83
83
|
},
|
|
84
84
|
"datePickerTag": {
|
|
85
|
-
"placeholder": "
|
|
85
|
+
"placeholder": "Select Date"
|
|
86
86
|
}
|
|
87
87
|
}
|
|
88
88
|
}
|