wca-designsystem 0.0.42 → 0.0.43

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "0.0.42",
2
+ "version": "0.0.43",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -2,6 +2,20 @@ import React from 'react';
2
2
  import { render } from '../../../test/render';
3
3
  import Notificacoes, { NotificacoesProps } from './index';
4
4
 
5
+ const mockFetch = (responseText: string) => {
6
+ global.fetch = jest.fn(() =>
7
+ Promise.resolve(({
8
+ ok: true,
9
+ status: 200,
10
+ text: async () => responseText,
11
+ headers: { get: () => 'application/xml' },
12
+ clone: () => this,
13
+ } as unknown) as Response)
14
+ );
15
+ };
16
+
17
+ mockFetch('');
18
+
5
19
  describe('Notificações', () => {
6
20
  it('Renderiza sem problemas', () => {
7
21
  const props: NotificacoesProps = {
@@ -3,12 +3,12 @@ import * as S from './styles';
3
3
  import { theme } from '../../../styles/theme';
4
4
  import Botao from '../../atomos/Botao';
5
5
  import SelectCustomizado from '../../atomos/Select';
6
- import { MRT_PaginationState } from 'mantine-react-table';
6
+ // import { MRT_PaginationState } from 'mantine-react-table';
7
7
 
8
8
  export type PaginacaoProps = {
9
9
  tamanhoPaginacao?: number;
10
10
  quantidadeRegistros?: number;
11
- setPagination: React.Dispatch<React.SetStateAction<MRT_PaginationState>>;
11
+ setPagination: React.Dispatch<React.SetStateAction<any>>;
12
12
  tabelaPaginacao: {
13
13
  pageIndex: number;
14
14
  pageSize: number;
@@ -57,7 +57,7 @@ const Paginacao = ({
57
57
  <div className="select-wrapper">
58
58
  <SelectCustomizado
59
59
  tipo="round"
60
- onChange={(e) => changeLinhas(e!)}
60
+ onChange={e => changeLinhas(e!)}
61
61
  defaultValue={'10'}
62
62
  data={['10', '20', '30']}
63
63
  allowDeselect={false}
@@ -78,7 +78,7 @@ const Paginacao = ({
78
78
  value={
79
79
  tabelaPaginacao.pageIndex === 0 ? 1 : tabelaPaginacao.pageIndex
80
80
  }
81
- onChange={(e) => {
81
+ onChange={e => {
82
82
  changePage(e);
83
83
  }}
84
84
  total={tamanhoPaginacao!}
@@ -22,7 +22,12 @@ describe('Relatorio Card Renderiza', () => {
22
22
  test('Relatorio criar renderiza certo', () => {
23
23
  const { getByTestId } = render(
24
24
  <>
25
- <RelatorioCard {...relatorioProps} />
25
+ <RelatorioCard
26
+ relatorioTitle="Nome do Relatório 02"
27
+ type="criar"
28
+ ultimaEdicao="Editado em 02 de Abril de 2024 | 16:55"
29
+ color={theme.colors.blue}
30
+ />
26
31
  </>
27
32
  );
28
33
  const containerCriar = getByTestId('criar');
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+ import { Skeleton } from '@mantine/core';
3
+ import * as S from './styles';
4
+ import { Column } from '.';
5
+
6
+ interface SkeletonTableProps<T extends { id: number | string }> {
7
+ data: Array<T>;
8
+ columns: Column<T>[];
9
+ }
10
+
11
+ function SkeletonTable<T extends { id: number | string }>({
12
+ data,
13
+ columns,
14
+ }: SkeletonTableProps<T>) {
15
+ return (
16
+ <S.TabelaBody>
17
+ {columns?.map(row => {
18
+ return (
19
+ <tr key={row.header}>
20
+ {data.map(cell => (
21
+ <td key={cell.id}>
22
+ <Skeleton height={19} radius="xl" animate={true} />
23
+ </td>
24
+ ))}
25
+ </tr>
26
+ );
27
+ })}
28
+ </S.TabelaBody>
29
+ );
30
+ }
31
+
32
+ export default SkeletonTable;
@@ -0,0 +1,84 @@
1
+ import React from 'react';
2
+ import { Meta } from '@storybook/react';
3
+ import Tabela from './index';
4
+ import { theme } from '../../../styles/theme';
5
+
6
+ export default {
7
+ title: 'Components/organismos/Tabela',
8
+ component: Tabela,
9
+ } as Meta;
10
+
11
+ const data: any[] = [
12
+ {
13
+ id: 1,
14
+ name: 'Produto 1',
15
+ price: '$10',
16
+ exemplo: 'opa',
17
+ exemplo2: 'opa2',
18
+ },
19
+ {
20
+ id: 2,
21
+ name: 'Produto 2',
22
+ price: '$15',
23
+ exemplo: 'opa',
24
+ exemplo2: 'opa2',
25
+ },
26
+ {
27
+ id: 3,
28
+ name: 'Produto 3',
29
+ price: '$20',
30
+ exemplo: 'opa',
31
+ exemplo2: 'opa2',
32
+ },
33
+ {
34
+ id: 4,
35
+ name: 'Produto 3',
36
+ price: '$20',
37
+ exemplo: 'opa',
38
+ exemplo2: 'opa2',
39
+ },
40
+ {
41
+ id: 5,
42
+ name: 'Produto 3',
43
+ price: '$20',
44
+ exemplo: 'opa',
45
+ exemplo2: 'opa2',
46
+ },
47
+ {
48
+ id: 6,
49
+ name: 'Produto 3',
50
+ price: '$20',
51
+ exemplo: 'opa',
52
+ exemplo2: 'opa2',
53
+ },
54
+ ];
55
+
56
+ const columns: any = [
57
+ { key: 'id', header: 'ID' },
58
+ { key: 'name', header: 'Nome' },
59
+ { key: 'price', header: 'Preço' },
60
+ { key: 'exemplo', header: 'Exemplo' },
61
+ { key: 'exemplo2', header: 'Exemplo2' },
62
+ ];
63
+
64
+ const Template: any = (args: any) => (
65
+ <>
66
+ <Tabela {...args} />
67
+ </>
68
+ );
69
+
70
+ export const TabelaProps = Template.bind({});
71
+
72
+ TabelaProps.args = {
73
+ data: data,
74
+ columns: columns,
75
+ color: theme.colors.blue,
76
+ tabelaPaginacao: {
77
+ pageIndex: 1,
78
+ pageSize: 10,
79
+ },
80
+ setFiltrosPor: () => console.log('aqui'),
81
+ setGlobalFilter: () => console.log('aqui'),
82
+ setPagination: () => console.log('aqui'),
83
+ setSimples: () => console.log('aqui'),
84
+ };
@@ -0,0 +1,78 @@
1
+ import React from 'react';
2
+ import Tabela from '.';
3
+ import { render } from '../../../test/render';
4
+
5
+ describe('Paginação', () => {
6
+ const data: any[] = [
7
+ {
8
+ id: 1,
9
+ name: 'Produto 1',
10
+ price: '$10',
11
+ exemplo: 'opa',
12
+ exemplo2: 'opa2',
13
+ },
14
+ {
15
+ id: 2,
16
+ name: 'Produto 2',
17
+ price: '$15',
18
+ exemplo: 'opa',
19
+ exemplo2: 'opa2',
20
+ },
21
+ {
22
+ id: 3,
23
+ name: 'Produto 3',
24
+ price: '$20',
25
+ exemplo: 'opa',
26
+ exemplo2: 'opa2',
27
+ },
28
+ {
29
+ id: 4,
30
+ name: 'Produto 3',
31
+ price: '$20',
32
+ exemplo: 'opa',
33
+ exemplo2: 'opa2',
34
+ },
35
+ {
36
+ id: 5,
37
+ name: 'Produto 3',
38
+ price: '$20',
39
+ exemplo: 'opa',
40
+ exemplo2: 'opa2',
41
+ },
42
+ {
43
+ id: 6,
44
+ name: 'Produto 3',
45
+ price: '$20',
46
+ exemplo: 'opa',
47
+ exemplo2: 'opa2',
48
+ },
49
+ ];
50
+
51
+ const columns: any = [
52
+ { key: 'id', header: 'ID' },
53
+ { key: 'name', header: 'Nome' },
54
+ { key: 'price', header: 'Preço' },
55
+ { key: 'exemplo', header: 'Exemplo' },
56
+ { key: 'exemplo2', header: 'Exemplo2' },
57
+ ];
58
+
59
+ test('Renderizando corretamente', () => {
60
+ const { getByText } = render(
61
+ <Tabela
62
+ data={data}
63
+ columns={columns}
64
+ tabelaPaginacao={{
65
+ pageIndex: 1,
66
+ pageSize: 10,
67
+ }}
68
+ setSimples={() => console.log('aqui')}
69
+ filtrosPor={{ label: 'exemplo', value: 'exemplo' }}
70
+ setFiltrosPor={() => console.log('aqui')}
71
+ setGlobalFilter={() => console.log('aqui')}
72
+ setPagination={() => console.log('aqui')}
73
+ />
74
+ );
75
+
76
+ expect(getByText('Anterior')).toBeDefined();
77
+ });
78
+ });
@@ -0,0 +1,89 @@
1
+ import React from 'react';
2
+ import { Checkbox } from '@mantine/core';
3
+ import { Column } from '.';
4
+ import * as S from './styles';
5
+ import { useCallback } from 'react';
6
+ import { theme } from '../../../styles/theme';
7
+
8
+ export interface BodyTableProps<T extends { id: string | number }> {
9
+ data: Array<T>;
10
+ columns: Column<T>[];
11
+ fixedPosition?: string[] | undefined;
12
+ color?: string;
13
+ acoesChildren?: JSX.Element;
14
+ calcStickPosition?: (index: number) => number;
15
+ hasSelect?: boolean;
16
+ rowSelection?: Array<T>;
17
+ setRowSelection?: React.Dispatch<React.SetStateAction<Array<T>>> | undefined;
18
+ }
19
+
20
+ function BodyTable<T extends { id: string | number }>({
21
+ data,
22
+ columns,
23
+ acoesChildren,
24
+ hasSelect,
25
+ rowSelection,
26
+ setRowSelection,
27
+ color,
28
+ }: BodyTableProps<T>) {
29
+ const handleRowSelect = useCallback(
30
+ (item: T, checked: boolean) => {
31
+ if (checked) {
32
+ setRowSelection!(
33
+ rowSelection?.filter(rowSelect => rowSelect.id !== item.id) ?? []
34
+ );
35
+ return;
36
+ }
37
+ setRowSelection!(prev => [...prev, item]);
38
+ },
39
+ [rowSelection, setRowSelection]
40
+ );
41
+ return (
42
+ <S.TabelaBody>
43
+ {data.map((item, rowIndex) => (
44
+ <tr key={rowIndex}>
45
+ {hasSelect && (
46
+ <td className="select">
47
+ <Checkbox
48
+ size="md"
49
+ color={color}
50
+ type="checkbox"
51
+ checked={rowSelection!.some(
52
+ itemSome => item.id === itemSome.id
53
+ )}
54
+ onChange={() =>
55
+ handleRowSelect(
56
+ item,
57
+ rowSelection!.some(itemSome => item.id === itemSome.id)
58
+ )
59
+ }
60
+ />
61
+ </td>
62
+ )}
63
+ {columns.map(column => (
64
+ <td
65
+ key={String(column.key)}
66
+ style={{
67
+ background: rowSelection?.some(row => row.id === item.id)
68
+ ? theme.colors.gray['500']
69
+ : 'transparent',
70
+ }}
71
+ >
72
+ {column.key === 'acoes' ? (
73
+ <>{acoesChildren}</>
74
+ ) : (
75
+ <>
76
+ {column.render
77
+ ? column.render(item[column.key])
78
+ : String(item[column.key])}
79
+ </>
80
+ )}
81
+ </td>
82
+ ))}
83
+ </tr>
84
+ ))}
85
+ </S.TabelaBody>
86
+ );
87
+ }
88
+
89
+ export default BodyTable;
@@ -0,0 +1,153 @@
1
+ import React from 'react';
2
+ import { Switch } from '@mantine/core';
3
+ import * as S from './styles';
4
+ import { Column } from '.';
5
+ import buscar from '../../../assets/imagens/icons/Busca.svg';
6
+ import { useCallback } from 'react';
7
+ import { theme } from '../../../styles/theme';
8
+ import InputDeTexto from '../../atomos/InputDeTexto';
9
+ import Icone from '../../atomos/Icone';
10
+
11
+ type HeaderTabelaProps<T> = {
12
+ columns: Column<T>[];
13
+ fixedPosition: Array<String>;
14
+ calcStickPosition?: (index: number) => number;
15
+ onFilterColunas: (id: string, value: unknown) => void;
16
+ headerSelection?: Array<String>;
17
+ color?: string;
18
+ toogleFiltros: boolean;
19
+ hasSelect?: boolean;
20
+ setSimples: React.Dispatch<React.SetStateAction<boolean>>;
21
+ setGlobalFilter: React.Dispatch<React.SetStateAction<string>>;
22
+ setPagination: React.Dispatch<any>;
23
+ setFiltrosPor: React.Dispatch<
24
+ React.SetStateAction<{
25
+ value: string;
26
+ label: string;
27
+ }>
28
+ >;
29
+ };
30
+ const HeaderTabela = <T,>({
31
+ columns,
32
+ fixedPosition,
33
+ color,
34
+ hasSelect,
35
+ headerSelection,
36
+ toogleFiltros,
37
+ calcStickPosition,
38
+ setFiltrosPor,
39
+ setGlobalFilter,
40
+ setPagination,
41
+ setSimples,
42
+ onFilterColunas,
43
+ }: HeaderTabelaProps<T>) => {
44
+ const coloredHeader = useCallback(
45
+ (key: string | number | symbol) => {
46
+ if (!headerSelection) {
47
+ return { background: color, color: theme.colors.white! };
48
+ }
49
+
50
+ const isHeaderSelect = headerSelection?.some(
51
+ headerSelect => headerSelect === key
52
+ );
53
+
54
+ if (isHeaderSelect) {
55
+ return { background: color!, color: theme.colors.white };
56
+ } else {
57
+ return { background: theme.colors.white, color: color! };
58
+ }
59
+ },
60
+ [headerSelection]
61
+ );
62
+ return (
63
+ <S.TabelaHeader color={color}>
64
+ <tr>
65
+ {hasSelect && <th className="select">*</th>}
66
+ {columns.map((header, index) => {
67
+ if (header.key !== 'acoes') {
68
+ return (
69
+ <th
70
+ key={index}
71
+ className={
72
+ fixedPosition?.some(fixed => header.key === fixed)
73
+ ? 'sticky'
74
+ : ''
75
+ }
76
+ style={{
77
+ background: coloredHeader(header.key).background,
78
+ color: coloredHeader(header.key).color,
79
+ left: fixedPosition?.some(fixed => header.key === fixed)
80
+ ? calcStickPosition!(index)
81
+ : 0,
82
+ }}
83
+ >
84
+ {toogleFiltros ? (
85
+ <div className="input-header">
86
+ {header.key === 'ativo' ? (
87
+ <Switch
88
+ defaultChecked
89
+ label="ativo"
90
+ color={color}
91
+ onChange={e => {
92
+ setSimples(false);
93
+ setFiltrosPor({
94
+ label: 'Ativo',
95
+ value: 'ativo',
96
+ });
97
+ setGlobalFilter(String(e.currentTarget.checked));
98
+ setPagination({ pageIndex: 0, pageSize: 10 });
99
+ }}
100
+ />
101
+ ) : (
102
+ <InputDeTexto
103
+ color={color}
104
+ disabled={
105
+ header.key === 'email' || header.key === 'modulos'
106
+ }
107
+ tipo="table"
108
+ placeholder={`Pesquisar por: ${header.header}`}
109
+ onChange={e => {
110
+ setPagination({ pageIndex: 0, pageSize: 10 });
111
+ setFiltrosPor({
112
+ label: header.header,
113
+ value:
114
+ header.key === 'nome'
115
+ ? 'nomeCompleto'
116
+ : String(header.key),
117
+ });
118
+ setGlobalFilter(e.currentTarget.value);
119
+ onFilterColunas(
120
+ String(header.key),
121
+ e.currentTarget.value
122
+ );
123
+ }}
124
+ leftSection={<Icone fill={color} svg={buscar} />}
125
+ />
126
+ )}
127
+ </div>
128
+ ) : (
129
+ <>{header.key === 'ativo' ? 'Status' : header.header}</>
130
+ )}
131
+ </th>
132
+ );
133
+ } else {
134
+ return (
135
+ <th
136
+ key={header.key}
137
+ className={'especial sticky'}
138
+ style={{
139
+ left: index === 0 ? '0' : '50px',
140
+ right: header.key === 'mrt-row-actions' ? '0' : undefined,
141
+ }}
142
+ >
143
+ <p>Ações</p>
144
+ </th>
145
+ );
146
+ }
147
+ })}
148
+ </tr>
149
+ </S.TabelaHeader>
150
+ );
151
+ };
152
+
153
+ export default HeaderTabela;
@@ -0,0 +1,120 @@
1
+ import React from 'react';
2
+ import BodyTable from './body';
3
+ import HeaderTabela from './header';
4
+ import Paginacao from './pagination';
5
+ import SkeletonTable from './SkeletonTable';
6
+ import * as S from './styles';
7
+ import filtrar from '../../../assets/imagens/icons/Filtrar.svg';
8
+ import { useState } from 'react';
9
+ import IconeBotao from '../../atomos/IconeBotao';
10
+ import Icone from '../../atomos/Icone';
11
+
12
+ // Tipo genérico para as colunas
13
+ export type Column<T> = {
14
+ key: keyof T;
15
+ header: string;
16
+ render?: (value: T[keyof T]) => React.ReactNode;
17
+ };
18
+
19
+ export type CustomTableProps<T extends { id: string | number }> = {
20
+ data: T[];
21
+ columns: Column<T>[];
22
+ fixedPosition?: Array<String>;
23
+ acoesChildren?: JSX.Element;
24
+ hasSelect?: boolean;
25
+ headerSelection?: Array<String>;
26
+ rowSelection?: Array<T>;
27
+ setRowSelection?: React.Dispatch<React.SetStateAction<Array<T>>> | undefined;
28
+ isLoading?: boolean;
29
+ color?: string;
30
+ setSimples: React.Dispatch<React.SetStateAction<boolean>>;
31
+ setGlobalFilter: React.Dispatch<React.SetStateAction<string>>;
32
+ setPagination: React.Dispatch<any>;
33
+ filtrosPor: {
34
+ value: string;
35
+ label: string;
36
+ };
37
+ setFiltrosPor: React.Dispatch<
38
+ React.SetStateAction<{
39
+ value: string;
40
+ label: string;
41
+ }>
42
+ >;
43
+ tabelaPaginacao: {
44
+ pageIndex: number;
45
+ pageSize: number;
46
+ };
47
+ };
48
+
49
+ const Tabela = <T extends { id: string | number }>({
50
+ data,
51
+ columns,
52
+ setPagination,
53
+ acoesChildren,
54
+ color,
55
+ rowSelection,
56
+ setRowSelection,
57
+ isLoading,
58
+ hasSelect,
59
+ setFiltrosPor,
60
+ setGlobalFilter,
61
+ headerSelection,
62
+ setSimples,
63
+ tabelaPaginacao,
64
+ fixedPosition,
65
+ }: CustomTableProps<T>) => {
66
+ const [toogleFiltros, setToogleFiltros] = useState(false);
67
+ return (
68
+ <S.TableWrapper>
69
+ <S.TableContainer>
70
+ <S.ToogleButton>
71
+ <IconeBotao
72
+ tipo="table"
73
+ color={color}
74
+ toolTipInfo="Filtros especificos"
75
+ onClick={() => setToogleFiltros(!toogleFiltros)}
76
+ >
77
+ <Icone svg={filtrar} fill={color} width={20} />
78
+ </IconeBotao>
79
+ </S.ToogleButton>
80
+ <S.StyledTable>
81
+ <HeaderTabela
82
+ headerSelection={headerSelection}
83
+ toogleFiltros={toogleFiltros}
84
+ setFiltrosPor={setFiltrosPor}
85
+ setGlobalFilter={setGlobalFilter}
86
+ setPagination={setPagination}
87
+ setSimples={setSimples}
88
+ color={color}
89
+ hasSelect={hasSelect}
90
+ columns={columns}
91
+ fixedPosition={fixedPosition!}
92
+ onFilterColunas={id => console.log(id)}
93
+ />
94
+ {isLoading ? (
95
+ <SkeletonTable columns={columns} data={data} />
96
+ ) : (
97
+ <BodyTable
98
+ color={color}
99
+ hasSelect={hasSelect}
100
+ rowSelection={rowSelection}
101
+ setRowSelection={setRowSelection}
102
+ acoesChildren={acoesChildren}
103
+ data={data}
104
+ columns={columns}
105
+ />
106
+ )}
107
+ </S.StyledTable>
108
+ </S.TableContainer>
109
+ <Paginacao
110
+ color={color}
111
+ setPagination={setPagination}
112
+ tabelaPaginacao={tabelaPaginacao}
113
+ quantidadeRegistros={10}
114
+ tamanhoPaginacao={5}
115
+ />
116
+ </S.TableWrapper>
117
+ );
118
+ };
119
+
120
+ export default Tabela;
@@ -0,0 +1,106 @@
1
+ import React from 'react';
2
+ import * as S from './styles';
3
+ import SelectCustomizado from '../../atomos/Select';
4
+ import Botao from '../../atomos/Botao';
5
+
6
+ export type PaginacaoProps = {
7
+ tamanhoPaginacao?: number;
8
+ color?: string;
9
+ quantidadeRegistros?: number;
10
+ setPagination: React.Dispatch<
11
+ React.SetStateAction<{ pageIndex: number; pageSize: number }>
12
+ >;
13
+ tabelaPaginacao: {
14
+ pageIndex: number;
15
+ pageSize: number;
16
+ };
17
+ };
18
+
19
+ const Paginacao = ({
20
+ tabelaPaginacao,
21
+ color,
22
+ tamanhoPaginacao,
23
+ setPagination,
24
+ quantidadeRegistros,
25
+ }: PaginacaoProps) => {
26
+ function nextPage() {
27
+ if (tabelaPaginacao.pageIndex + 1 > tabelaPaginacao.pageSize) {
28
+ return;
29
+ }
30
+ setPagination({ pageIndex: tabelaPaginacao.pageIndex + 1, pageSize: 10 });
31
+ }
32
+
33
+ function previousPage() {
34
+ if (tabelaPaginacao.pageIndex <= 0) {
35
+ return;
36
+ }
37
+ setPagination({ pageIndex: tabelaPaginacao.pageIndex - 1, pageSize: 10 });
38
+ }
39
+
40
+ function changePage(e: number) {
41
+ setPagination({ pageIndex: e, pageSize: 10 });
42
+ }
43
+
44
+ function changeLinhas(e: string) {
45
+ setPagination({
46
+ pageIndex: tabelaPaginacao.pageIndex,
47
+ pageSize: Number(e),
48
+ });
49
+ }
50
+
51
+ return (
52
+ <S.PaginacaoWrapper color={color}>
53
+ <div className="pagination-header">
54
+ <p>
55
+ Exibindo{' '}
56
+ {tabelaPaginacao.pageIndex === 0 ? 1 : tabelaPaginacao.pageIndex} de{' '}
57
+ {quantidadeRegistros}
58
+ </p>
59
+ <div className="select-wrapper">
60
+ <SelectCustomizado
61
+ tipo="round"
62
+ onChange={e => changeLinhas(e!)}
63
+ defaultValue={'10'}
64
+ data={['10', '20', '30']}
65
+ allowDeselect={false}
66
+ />
67
+ </div>
68
+ </div>
69
+ <S.PaginationButtons color={color}>
70
+ <Botao
71
+ color={color}
72
+ data-testid="Anterior"
73
+ className="button-pagination"
74
+ tipo="default"
75
+ disabled={tabelaPaginacao.pageIndex === 1}
76
+ onClick={() => previousPage()}
77
+ >
78
+ Anterior
79
+ </Botao>
80
+ <S.PaginationMantine
81
+ value={
82
+ tabelaPaginacao.pageIndex === 0 ? 1 : tabelaPaginacao.pageIndex
83
+ }
84
+ onChange={e => {
85
+ changePage(e);
86
+ }}
87
+ total={tamanhoPaginacao!}
88
+ withControls={false}
89
+ color={color}
90
+ />
91
+ <Botao
92
+ color={color}
93
+ data-testid="Proximo"
94
+ tipo={'default'}
95
+ disabled={tamanhoPaginacao === tabelaPaginacao.pageIndex}
96
+ onClick={() => nextPage()}
97
+ className="button-pagination"
98
+ >
99
+ Próximo
100
+ </Botao>
101
+ </S.PaginationButtons>
102
+ </S.PaginacaoWrapper>
103
+ );
104
+ };
105
+
106
+ export default Paginacao;
@@ -0,0 +1,196 @@
1
+ import styled, { css } from 'styled-components'
2
+ import { Pagination } from '@mantine/core'
3
+
4
+ type ColorsProp = {
5
+ color?: string
6
+ headerSelection?: Array<String>
7
+ }
8
+
9
+ export const TableWrapper = styled.div`
10
+ ${() => css`
11
+ max-width: 1500px;
12
+ overflow-x: hidden;
13
+ `}
14
+ `
15
+
16
+ export const TableContainer = styled.div`
17
+ overflow-x: auto;
18
+ border-radius: 5px;
19
+ font-family: 'Open Sans', sans-serif;
20
+ `
21
+
22
+ export const ToogleButton = styled.div`
23
+ ${() => css`
24
+ display: flex;
25
+ justify-content: end;
26
+ align-items: center;
27
+ margin-left: auto;
28
+ `}
29
+ `
30
+
31
+ export const StyledTable = styled.table`
32
+ ${({ theme }) => css`
33
+ width: 100%;
34
+ border-collapse: collapse;
35
+
36
+ th,
37
+ td {
38
+ border-bottom: 1px solid ${theme.colors.gray['300']};
39
+ font-size: ${theme.sizes.meddium};
40
+ }
41
+
42
+ th {
43
+ background-color: ${theme.colors.gray['300']};
44
+ font-weight: 400;
45
+ }
46
+
47
+ tr:nth-child(even) {
48
+ background-color: ${theme.colors.white};
49
+ }
50
+
51
+ tr:hover {
52
+ background-color: ${theme.colors.gray['700']};
53
+ }
54
+
55
+ th.select {
56
+ min-width: 50px;
57
+ padding: 0;
58
+ }
59
+ `}
60
+ `
61
+
62
+ export const TabelaHeader = styled.thead<ColorsProp>`
63
+ ${({ theme, color }) => css`
64
+ th {
65
+ min-width: 200px;
66
+ text-align: center;
67
+ padding: 5px;
68
+ background-color: ${color};
69
+ opacity: 0.8;
70
+ color: ${theme.colors.white};
71
+ font-weight: bold;
72
+ }
73
+
74
+ .sticky {
75
+ background-color: ${color};
76
+ color: ${theme.colors.white};
77
+ }
78
+
79
+ .input-header {
80
+ background-color: ${theme.colors.white};
81
+ padding: 5px;
82
+ border-radius: 5px;
83
+ text-align: center;
84
+ display: flex;
85
+ justify-content: center;
86
+ }
87
+
88
+ .especial {
89
+ min-width: 50px;
90
+ }
91
+ `}
92
+ `
93
+ export const TabelaBody = styled.tbody`
94
+ ${({ theme }) => css`
95
+ /* height: 430px; */
96
+ width: 100%;
97
+
98
+ tr {
99
+ background-color: ${theme.colors.gray['300']};
100
+
101
+ td {
102
+ cursor: pointer;
103
+ text-align: center;
104
+ color: ${theme.colors.blackWca};
105
+ height: 40px;
106
+ font-size: ${theme.sizes.small};
107
+ }
108
+
109
+ &:hover {
110
+ opacity: 0.8;
111
+ background: ${theme.colors.white};
112
+ }
113
+
114
+ &[data-active='true'] {
115
+ background-color: ${theme.colors.gray['500']};
116
+ color: ${theme.colors.white};
117
+ }
118
+
119
+ td.select {
120
+ display: flex;
121
+ align-items: center;
122
+ justify-content: center;
123
+ height: 42px;
124
+ }
125
+ }
126
+
127
+ svg {
128
+ color: ${theme.colors.white};
129
+ }
130
+
131
+ .sticky {
132
+ background-color:;
133
+ color: ${theme.colors.white};
134
+ font-weight: bold;
135
+ }
136
+ `}
137
+ `
138
+
139
+ export const PaginacaoWrapper = styled.div<ColorsProp>`
140
+ ${({ theme, color }) => css`
141
+ color: ${color};
142
+ font-size: ${theme.sizes.small};
143
+ font-weight: bold;
144
+ text-align: center;
145
+ margin: 30px auto;
146
+ max-width: 455px;
147
+
148
+ .pagination-header {
149
+ display: flex;
150
+ justify-content: center;
151
+ align-items: center;
152
+ }
153
+
154
+ .select-wrapper {
155
+ width: 85px;
156
+ margin-left: 15px;
157
+ }
158
+ `}
159
+ `
160
+
161
+ export const PaginationMantine = styled(Pagination)`
162
+ ${({ theme }) => css`
163
+ margin: 15px 0;
164
+
165
+ button {
166
+ color: ${theme.colors.gray['700']};
167
+ font-weight: 500;
168
+ font-size: ${theme.sizes.meddium};
169
+
170
+ &[data-active='true'] {
171
+ color: ${theme.colors.white};
172
+ }
173
+ }
174
+ `}
175
+ `
176
+
177
+ export const PaginationButtons = styled.div<ColorsProp>`
178
+ ${({ theme, color }) => css`
179
+ display: flex;
180
+ align-items: center;
181
+ justify-content: center;
182
+ gap: 0.5rem;
183
+
184
+ .button-pagination {
185
+ border: 1px solid red;
186
+ height: 32px;
187
+ border: none;
188
+ color: ${color};
189
+ background-color: ${theme.colors.white};
190
+ border-radius: 5px;
191
+ font-weight: 500;
192
+ font-size: ${theme.sizes.small};
193
+ padding: 0 15px;
194
+ }
195
+ `}
196
+ `
@@ -62,7 +62,7 @@ beforeEach(() => {
62
62
  // Mock de matchMedia específico para esse teste
63
63
  Object.defineProperty(window, 'matchMedia', {
64
64
  writable: true,
65
- value: jest.fn().mockImplementation((query) => ({
65
+ value: jest.fn().mockImplementation(query => ({
66
66
  matches: false, // Aqui você pode ajustar de acordo com suas necessidades de teste
67
67
  media: query,
68
68
  onchange: null,
@@ -1,6 +1,6 @@
1
- import { MRT_Localization } from 'mantine-react-table';
1
+ // import { MRT_Localization } from 'mantine-react-table';
2
2
 
3
- export const MRT_Localization_PT_BR: MRT_Localization = {
3
+ export const MRT_Localization_PT_BR = {
4
4
  actions: 'Ações',
5
5
  and: 'e',
6
6
  cancel: 'Cancelar',
@@ -1,36 +0,0 @@
1
- import React from 'react';
2
- import TabelaHeader, { TabelaHeaderProps } from './index';
3
- import { Meta } from '@storybook/react';
4
-
5
- export default {
6
- title: 'Components/moleculas/TabelaHeader',
7
- component: TabelaHeader,
8
- } as Meta;
9
-
10
- const props: TabelaHeaderProps<any> = {
11
- setPagination: () => console.log('aqui'),
12
- setSimples: () => console.log('aqui'),
13
- filtrosPelaTabela: [{ label: 'exemplo', value: 'exemplo' }],
14
- filtrosPor: { label: 'exemplo', value: 'exemplo' },
15
- setGlobalFilter: () => console.log('aqui'),
16
- ordenarPor: { label: 'exemplo', value: 'exemplo' },
17
- setFiltrosPor: () => console.log('aqui'),
18
- setOrdenarPor: () => console.log('aqui'),
19
- setToogleBuscarColuna: () => console.log('aqui'),
20
- toogleBuscarColuna: false,
21
- btnAdicionar: false,
22
- };
23
-
24
- const Template: any = (args: TabelaHeaderProps<any>) => (
25
- <>
26
- <TabelaHeader {...args} />
27
- </>
28
- );
29
-
30
- export const TabelaHeaderStory = Template.bind({
31
- ...props,
32
- });
33
-
34
- TabelaHeaderStory.args = {
35
- ...props,
36
- };
@@ -1,53 +0,0 @@
1
- import React from 'react';
2
- import { render } from '../../../test/render';
3
- import TabelaHeader, { SelectDataProps } from './index';
4
-
5
- describe('Tabela Header', () => {
6
- const mockFilterPor: SelectDataProps = { value: 'exemplo', label: 'exemplo' };
7
-
8
- it('Renderiza corretamente', () => {
9
- const { getByText } = render(
10
- <TabelaHeader
11
- btnAdicionar={false}
12
- setSimples={() => console.log('auqi')}
13
- setPagination={() => console.log('auqi')}
14
- toogleBuscarColuna={false}
15
- setToogleBuscarColuna={() => console.log('aqui')}
16
- setGlobalFilter={() => console.log('aqui')}
17
- filtrosPelaTabela={[]}
18
- filtrosPor={mockFilterPor}
19
- ordenarPor={mockFilterPor}
20
- setFiltrosPor={() => console.log('aqui')}
21
- setOrdenarPor={() => console.log('aqui')}
22
- tituloTabela="exemplo"
23
- />
24
- );
25
-
26
- const titulo = getByText('exemplo');
27
- expect(titulo).toBeDefined();
28
- });
29
- it('botões disparam', () => {
30
- const onClickEvent = jest.fn();
31
-
32
- const { getByText } = render(
33
- <TabelaHeader
34
- btnAdicionar={false}
35
- setSimples={() => console.log('auqi')}
36
- setPagination={() => console.log('auqi')}
37
- toogleBuscarColuna={false}
38
- setToogleBuscarColuna={() => console.log('aqui')}
39
- setGlobalFilter={() => console.log('aqui')}
40
- filtrosPelaTabela={[]}
41
- filtrosPor={mockFilterPor}
42
- ordenarPor={mockFilterPor}
43
- setFiltrosPor={onClickEvent}
44
- setOrdenarPor={onClickEvent}
45
- tituloTabela="exemplo"
46
- exportarXlsx={onClickEvent}
47
- />
48
- );
49
- const botaoExportarXlsx = getByText('Baixar Planilha de Dados');
50
- botaoExportarXlsx.click();
51
- expect(onClickEvent).toHaveBeenCalled();
52
- });
53
- });
@@ -1,178 +0,0 @@
1
- import React from 'react';
2
- import { theme } from '../../../styles/theme';
3
- import Icone from '../../atomos/Icone';
4
- import SelectCustomizado from '../../atomos/Select';
5
- import ordernar from '../../../assets/imagens/icons/Ordernar.svg';
6
- import filtrar from '../../../assets/imagens/icons/Filtrar.svg';
7
- import baixarDados from '../../../assets/imagens/icons/BaixarPlanilha.svg';
8
- import buscar from '../../../assets/imagens/icons/Busca.svg';
9
- import mais from '../../../assets/imagens/icons/Mais.svg';
10
- import * as S from './styles';
11
- import Botao from '../../atomos/Botao';
12
- import InputDeTexto from '../../atomos/InputDeTexto';
13
- import {
14
- MRT_PaginationState,
15
- MRT_RowData,
16
- MRT_TableInstance,
17
- MRT_ToggleFiltersButton,
18
- } from 'mantine-react-table';
19
- import { ComboboxData } from '@mantine/core';
20
- import { MRT_ShowHideColumnsButton } from 'mantine-react-table';
21
-
22
- export type SelectDataProps = {
23
- label: string;
24
- value: string;
25
- };
26
-
27
- export type TabelaHeaderProps<T extends MRT_RowData> = {
28
- tituloTabela?: string;
29
- setOrdenarPor: React.Dispatch<React.SetStateAction<SelectDataProps>>;
30
- ordenarPor: SelectDataProps;
31
- setFiltrosPor: React.Dispatch<React.SetStateAction<SelectDataProps>>;
32
- filtrosPor: SelectDataProps;
33
- btnAdicionar: boolean;
34
- handleAdicionar?: () => void;
35
- exportarXlsx?: () => void;
36
- filtrosPelaTabela: ComboboxData | undefined;
37
- setGlobalFilter: React.Dispatch<React.SetStateAction<string>>;
38
- setToogleBuscarColuna: React.Dispatch<React.SetStateAction<boolean>>;
39
- toogleBuscarColuna: boolean;
40
- table?: MRT_TableInstance<T>;
41
- setPagination: React.Dispatch<React.SetStateAction<MRT_PaginationState>>;
42
- setSimples: React.Dispatch<React.SetStateAction<boolean>>;
43
- };
44
- const TabelaHeader = <T extends MRT_RowData>({
45
- tituloTabela,
46
- setOrdenarPor,
47
- ordenarPor,
48
- filtrosPor,
49
- setFiltrosPor,
50
- setPagination,
51
- setSimples,
52
- exportarXlsx,
53
- btnAdicionar,
54
- handleAdicionar,
55
- filtrosPelaTabela,
56
- setGlobalFilter,
57
- setToogleBuscarColuna,
58
- table,
59
- toogleBuscarColuna,
60
- }: TabelaHeaderProps<T>) => {
61
- /* exporta os dados para XLSX */
62
-
63
- return (
64
- <>
65
- <S.TabelaHeaderContainer>
66
- <h2>{tituloTabela}</h2>
67
-
68
- <div className="direita">
69
- <InputDeTexto
70
- placeholder="Pesquisar na Tabela"
71
- maw={180}
72
- tipo="table"
73
- leftSection={<Icone fill={theme.colors.blue} svg={buscar} />}
74
- onChange={e => {
75
- setSimples(true);
76
- setPagination({ pageIndex: 0, pageSize: 10 });
77
- setGlobalFilter(e.currentTarget.value);
78
- }}
79
- />
80
-
81
- <SelectCustomizado
82
- tipo="table"
83
- maw={160}
84
- data={filtrosPelaTabela}
85
- onChange={(_value, option) => setFiltrosPor(option)}
86
- value={filtrosPor ? filtrosPor.value : null}
87
- placeholder={`Aplicar Filtros`}
88
- allowDeselect={false}
89
- comboboxProps={{
90
- position: 'bottom',
91
- middlewares: { flip: false, shift: false },
92
- offset: 0,
93
- }}
94
- leftSection={
95
- <Icone
96
- width={15}
97
- height={15}
98
- fill={theme.colors.blue}
99
- svg={filtrar}
100
- />
101
- }
102
- />
103
- <SelectCustomizado
104
- tipo="table"
105
- data={[
106
- { value: 'Maior', label: 'Ordenar por: Maior' },
107
- { value: 'Menor', label: 'Ordenar por: Menor' },
108
- ]}
109
- onChange={(_value, option) => setOrdenarPor(option)}
110
- value={ordenarPor ? ordenarPor.value : null}
111
- allowDeselect={false}
112
- placeholder={`Ordenar por ${ordenarPor}`}
113
- maw={200}
114
- comboboxProps={{
115
- position: 'bottom',
116
- middlewares: { flip: false, shift: false },
117
- offset: 0,
118
- }}
119
- leftSection={
120
- <Icone
121
- width={15}
122
- height={15}
123
- fill={theme.colors.blue}
124
- svg={ordernar}
125
- />
126
- }
127
- />
128
- {exportarXlsx && (
129
- <Botao
130
- onClick={() => exportarXlsx!()}
131
- leftSection={
132
- <Icone
133
- svg={baixarDados}
134
- width={20}
135
- height={20}
136
- fill={theme.colors.blue}
137
- />
138
- }
139
- tipo="table"
140
- >
141
- Baixar Planilha de Dados
142
- </Botao>
143
- )}
144
-
145
- {btnAdicionar && (
146
- <Botao
147
- onClick={() => handleAdicionar!()}
148
- tipo="default"
149
- mah={35}
150
- color={theme.colors.blue}
151
- variant="outline"
152
- leftSection={<Icone svg={mais} fill={theme.colors.blue} />}
153
- >
154
- Adicionar
155
- </Botao>
156
- )}
157
- </div>
158
- </S.TabelaHeaderContainer>
159
- {table && (
160
- <S.TabelaHeaderIcons>
161
- <div className="mostrar-colunas">
162
- <MRT_ShowHideColumnsButton table={table!} />
163
- </div>
164
- <div className="mostrar-colunas">
165
- <MRT_ToggleFiltersButton
166
- table={table!}
167
- onClick={() => {
168
- setToogleBuscarColuna(!toogleBuscarColuna);
169
- }}
170
- />
171
- </div>
172
- </S.TabelaHeaderIcons>
173
- )}
174
- </>
175
- );
176
- };
177
-
178
- export default TabelaHeader;
@@ -1,51 +0,0 @@
1
- import styled, { css } from "styled-components";
2
-
3
- export const TabelaHeaderContainer = styled.div`
4
- ${({ theme }) => css`
5
- padding: 20px 0 15px 0;
6
- /* border-bottom: 1px dotted ${theme.colors.blue}; */
7
- display: flex;
8
- align-items: center;
9
- justify-content: space-between;
10
- gap: 20px;
11
- max-width: 100%;
12
- overflow: auto;
13
- flex-wrap: wrap;
14
-
15
- h2 {
16
- font-size: ${theme.sizes.large};
17
- color: ${theme.colors.blue};
18
- }
19
-
20
- .direita {
21
- display: flex;
22
- align-items: center;
23
- flex-wrap: wrap;
24
- gap: 20px;
25
- }
26
- `}
27
- `;
28
-
29
- export const TabelaHeaderIcons = styled.div`
30
- ${({ theme }) => css`
31
- margin-bottom: 5px;
32
- display: flex;
33
- align-items: end;
34
- justify-content: end;
35
- gap: 5px;
36
-
37
- .mostrar-colunas {
38
- border: 1px solid ${theme.colors.blue};
39
- border-radius: 5px;
40
- width: 32px;
41
- height: 32px;
42
- display: flex;
43
- align-items: center;
44
- justify-content: center;
45
-
46
- svg {
47
- color: ${theme.colors.blue};
48
- }
49
- }
50
- `}
51
- `;