wca-designsystem 1.0.39 → 1.0.41

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": "1.0.39",
2
+ "version": "1.0.41",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -0,0 +1 @@
1
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M7,10L12,15L17,10H7Z" /></svg>
@@ -64,7 +64,7 @@ export function ConchaAplicacao({
64
64
  />
65
65
  </S.NavbarWrapper>
66
66
  <S.ConchaAplicacaoMainWrapper>
67
- <Container size={1500} fluid>
67
+ <Container size={1500}>
68
68
  <Cabecalho
69
69
  icone={icone}
70
70
  info={info}
@@ -12,7 +12,7 @@ export default {
12
12
  const generateData = () => {
13
13
  const data = [];
14
14
 
15
- for (let i = 1; i <= 5; i++) {
15
+ for (let i = 1; i <= 3; i++) {
16
16
  const children = [
17
17
  {
18
18
  id: `${i}-1`,
@@ -20,6 +20,22 @@ const generateData = () => {
20
20
  price: '$10',
21
21
  exemplo: 'opa',
22
22
  exemplo2: 'opa2',
23
+ children: [
24
+ {
25
+ id: `${i}-1-1`,
26
+ name: `Task ${i}-2`,
27
+ price: '$10',
28
+ exemplo: 'opa',
29
+ exemplo2: 'opa2',
30
+ },
31
+ {
32
+ id: `${i}-1-2`,
33
+ name: `Task ${i}-2`,
34
+ price: '$10',
35
+ exemplo: 'opa',
36
+ exemplo2: 'opa2',
37
+ },
38
+ ],
23
39
  },
24
40
  {
25
41
  id: `${i}-2`,
@@ -51,6 +67,7 @@ const footer = {
51
67
  };
52
68
  const data = generateData();
53
69
  const columns: any = [
70
+ { key: 'expand', header: 'expand' },
54
71
  { key: 'id', header: 'ID' },
55
72
  { key: 'name', header: 'Nome' },
56
73
  { key: 'price', header: 'Preço' },
@@ -69,7 +86,7 @@ export const TabelaProps = Template.bind({});
69
86
  TabelaProps.args = {
70
87
  data: data,
71
88
  footer: footer,
72
- hasExpand: false,
89
+ hasExpand: true,
73
90
  hasSelect: false,
74
91
  isLoading: false,
75
92
  acoesChildren: (row: any): JSX.Element => (
@@ -89,6 +106,7 @@ TabelaProps.args = {
89
106
  pageSize: 10,
90
107
  },
91
108
  rowSelection: [],
109
+ tdMinWidth: '200px',
92
110
  setRowSelection: () => console.log('selecionou'),
93
111
  setFiltrosPor: () => console.log('aqui'),
94
112
  fetchMoreData: () => console.log('fetchMoreData'),
@@ -3,7 +3,7 @@ import { Checkbox } from '@mantine/core';
3
3
  import { Column } from '.';
4
4
  import * as S from './styles';
5
5
  import { theme } from '../../../styles/theme';
6
- import SetaBaixo from '../../../assets/imagens/icons/SetaAbaixo.svg';
6
+ import SetaBaixo from '../../../assets/imagens/icons/SetaAbaixoALt.svg';
7
7
  import Icone from '../../atomos/Icone';
8
8
 
9
9
  export interface BodyTableProps<
@@ -80,7 +80,8 @@ function BodyTable<
80
80
  setRowSelection?:
81
81
  | React.Dispatch<React.SetStateAction<Array<T>>>
82
82
  | undefined,
83
- color?: string
83
+ color?: string,
84
+ nivel: number = 0
84
85
  ): JSX.Element[] {
85
86
  const isSelected = rowSelection?.some(row => row.id === item.id);
86
87
  const hasChildren = item.children && item.children.length > 0;
@@ -114,18 +115,19 @@ function BodyTable<
114
115
  style={{
115
116
  cursor: hasChildren ? 'pointer' : 'not-allowed',
116
117
  opacity: hasChildren ? 1 : 0.5,
118
+ marginLeft: 25 * nivel,
117
119
  }}
118
120
  >
119
121
  <Icone
120
122
  svg={SetaBaixo}
121
- fill={theme.colors.white}
123
+ fill={color}
122
124
  style={{
123
125
  transform: expandedRows.has(item.id)
124
126
  ? 'rotate(-180deg)'
125
127
  : hasChildren
126
128
  ? 'rotate(0deg)'
127
129
  : 'rotate(-90deg)',
128
- color: theme.colors.white,
130
+ color: color,
129
131
  transition: 'ease-in 0.2s',
130
132
  }}
131
133
  />
@@ -201,7 +203,8 @@ function BodyTable<
201
203
  acoesChildren,
202
204
  rowSelection,
203
205
  setRowSelection,
204
- color
206
+ color,
207
+ nivel + 1
205
208
  )
206
209
  )
207
210
  : []),
@@ -19,7 +19,12 @@ const FooterTabela = <T,>({
19
19
  <tfoot style={{ background: color }}>
20
20
  <S.FooterRow>
21
21
  {columns.map((column, index) => (
22
- <S.FooterCell key={index} tdMinWidth={tdMinWidth} color={color}>
22
+ <S.FooterCell
23
+ className={column.key == 'expand' ? 'expand' : ''}
24
+ key={index}
25
+ tdMinWidth={tdMinWidth}
26
+ color={color}
27
+ >
23
28
  {footer[column.key] ?? '-'}
24
29
  </S.FooterCell>
25
30
  ))}
@@ -110,6 +110,10 @@ const Tabela = <
110
110
  setSelectAllChecked,
111
111
  tdMinWidth = '260px',
112
112
  }: CustomTableProps<T>) => {
113
+
114
+ const tableRef = useRef<HTMLDivElement>(null);
115
+ const topScrollRef = useRef<HTMLDivElement>(null);
116
+
113
117
  const [toogleFiltros, setToogleFiltros] = useState(false);
114
118
  const [formatedColumns, setFormatedColumns] = useState(
115
119
  columns.map(column => ({
@@ -122,32 +126,34 @@ const Tabela = <
122
126
  column => column.active === true
123
127
  );
124
128
 
125
- const topScrollRef = useRef<HTMLDivElement>(null);
126
- const tabelaRef = useRef<HTMLTableElement>(null);
127
- const TableContainerRef = useRef<HTMLDivElement>(null);
128
-
129
- // Sincroniza o scroll horizontal entre os dois scrollbars
130
129
  useEffect(() => {
131
- if (!fetchMoreData || !TableContainerRef.current) return;
132
-
133
- const handleScroll = () => {
134
- const element = TableContainerRef.current;
135
- if (element) {
136
- const atBottom =
137
- element.scrollHeight - element.scrollTop <= element.clientHeight + 10; // Margem de erro
138
- if (atBottom) {
139
- fetchMoreData(); // Dispara a função ao atingir o final do scroll
140
- }
130
+ const table = tableRef.current;
131
+ const topScroll = topScrollRef.current;
132
+
133
+ if (!table || !topScroll) return;
134
+
135
+ const syncScroll = (source: HTMLElement, target: HTMLElement) => {
136
+ if (source.scrollLeft !== target.scrollLeft) {
137
+ target.scrollLeft = source.scrollLeft;
141
138
  }
142
139
  };
143
140
 
144
- const currentRef = TableContainerRef.current;
145
- currentRef.addEventListener('scroll', handleScroll);
141
+ const handleTableScroll = () => table && topScroll && syncScroll(table, topScroll);
142
+ const handleTopScroll = () => topScroll && table && syncScroll(topScroll, table);
143
+
144
+ table.addEventListener('scroll', handleTableScroll);
145
+ topScroll.addEventListener('scroll', handleTopScroll);
146
+
147
+ if (table.firstChild && table.firstChild instanceof HTMLElement) {
148
+ const tableWidth = table.firstChild.scrollWidth;
149
+ topScroll.style.setProperty('--table-width', `${tableWidth}px`);
150
+ }
146
151
 
147
152
  return () => {
148
- currentRef.removeEventListener('scroll', handleScroll);
153
+ table.removeEventListener('scroll', handleTableScroll);
154
+ topScroll.removeEventListener('scroll', handleTopScroll);
149
155
  };
150
- }, [fetchMoreData]);
156
+ }, []);
151
157
 
152
158
  return (
153
159
  <S.TableWrapper>
@@ -166,10 +172,15 @@ const Tabela = <
166
172
  ordenarPor={ordenarPor}
167
173
  setOrdenarPor={setOrdenarPor}
168
174
  />
169
- {/* Scroll horizontal no topo */}
170
- <S.TableContainer ref={TableContainerRef}>
171
- <S.ScrollWrapper ref={topScrollRef}></S.ScrollWrapper>
172
- <S.StyledTable ref={tabelaRef}>
175
+ <S.DualScrollWrapper>
176
+ <S.TopScroll ref={topScrollRef} id="top-scroll" />
177
+ </S.DualScrollWrapper>
178
+
179
+ <S.TableContainer
180
+ ref={tableRef}
181
+ id="table-container"
182
+ >
183
+ <S.StyledTable>
173
184
  {data?.length == 0 ? (
174
185
  <></>
175
186
  ) : (
@@ -17,13 +17,69 @@ export const TableWrapper = styled.div`
17
17
  `}
18
18
  `;
19
19
 
20
+ export const DualScrollWrapper = styled.div`
21
+ max-width: 1500px;
22
+ width: 100%;
23
+ display: flex;
24
+ flex-direction: column;
25
+ `;
26
+
27
+ export const TopScroll = styled.div`
28
+ overflow-x: auto;
29
+ height: 20px;
30
+ background: #f5f5f5;
31
+ border-bottom: none;
32
+ border-radius: 5px 5px 0 0;
33
+
34
+ scrollbar-width: initial;
35
+ scrollbar-color:rgb(160, 160, 160) #f1f1f1;
36
+
37
+ &::-webkit-scrollbar {
38
+ height: 8px;
39
+ display: none;
40
+ }
41
+
42
+ &::-webkit-scrollbar-track {
43
+ background: #f1f1f1;
44
+ border-radius: 4px;
45
+ }
46
+
47
+ &::-webkit-scrollbar-thumb {
48
+ background: #888;
49
+ border-radius: 4px;
50
+ &:hover {
51
+ background: #555;
52
+ }
53
+ }
54
+
55
+ &::after {
56
+ content: '';
57
+ display: block;
58
+ width: var(--table-width, 100%);
59
+ height: 1px;
60
+ }
61
+ `;
62
+
20
63
  export const TableContainer = styled.div`
21
64
  overflow-x: auto;
22
65
  max-height: 500px;
23
66
  border-radius: 5px;
24
67
  font-family: 'Open Sans', sans-serif;
25
68
  max-width: 1500px;
26
- width: 100%;
69
+ width: 100;
70
+
71
+ scrollbar-width: initial;
72
+ scrollbar-color:rgb(160, 160, 160) #f1f1f1;
73
+
74
+ &::-webkit-scrollbar-track {
75
+ background: #f1f1f1;
76
+ border-radius: 6px;
77
+ }
78
+
79
+
80
+ &::-webkit-scrollbar-corner {
81
+ background: #f1f1f1;
82
+ }
27
83
  `;
28
84
 
29
85
  export const StyledTable = styled.table`
@@ -139,12 +195,14 @@ export const TabelaBody = styled.tbody<ColorsProp>`
139
195
 
140
196
  .expand {
141
197
  position: relative;
142
- width: 50px;
143
- min-height: 53px;
144
- background-color: ${color};
198
+ width: 30px;
199
+ min-height: 25px;
200
+ border-radius: 50px;
145
201
  display: flex;
146
202
  align-items: center;
147
203
  justify-content: center;
204
+ border: unset;
205
+ padding-left: 5px;
148
206
  }
149
207
 
150
208
  tr {
@@ -259,8 +317,10 @@ export const PaginationButtons = styled.div<ColorsProp>`
259
317
  export const ScrollWrapper = styled.div`
260
318
  position: relative;
261
319
  z-index: 10;
262
- overflow-x: visible;
320
+ overflow-x: auto;
263
321
  width: 100%;
322
+ background: red;
323
+ border: 10px solid blue;
264
324
  `;
265
325
 
266
326
  export const FakeTable = styled.div`
@@ -281,4 +341,9 @@ export const FooterCell = styled.td<{ tdMinWidth: string; color?: string }>`
281
341
  min-width: ${({ tdMinWidth }) => tdMinWidth};
282
342
  padding: 5px;
283
343
  border-top: 1px solid ${({ theme }) => theme.colors.gray[500]};
344
+
345
+ &.expand {
346
+ min-width: 50px;
347
+ max-width: 100%;
348
+ }
284
349
  `;