@omniumretail/component-library 1.2.53 → 1.2.55

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.
@@ -48,5 +48,6 @@ export interface ResponsiveTableCustomProps extends TableProps<any> {
48
48
  cleanRowSelection?: boolean;
49
49
  getRowActions?: (record: any) => any;
50
50
  customSelectAllButton?: string;
51
+ buttonActionIcon?: (record: any) => any | null;
51
52
  }
52
53
  export declare const ResponsiveTable: (props: ResponsiveTableCustomProps) => import("react/jsx-runtime").JSX.Element;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omniumretail/component-library",
3
- "version": "1.2.53",
3
+ "version": "1.2.55",
4
4
  "private": false,
5
5
  "main": "dist/bundle.js",
6
6
  "typings": "./dist/types/index",
@@ -2,6 +2,7 @@ import { Meta, Story } from "@storybook/react";
2
2
  import { ResponsiveTable, ResponsiveTableCustomProps } from '.';
3
3
  import { useState } from "react";
4
4
  import { useTranslation } from "react-i18next";
5
+ import { DownloadOutlined } from "@ant-design/icons";
5
6
 
6
7
  export default {
7
8
  title: 'ResponsiveTable',
@@ -23,10 +24,10 @@ const Template: Story<ResponsiveTableCustomProps> = (args) => {
23
24
 
24
25
  const getButtonLabel = (record: any) => {
25
26
  return (record as any)?.type === "Efetivo" ? "Pog" : null;
26
- };
27
+ };
27
28
 
28
- const getActionsForRecord = (record: any) => {
29
- return (record as any)?.role === "Gerente"
29
+ const getActionsForRecord = (record: any) => {
30
+ return (record as any)?.role === "Gerente"
30
31
  ? [
31
32
  {
32
33
  key: '1', label: `${t('actions.one')}`, onClick: () => {
@@ -52,14 +53,23 @@ const getActionsForRecord = (record: any) => {
52
53
  key: '4', label: 'label 4'
53
54
  }
54
55
  ];
55
- };
56
+ };
57
+
58
+ const getIcon = (record: any) => {
59
+ return record.id === "1"
60
+ ? <DownloadOutlined />
61
+ : record.id === "3"
62
+ ? <DownloadOutlined />
63
+ : null;
64
+ };
56
65
 
66
+ const actionsArray = [{ key: '1', label: `` }];
57
67
 
58
68
  return <ResponsiveTable
59
69
  cleanRowSelection={clearRowSelection}
60
70
  columnsSortChange={handleSortByColumnChange} paginationInfo={setPageInfo} headingTranslationsKey={'tableHeadings'} rowSelectionInfo={setRowSelectionInfo}
61
- getRowActions={getActionsForRecord}
62
- fixedColumns={[{ dataIndex: 'action', side: 'right' }]} buttonActionMethod={() => handleSortByColumnChange} buttonActionLabel={getButtonLabel} {...args}>
71
+ actionsArray={actionsArray}
72
+ fixedColumns={[{ dataIndex: 'action', side: 'right' }]} buttonActionIcon={getIcon} {...args}>
63
73
  </ResponsiveTable>;
64
74
  };
65
75
 
@@ -54,6 +54,7 @@ export interface ResponsiveTableCustomProps extends TableProps<any> {
54
54
  cleanRowSelection?: boolean;
55
55
  getRowActions?: (record: any) => any;
56
56
  customSelectAllButton?: string;
57
+ buttonActionIcon?: (record: any) => any | null;
57
58
  }
58
59
 
59
60
  export const ResponsiveTable = (props: ResponsiveTableCustomProps) => {
@@ -85,7 +86,8 @@ export const ResponsiveTable = (props: ResponsiveTableCustomProps) => {
85
86
  buttonActionLabel,
86
87
  cleanRowSelection,
87
88
  getRowActions,
88
- customSelectAllButton
89
+ customSelectAllButton,
90
+ buttonActionIcon
89
91
  } = props;
90
92
 
91
93
  const [customFilters, setCustomFilters] = useState<any>([]);
@@ -217,21 +219,48 @@ export const ResponsiveTable = (props: ResponsiveTableCustomProps) => {
217
219
  render: (_: any, record: any) => {
218
220
  const rowActions = getRowActions ? getRowActions(record) : null;
219
221
 
220
- if ((!items?.[0] && !rowActions)) return null;
222
+ if ((!items?.[0] && !rowActions)) return null;
221
223
 
222
224
  const actions = rowActions ? rowActions : items;
223
225
 
224
226
  const buttonLabel = buttonActionLabel ? buttonActionLabel(record) : null;
225
-
226
- const buttonClass = typeof buttonActionStyle === 'function'
227
- ? buttonActionStyle(record) // Se for uma função, chama com o `record`
228
- : buttonActionStyle || ''; // Se for string, usa diretamente
227
+
228
+ const icon = buttonActionIcon ? buttonActionIcon(record) : null;
229
+
230
+ const buttonClass = typeof buttonActionStyle === 'function'
231
+ ? buttonActionStyle(record) // Se for uma função, chama com o `record`
232
+ : buttonActionStyle || ''; // Se for string, usa diretamente
233
+
234
+ const renderActionElement = () => {
235
+ if (icon) {
236
+ return (
237
+ <span
238
+ className={buttonClass}
239
+ onClick={() => buttonActionMethod?.()}
240
+ >
241
+ {icon}
242
+ </span>
243
+ );
244
+ }
245
+
246
+ // Senão, renderiza botão como antes
247
+ if (buttonActionName || buttonLabel) {
248
+ return (
249
+ <Button
250
+ customClass={buttonClass}
251
+ onClick={() => buttonActionMethod?.()}
252
+ >
253
+ {buttonActionName || buttonLabel}
254
+ </Button>
255
+ );
256
+ }
257
+
258
+ return null;
259
+ };
229
260
 
230
261
  return (
231
262
  <Space size="middle">
232
- {(buttonActionName || buttonLabel) &&
233
- <Button customClass={buttonClass} onClick={() => buttonActionMethod?.()}>{buttonActionName || buttonLabel}</Button>
234
- }
263
+ {renderActionElement()}
235
264
 
236
265
  <Dropdown menu={{ items: actions }}>
237
266
  <a>