@omniumretail/component-library 1.1.8 → 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.08",
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,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'