wca-designsystem 1.0.67 → 1.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": "1.0.67",
2
+ "version": "1.0.68",
3
3
  "license": "MIT",
4
4
  "main": "dist/index.js",
5
5
  "typings": "dist/index.d.ts",
@@ -1,16 +1,16 @@
1
- import React from 'react';
2
- import { Meta } from '@storybook/react';
3
- import Tabela from './index';
4
- import { theme } from '../../../styles/theme';
5
- import Botao from '../../atomos/Botao';
1
+ import React from 'react'
2
+ import { Meta } from '@storybook/react'
3
+ import Tabela from './index'
4
+ import { theme } from '../../../styles/theme'
5
+ import Botao from '../../atomos/Botao'
6
6
 
7
7
  export default {
8
8
  title: 'Components/organismos/Tabela',
9
9
  component: Tabela,
10
- } as Meta;
10
+ } as Meta
11
11
 
12
12
  const generateData = () => {
13
- const data = [];
13
+ const data = []
14
14
 
15
15
  for (let i = 1; i <= 3; i++) {
16
16
  const children = [
@@ -44,7 +44,7 @@ const generateData = () => {
44
44
  exemplo: 'opa',
45
45
  exemplo2: 'opa2',
46
46
  },
47
- ];
47
+ ]
48
48
 
49
49
  data.push({
50
50
  id: i,
@@ -53,40 +53,38 @@ const generateData = () => {
53
53
  exemplo: 'opa',
54
54
  exemplo2: 'opa2',
55
55
  children,
56
- });
56
+ })
57
57
  }
58
58
 
59
- return data;
60
- };
59
+ return data
60
+ }
61
61
 
62
62
  const footer = {
63
63
  id: 0,
64
64
  name: 455,
65
65
  price: 2,
66
66
  exemplo: 4689815.609999999,
67
- };
68
- const data = generateData();
67
+ }
68
+ const data = generateData()
69
69
  const columns: any = [
70
- { key: 'expand', header: 'expand' },
71
- { key: 'id', header: 'ID' },
70
+ { key: 'id', header: 'ID', minWidth: '50px' },
72
71
  { key: 'name', header: 'Nome' },
73
72
  { key: 'price', header: 'Preço' },
74
73
  { key: 'exemplo', header: 'Exemplo' },
75
74
  { key: 'acoes', header: 'Ações' },
76
- ];
75
+ ]
77
76
 
78
77
  const Template: any = (args: any) => (
79
78
  <>
80
79
  <Tabela {...args} />
81
80
  </>
82
- );
81
+ )
83
82
 
84
- export const TabelaProps = Template.bind({});
83
+ export const TabelaProps = Template.bind({})
85
84
 
86
85
  TabelaProps.args = {
87
86
  data: data,
88
87
  footer: footer,
89
- hasExpand: true,
90
88
  hasSelect: false,
91
89
  isLoading: false,
92
90
  acoesChildren: (row: any): JSX.Element => (
@@ -117,4 +115,4 @@ TabelaProps.args = {
117
115
  quantidadeDeRegistros: 10,
118
116
  tamanhoPaginacao: 97,
119
117
  setSimples: () => console.log('aqui'),
120
- };
118
+ }
@@ -15,7 +15,7 @@ type HeaderOptions = {
15
15
 
16
16
  type HeaderTabelaProps<T> = {
17
17
  data: Array<T>
18
- rowSelection?: Array<T>;
18
+ rowSelection?: Array<T>
19
19
  columns: Column<T>[]
20
20
  selectAllChecked?: boolean
21
21
  setSelectAllChecked?: React.Dispatch<React.SetStateAction<boolean>>
@@ -103,10 +103,9 @@ const HeaderTabela = <T,>({
103
103
 
104
104
  useEffect(() => {
105
105
  if (selectAllChecked && rowSelection?.length === 0) {
106
- setSelectAllChecked?.(false);
106
+ setSelectAllChecked?.(false)
107
107
  }
108
- }, [rowSelection, selectAllChecked]);
109
-
108
+ }, [rowSelection, selectAllChecked])
110
109
  return (
111
110
  <S.TabelaHeader color={color}>
112
111
  <tr>
@@ -137,7 +136,7 @@ const HeaderTabela = <T,>({
137
136
  : ''
138
137
  }
139
138
  style={{
140
- minWidth: tdMinWidth,
139
+ minWidth: header.minWidth ? header.minWidth : tdMinWidth,
141
140
  background: coloredHeader(header.key).background,
142
141
  color: coloredHeader(header.key).color,
143
142
  left: fixedPosition?.some((fixed) => header.key === fixed)
@@ -10,6 +10,7 @@ import FooterTabela from './footer'
10
10
  export type Column<T> = {
11
11
  key: keyof T
12
12
  header: string
13
+ minWidth?: string
13
14
  render?: (value: T) => React.ReactNode
14
15
  cell?: (row: T) => React.ReactNode
15
16
  expand?: (item: T) => React.ReactNode
@@ -110,9 +111,9 @@ const Tabela = <
110
111
  setSelectAllChecked,
111
112
  tdMinWidth = '260px',
112
113
  }: CustomTableProps<T>) => {
113
- const dualScrollWrapperRef = useRef<HTMLDivElement>(null);
114
- const topScrollRef = useRef<HTMLDivElement>(null);
115
- const tableRef = useRef<HTMLDivElement>(null);
114
+ const dualScrollWrapperRef = useRef<HTMLDivElement>(null)
115
+ const topScrollRef = useRef<HTMLDivElement>(null)
116
+ const tableRef = useRef<HTMLDivElement>(null)
116
117
 
117
118
  const [toogleFiltros, setToogleFiltros] = useState(false)
118
119
  const [formatedColumns, setFormatedColumns] = useState(
@@ -127,49 +128,49 @@ const Tabela = <
127
128
  )
128
129
 
129
130
  useEffect(() => {
130
- const table = tableRef.current;
131
- const topScroll = topScrollRef.current;
132
- const dualWrapper = dualScrollWrapperRef.current;
131
+ const table = tableRef.current
132
+ const topScroll = topScrollRef.current
133
+ const dualWrapper = dualScrollWrapperRef.current
133
134
 
134
- if (!table || !topScroll || !dualWrapper) return;
135
+ if (!table || !topScroll || !dualWrapper) return
135
136
 
136
137
  const checkScrollNeeded = () => {
137
- const needsScroll = table.scrollWidth > table.clientWidth;
138
- dualWrapper.classList.toggle('has-scroll', needsScroll);
139
- topScroll.style.display = needsScroll ? 'block' : 'none';
138
+ const needsScroll = table.scrollWidth > table.clientWidth
139
+ dualWrapper.classList.toggle('has-scroll', needsScroll)
140
+ topScroll.style.display = needsScroll ? 'block' : 'none'
140
141
 
141
142
  if (table.firstChild && table.firstChild instanceof HTMLElement) {
142
- const tableWidth = table.firstChild.scrollWidth;
143
- topScroll.style.setProperty('--table-width', `${tableWidth}px`);
143
+ const tableWidth = table.firstChild.scrollWidth
144
+ topScroll.style.setProperty('--table-width', `${tableWidth}px`)
144
145
  }
145
- };
146
+ }
146
147
 
147
148
  const syncScroll = (source: HTMLElement, target: HTMLElement) => {
148
149
  if (source.scrollLeft !== target.scrollLeft) {
149
- target.scrollLeft = source.scrollLeft;
150
+ target.scrollLeft = source.scrollLeft
150
151
  }
151
- };
152
+ }
152
153
 
153
- const handleTableScroll = () => syncScroll(table, topScroll);
154
- const handleTopScroll = () => syncScroll(topScroll, table);
154
+ const handleTableScroll = () => syncScroll(table, topScroll)
155
+ const handleTopScroll = () => syncScroll(topScroll, table)
155
156
 
156
- const resizeObserver = new ResizeObserver(checkScrollNeeded);
157
- resizeObserver.observe(table);
157
+ const resizeObserver = new ResizeObserver(checkScrollNeeded)
158
+ resizeObserver.observe(table)
158
159
  if (table.firstChild) {
159
- resizeObserver.observe(table.firstChild as HTMLElement);
160
+ resizeObserver.observe(table.firstChild as HTMLElement)
160
161
  }
161
162
 
162
- checkScrollNeeded();
163
+ checkScrollNeeded()
163
164
 
164
- table.addEventListener('scroll', handleTableScroll);
165
- topScroll.addEventListener('scroll', handleTopScroll);
165
+ table.addEventListener('scroll', handleTableScroll)
166
+ topScroll.addEventListener('scroll', handleTopScroll)
166
167
 
167
168
  return () => {
168
- resizeObserver.disconnect();
169
- table.removeEventListener('scroll', handleTableScroll);
170
- topScroll.removeEventListener('scroll', handleTopScroll);
171
- };
172
- }, [data]);
169
+ resizeObserver.disconnect()
170
+ table.removeEventListener('scroll', handleTableScroll)
171
+ topScroll.removeEventListener('scroll', handleTopScroll)
172
+ }
173
+ }, [data])
173
174
 
174
175
  return (
175
176
  <S.TableWrapper>
@@ -190,10 +191,7 @@ const Tabela = <
190
191
  />
191
192
 
192
193
  <S.DualScrollWrapper ref={dualScrollWrapperRef}>
193
- <S.TopScroll
194
- ref={topScrollRef}
195
- id="table-top-scroll"
196
- />
194
+ <S.TopScroll ref={topScrollRef} id="table-top-scroll" />
197
195
  </S.DualScrollWrapper>
198
196
 
199
197
  <S.TableContainer ref={tableRef} id="table-container">
@@ -276,7 +274,6 @@ const Tabela = <
276
274
  />
277
275
  )}
278
276
  </S.ContentWrapper>
279
-
280
277
  </S.TableWrapper>
281
278
  )
282
279
  }