norma-library 0.6.89 → 0.6.91
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 +43 -0
- package/dist/esm/components/UncontrolledTable/components/TableButton/TableButton.js.map +1 -0
- package/dist/esm/components/UncontrolledTable/components/TableButton/TableButton.style.d.ts +13 -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 +30 -13
- 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/hooks/useOutsideScreen.d.ts +7 -0
- package/dist/esm/hooks/useOutsideScreen.js +30 -0
- package/dist/esm/hooks/useOutsideScreen.js.map +1 -0
- 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} +76 -88
- package/src/components/UncontrolledTable/components/TableButton/TableButton.style.tsx +49 -0
- package/src/components/UncontrolledTable/components/TableButton/TableButton.tsx +83 -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/hooks/useOutsideScreen.tsx +35 -0
- 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,45 +17,45 @@ 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'
|
|
26
23
|
|
|
27
|
-
import
|
|
28
|
-
import {
|
|
29
|
-
import
|
|
24
|
+
import useClickOutside from '../../hooks/useClickOutside'
|
|
25
|
+
import { Pagination, Header, SimpleRow, DraggableRow, RowDragHandleCell } from './components'
|
|
26
|
+
import { UncontrolledTableProps } from './interface'
|
|
27
|
+
|
|
28
|
+
import * as S from './UncontrolledTable.style'
|
|
30
29
|
|
|
31
30
|
const UncontrolledTable = (props: UncontrolledTableProps) => {
|
|
32
31
|
const {
|
|
33
32
|
data,
|
|
34
33
|
columns,
|
|
34
|
+
pagination,
|
|
35
|
+
totalPages,
|
|
36
|
+
labels,
|
|
37
|
+
tableClassName,
|
|
38
|
+
sticky,
|
|
39
|
+
draggable,
|
|
40
|
+
buttons,
|
|
41
|
+
configs,
|
|
42
|
+
hideColumns,
|
|
43
|
+
} = props
|
|
44
|
+
|
|
45
|
+
const {
|
|
35
46
|
onClick,
|
|
36
47
|
onMouseOver,
|
|
37
48
|
onMouseOut,
|
|
38
|
-
showTotalResults,
|
|
39
|
-
showSettings,
|
|
40
49
|
onChangePage,
|
|
41
|
-
pagination,
|
|
42
|
-
totalPages,
|
|
43
|
-
showClearFields,
|
|
44
|
-
onClearFieldsClick,
|
|
45
50
|
onFilterClick,
|
|
46
51
|
onSortClick,
|
|
47
|
-
customTotalResults,
|
|
48
|
-
labels,
|
|
49
|
-
tableClassName,
|
|
50
|
-
stickyHeader,
|
|
51
|
-
stickyHeaderP,
|
|
52
|
-
draggable,
|
|
53
52
|
onDragEnd,
|
|
54
|
-
|
|
53
|
+
onColumnVisibilityChange,
|
|
54
|
+
} = props
|
|
55
55
|
|
|
56
|
-
const [openFilterDialog, setOpenFilterDialog] = useState('')
|
|
57
|
-
const [sorting, setSorting] = useState<any>([])
|
|
58
|
-
const [filterByColumn, setFilterByColumn] = useState<ColumnFiltersState>([])
|
|
59
|
-
const [globalFilters, setGlobalFilters] = useState<any>([]);
|
|
60
|
-
const [orderSmallest, setOrderSmallest] = useState(false);
|
|
61
|
-
const [orderLargest, setOrderLargest] = useState(false);
|
|
56
|
+
const [openFilterDialog, setOpenFilterDialog] = useState('')
|
|
57
|
+
const [sorting, setSorting] = useState<any>([])
|
|
58
|
+
const [filterByColumn, setFilterByColumn] = useState<ColumnFiltersState>([])
|
|
62
59
|
|
|
63
60
|
const _columns: any[] = useMemo(() => {
|
|
64
61
|
return draggable
|
|
@@ -66,7 +63,7 @@ const UncontrolledTable = (props: UncontrolledTableProps) => {
|
|
|
66
63
|
{
|
|
67
64
|
id: 'drag',
|
|
68
65
|
header: '',
|
|
69
|
-
cell: ({ row }: { row: any }) => <RowDragHandleCell rowId={row.id}/>,
|
|
66
|
+
cell: ({ row }: { row: any }) => <RowDragHandleCell rowId={row.id} />,
|
|
70
67
|
disableMenu: true,
|
|
71
68
|
},
|
|
72
69
|
...columns.map((column) => ({
|
|
@@ -74,8 +71,8 @@ const UncontrolledTable = (props: UncontrolledTableProps) => {
|
|
|
74
71
|
disableMenu: true,
|
|
75
72
|
})),
|
|
76
73
|
]
|
|
77
|
-
: columns
|
|
78
|
-
}, [columns])
|
|
74
|
+
: columns
|
|
75
|
+
}, [columns])
|
|
79
76
|
|
|
80
77
|
const reactTableConfig = useMemo(() => {
|
|
81
78
|
const config: TableOptions<unknown> = {
|
|
@@ -87,64 +84,59 @@ const UncontrolledTable = (props: UncontrolledTableProps) => {
|
|
|
87
84
|
pagination: pagination,
|
|
88
85
|
},
|
|
89
86
|
rowCount: totalPages,
|
|
90
|
-
getCoreRowModel: getCoreRowModel(),
|
|
91
|
-
getSortedRowModel: getSortedRowModel(),
|
|
92
|
-
onSortingChange: setSorting,
|
|
93
|
-
onColumnFiltersChange: setFilterByColumn,
|
|
94
87
|
manualPagination: true,
|
|
95
|
-
getRowId: (row: any) => row.id,
|
|
96
88
|
debugTable: true,
|
|
97
89
|
debugHeaders: true,
|
|
98
90
|
debugColumns: true,
|
|
99
|
-
|
|
91
|
+
getRowId: (row: any) => row.id,
|
|
92
|
+
getCoreRowModel: getCoreRowModel(),
|
|
93
|
+
getSortedRowModel: getSortedRowModel(),
|
|
94
|
+
onSortingChange: setSorting,
|
|
95
|
+
onColumnFiltersChange: setFilterByColumn,
|
|
96
|
+
}
|
|
100
97
|
|
|
101
|
-
return config
|
|
102
|
-
}, [data, sorting, filterByColumn, _columns, pagination])
|
|
98
|
+
return config
|
|
99
|
+
}, [data, sorting, filterByColumn, _columns, pagination])
|
|
103
100
|
|
|
104
|
-
const table = useReactTable(reactTableConfig)
|
|
105
|
-
const filterRef = useRef<HTMLDivElement>(null)
|
|
101
|
+
const table = useReactTable(reactTableConfig)
|
|
102
|
+
const filterRef = useRef<HTMLDivElement>(null)
|
|
106
103
|
|
|
107
|
-
useClickOutside(filterRef, () => setOpenFilterDialog(''))
|
|
104
|
+
useClickOutside(filterRef, () => setOpenFilterDialog(''))
|
|
108
105
|
|
|
109
106
|
const handleDragEnd = (event: DragEndEvent) => {
|
|
110
|
-
const { active, over } = event
|
|
111
|
-
|
|
107
|
+
const { active, over } = event
|
|
112
108
|
|
|
113
109
|
if (active && over && active.id !== over.id && onDragEnd) {
|
|
114
|
-
const oldIndex = dataIds.indexOf(active.id)
|
|
115
|
-
const newIndex = dataIds.indexOf(over.id)
|
|
110
|
+
const oldIndex = dataIds.indexOf(active.id)
|
|
111
|
+
const newIndex = dataIds.indexOf(over.id)
|
|
116
112
|
|
|
117
|
-
const _data = arrayMove(data, oldIndex, newIndex)
|
|
118
|
-
onDragEnd(_data)
|
|
113
|
+
const _data = arrayMove(data, oldIndex, newIndex)
|
|
114
|
+
onDragEnd(_data)
|
|
119
115
|
}
|
|
120
|
-
}
|
|
116
|
+
}
|
|
121
117
|
|
|
122
|
-
const sensors = useSensors(
|
|
118
|
+
const sensors = useSensors(
|
|
119
|
+
useSensor(MouseSensor, {}),
|
|
120
|
+
useSensor(TouchSensor, {}),
|
|
121
|
+
useSensor(KeyboardSensor, {}),
|
|
122
|
+
)
|
|
123
123
|
|
|
124
124
|
const dataIds = useMemo<UniqueIdentifier[]>(
|
|
125
125
|
() => data?.map((item: { id: UniqueIdentifier }) => item.id) || [],
|
|
126
126
|
[data],
|
|
127
|
-
)
|
|
127
|
+
)
|
|
128
128
|
|
|
129
129
|
return (
|
|
130
|
-
<S.Container>
|
|
130
|
+
<S.Container className="Norma__Table">
|
|
131
131
|
<Header
|
|
132
132
|
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}
|
|
133
|
+
labels={{
|
|
134
|
+
columns: labels?.columns || 'Colunas',
|
|
135
|
+
}}
|
|
136
|
+
configs={configs}
|
|
137
|
+
menus={buttons}
|
|
138
|
+
hideColumns={hideColumns}
|
|
139
|
+
onColumnVisibilityChange={onColumnVisibilityChange}
|
|
148
140
|
/>
|
|
149
141
|
<DndContext
|
|
150
142
|
collisionDetection={closestCenter}
|
|
@@ -153,7 +145,7 @@ const UncontrolledTable = (props: UncontrolledTableProps) => {
|
|
|
153
145
|
sensors={sensors}
|
|
154
146
|
>
|
|
155
147
|
<S.Table className={tableClassName || ''}>
|
|
156
|
-
<S.Thead $sticky={
|
|
148
|
+
<S.Thead $sticky={sticky?.enabled} $stickyTopP={sticky?.top}>
|
|
157
149
|
{table.getHeaderGroups().map((headerGroup: any) => (
|
|
158
150
|
<S.TableRow key={headerGroup.id}>
|
|
159
151
|
{headerGroup.headers.map((header: any) => (
|
|
@@ -161,11 +153,12 @@ const UncontrolledTable = (props: UncontrolledTableProps) => {
|
|
|
161
153
|
<S.ColumnContent
|
|
162
154
|
onClick={() => {
|
|
163
155
|
if (!header?.column?.columnDef?.disableMenu)
|
|
164
|
-
setOpenFilterDialog(header.column.columnDef.accessorKey)
|
|
156
|
+
setOpenFilterDialog(header.column.columnDef.accessorKey)
|
|
165
157
|
}}
|
|
166
158
|
>
|
|
167
159
|
<S.TextColumn>
|
|
168
|
-
{!header.isPlaceholder &&
|
|
160
|
+
{!header.isPlaceholder &&
|
|
161
|
+
flexRender(header.column.columnDef.header, header.getContext())}
|
|
169
162
|
</S.TextColumn>
|
|
170
163
|
{!header?.column?.columnDef?.disableMenu && (
|
|
171
164
|
<S.IconFilterDialog>
|
|
@@ -179,12 +172,9 @@ const UncontrolledTable = (props: UncontrolledTableProps) => {
|
|
|
179
172
|
<S.FilterDialog ref={filterRef}>
|
|
180
173
|
<S.ListFilterDialog>
|
|
181
174
|
<S.OptionFilterDialog
|
|
182
|
-
style={{
|
|
183
|
-
background: orderSmallest ? 'rgba(0, 0, 0, 0.04)' : '',
|
|
184
|
-
}}
|
|
185
175
|
onClick={() => {
|
|
186
|
-
onSortClick && onSortClick(header.column.columnDef.accessorKey, 'asc')
|
|
187
|
-
setOpenFilterDialog('')
|
|
176
|
+
onSortClick && onSortClick(header.column.columnDef.accessorKey, 'asc')
|
|
177
|
+
setOpenFilterDialog('')
|
|
188
178
|
}}
|
|
189
179
|
>
|
|
190
180
|
<div className="icon">
|
|
@@ -208,12 +198,10 @@ const UncontrolledTable = (props: UncontrolledTableProps) => {
|
|
|
208
198
|
<p>{labels?.orderAsc || 'Menor primeiro'}</p>
|
|
209
199
|
</S.OptionFilterDialog>
|
|
210
200
|
<S.OptionFilterDialog
|
|
211
|
-
style={{
|
|
212
|
-
background: orderLargest ? 'rgba(0, 0, 0, 0.04)' : '',
|
|
213
|
-
}}
|
|
214
201
|
onClick={() => {
|
|
215
|
-
onSortClick &&
|
|
216
|
-
|
|
202
|
+
onSortClick &&
|
|
203
|
+
onSortClick(header.column.columnDef.accessorKey, 'desc')
|
|
204
|
+
setOpenFilterDialog('')
|
|
217
205
|
}}
|
|
218
206
|
>
|
|
219
207
|
<div className="icon rotate">
|
|
@@ -239,8 +227,8 @@ const UncontrolledTable = (props: UncontrolledTableProps) => {
|
|
|
239
227
|
{!header?.column?.columnDef?.nofilter && (
|
|
240
228
|
<S.OptionFilterDialog
|
|
241
229
|
onClick={() => {
|
|
242
|
-
onFilterClick && onFilterClick(header.column.columnDef.accessorKey)
|
|
243
|
-
setOpenFilterDialog('')
|
|
230
|
+
onFilterClick && onFilterClick(header.column.columnDef.accessorKey)
|
|
231
|
+
setOpenFilterDialog('')
|
|
244
232
|
}}
|
|
245
233
|
>
|
|
246
234
|
<div className="icon">
|
|
@@ -291,7 +279,7 @@ const UncontrolledTable = (props: UncontrolledTableProps) => {
|
|
|
291
279
|
onMouseOver={onMouseOver}
|
|
292
280
|
onMouseOut={onMouseOut}
|
|
293
281
|
/>
|
|
294
|
-
)
|
|
282
|
+
)
|
|
295
283
|
})}
|
|
296
284
|
</SortableContext>
|
|
297
285
|
</tbody>
|
|
@@ -305,7 +293,7 @@ const UncontrolledTable = (props: UncontrolledTableProps) => {
|
|
|
305
293
|
/>
|
|
306
294
|
)}
|
|
307
295
|
</S.Container>
|
|
308
|
-
)
|
|
309
|
-
}
|
|
296
|
+
)
|
|
297
|
+
}
|
|
310
298
|
|
|
311
|
-
export default UncontrolledTable
|
|
299
|
+
export default UncontrolledTable
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import styled from 'styled-components'
|
|
2
|
+
|
|
3
|
+
export const TableButtonContainer = styled.div`
|
|
4
|
+
display: block;
|
|
5
|
+
position: relative;
|
|
6
|
+
cursor: pointer;
|
|
7
|
+
`
|
|
8
|
+
|
|
9
|
+
export const TableButton = styled.div<{ $config?: boolean; $list?: boolean }>`
|
|
10
|
+
background-color: ${(props) => (!props.$config ? '#f0f0f0' : '#fff')};
|
|
11
|
+
border: ${(props) => (props.$config ? '1px solid #ccc' : 'none')};
|
|
12
|
+
box-sizing: border-box;
|
|
13
|
+
padding: 10px;
|
|
14
|
+
border-radius: 4px;
|
|
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<{ $position?: 'left' | 'right', $visible?: boolean }>`
|
|
28
|
+
visibility: ${(props) => (props.$visible ? 'visible' : 'hidden')};
|
|
29
|
+
position: absolute;
|
|
30
|
+
background-color: #fff;
|
|
31
|
+
box-shadow: 0px 2px 4px rgba(0, 0, 0, 0.1);
|
|
32
|
+
border-radius: 4px;
|
|
33
|
+
padding: 10px;
|
|
34
|
+
z-index: 1000;
|
|
35
|
+
${(props) => (props.$position === 'left' ? 'left: 0;' : 'right: 0;')}
|
|
36
|
+
top: calc(100% + 10px);
|
|
37
|
+
width: 200px;
|
|
38
|
+
`
|
|
39
|
+
|
|
40
|
+
export const TableListItem = styled.div<{ $disabled?: boolean }>`
|
|
41
|
+
filter: ${(props) => (props.$disabled ? 'grayscale(1)' : 'none')};
|
|
42
|
+
pointer-events: ${(props) => (props.$disabled ? 'none' : 'auto')};
|
|
43
|
+
color: ${(props) => (props.$disabled ? '#999' : '#333')};
|
|
44
|
+
display: flex;
|
|
45
|
+
justify-content: space-between;
|
|
46
|
+
align-items: center;
|
|
47
|
+
padding: 5px 10px;
|
|
48
|
+
cursor: pointer;
|
|
49
|
+
`
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import React, { useEffect, 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
|
+
const ListRef = useRef<HTMLDivElement>(null)
|
|
22
|
+
const [isOutside, setIsOutside] = useState<boolean>(true)
|
|
23
|
+
|
|
24
|
+
useClickOutside(TableListItemRef, () => {
|
|
25
|
+
if (isOpen) setIsOpen(false)
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
|
|
30
|
+
if (isOpen && ListRef.current) {
|
|
31
|
+
|
|
32
|
+
const listRect = ListRef.current.getBoundingClientRect()
|
|
33
|
+
const viewportWidth = window.innerWidth
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
setIsOutside(listRect.right < viewportWidth)
|
|
37
|
+
|
|
38
|
+
return () => {
|
|
39
|
+
setIsOutside(true)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}, [isOpen])
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
return (
|
|
46
|
+
<S.TableButtonContainer ref={TableListItemRef}>
|
|
47
|
+
<S.TableButton
|
|
48
|
+
ref={TableListItemRef}
|
|
49
|
+
$config={theme === 'config'}
|
|
50
|
+
$list={!!list}
|
|
51
|
+
onClick={() => {
|
|
52
|
+
setIsOpen(!isOpen)
|
|
53
|
+
if (!list) onClick?.()
|
|
54
|
+
}}
|
|
55
|
+
>
|
|
56
|
+
<S.TableLabel>{children}</S.TableLabel>
|
|
57
|
+
</S.TableButton>
|
|
58
|
+
{list && (
|
|
59
|
+
<S.TableList ref={ListRef} $position={isOutside ? 'left' : 'right'} $visible={isOpen}>
|
|
60
|
+
{list?.options.map((item, index) => (
|
|
61
|
+
<S.TableListItem
|
|
62
|
+
key={index}
|
|
63
|
+
onClick={() => {
|
|
64
|
+
item.onClick?.(item.id)
|
|
65
|
+
}}
|
|
66
|
+
$disabled={item.disabled}
|
|
67
|
+
>
|
|
68
|
+
<span>{item.label}</span>
|
|
69
|
+
{list.toggleableList && (
|
|
70
|
+
<Switch
|
|
71
|
+
size="small"
|
|
72
|
+
checked={typeof item.checked === 'function' ? item.checked?.() : item.checked}
|
|
73
|
+
/>
|
|
74
|
+
)}
|
|
75
|
+
</S.TableListItem>
|
|
76
|
+
))}
|
|
77
|
+
</S.TableList>
|
|
78
|
+
)}
|
|
79
|
+
</S.TableButtonContainer>
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
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
|
+
`
|