wca-designsystem 0.0.66 → 0.0.68

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.66",
2
+ "version": "0.0.68",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -14,7 +14,7 @@ import plus from '../../../assets/imagens/icons/Mais.svg';
14
14
  import { Menu, Switch } from '@mantine/core';
15
15
 
16
16
  export type TabelaHeaderProps<
17
- T extends { id: string | number; children: Array<T> }
17
+ T extends { id: string | number; children?: Array<T> }
18
18
  > = {
19
19
  globalFilter: string;
20
20
  setGlobalFilter: React.Dispatch<React.SetStateAction<string>>;
@@ -30,7 +30,7 @@ export type TabelaHeaderProps<
30
30
  columns: Column<T>[];
31
31
  setFormatedColumns: React.Dispatch<React.SetStateAction<Column<T>[]>>;
32
32
  };
33
- const TabelaHeader = <T extends { id: string | number; children: Array<T> }>({
33
+ const TabelaHeader = <T extends { id: string | number; children?: Array<T> }>({
34
34
  globalFilter,
35
35
  setGlobalFilter,
36
36
  setToogleFiltros,
@@ -46,8 +46,8 @@ const generateData = () => {
46
46
  const data = generateData();
47
47
  const columns: any = [
48
48
  {
49
- key: 'expand',
50
- header: 'expand',
49
+ key: 'select',
50
+ header: 'select',
51
51
  },
52
52
  { key: 'id', header: 'ID' },
53
53
  { key: 'name', header: 'Nome' },
@@ -66,7 +66,8 @@ export const TabelaProps = Template.bind({});
66
66
 
67
67
  TabelaProps.args = {
68
68
  data: data,
69
- hasExpand: true,
69
+ hasExpand: false,
70
+ hasSelect: true,
70
71
  acoesChildren: (row: any): JSX.Element => (
71
72
  <>
72
73
  <Botao onClick={() => console.log(row)} tipo={'table'} children={'▶'} />
@@ -1,4 +1,4 @@
1
- import React, { useState, useCallback, useRef, useEffect } from 'react';
1
+ import React, { useState, useCallback, useRef } from 'react';
2
2
  import { Checkbox } from '@mantine/core';
3
3
  import { Column } from '.';
4
4
  import * as S from './styles';
@@ -7,7 +7,7 @@ import SetaBaixo from '../../../assets/imagens/icons/SetaAbaixo.svg';
7
7
  import Icone from '../../atomos/Icone';
8
8
 
9
9
  export interface BodyTableProps<
10
- T extends { id: string | number; children: Array<T> }
10
+ T extends { id: string | number; children?: Array<T> }
11
11
  > {
12
12
  data: Array<T>;
13
13
  columns: Column<T>[];
@@ -20,10 +20,9 @@ export interface BodyTableProps<
20
20
  setRowSelection?: React.Dispatch<React.SetStateAction<Array<T>>> | undefined;
21
21
  hasInfinitScrool?: boolean;
22
22
  hasMoreData?: boolean;
23
- fetchMoreData?: () => void;
24
23
  }
25
24
 
26
- function BodyTable<T extends { id: string | number; children: Array<T> }>(
25
+ function BodyTable<T extends { id: string | number; children?: Array<T> }>(
27
26
  props: BodyTableProps<T>
28
27
  ) {
29
28
  const {
@@ -32,7 +31,6 @@ function BodyTable<T extends { id: string | number; children: Array<T> }>(
32
31
  acoesChildren,
33
32
  hasSelect,
34
33
  rowSelection,
35
- fetchMoreData,
36
34
  hasMoreData,
37
35
  hasInfinitScrool,
38
36
  setRowSelection,
@@ -87,22 +85,6 @@ function BodyTable<T extends { id: string | number; children: Array<T> }>(
87
85
 
88
86
  return [
89
87
  <tr key={`row-${item.id}`}>
90
- {hasSelect && (
91
- <td className="select">
92
- <Checkbox
93
- size="md"
94
- color={color}
95
- type="checkbox"
96
- checked={rowSelection?.some(selected => selected.id === item.id)}
97
- onChange={() => {
98
- handleRowSelect(
99
- item,
100
- rowSelection!.some(selected => selected.id === item.id)
101
- );
102
- }}
103
- />
104
- </td>
105
- )}
106
88
  {columns.map((column, colIndex) => {
107
89
  if (column.key === 'expand') {
108
90
  return (
@@ -134,6 +116,26 @@ function BodyTable<T extends { id: string | number; children: Array<T> }>(
134
116
  );
135
117
  }
136
118
 
119
+ if (column.key === 'select') {
120
+ return (
121
+ <td className="select" key={`select-${colIndex}`}>
122
+ <Checkbox
123
+ size="md"
124
+ color={color}
125
+ type="checkbox"
126
+ checked={rowSelection?.some(
127
+ selected => selected.id === item.id
128
+ )}
129
+ onChange={() => {
130
+ handleRowSelect(
131
+ item,
132
+ rowSelection!.some(selected => selected.id === item.id)
133
+ );
134
+ }}
135
+ />
136
+ </td>
137
+ );
138
+ }
137
139
  if (column.key === 'acoes' && acoesChildren) {
138
140
  return (
139
141
  <td key={`acoes-${colIndex}`} className="acoes">
@@ -172,7 +174,7 @@ function BodyTable<T extends { id: string | number; children: Array<T> }>(
172
174
  })}
173
175
  </tr>,
174
176
  ...(expandedRows.has(item.id)
175
- ? item.children.flatMap(child =>
177
+ ? item?.children!.flatMap(child =>
176
178
  renderRows(
177
179
  child,
178
180
  columns,
@@ -82,8 +82,10 @@ const HeaderTabela = <T,>({
82
82
  {hasExpand && <></>}
83
83
  {hasSelect && <></>}
84
84
  {columns.map((header, index) => {
85
- if (header.key === 'expand' || header.key === 'select')
85
+ if (header.key === 'expand')
86
86
  return <th key={index} className="expand"></th>;
87
+ if (header.key === 'select')
88
+ return <th key={index} className="select"></th>;
87
89
  if (header.key !== 'acoes') {
88
90
  return (
89
91
  <th
@@ -65,7 +65,7 @@ export type CustomTableProps<
65
65
  hasInfinitScrool?: boolean;
66
66
  };
67
67
 
68
- const Tabela = <T extends { id: string | number; children: Array<T> }>({
68
+ const Tabela = <T extends { id: string | number; children?: Array<T> }>({
69
69
  data,
70
70
  columns,
71
71
  setPagination,
@@ -185,7 +185,6 @@ const Tabela = <T extends { id: string | number; children: Array<T> }>({
185
185
  ) : (
186
186
  <BodyTable
187
187
  color={color}
188
- fetchMoreData={fetchMoreData}
189
188
  hasInfinitScrool={hasInfinitScrool}
190
189
  hasSelect={hasSelect}
191
190
  hasMoreData={quantidadeRegistros !== data.length}
@@ -76,7 +76,7 @@ export const TabelaHeader = styled.thead<ColorsProp>`
76
76
 
77
77
  th.expand {
78
78
  width: 50px;
79
- min-width: 50px;
79
+ min-width: 100%;
80
80
  }
81
81
 
82
82
  .sticky {
@@ -101,14 +101,19 @@ export const TabelaHeader = styled.thead<ColorsProp>`
101
101
 
102
102
  export const TabelaBody = styled.tbody<ColorsProp>`
103
103
  ${({ theme, color }) => css`
104
- overflow-x: auto;
105
- overflow-y: auto; /* Habilita o scroll vertical */
106
- max-height: 500px; /*
104
+ overflow-x: auto;
105
+ overflow-y: auto; /* Habilita o scroll vertical */
106
+ max-height: 500px;
107
107
 
108
108
  .select {
109
109
  background-color: ${color};
110
- position: absolute;
111
- /* left: 17px; */
110
+ position: relative;
111
+ width: 50px;
112
+ min-height: 53px;
113
+ background-color: ${color};
114
+ display: flex;
115
+ align-items: center;
116
+ justify-content: center;
112
117
  }
113
118
 
114
119
  .expand {