@campxdev/shared 1.10.65 → 1.10.67

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.
@@ -1,218 +0,0 @@
1
- import {
2
- Box,
3
- IconButton,
4
- ListItemIcon,
5
- Table as MuiTable,
6
- TableBody,
7
- TableCell,
8
- TableContainer,
9
- TableHead,
10
- TableRow,
11
- alpha,
12
- styled,
13
- } from '@mui/material'
14
- import _ from 'lodash'
15
- import { useEffect, useState } from 'react'
16
- import Spinner from '../../Spinner'
17
- import TableFooter from '../BasicTable/TableFooter'
18
- import NoRecordsFound from '../common/NoRecordsFound'
19
- import { SortAscIcon, SortDescIcon, SortIcon } from '../common/icons'
20
-
21
- export interface ColumnProps {
22
- dataIndex: string
23
- key: string
24
- title: any
25
- render?: (cellData: any, row: any, index: number) => any
26
- textColor?: string
27
- sort?: boolean
28
- width?: string //pixels
29
- }
30
-
31
- interface TableProps {
32
- columns: Array<ColumnProps>
33
- rowKey?: string
34
- dataSource?: any[]
35
- loading?: boolean
36
- onRowClick?: (row: any) => void
37
- pagination?: {
38
- page: number
39
- limit: number
40
- totalCount: number
41
- onChange: (v: number) => void
42
- onChangeLimit?: (v: number) => void
43
- }
44
- onSort?: (sort: any) => void
45
- dense?: boolean
46
- isLastRowColorChange?: boolean
47
- }
48
-
49
- type Order = 'asc' | 'desc' | ''
50
- type Sort = {}
51
-
52
- export default function MobileTable({
53
- columns,
54
- dataSource,
55
- onRowClick,
56
- pagination,
57
- loading,
58
- onSort,
59
- dense = false,
60
- isLastRowColorChange = false,
61
- }: TableProps) {
62
- const [sort, setSort] = useState<Sort>({})
63
-
64
- const handleSortClick = (sortBykey) => {
65
- setSort((prev) => {
66
- if (prev[sortBykey]) {
67
- if (prev[sortBykey] === 'desc') return { ...prev, [sortBykey]: 'asc' }
68
- if (prev[sortBykey] === 'asc') {
69
- delete prev[sortBykey]
70
- return { ...prev }
71
- }
72
- } else {
73
- return {
74
- ...prev,
75
- [sortBykey]: 'desc',
76
- }
77
- }
78
- })
79
- }
80
-
81
- useEffect(() => {
82
- if (!onSort) return
83
-
84
- onSort({
85
- sortBy: Object.keys(sort).join(','),
86
- sortOrder: Object.keys(sort)
87
- .map((item) => sort[item])
88
- .join(','),
89
- })
90
- }, [sort])
91
-
92
- return (
93
- <StyledTableContainer>
94
- <>
95
- <StyledMuiTable>
96
- <TableHead>
97
- <TableRow>
98
- {columns.map((col, index) => (
99
- <TableCell
100
- key={index}
101
- sx={{
102
- ...(col?.width && {
103
- width: col?.width,
104
- }),
105
- borderRightColor: '#1212121A',
106
- borderRightStyle: 'solid',
107
- }}
108
- >
109
- <Box sx={{ fontWeight: 500, fontSize: '14px' }}>
110
- {col.title}
111
- </Box>
112
- {col.sort && (
113
- <IconButton onClick={() => handleSortClick(col.dataIndex)}>
114
- <ListItemIcon>
115
- {sort[col.dataIndex] === 'asc' ? (
116
- <SortAscIcon />
117
- ) : sort[col.dataIndex] === 'desc' ? (
118
- <SortDescIcon />
119
- ) : (
120
- <SortIcon />
121
- )}
122
- </ListItemIcon>
123
- </IconButton>
124
- )}
125
- </TableCell>
126
- ))}
127
- </TableRow>
128
- </TableHead>
129
- {!loading ? (
130
- <>
131
- {dataSource?.length ? (
132
- <TableBody>
133
- {dataSource?.map((row, index) => (
134
- <StyledTableRow
135
- canRowClick={!!onRowClick}
136
- hover={!!onRowClick}
137
- key={index}
138
- onClick={() => {
139
- return onRowClick && onRowClick(row)
140
- }}
141
- isLastRowColorChange={isLastRowColorChange}
142
- >
143
- {columns.map((col, colIndex) => (
144
- <TableCell
145
- sx={{
146
- color: col.textColor,
147
- padding: dense ? '10px' : '15px',
148
- font: 'avenir',
149
- fontSize: '14px',
150
- borderRightColor: '#1212121A',
151
- borderRightStyle: 'solid',
152
- }}
153
- key={colIndex}
154
- >
155
- <>
156
- {col?.render
157
- ? col.render(row[col.dataIndex], row, index)
158
- : _.get(row, col.dataIndex)}
159
- </>
160
- </TableCell>
161
- ))}
162
- </StyledTableRow>
163
- ))}
164
- </TableBody>
165
- ) : (
166
- <>
167
- <NoRecordsFound colLength={columns?.length} />
168
- </>
169
- )}
170
- </>
171
- ) : (
172
- <Spinner />
173
- )}
174
- </StyledMuiTable>
175
- </>
176
- <>
177
- {pagination && (
178
- <TableFooter
179
- page={pagination.page + 1}
180
- limit={pagination.limit}
181
- totalCount={pagination.totalCount ?? 0}
182
- handlePagination={pagination.onChange}
183
- handlePageLimit={pagination.onChangeLimit}
184
- />
185
- )}
186
- </>
187
- </StyledTableContainer>
188
- )
189
- }
190
-
191
- const StyledTableContainer = styled(TableContainer)<{}>(({ theme }) => ({
192
- width: '100%',
193
- overflowX: 'auto',
194
- borderRadius: '10px 10px 10px 10px',
195
- border: '1px solid #1212121A',
196
- }))
197
-
198
- const StyledMuiTable = styled(MuiTable)<{}>(({ theme }) => ({
199
- border: 'none',
200
- }))
201
-
202
- const StyledTableRow = styled(TableRow, {
203
- shouldForwardProp: (prop) => prop !== 'canRowClick',
204
- })<{ canRowClick: boolean; isLastRowColorChange?: boolean }>(
205
- ({ canRowClick, isLastRowColorChange }) => ({
206
- ...(canRowClick && {
207
- cursor: 'pointer',
208
- '&.MuiTableRow-hover:hover': {
209
- backgroundColor: alpha('#f2f2f2', 0.4),
210
- },
211
- }),
212
- ...(isLastRowColorChange && {
213
- '&:last-child': {
214
- backgroundColor: '#F2F2F2',
215
- },
216
- }),
217
- }),
218
- )
@@ -1 +0,0 @@
1
- export { default } from './MobileTable'