wca-designsystem 0.0.15 → 0.0.17
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/package.json +5 -5
- package/src/components/molecules/TabelaHeader/TabelaHeader.test.tsx +2 -0
- package/src/components/molecules/TabelaHeader/index.tsx +7 -1
- package/src/components/organismos/Tabela/HeaderTable.tsx +5 -1
- package/src/components/organismos/Tabela/Tabela.test.tsx +2 -0
- package/src/components/organismos/Tabela/index.tsx +87 -80
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "0.0.
|
|
2
|
+
"version": "0.0.17",
|
|
3
3
|
"license": "MIT",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"typings": "dist/index.d.ts",
|
|
@@ -88,10 +88,10 @@
|
|
|
88
88
|
"typescript": "^5.4.5"
|
|
89
89
|
},
|
|
90
90
|
"dependencies": {
|
|
91
|
-
"@mantine/core": "7.
|
|
92
|
-
"@mantine/dates": "^7.
|
|
93
|
-
"@mantine/form": "^7.
|
|
94
|
-
"@mantine/hooks": "7.
|
|
91
|
+
"@mantine/core": "7.12.2",
|
|
92
|
+
"@mantine/dates": "^7.12.2",
|
|
93
|
+
"@mantine/form": "^7.12.2",
|
|
94
|
+
"@mantine/hooks": "7.12.2",
|
|
95
95
|
"@tanstack/query-sync-storage-persister": "^5.40.0",
|
|
96
96
|
"@tanstack/react-query": "^5.40.1",
|
|
97
97
|
"@tanstack/react-query-persist-client": "^5.40.1",
|
|
@@ -8,6 +8,7 @@ describe('Tabela Header', () => {
|
|
|
8
8
|
it('Renderiza corretamente', () => {
|
|
9
9
|
const { getByText } = render(
|
|
10
10
|
<TabelaHeader
|
|
11
|
+
setPagination={() => console.log('auqi')}
|
|
11
12
|
toogleBuscarColuna={false}
|
|
12
13
|
setToogleBuscarColuna={() => console.log('aqui')}
|
|
13
14
|
setGlobalFilter={() => console.log('aqui')}
|
|
@@ -28,6 +29,7 @@ describe('Tabela Header', () => {
|
|
|
28
29
|
|
|
29
30
|
const { getByText } = render(
|
|
30
31
|
<TabelaHeader
|
|
32
|
+
setPagination={() => console.log('auqi')}
|
|
31
33
|
toogleBuscarColuna={false}
|
|
32
34
|
setToogleBuscarColuna={() => console.log('aqui')}
|
|
33
35
|
setGlobalFilter={() => console.log('aqui')}
|
|
@@ -11,6 +11,7 @@ import * as S from './styles';
|
|
|
11
11
|
import Botao from '../../atomos/Botao';
|
|
12
12
|
import InputDeTexto from '../../atomos/InputDeTexto';
|
|
13
13
|
import {
|
|
14
|
+
MRT_PaginationState,
|
|
14
15
|
MRT_RowData,
|
|
15
16
|
MRT_TableInstance,
|
|
16
17
|
MRT_ToggleFiltersButton,
|
|
@@ -36,6 +37,7 @@ export type TabelaHeaderProps<T extends MRT_RowData> = {
|
|
|
36
37
|
setToogleBuscarColuna: React.Dispatch<React.SetStateAction<boolean>>;
|
|
37
38
|
toogleBuscarColuna: boolean;
|
|
38
39
|
table?: MRT_TableInstance<T>;
|
|
40
|
+
setPagination: React.Dispatch<React.SetStateAction<MRT_PaginationState>>;
|
|
39
41
|
};
|
|
40
42
|
const TabelaHeader = <T extends MRT_RowData>({
|
|
41
43
|
tituloTabela,
|
|
@@ -43,6 +45,7 @@ const TabelaHeader = <T extends MRT_RowData>({
|
|
|
43
45
|
ordenarPor,
|
|
44
46
|
filtrosPor,
|
|
45
47
|
setFiltrosPor,
|
|
48
|
+
setPagination,
|
|
46
49
|
exportarXlsx,
|
|
47
50
|
handleAdicionar,
|
|
48
51
|
filtrosPelaTabela,
|
|
@@ -64,7 +67,10 @@ const TabelaHeader = <T extends MRT_RowData>({
|
|
|
64
67
|
maw={180}
|
|
65
68
|
tipo="table"
|
|
66
69
|
leftSection={<Icone fill={theme.colors.blue} svg={buscar} />}
|
|
67
|
-
onChange={(e) =>
|
|
70
|
+
onChange={(e) => {
|
|
71
|
+
setPagination({ pageIndex: 0, pageSize: 10 });
|
|
72
|
+
setGlobalFilter(e.currentTarget.value);
|
|
73
|
+
}}
|
|
68
74
|
/>
|
|
69
75
|
|
|
70
76
|
<SelectCustomizado
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Table } from '@mantine/core';
|
|
3
3
|
import * as S from './styles';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
MRT_PaginationState,
|
|
6
|
+
MRT_RowData,
|
|
7
|
+
MRT_TableInstance,
|
|
8
|
+
} from 'mantine-react-table';
|
|
5
9
|
import { theme } from '../../../styles/theme';
|
|
6
10
|
import Icone from '../../atomos/Icone';
|
|
7
11
|
import InputDeTexto from '../../atomos/InputDeTexto';
|
|
@@ -33,6 +33,7 @@ describe('Tabela', () => {
|
|
|
33
33
|
it('Renderiza corretamente', () => {
|
|
34
34
|
const { getByText } = render(
|
|
35
35
|
<Tabela<any>
|
|
36
|
+
setPagination={() => console.log('auqi')}
|
|
36
37
|
loading={false}
|
|
37
38
|
data={[]}
|
|
38
39
|
tituloTabela="Usuário"
|
|
@@ -50,6 +51,7 @@ describe('Tabela', () => {
|
|
|
50
51
|
|
|
51
52
|
const { getByText } = render(
|
|
52
53
|
<Tabela<any>
|
|
54
|
+
setPagination={() => console.log('auqi')}
|
|
53
55
|
data={[]}
|
|
54
56
|
loading={false}
|
|
55
57
|
enableExpanding={false}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import React from 'react'
|
|
1
|
+
import React from 'react';
|
|
2
2
|
import {
|
|
3
3
|
type MRT_ColumnDef,
|
|
4
4
|
useMantineReactTable,
|
|
5
5
|
MRT_RowData,
|
|
6
|
-
|
|
7
6
|
MRT_ColumnFilterFnsState,
|
|
8
7
|
MRT_ColumnFiltersState,
|
|
9
8
|
MRT_SortingState,
|
|
@@ -12,44 +11,46 @@ import {
|
|
|
12
11
|
MRT_Cell,
|
|
13
12
|
MRT_Row,
|
|
14
13
|
MRT_TableInstance,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
import
|
|
18
|
-
import {
|
|
14
|
+
MRT_PaginationState,
|
|
15
|
+
} from 'mantine-react-table';
|
|
16
|
+
import * as S from './styles';
|
|
17
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
18
|
+
import { MRT_Localization_PT_BR } from '../../../utils/tableLocale';
|
|
19
19
|
|
|
20
|
-
import { utils, writeFileXLSX } from 'xlsx'
|
|
21
|
-
import { Table } from '@mantine/core'
|
|
22
|
-
import SkeletonTable from './SkeletonTable'
|
|
23
|
-
import HeaderTable from './HeaderTable'
|
|
24
|
-
import BodyTable from './BodyTable'
|
|
25
|
-
import FooterTable from './FooterTable'
|
|
26
|
-
import { useSearchParams } from 'react-router-dom'
|
|
27
|
-
import Paginacao from '../../molecules/Paginacao'
|
|
28
|
-
import TabelaHeader, { SelectDataProps } from '../../molecules/TabelaHeader'
|
|
20
|
+
import { utils, writeFileXLSX } from 'xlsx';
|
|
21
|
+
import { Table } from '@mantine/core';
|
|
22
|
+
import SkeletonTable from './SkeletonTable';
|
|
23
|
+
import HeaderTable from './HeaderTable';
|
|
24
|
+
import BodyTable from './BodyTable';
|
|
25
|
+
import FooterTable from './FooterTable';
|
|
26
|
+
import { useSearchParams } from 'react-router-dom';
|
|
27
|
+
import Paginacao from '../../molecules/Paginacao';
|
|
28
|
+
import TabelaHeader, { SelectDataProps } from '../../molecules/TabelaHeader';
|
|
29
29
|
|
|
30
30
|
export interface TabelaProps<T extends MRT_RowData> {
|
|
31
|
-
data: Array<T
|
|
31
|
+
data: Array<T>;
|
|
32
32
|
acoes?:
|
|
33
33
|
| ((props: {
|
|
34
|
-
cell: MRT_Cell<T, unknown
|
|
35
|
-
renderedRowIndex?: number
|
|
36
|
-
row: MRT_Row<T
|
|
37
|
-
table: MRT_TableInstance<T
|
|
34
|
+
cell: MRT_Cell<T, unknown>;
|
|
35
|
+
renderedRowIndex?: number;
|
|
36
|
+
row: MRT_Row<T>;
|
|
37
|
+
table: MRT_TableInstance<T>;
|
|
38
38
|
}) => React.ReactNode)
|
|
39
|
-
| undefined
|
|
40
|
-
handleAdicionar?: (() => void) | undefined
|
|
41
|
-
columns: MRT_ColumnDef<T>[]
|
|
42
|
-
tituloTabela?: string
|
|
43
|
-
enableRowSelection: boolean
|
|
44
|
-
setRowSelection?: React.Dispatch<React.SetStateAction<MRT_RowSelectionState
|
|
45
|
-
rowSelection?: MRT_RowSelectionState | undefined
|
|
46
|
-
enableExpanding: boolean
|
|
47
|
-
fixedPosition?: Array<string
|
|
48
|
-
enableRowActions?: boolean
|
|
49
|
-
hasTotalFooter?: boolean
|
|
50
|
-
tamanhoPaginacao?: number
|
|
51
|
-
quantidadeRegistros?: number
|
|
52
|
-
|
|
39
|
+
| undefined;
|
|
40
|
+
handleAdicionar?: (() => void) | undefined;
|
|
41
|
+
columns: MRT_ColumnDef<T>[];
|
|
42
|
+
tituloTabela?: string;
|
|
43
|
+
enableRowSelection: boolean;
|
|
44
|
+
setRowSelection?: React.Dispatch<React.SetStateAction<MRT_RowSelectionState>>;
|
|
45
|
+
rowSelection?: MRT_RowSelectionState | undefined;
|
|
46
|
+
enableExpanding: boolean;
|
|
47
|
+
fixedPosition?: Array<string>;
|
|
48
|
+
enableRowActions?: boolean;
|
|
49
|
+
hasTotalFooter?: boolean;
|
|
50
|
+
tamanhoPaginacao?: number;
|
|
51
|
+
quantidadeRegistros?: number;
|
|
52
|
+
setPagination: React.Dispatch<React.SetStateAction<MRT_PaginationState>>;
|
|
53
|
+
loading?: boolean;
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
function Tabela<T extends MRT_RowData>({
|
|
@@ -62,6 +63,7 @@ function Tabela<T extends MRT_RowData>({
|
|
|
62
63
|
enableRowActions,
|
|
63
64
|
quantidadeRegistros,
|
|
64
65
|
hasTotalFooter,
|
|
66
|
+
setPagination,
|
|
65
67
|
loading,
|
|
66
68
|
handleAdicionar,
|
|
67
69
|
data,
|
|
@@ -69,66 +71,69 @@ function Tabela<T extends MRT_RowData>({
|
|
|
69
71
|
rowSelection = {},
|
|
70
72
|
fixedPosition,
|
|
71
73
|
}: TabelaProps<T>) {
|
|
72
|
-
const [searchParams] = useSearchParams()
|
|
73
|
-
const pagina = searchParams.get('pagina')
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
74
|
+
const [searchParams] = useSearchParams();
|
|
75
|
+
const pagina = searchParams.get('pagina')
|
|
76
|
+
? Number(searchParams.get('pagina'))
|
|
77
|
+
: 0;
|
|
78
|
+
const linhas = searchParams.get('linhas')
|
|
79
|
+
? Number(searchParams.get('linhas'))
|
|
80
|
+
: 10;
|
|
77
81
|
|
|
78
82
|
const filtrosPelaTabela = useMemo(() => {
|
|
79
83
|
return columns.map((header) => {
|
|
80
84
|
return {
|
|
81
85
|
value: String(header.accessorKey),
|
|
82
86
|
label: header.header,
|
|
83
|
-
}
|
|
84
|
-
})
|
|
85
|
-
}, [])
|
|
87
|
+
};
|
|
88
|
+
});
|
|
89
|
+
}, []);
|
|
86
90
|
|
|
87
|
-
const [columnFilters, setColunaFiltros] = useState<MRT_ColumnFiltersState>(
|
|
91
|
+
const [columnFilters, setColunaFiltros] = useState<MRT_ColumnFiltersState>(
|
|
92
|
+
[]
|
|
93
|
+
);
|
|
88
94
|
|
|
89
95
|
const [columnFilterFns, setFiltrosDeColunaFn] =
|
|
90
96
|
useState<MRT_ColumnFilterFnsState>(
|
|
91
97
|
Object.fromEntries(
|
|
92
98
|
columns.map(({ accessorKey }) => [accessorKey, 'contains'])
|
|
93
99
|
)
|
|
94
|
-
)
|
|
95
|
-
const [globalFilter, setGlobalFilter] = useState('')
|
|
96
|
-
const [sorting, setSorting] = useState<MRT_SortingState>([])
|
|
100
|
+
);
|
|
101
|
+
const [globalFilter, setGlobalFilter] = useState('');
|
|
102
|
+
const [sorting, setSorting] = useState<MRT_SortingState>([]);
|
|
97
103
|
const [ordenarPor, setOrdenarPor] = useState<SelectDataProps>({
|
|
98
104
|
label: 'Ordenar por: Maior',
|
|
99
105
|
value: 'Maior',
|
|
100
|
-
})
|
|
101
|
-
const [columnOrder, setColumnOrder] = useState<MRT_ColumnOrderState>([])
|
|
102
|
-
const [filtrosPor, setFiltrosPor] = useState(filtrosPelaTabela[0] ?? [])
|
|
103
|
-
const [toogleBuscarColuna, setToogleBuscarColuna] = useState(false)
|
|
106
|
+
});
|
|
107
|
+
const [columnOrder, setColumnOrder] = useState<MRT_ColumnOrderState>([]);
|
|
108
|
+
const [filtrosPor, setFiltrosPor] = useState(filtrosPelaTabela[0] ?? []);
|
|
109
|
+
const [toogleBuscarColuna, setToogleBuscarColuna] = useState(false);
|
|
104
110
|
|
|
105
111
|
const calcStickPosition = useCallback(
|
|
106
112
|
(index: number) => {
|
|
107
113
|
if (enableExpanding) {
|
|
108
|
-
index = index - 1
|
|
114
|
+
index = index - 1;
|
|
109
115
|
}
|
|
110
116
|
if (enableRowSelection) {
|
|
111
|
-
index = index - 1
|
|
117
|
+
index = index - 1;
|
|
112
118
|
}
|
|
113
|
-
const expanding = enableExpanding ? 50 : 0
|
|
114
|
-
const selection = enableRowSelection ? 50 : 0
|
|
115
|
-
const newIndex = index * 200
|
|
116
|
-
const total = expanding + selection + newIndex
|
|
119
|
+
const expanding = enableExpanding ? 50 : 0;
|
|
120
|
+
const selection = enableRowSelection ? 50 : 0;
|
|
121
|
+
const newIndex = index * 200;
|
|
122
|
+
const total = expanding + selection + newIndex;
|
|
117
123
|
|
|
118
|
-
return total
|
|
124
|
+
return total;
|
|
119
125
|
},
|
|
120
126
|
[enableRowSelection]
|
|
121
|
-
)
|
|
127
|
+
);
|
|
122
128
|
|
|
123
129
|
const onFilterColunas = useCallback(
|
|
124
130
|
(id: string, value: unknown) => {
|
|
125
|
-
setColunaFiltros([{ id, value }])
|
|
131
|
+
setColunaFiltros([{ id, value }]);
|
|
126
132
|
},
|
|
127
133
|
[columnFilters]
|
|
128
|
-
)
|
|
129
|
-
|
|
130
|
-
const fetchData = data ?? []
|
|
134
|
+
);
|
|
131
135
|
|
|
136
|
+
const fetchData = data ?? [];
|
|
132
137
|
|
|
133
138
|
const table = useMantineReactTable({
|
|
134
139
|
columns: columns,
|
|
@@ -162,7 +167,7 @@ function Tabela<T extends MRT_RowData>({
|
|
|
162
167
|
isLoading: loading,
|
|
163
168
|
showColumnFilters: false,
|
|
164
169
|
showGlobalFilter: false,
|
|
165
|
-
|
|
170
|
+
/* pagination: {
|
|
166
171
|
pageIndex: 0,
|
|
167
172
|
pageSize: 10,
|
|
168
173
|
}, */
|
|
@@ -198,34 +203,35 @@ function Tabela<T extends MRT_RowData>({
|
|
|
198
203
|
fz: 'xs',
|
|
199
204
|
},
|
|
200
205
|
renderRowActions: acoes,
|
|
201
|
-
})
|
|
206
|
+
});
|
|
202
207
|
|
|
203
208
|
const exportarXlsx = useCallback(() => {
|
|
204
|
-
const ws = utils.json_to_sheet(data)
|
|
205
|
-
const wb = utils.book_new()
|
|
206
|
-
utils.book_append_sheet(wb, ws, 'Data')
|
|
207
|
-
writeFileXLSX(wb, 'SheetJSReactAoO.xlsx')
|
|
208
|
-
}, [data])
|
|
209
|
+
const ws = utils.json_to_sheet(data);
|
|
210
|
+
const wb = utils.book_new();
|
|
211
|
+
utils.book_append_sheet(wb, ws, 'Data');
|
|
212
|
+
writeFileXLSX(wb, 'SheetJSReactAoO.xlsx');
|
|
213
|
+
}, [data]);
|
|
209
214
|
|
|
210
215
|
const getValorTotalSelecionados = useMemo(() => {
|
|
211
|
-
const columnsWithFooter = columns.find((column) => column.footer)
|
|
216
|
+
const columnsWithFooter = columns.find((column) => column.footer);
|
|
212
217
|
if (columnsWithFooter?.accessorKey) {
|
|
213
|
-
let total = 0
|
|
218
|
+
let total = 0;
|
|
214
219
|
data?.forEach((dado: T) => {
|
|
215
220
|
if (rowSelection[dado.id]) {
|
|
216
|
-
total += dado[columnsWithFooter?.accessorKey!]
|
|
221
|
+
total += dado[columnsWithFooter?.accessorKey!];
|
|
217
222
|
}
|
|
218
|
-
})
|
|
219
|
-
return total
|
|
223
|
+
});
|
|
224
|
+
return total;
|
|
220
225
|
}
|
|
221
226
|
|
|
222
|
-
return 0
|
|
223
|
-
}, [rowSelection])
|
|
227
|
+
return 0;
|
|
228
|
+
}, [rowSelection]);
|
|
224
229
|
|
|
225
230
|
return (
|
|
226
231
|
<S.TabelaWrapper>
|
|
227
232
|
{/* Filtros e titulo */}
|
|
228
233
|
<TabelaHeader<T>
|
|
234
|
+
setPagination={setPagination}
|
|
229
235
|
table={table}
|
|
230
236
|
toogleBuscarColuna={toogleBuscarColuna}
|
|
231
237
|
setToogleBuscarColuna={setToogleBuscarColuna}
|
|
@@ -281,16 +287,17 @@ function Tabela<T extends MRT_RowData>({
|
|
|
281
287
|
{/* Paginação */}
|
|
282
288
|
<S.TabelaPaginationWrapper>
|
|
283
289
|
<Paginacao
|
|
290
|
+
setPagination={setPagination}
|
|
284
291
|
tamanhoPaginacao={tamanhoPaginacao}
|
|
285
292
|
quantidadeRegistros={quantidadeRegistros}
|
|
286
293
|
tabelaPaginacao={{
|
|
287
|
-
pageIndex:
|
|
288
|
-
pageSize:linhas
|
|
294
|
+
pageIndex: pagina,
|
|
295
|
+
pageSize: linhas,
|
|
289
296
|
}}
|
|
290
297
|
/>
|
|
291
298
|
</S.TabelaPaginationWrapper>
|
|
292
299
|
</S.TabelaWrapper>
|
|
293
|
-
)
|
|
300
|
+
);
|
|
294
301
|
}
|
|
295
302
|
|
|
296
|
-
export default Tabela
|
|
303
|
+
export default Tabela;
|