norma-library 0.6.89 → 0.6.90
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/dist/esm/components/Accordion.js +2 -3
- package/dist/esm/components/Accordion.js.map +1 -1
- package/dist/esm/components/ProgressBar.js +6 -7
- package/dist/esm/components/ProgressBar.js.map +1 -1
- package/dist/esm/components/StatusModal/StatusModal.d.ts +2 -2
- package/dist/esm/components/StatusModal/StatusModal.js.map +1 -1
- package/dist/esm/components/Svgs.js +3 -4
- package/dist/esm/components/Svgs.js.map +1 -1
- package/dist/esm/components/UncontrolledTable/UncontrolledTable.d.ts +4 -0
- package/dist/esm/components/UncontrolledTable/UncontrolledTable.js +120 -0
- package/dist/esm/components/UncontrolledTable/UncontrolledTable.js.map +1 -0
- package/dist/esm/components/UncontrolledTable/UncontrolledTable.style.d.ts +14 -0
- package/dist/esm/components/UncontrolledTable/UncontrolledTable.style.js +22 -0
- package/dist/esm/components/UncontrolledTable/UncontrolledTable.style.js.map +1 -0
- package/dist/esm/components/UncontrolledTable/components/TableButton/TableButton.d.ts +13 -0
- package/dist/esm/components/UncontrolledTable/components/TableButton/TableButton.js +31 -0
- package/dist/esm/components/UncontrolledTable/components/TableButton/TableButton.js.map +1 -0
- package/dist/esm/components/UncontrolledTable/components/TableButton/TableButton.style.d.ts +10 -0
- package/dist/esm/components/UncontrolledTable/components/TableButton/TableButton.style.js +9 -0
- package/dist/esm/components/UncontrolledTable/components/TableButton/TableButton.style.js.map +1 -0
- package/dist/esm/components/UncontrolledTable/components/header/header.d.ts +15 -0
- package/dist/esm/components/UncontrolledTable/components/header/header.js +49 -0
- package/dist/esm/components/UncontrolledTable/components/header/header.js.map +1 -0
- package/dist/esm/components/UncontrolledTable/components/header/header.styles.d.ts +4 -0
- package/dist/esm/components/UncontrolledTable/components/header/header.styles.js +8 -0
- package/dist/esm/components/UncontrolledTable/components/header/header.styles.js.map +1 -0
- package/dist/esm/components/UncontrolledTable/components/index.d.ts +4 -3
- package/dist/esm/components/UncontrolledTable/components/index.js +4 -3
- package/dist/esm/components/UncontrolledTable/components/index.js.map +1 -1
- package/dist/esm/components/UncontrolledTable/components/pagination/pagination.d.ts +11 -0
- package/dist/esm/components/UncontrolledTable/components/pagination/pagination.js +18 -0
- package/dist/esm/components/UncontrolledTable/components/pagination/pagination.js.map +1 -0
- package/dist/esm/components/UncontrolledTable/components/pagination/pagination.styles.d.ts +1 -0
- package/dist/esm/components/UncontrolledTable/components/pagination/pagination.styles.js +5 -0
- package/dist/esm/components/UncontrolledTable/components/pagination/pagination.styles.js.map +1 -0
- package/dist/esm/components/UncontrolledTable/components/row/DraggableRow.js +1 -1
- package/dist/esm/components/UncontrolledTable/components/row/DraggableRow.js.map +1 -1
- package/dist/esm/components/UncontrolledTable/components/row/SimpleRow.js +1 -1
- package/dist/esm/components/UncontrolledTable/components/row/SimpleRow.js.map +1 -1
- package/dist/esm/components/UncontrolledTable/components/row/styles.d.ts +1 -1
- package/dist/esm/components/UncontrolledTable/components/row/styles.js +2 -8
- package/dist/esm/components/UncontrolledTable/components/row/styles.js.map +1 -1
- package/dist/esm/components/UncontrolledTable/interface.d.ts +27 -10
- package/dist/esm/components/UncontrolledTabs/UncontrolledTabs.d.ts +1 -0
- package/dist/esm/components/UncontrolledTabs/UncontrolledTabs.js +3 -3
- package/dist/esm/components/UncontrolledTabs/UncontrolledTabs.js.map +1 -1
- package/dist/esm/hooks/useClickOutside.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/package.json +3 -3
- package/src/components/Accordion.tsx +19 -15
- package/src/components/ProgressBar.tsx +28 -28
- package/src/components/StatusModal/StatusModal.tsx +2 -2
- package/src/components/Svgs.tsx +1 -5
- package/src/components/UncontrolledTable/{styles.tsx → UncontrolledTable.style.tsx} +2 -1
- package/src/components/UncontrolledTable/{index.tsx → UncontrolledTable.tsx} +69 -87
- package/src/components/UncontrolledTable/components/TableButton/TableButton.style.tsx +48 -0
- package/src/components/UncontrolledTable/components/TableButton/TableButton.tsx +64 -0
- package/src/components/UncontrolledTable/components/header/header.styles.tsx +26 -0
- package/src/components/UncontrolledTable/components/header/header.tsx +85 -0
- package/src/components/UncontrolledTable/components/index.tsx +6 -3
- package/src/components/UncontrolledTable/components/pagination/{index.tsx → pagination.tsx} +1 -1
- package/src/components/UncontrolledTable/components/row/DraggableRow.tsx +11 -11
- package/src/components/UncontrolledTable/components/row/SimpleRow.tsx +7 -8
- package/src/components/UncontrolledTable/components/row/styles.tsx +5 -15
- package/src/components/UncontrolledTable/interface.ts +58 -38
- package/src/components/UncontrolledTabs/UncontrolledTabs.tsx +5 -3
- package/src/hooks/useClickOutside.tsx +9 -9
- package/src/index.ts +1 -1
- package/src/stories/ModalStatus.stories.tsx +8 -0
- package/src/stories/ProductCard.stories.tsx +1 -1
- package/src/stories/UncontrolledTable.stories.tsx +322 -20
- package/src/stories/UncontrolledTabs.stories.tsx +19 -1
- package/src/components/UncontrolledTable/components/header/index.tsx +0 -89
- package/src/components/UncontrolledTable/components/header/styles.tsx +0 -67
- /package/src/components/UncontrolledTable/components/pagination/{styles.tsx → pagination.styles.tsx} +0 -0
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import React, { useState, useMemo, useRef } from 'react'
|
|
2
|
-
import * as S from './styles';
|
|
3
|
-
|
|
1
|
+
import React, { useState, useMemo, useRef } from 'react'
|
|
4
2
|
import {
|
|
5
3
|
flexRender,
|
|
6
4
|
getCoreRowModel,
|
|
@@ -8,8 +6,7 @@ import {
|
|
|
8
6
|
useReactTable,
|
|
9
7
|
ColumnFiltersState,
|
|
10
8
|
TableOptions,
|
|
11
|
-
} from '@tanstack/react-table'
|
|
12
|
-
|
|
9
|
+
} from '@tanstack/react-table'
|
|
13
10
|
import {
|
|
14
11
|
DndContext,
|
|
15
12
|
MouseSensor,
|
|
@@ -20,13 +17,15 @@ import {
|
|
|
20
17
|
useSensors,
|
|
21
18
|
TouchSensor,
|
|
22
19
|
KeyboardSensor,
|
|
23
|
-
} from '@dnd-kit/core'
|
|
24
|
-
import { restrictToVerticalAxis } from '@dnd-kit/modifiers'
|
|
25
|
-
import { arrayMove, SortableContext, verticalListSortingStrategy } from '@dnd-kit/sortable'
|
|
20
|
+
} from '@dnd-kit/core'
|
|
21
|
+
import { restrictToVerticalAxis } from '@dnd-kit/modifiers'
|
|
22
|
+
import { arrayMove, SortableContext, verticalListSortingStrategy } from '@dnd-kit/sortable'
|
|
23
|
+
|
|
24
|
+
import useClickOutside from '../../hooks/useClickOutside'
|
|
25
|
+
import { Pagination, Header, SimpleRow, DraggableRow, RowDragHandleCell } from './components'
|
|
26
|
+
import { UncontrolledTableProps } from './interface'
|
|
26
27
|
|
|
27
|
-
import
|
|
28
|
-
import { UncontrolledTableProps } from './interface';
|
|
29
|
-
import useClickOutside from '../../hooks/useClickOutside';
|
|
28
|
+
import * as S from './UncontrolledTable.style'
|
|
30
29
|
|
|
31
30
|
const UncontrolledTable = (props: UncontrolledTableProps) => {
|
|
32
31
|
const {
|
|
@@ -35,30 +34,22 @@ const UncontrolledTable = (props: UncontrolledTableProps) => {
|
|
|
35
34
|
onClick,
|
|
36
35
|
onMouseOver,
|
|
37
36
|
onMouseOut,
|
|
38
|
-
showTotalResults,
|
|
39
|
-
showSettings,
|
|
40
|
-
onChangePage,
|
|
41
37
|
pagination,
|
|
42
38
|
totalPages,
|
|
43
|
-
showClearFields,
|
|
44
|
-
onClearFieldsClick,
|
|
45
|
-
onFilterClick,
|
|
46
|
-
onSortClick,
|
|
47
|
-
customTotalResults,
|
|
48
39
|
labels,
|
|
49
40
|
tableClassName,
|
|
50
|
-
|
|
51
|
-
stickyHeaderP,
|
|
41
|
+
sticky,
|
|
52
42
|
draggable,
|
|
53
|
-
|
|
54
|
-
|
|
43
|
+
buttons,
|
|
44
|
+
configs,
|
|
45
|
+
hideColumns,
|
|
46
|
+
} = props
|
|
55
47
|
|
|
56
|
-
const
|
|
57
|
-
|
|
58
|
-
const [
|
|
59
|
-
const [
|
|
60
|
-
const [
|
|
61
|
-
const [orderLargest, setOrderLargest] = useState(false);
|
|
48
|
+
const { onChangePage, onFilterClick, onSortClick, onDragEnd, onColumnVisibilityChange } = props
|
|
49
|
+
|
|
50
|
+
const [openFilterDialog, setOpenFilterDialog] = useState('')
|
|
51
|
+
const [sorting, setSorting] = useState<any>([])
|
|
52
|
+
const [filterByColumn, setFilterByColumn] = useState<ColumnFiltersState>([])
|
|
62
53
|
|
|
63
54
|
const _columns: any[] = useMemo(() => {
|
|
64
55
|
return draggable
|
|
@@ -66,7 +57,7 @@ const UncontrolledTable = (props: UncontrolledTableProps) => {
|
|
|
66
57
|
{
|
|
67
58
|
id: 'drag',
|
|
68
59
|
header: '',
|
|
69
|
-
cell: ({ row }: { row: any }) => <RowDragHandleCell rowId={row.id}/>,
|
|
60
|
+
cell: ({ row }: { row: any }) => <RowDragHandleCell rowId={row.id} />,
|
|
70
61
|
disableMenu: true,
|
|
71
62
|
},
|
|
72
63
|
...columns.map((column) => ({
|
|
@@ -74,8 +65,8 @@ const UncontrolledTable = (props: UncontrolledTableProps) => {
|
|
|
74
65
|
disableMenu: true,
|
|
75
66
|
})),
|
|
76
67
|
]
|
|
77
|
-
: columns
|
|
78
|
-
}, [columns])
|
|
68
|
+
: columns
|
|
69
|
+
}, [columns])
|
|
79
70
|
|
|
80
71
|
const reactTableConfig = useMemo(() => {
|
|
81
72
|
const config: TableOptions<unknown> = {
|
|
@@ -87,64 +78,59 @@ const UncontrolledTable = (props: UncontrolledTableProps) => {
|
|
|
87
78
|
pagination: pagination,
|
|
88
79
|
},
|
|
89
80
|
rowCount: totalPages,
|
|
90
|
-
getCoreRowModel: getCoreRowModel(),
|
|
91
|
-
getSortedRowModel: getSortedRowModel(),
|
|
92
|
-
onSortingChange: setSorting,
|
|
93
|
-
onColumnFiltersChange: setFilterByColumn,
|
|
94
81
|
manualPagination: true,
|
|
95
|
-
getRowId: (row: any) => row.id,
|
|
96
82
|
debugTable: true,
|
|
97
83
|
debugHeaders: true,
|
|
98
84
|
debugColumns: true,
|
|
99
|
-
|
|
85
|
+
getRowId: (row: any) => row.id,
|
|
86
|
+
getCoreRowModel: getCoreRowModel(),
|
|
87
|
+
getSortedRowModel: getSortedRowModel(),
|
|
88
|
+
onSortingChange: setSorting,
|
|
89
|
+
onColumnFiltersChange: setFilterByColumn,
|
|
90
|
+
}
|
|
100
91
|
|
|
101
|
-
return config
|
|
102
|
-
}, [data, sorting, filterByColumn, _columns, pagination])
|
|
92
|
+
return config
|
|
93
|
+
}, [data, sorting, filterByColumn, _columns, pagination])
|
|
103
94
|
|
|
104
|
-
const table = useReactTable(reactTableConfig)
|
|
105
|
-
const filterRef = useRef<HTMLDivElement>(null)
|
|
95
|
+
const table = useReactTable(reactTableConfig)
|
|
96
|
+
const filterRef = useRef<HTMLDivElement>(null)
|
|
106
97
|
|
|
107
|
-
useClickOutside(filterRef, () => setOpenFilterDialog(''))
|
|
98
|
+
useClickOutside(filterRef, () => setOpenFilterDialog(''))
|
|
108
99
|
|
|
109
100
|
const handleDragEnd = (event: DragEndEvent) => {
|
|
110
|
-
const { active, over } = event
|
|
111
|
-
|
|
101
|
+
const { active, over } = event
|
|
112
102
|
|
|
113
103
|
if (active && over && active.id !== over.id && onDragEnd) {
|
|
114
|
-
const oldIndex = dataIds.indexOf(active.id)
|
|
115
|
-
const newIndex = dataIds.indexOf(over.id)
|
|
104
|
+
const oldIndex = dataIds.indexOf(active.id)
|
|
105
|
+
const newIndex = dataIds.indexOf(over.id)
|
|
116
106
|
|
|
117
|
-
const _data = arrayMove(data, oldIndex, newIndex)
|
|
118
|
-
onDragEnd(_data)
|
|
107
|
+
const _data = arrayMove(data, oldIndex, newIndex)
|
|
108
|
+
onDragEnd(_data)
|
|
119
109
|
}
|
|
120
|
-
}
|
|
110
|
+
}
|
|
121
111
|
|
|
122
|
-
const sensors = useSensors(
|
|
112
|
+
const sensors = useSensors(
|
|
113
|
+
useSensor(MouseSensor, {}),
|
|
114
|
+
useSensor(TouchSensor, {}),
|
|
115
|
+
useSensor(KeyboardSensor, {}),
|
|
116
|
+
)
|
|
123
117
|
|
|
124
118
|
const dataIds = useMemo<UniqueIdentifier[]>(
|
|
125
119
|
() => data?.map((item: { id: UniqueIdentifier }) => item.id) || [],
|
|
126
120
|
[data],
|
|
127
|
-
)
|
|
121
|
+
)
|
|
128
122
|
|
|
129
123
|
return (
|
|
130
|
-
<S.Container>
|
|
124
|
+
<S.Container className="Norma__Table">
|
|
131
125
|
<Header
|
|
132
126
|
table={table}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
setOrderSmallest={setOrderSmallest}
|
|
141
|
-
showClearFiels={showClearFields}
|
|
142
|
-
customTotalResults={customTotalResults}
|
|
143
|
-
clearLabel={labels?.clearFilter}
|
|
144
|
-
onClearFieldsClick={() => onClearFieldsClick && onClearFieldsClick()}
|
|
145
|
-
customIcons={props.customIcons}
|
|
146
|
-
hideColumns={props.hideColumns}
|
|
147
|
-
onColumnVisibilityChange={props.onColumnVisibilityChange}
|
|
127
|
+
labels={{
|
|
128
|
+
columns: labels?.columns || 'Colunas',
|
|
129
|
+
}}
|
|
130
|
+
configs={configs}
|
|
131
|
+
menus={buttons}
|
|
132
|
+
hideColumns={hideColumns}
|
|
133
|
+
onColumnVisibilityChange={onColumnVisibilityChange}
|
|
148
134
|
/>
|
|
149
135
|
<DndContext
|
|
150
136
|
collisionDetection={closestCenter}
|
|
@@ -153,7 +139,7 @@ const UncontrolledTable = (props: UncontrolledTableProps) => {
|
|
|
153
139
|
sensors={sensors}
|
|
154
140
|
>
|
|
155
141
|
<S.Table className={tableClassName || ''}>
|
|
156
|
-
<S.Thead $sticky={
|
|
142
|
+
<S.Thead $sticky={sticky?.enabled} $stickyTopP={sticky?.top}>
|
|
157
143
|
{table.getHeaderGroups().map((headerGroup: any) => (
|
|
158
144
|
<S.TableRow key={headerGroup.id}>
|
|
159
145
|
{headerGroup.headers.map((header: any) => (
|
|
@@ -161,11 +147,12 @@ const UncontrolledTable = (props: UncontrolledTableProps) => {
|
|
|
161
147
|
<S.ColumnContent
|
|
162
148
|
onClick={() => {
|
|
163
149
|
if (!header?.column?.columnDef?.disableMenu)
|
|
164
|
-
setOpenFilterDialog(header.column.columnDef.accessorKey)
|
|
150
|
+
setOpenFilterDialog(header.column.columnDef.accessorKey)
|
|
165
151
|
}}
|
|
166
152
|
>
|
|
167
153
|
<S.TextColumn>
|
|
168
|
-
{!header.isPlaceholder &&
|
|
154
|
+
{!header.isPlaceholder &&
|
|
155
|
+
flexRender(header.column.columnDef.header, header.getContext())}
|
|
169
156
|
</S.TextColumn>
|
|
170
157
|
{!header?.column?.columnDef?.disableMenu && (
|
|
171
158
|
<S.IconFilterDialog>
|
|
@@ -179,12 +166,9 @@ const UncontrolledTable = (props: UncontrolledTableProps) => {
|
|
|
179
166
|
<S.FilterDialog ref={filterRef}>
|
|
180
167
|
<S.ListFilterDialog>
|
|
181
168
|
<S.OptionFilterDialog
|
|
182
|
-
style={{
|
|
183
|
-
background: orderSmallest ? 'rgba(0, 0, 0, 0.04)' : '',
|
|
184
|
-
}}
|
|
185
169
|
onClick={() => {
|
|
186
|
-
onSortClick && onSortClick(header.column.columnDef.accessorKey, 'asc')
|
|
187
|
-
setOpenFilterDialog('')
|
|
170
|
+
onSortClick && onSortClick(header.column.columnDef.accessorKey, 'asc')
|
|
171
|
+
setOpenFilterDialog('')
|
|
188
172
|
}}
|
|
189
173
|
>
|
|
190
174
|
<div className="icon">
|
|
@@ -208,12 +192,10 @@ const UncontrolledTable = (props: UncontrolledTableProps) => {
|
|
|
208
192
|
<p>{labels?.orderAsc || 'Menor primeiro'}</p>
|
|
209
193
|
</S.OptionFilterDialog>
|
|
210
194
|
<S.OptionFilterDialog
|
|
211
|
-
style={{
|
|
212
|
-
background: orderLargest ? 'rgba(0, 0, 0, 0.04)' : '',
|
|
213
|
-
}}
|
|
214
195
|
onClick={() => {
|
|
215
|
-
onSortClick &&
|
|
216
|
-
|
|
196
|
+
onSortClick &&
|
|
197
|
+
onSortClick(header.column.columnDef.accessorKey, 'desc')
|
|
198
|
+
setOpenFilterDialog('')
|
|
217
199
|
}}
|
|
218
200
|
>
|
|
219
201
|
<div className="icon rotate">
|
|
@@ -239,8 +221,8 @@ const UncontrolledTable = (props: UncontrolledTableProps) => {
|
|
|
239
221
|
{!header?.column?.columnDef?.nofilter && (
|
|
240
222
|
<S.OptionFilterDialog
|
|
241
223
|
onClick={() => {
|
|
242
|
-
onFilterClick && onFilterClick(header.column.columnDef.accessorKey)
|
|
243
|
-
setOpenFilterDialog('')
|
|
224
|
+
onFilterClick && onFilterClick(header.column.columnDef.accessorKey)
|
|
225
|
+
setOpenFilterDialog('')
|
|
244
226
|
}}
|
|
245
227
|
>
|
|
246
228
|
<div className="icon">
|
|
@@ -291,7 +273,7 @@ const UncontrolledTable = (props: UncontrolledTableProps) => {
|
|
|
291
273
|
onMouseOver={onMouseOver}
|
|
292
274
|
onMouseOut={onMouseOut}
|
|
293
275
|
/>
|
|
294
|
-
)
|
|
276
|
+
)
|
|
295
277
|
})}
|
|
296
278
|
</SortableContext>
|
|
297
279
|
</tbody>
|
|
@@ -305,7 +287,7 @@ const UncontrolledTable = (props: UncontrolledTableProps) => {
|
|
|
305
287
|
/>
|
|
306
288
|
)}
|
|
307
289
|
</S.Container>
|
|
308
|
-
)
|
|
309
|
-
}
|
|
290
|
+
)
|
|
291
|
+
}
|
|
310
292
|
|
|
311
|
-
export default UncontrolledTable
|
|
293
|
+
export default UncontrolledTable
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import styled from 'styled-components'
|
|
2
|
+
|
|
3
|
+
export const TableButtonContainer = styled.div`
|
|
4
|
+
display: block;
|
|
5
|
+
position: relative;
|
|
6
|
+
`
|
|
7
|
+
|
|
8
|
+
export const TableButton = styled.div<{ $config?: boolean; $list?: boolean }>`
|
|
9
|
+
background-color: ${(props) => (!props.$config ? '#f0f0f0' : '#fff')};
|
|
10
|
+
border: ${(props) => (props.$config ? '1px solid #ccc' : 'none')};
|
|
11
|
+
box-sizing: border-box;
|
|
12
|
+
padding: 10px;
|
|
13
|
+
border-radius: 4px;
|
|
14
|
+
cursor: ${(props) => (props.$list ? 'default' : 'pointer')};
|
|
15
|
+
&:hover {
|
|
16
|
+
background-color: ${(props) => (!props.$config ? '#e0e0e0' : '#f9f9f9')};
|
|
17
|
+
}
|
|
18
|
+
`
|
|
19
|
+
|
|
20
|
+
export const TableLabel = styled.div`
|
|
21
|
+
font-size: 14px;
|
|
22
|
+
color: #333;
|
|
23
|
+
font-weight: 500;
|
|
24
|
+
cursor: pointer;
|
|
25
|
+
`
|
|
26
|
+
|
|
27
|
+
export const TableList = styled.div`
|
|
28
|
+
position: absolute;
|
|
29
|
+
background-color: #fff;
|
|
30
|
+
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
|
|
31
|
+
border-radius: 4px;
|
|
32
|
+
padding: 10px;
|
|
33
|
+
z-index: 1000;
|
|
34
|
+
left: 0;
|
|
35
|
+
top: calc(100% + 10px);
|
|
36
|
+
width: 200px;
|
|
37
|
+
`
|
|
38
|
+
|
|
39
|
+
export const TableListItem = styled.div<{ $disabled?: boolean }>`
|
|
40
|
+
filter: ${(props) => (props.$disabled ? 'grayscale(1)' : 'none')};
|
|
41
|
+
pointer-events: ${(props) => (props.$disabled ? 'none' : 'auto')};
|
|
42
|
+
color: ${(props) => (props.$disabled ? '#999' : '#333')};
|
|
43
|
+
display: flex;
|
|
44
|
+
justify-content: space-between;
|
|
45
|
+
align-items: center;
|
|
46
|
+
padding: 5px 10px;
|
|
47
|
+
cursor: pointer;
|
|
48
|
+
`
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import React, { useRef, useState } from 'react'
|
|
2
|
+
import * as S from './TableButton.style'
|
|
3
|
+
import { TableList } from '../../interface'
|
|
4
|
+
import { Switch } from '@mui/material'
|
|
5
|
+
import useClickOutside from '../../../../hooks/useClickOutside'
|
|
6
|
+
|
|
7
|
+
interface TableButtonProps {
|
|
8
|
+
children: React.ReactNode
|
|
9
|
+
theme: 'menu' | 'config'
|
|
10
|
+
list?: {
|
|
11
|
+
options: TableList[]
|
|
12
|
+
toggleableList?: boolean
|
|
13
|
+
}
|
|
14
|
+
onClick?: () => void
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const TableButton = (props: TableButtonProps) => {
|
|
18
|
+
const { children, theme, list, onClick } = props
|
|
19
|
+
const [isOpen, setIsOpen] = useState(false)
|
|
20
|
+
const TableListItemRef = useRef<HTMLDivElement>(null)
|
|
21
|
+
|
|
22
|
+
useClickOutside(TableListItemRef, () => {
|
|
23
|
+
if (isOpen) setIsOpen(false)
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<S.TableButtonContainer ref={TableListItemRef}>
|
|
28
|
+
<S.TableButton
|
|
29
|
+
ref={TableListItemRef}
|
|
30
|
+
$config={theme === 'config'}
|
|
31
|
+
$list={!!list}
|
|
32
|
+
onClick={() => {
|
|
33
|
+
setIsOpen(!isOpen)
|
|
34
|
+
if (!list) onClick?.()
|
|
35
|
+
}}
|
|
36
|
+
>
|
|
37
|
+
<S.TableLabel>{children}</S.TableLabel>
|
|
38
|
+
</S.TableButton>
|
|
39
|
+
{list && isOpen && (
|
|
40
|
+
<S.TableList>
|
|
41
|
+
{list?.options.map((item, index) => (
|
|
42
|
+
<S.TableListItem
|
|
43
|
+
key={index}
|
|
44
|
+
onClick={() => {
|
|
45
|
+
item.onClick?.(item.id)
|
|
46
|
+
}}
|
|
47
|
+
$disabled={item.disabled}
|
|
48
|
+
>
|
|
49
|
+
<span>{item.label}</span>
|
|
50
|
+
{list.toggleableList && (
|
|
51
|
+
<Switch
|
|
52
|
+
size="small"
|
|
53
|
+
checked={typeof item.checked === 'function' ? item.checked?.() : item.checked}
|
|
54
|
+
/>
|
|
55
|
+
)}
|
|
56
|
+
</S.TableListItem>
|
|
57
|
+
))}
|
|
58
|
+
</S.TableList>
|
|
59
|
+
)}
|
|
60
|
+
</S.TableButtonContainer>
|
|
61
|
+
)
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export default TableButton
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import styled from 'styled-components'
|
|
2
|
+
|
|
3
|
+
export const Header = styled.div`
|
|
4
|
+
display: flex;
|
|
5
|
+
padding: 10px 0;
|
|
6
|
+
border-bottom: 1px solid #e0e0e0;
|
|
7
|
+
justify-content: space-between;
|
|
8
|
+
`
|
|
9
|
+
|
|
10
|
+
export const HeaderMenus = styled.div`
|
|
11
|
+
display: flex;
|
|
12
|
+
gap: 10px;
|
|
13
|
+
align-items: center;
|
|
14
|
+
`
|
|
15
|
+
|
|
16
|
+
export const BtnColumns = styled.div`
|
|
17
|
+
display: flex;
|
|
18
|
+
gap: 5px;
|
|
19
|
+
align-items: center;
|
|
20
|
+
`
|
|
21
|
+
|
|
22
|
+
export const HeaderConfigs = styled.div`
|
|
23
|
+
display: flex;
|
|
24
|
+
gap: 10px;
|
|
25
|
+
align-items: center;
|
|
26
|
+
`
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import React, { useCallback, useEffect, useMemo } from 'react'
|
|
2
|
+
import { Table } from '@tanstack/react-table'
|
|
3
|
+
import TableButton from '../TableButton/TableButton'
|
|
4
|
+
import TableChartIcon from '@mui/icons-material/TableChart'
|
|
5
|
+
|
|
6
|
+
import * as S from './header.styles'
|
|
7
|
+
import { TableButton as TypeTableButton } from '../../interface'
|
|
8
|
+
|
|
9
|
+
interface HeaderProps {
|
|
10
|
+
table: Table<unknown>
|
|
11
|
+
menus?: TypeTableButton[]
|
|
12
|
+
configs?: TypeTableButton[]
|
|
13
|
+
labels: {
|
|
14
|
+
columns: string
|
|
15
|
+
}
|
|
16
|
+
hideColumns?: string[]
|
|
17
|
+
onColumnVisibilityChange?: (column: string, value: boolean) => void
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const Header = (props: HeaderProps) => {
|
|
21
|
+
const { table, menus, configs, labels, hideColumns, onColumnVisibilityChange } = props
|
|
22
|
+
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
if (!hideColumns) return
|
|
25
|
+
table
|
|
26
|
+
.getAllLeafColumns()
|
|
27
|
+
.filter((column: any) => hideColumns.includes(column.id))
|
|
28
|
+
.forEach((column: any) => column.toggleVisibility(false))
|
|
29
|
+
}, [hideColumns, table])
|
|
30
|
+
|
|
31
|
+
const _tableFields = useCallback(() => {
|
|
32
|
+
return table.getAllLeafColumns().map((column: any) => ({
|
|
33
|
+
id: column.id,
|
|
34
|
+
label: column.columnDef.header || column.id,
|
|
35
|
+
onClick: () => {
|
|
36
|
+
const isVisible = !column.getIsVisible()
|
|
37
|
+
column.toggleVisibility(isVisible)
|
|
38
|
+
onColumnVisibilityChange?.(column.id, isVisible)
|
|
39
|
+
},
|
|
40
|
+
checked: () => column.getIsVisible(),
|
|
41
|
+
}))
|
|
42
|
+
}, [table])
|
|
43
|
+
|
|
44
|
+
const _menus = useMemo(() => {
|
|
45
|
+
return menus
|
|
46
|
+
}, [menus])
|
|
47
|
+
|
|
48
|
+
const _configs = useMemo(() => {
|
|
49
|
+
const _fields: TypeTableButton = {
|
|
50
|
+
render: () => (
|
|
51
|
+
<S.BtnColumns>
|
|
52
|
+
<TableChartIcon style={{ fontSize: '1rem' }} />
|
|
53
|
+
{labels.columns}
|
|
54
|
+
</S.BtnColumns>
|
|
55
|
+
),
|
|
56
|
+
toggleableList: true,
|
|
57
|
+
list: {
|
|
58
|
+
options: _tableFields(),
|
|
59
|
+
toggleableList: true,
|
|
60
|
+
},
|
|
61
|
+
}
|
|
62
|
+
return [...(configs || []), _fields]
|
|
63
|
+
}, [configs])
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<S.Header>
|
|
67
|
+
<S.HeaderMenus>
|
|
68
|
+
{_menus?.map((menu, index) => (
|
|
69
|
+
<TableButton key={index} theme="menu" onClick={() => menu.onClick?.()} list={menu.list}>
|
|
70
|
+
{menu.render()}
|
|
71
|
+
</TableButton>
|
|
72
|
+
))}
|
|
73
|
+
</S.HeaderMenus>
|
|
74
|
+
<S.HeaderConfigs>
|
|
75
|
+
{_configs?.map((menu, index) => (
|
|
76
|
+
<TableButton key={index} theme="config" onClick={() => menu.onClick?.()} list={menu.list}>
|
|
77
|
+
{menu.render()}
|
|
78
|
+
</TableButton>
|
|
79
|
+
))}
|
|
80
|
+
</S.HeaderConfigs>
|
|
81
|
+
</S.Header>
|
|
82
|
+
)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export default Header
|
|
@@ -1,13 +1,16 @@
|
|
|
1
|
-
import Pagination from "./pagination";
|
|
2
|
-
import Header from "./header"
|
|
1
|
+
import Pagination from "./pagination/pagination";
|
|
2
|
+
import Header from "./header/header"
|
|
3
3
|
import SimpleRow from "./row/SimpleRow";
|
|
4
4
|
import DraggableRow from "./row/DraggableRow";
|
|
5
5
|
import RowDragHandleCell from "./row/RowDragHandleCell";
|
|
6
|
+
import TableButton from "./TableButton/TableButton";
|
|
7
|
+
|
|
6
8
|
|
|
7
9
|
export {
|
|
8
10
|
Pagination,
|
|
9
11
|
Header,
|
|
10
12
|
SimpleRow,
|
|
11
13
|
DraggableRow,
|
|
12
|
-
RowDragHandleCell
|
|
14
|
+
RowDragHandleCell,
|
|
15
|
+
TableButton
|
|
13
16
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import React, { CSSProperties } from 'react'
|
|
2
|
-
import * as S from './styles'
|
|
1
|
+
import React, { CSSProperties } from 'react'
|
|
2
|
+
import * as S from './styles'
|
|
3
3
|
|
|
4
|
-
import { flexRender } from '@tanstack/react-table'
|
|
5
|
-
import { useSortable } from '@dnd-kit/sortable'
|
|
6
|
-
import { CSS } from '@dnd-kit/utilities'
|
|
4
|
+
import { flexRender } from '@tanstack/react-table'
|
|
5
|
+
import { useSortable } from '@dnd-kit/sortable'
|
|
6
|
+
import { CSS } from '@dnd-kit/utilities'
|
|
7
7
|
|
|
8
8
|
const DraggableRow: React.FC<any> = ({ row, onClick, onMouseOver, onMouseOut }) => {
|
|
9
9
|
const { transform, transition, setNodeRef, isDragging } = useSortable({
|
|
10
10
|
id: row.id,
|
|
11
|
-
})
|
|
11
|
+
})
|
|
12
12
|
|
|
13
13
|
const style: CSSProperties = {
|
|
14
14
|
transform: CSS.Transform.toString(transform),
|
|
@@ -16,10 +16,10 @@ const DraggableRow: React.FC<any> = ({ row, onClick, onMouseOver, onMouseOut })
|
|
|
16
16
|
opacity: isDragging ? 0.8 : 1,
|
|
17
17
|
zIndex: isDragging ? 1 : 0,
|
|
18
18
|
position: 'relative',
|
|
19
|
-
}
|
|
19
|
+
}
|
|
20
20
|
|
|
21
21
|
return (
|
|
22
|
-
<S.Tr
|
|
22
|
+
<S.Tr ref={setNodeRef} style={style}>
|
|
23
23
|
{row.getVisibleCells().map((cell: any) => (
|
|
24
24
|
<S.Td key={cell.id} onClick={onClick} onMouseOver={onMouseOver} onMouseOut={onMouseOut}>
|
|
25
25
|
{cell.column.columnDef.type == 'action'
|
|
@@ -28,7 +28,7 @@ const DraggableRow: React.FC<any> = ({ row, onClick, onMouseOver, onMouseOut })
|
|
|
28
28
|
</S.Td>
|
|
29
29
|
))}
|
|
30
30
|
</S.Tr>
|
|
31
|
-
)
|
|
32
|
-
}
|
|
31
|
+
)
|
|
32
|
+
}
|
|
33
33
|
|
|
34
|
-
export default DraggableRow
|
|
34
|
+
export default DraggableRow
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import { flexRender } from '@tanstack/react-table'
|
|
3
|
-
import * as S from './styles'
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { flexRender } from '@tanstack/react-table'
|
|
3
|
+
import * as S from './styles'
|
|
4
4
|
|
|
5
5
|
const SimpleRow: React.FC<any> = ({ row, onClick, onMouseOver, onMouseOut }) => {
|
|
6
6
|
return (
|
|
7
7
|
<S.Tr
|
|
8
|
-
$hasAction={!!onClick || !!onMouseOver || !!onMouseOut}
|
|
9
8
|
onClick={() => (onClick ? onClick(row.original) : null)}
|
|
10
9
|
onMouseOver={() => (onMouseOver ? onMouseOver(row.original) : null)}
|
|
11
10
|
onMouseOut={() => (onMouseOut ? onMouseOut(row.original) : null)}
|
|
@@ -17,10 +16,10 @@ const SimpleRow: React.FC<any> = ({ row, onClick, onMouseOver, onMouseOut }) =>
|
|
|
17
16
|
? cell.getValue()
|
|
18
17
|
: flexRender(cell.column.columnDef.cell, cell.getContext())}
|
|
19
18
|
</S.Td>
|
|
20
|
-
)
|
|
19
|
+
)
|
|
21
20
|
})}
|
|
22
21
|
</S.Tr>
|
|
23
|
-
)
|
|
24
|
-
}
|
|
22
|
+
)
|
|
23
|
+
}
|
|
25
24
|
|
|
26
|
-
export default SimpleRow
|
|
25
|
+
export default SimpleRow
|
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
import
|
|
2
|
-
import styled from 'styled-components';
|
|
1
|
+
import styled from 'styled-components'
|
|
3
2
|
|
|
4
|
-
export const Tr = styled.tr
|
|
3
|
+
export const Tr = styled.tr`
|
|
5
4
|
color: inherit;
|
|
6
5
|
display: table-row;
|
|
7
6
|
vertical-align: middle;
|
|
8
7
|
outline: 0;
|
|
9
|
-
|
|
10
|
-
background-color: #fafafa;
|
|
11
|
-
}
|
|
12
|
-
`;
|
|
8
|
+
`
|
|
13
9
|
|
|
14
10
|
export const Td = styled.td`
|
|
15
11
|
font-weight: 500;
|
|
@@ -20,13 +16,7 @@ export const Td = styled.td`
|
|
|
20
16
|
vertical-align: inherit;
|
|
21
17
|
border-bottom: 1px solid rgba(224, 224, 224, 1);
|
|
22
18
|
text-align: left;
|
|
23
|
-
padding:
|
|
24
|
-
${breakpoints({
|
|
25
|
-
cssProp: 'padding',
|
|
26
|
-
cssPropUnits: 'px',
|
|
27
|
-
values: [{ 1440: 8 }],
|
|
28
|
-
mediaQueryType: 'max-width',
|
|
29
|
-
})};
|
|
19
|
+
padding: 8px;
|
|
30
20
|
color: #666666;
|
|
31
21
|
font-size: 0.875rem;
|
|
32
|
-
|
|
22
|
+
`
|