@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.
@@ -0,0 +1,4 @@
1
+ import { Meta, Story } from '@storybook/react';
2
+ declare const _default: Meta<import("@storybook/react").Args>;
3
+ export default _default;
4
+ export declare const ExportButton: Story<any>;
@@ -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 {};
@@ -23,3 +23,4 @@ export * from './Upload';
23
23
  export * from './UserInfo';
24
24
  export * from './CategoryReadOnly';
25
25
  export * from './Notification';
26
+ export * from './ExportTableData';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omniumretail/component-library",
3
- "version": "1.1.07",
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: "100px"}]} columnsSortChange={handleSortByColumnChange} paginationInfo={setPageInfo} headingTranslationsKey={'tableHeadings'} rowSelectionInfo={setRowSelectionInfo} actionsArray={
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');
@@ -23,3 +23,4 @@ export * from './Upload';
23
23
  export * from './UserInfo';
24
24
  export * from './CategoryReadOnly';
25
25
  export * from './Notification';
26
+ export * from './ExportTableData'
@@ -1,35 +1,35 @@
1
1
  {
2
2
  "tableHeadings": {
3
- "key": "Chave",
4
- "name": "Nome",
5
- "mecanographicNumber": "Número Mecanográfico",
6
- "store": "Loja",
7
- "role": "Posição",
8
- "type": "Tipo",
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": "Ação"
10
+ "action": "Action"
11
11
  },
12
12
  "userInfoColumn": {
13
- "Date": "Data",
14
- "Store": "Loja",
15
- "Team": "Equipa em Gestão",
13
+ "Date": "Date",
14
+ "Store": "Store",
15
+ "Team": "Team",
16
16
  "Supervisor": "Supervisor",
17
- "TypeOfContract": "Tipo de contrato",
18
- "Nationality": "Nacionalidade",
19
- "CivilStatus": "Estado Civil",
20
- "IdentificationDocument": "Doc.Identificação",
21
- "NTaxpayer": " Contribuinte",
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": "Nr Segurança Social",
24
- "NChildren": " Filhos",
25
- "Workload": "Carga horária",
26
- "Description": "Descrição",
27
- "Comments": "Comentários"
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": "Voltar Atrás ENG",
31
- "logout": "Terminar Sessão ENG",
32
- "home": "Início ENG"
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": "Adicionar questão",
41
- "placeholderInfo": "Informação da questão",
42
- "errorInfo": "Informação da questão em falta",
43
- "placeholderQuestion": "Questão",
44
- "errorQuestion": "Questão em falta",
45
- "placeholderGrade": "Ponderação",
46
- "errorGrade": "Ponderação em falta",
47
- "newCategory": "Nova categoria"
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": "Adicionar categoria",
51
- "removeCategory": "Remover categoria"
50
+ "addCategory": "Add Category",
51
+ "removeCategory": "Remove Category"
52
52
  },
53
53
  "categoryContent": {
54
- "message": "Por favor selecione uma categoria na barra lateral",
55
- "categoryName": "Nome da categoria",
56
- "categoryNameError": "Nome categoria em falta",
57
- "weighting": "Ponderação",
58
- "openAnswer": "Resposta aberta",
59
- "answerOption": "Opção de resposta",
60
- "answers": "Questões"
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": "Não Aplicável",
64
- "answer": "Resposta"
63
+ "notApplicable": "Not Applicable",
64
+ "answer": "Answer"
65
65
  },
66
66
  "categoryReadOnly": {
67
- "categories": "Categorias",
68
- "categoryAverage": "Ponderação da categoria",
69
- "userResponse": "Resposta Utilizador:",
70
- "supervisorResponse": "Resposta Supervisor:"
67
+ "categories": "Categories",
68
+ "categoryAverage": "Category Average",
69
+ "userResponse": "User Response:",
70
+ "supervisorResponse": "Supervisor Response:"
71
71
  },
72
72
  "analyticsBar": {
73
- "desc": "Decrescente",
74
- "asc": "Crescente"
73
+ "desc": "Descending",
74
+ "asc": "Ascending"
75
75
  },
76
76
  "tag": {
77
- "search": "Procurar",
78
- "advancedFields": "Filtros avançados"
77
+ "search": "Search",
78
+ "advancedFields": "Advanced Filters"
79
79
  },
80
80
  "table": {
81
- "selectAll": "Selecionar todos",
82
- "deselectAll": "Desselecionar Todos"
81
+ "selectAll": "Select All",
82
+ "deselectAll": "Deselect All"
83
83
  },
84
84
  "datePickerTag": {
85
- "placeholder": "Selecionar Data"
85
+ "placeholder": "Select Date"
86
86
  }
87
87
  }
88
88
  }