@campxdev/shared 1.3.1 → 1.4.0

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.
@@ -13,7 +13,6 @@ import {
13
13
  } from '@mui/material'
14
14
  import { useEffect, useMemo, useState } from 'react'
15
15
  import { usePagination, useRowSelect, useTable } from 'react-table'
16
- import ErrorBoundary from '../ErrorBoundary'
17
16
  import BatchActionsHeader from './BatchActionsHeader'
18
17
  import { SortAscIcon, SortDescIcon, SortIcon } from './Icons'
19
18
  import { RenderTableBody } from './RenderTableBody'
@@ -74,6 +73,7 @@ export default function TableComponent({
74
73
  select = {
75
74
  enable: false,
76
75
  },
76
+ onRowClick,
77
77
  }: TableProps) {
78
78
  const [sort, setSort] = useState<Sort>({})
79
79
 
@@ -97,7 +97,6 @@ export default function TableComponent({
97
97
  pageCount,
98
98
  gotoPage,
99
99
  setPageSize,
100
- selectedFlatRows,
101
100
  toggleAllRowsSelected,
102
101
  state: { pageIndex, pageSize, selectedRowIds },
103
102
  } = useTable(
@@ -217,6 +216,7 @@ export default function TableComponent({
217
216
  ))}
218
217
  </TableHead>
219
218
  <RenderTableBody
219
+ onRowClick={onRowClick}
220
220
  colLength={columns?.length}
221
221
  loading={loading || refetching}
222
222
  getTableBodyProps={getTableBodyProps}
@@ -9,6 +9,7 @@ export const RenderTableBody = ({
9
9
  rows,
10
10
  loading,
11
11
  colLength,
12
+ onRowClick,
12
13
  }) => {
13
14
  if (loading)
14
15
  return (
@@ -45,6 +46,7 @@ export const RenderTableBody = ({
45
46
  prepareRow(row)
46
47
  return (
47
48
  <StyledTableRow
49
+ onClick={onRowClick && onRowClick}
48
50
  key={index}
49
51
  {...row.getRowProps()}
50
52
  isSelected={row?.isSelected}
@@ -0,0 +1,200 @@
1
+ import {
2
+ alpha,
3
+ Box,
4
+ IconButton,
5
+ ListItemIcon,
6
+ styled,
7
+ Table as MuiTable,
8
+ TableBody,
9
+ TableCell,
10
+ TableContainer,
11
+ TableHead,
12
+ TableRow,
13
+ Typography,
14
+ } from '@mui/material'
15
+ import _ from 'lodash'
16
+ import { useEffect, useState } from 'react'
17
+ import Spinner from '../Spinner'
18
+ import { SortAscIcon, SortDescIcon, SortIcon } from './Icons'
19
+ import TableFooter from './TableFooter'
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
+ }
47
+
48
+ type Order = 'asc' | 'desc' | ''
49
+ type Sort = {}
50
+
51
+ export default function Table({
52
+ columns,
53
+ dataSource,
54
+ onRowClick,
55
+ pagination,
56
+ loading,
57
+ onSort,
58
+ dense = false,
59
+ }: TableProps) {
60
+ const [sort, setSort] = useState<Sort>({})
61
+
62
+ const handleSortClick = (sortBykey) => {
63
+ setSort((prev) => {
64
+ if (prev[sortBykey]) {
65
+ if (prev[sortBykey] === 'desc') return { ...prev, [sortBykey]: 'asc' }
66
+ if (prev[sortBykey] === 'asc') {
67
+ delete prev[sortBykey]
68
+ return { ...prev }
69
+ }
70
+ } else {
71
+ return {
72
+ ...prev,
73
+ [sortBykey]: 'desc',
74
+ }
75
+ }
76
+ })
77
+ }
78
+
79
+ useEffect(() => {
80
+ if (!onSort) return
81
+
82
+ onSort({
83
+ sortBy: Object.keys(sort).join(','),
84
+ sortOrder: Object.keys(sort)
85
+ .map((item) => sort[item])
86
+ .join(','),
87
+ })
88
+ }, [sort])
89
+
90
+ return (
91
+ <TableContainer>
92
+ <>
93
+ <MuiTable>
94
+ <TableHead>
95
+ <TableRow>
96
+ {columns.map((col, index) => (
97
+ <TableCell
98
+ key={index}
99
+ sx={{
100
+ ...(col?.width && {
101
+ width: col?.width,
102
+ }),
103
+ }}
104
+ >
105
+ <>
106
+ <Box sx={{ fontWeight: 600, fontSize: '14px' }}>
107
+ {' '}
108
+ {col.title}
109
+ </Box>
110
+ </>
111
+ {col.sort && (
112
+ <IconButton onClick={() => handleSortClick(col.dataIndex)}>
113
+ <ListItemIcon>
114
+ {sort[col.dataIndex] === 'asc' ? (
115
+ <SortAscIcon />
116
+ ) : sort[col.dataIndex] === 'desc' ? (
117
+ <SortDescIcon />
118
+ ) : (
119
+ <SortIcon />
120
+ )}
121
+ </ListItemIcon>
122
+ </IconButton>
123
+ )}
124
+ </TableCell>
125
+ ))}
126
+ </TableRow>
127
+ </TableHead>
128
+ {!loading ? (
129
+ <>
130
+ {dataSource?.length ? (
131
+ <TableBody>
132
+ {dataSource?.map((row, index) => (
133
+ <StyledTableRow
134
+ canRowClick={!!onRowClick}
135
+ hover={!!onRowClick}
136
+ key={index}
137
+ onClick={() => {
138
+ return onRowClick && onRowClick(row)
139
+ }}
140
+ >
141
+ {columns.map((col, colIndex) => (
142
+ <TableCell
143
+ sx={{
144
+ color: col.textColor,
145
+ padding: dense ? '10px' : '15px',
146
+ font: 'avenir',
147
+ fontSize: '14px',
148
+ }}
149
+ key={colIndex}
150
+ >
151
+ <>
152
+ {col?.render
153
+ ? col.render(row[col.dataIndex], row, index)
154
+ : _.get(row, col.dataIndex)}
155
+ </>
156
+ </TableCell>
157
+ ))}
158
+ </StyledTableRow>
159
+ ))}
160
+ </TableBody>
161
+ ) : (
162
+ <Box>
163
+ {dataSource && (
164
+ <Typography sx={{ padding: '10px' }}>
165
+ No Records Found !..
166
+ </Typography>
167
+ )}
168
+ </Box>
169
+ )}
170
+ </>
171
+ ) : (
172
+ <Spinner />
173
+ )}
174
+ </MuiTable>
175
+ </>
176
+ <>
177
+ {pagination && (
178
+ <TableFooter
179
+ page={pagination.page}
180
+ limit={pagination.limit}
181
+ totalCount={pagination.totalCount}
182
+ handlePagination={pagination.onChange}
183
+ handlePageLimit={pagination.onChangeLimit}
184
+ />
185
+ )}
186
+ </>
187
+ </TableContainer>
188
+ )
189
+ }
190
+
191
+ const StyledTableRow = styled(TableRow, {
192
+ shouldForwardProp: (prop) => prop !== 'canRowClick',
193
+ })<{ canRowClick: boolean }>(({ canRowClick }) => ({
194
+ ...(canRowClick && {
195
+ cursor: 'pointer',
196
+ '&.MuiTableRow-hover:hover': {
197
+ backgroundColor: alpha('#f2f2f2', 0.4),
198
+ },
199
+ }),
200
+ }))
@@ -1,226 +1 @@
1
- import {
2
- alpha,
3
- Box,
4
- IconButton,
5
- ListItemIcon,
6
- styled,
7
- Table as MuiTable,
8
- TableBody,
9
- TableCell,
10
- TableContainer,
11
- TableHead,
12
- TableRow,
13
- Typography,
14
- } from '@mui/material'
15
- import _ from 'lodash'
16
- import { useEffect, useState } from 'react'
17
- import Spinner from '../Spinner'
18
- import { SortAscIcon, SortDescIcon, SortIcon } from './Icons'
19
- import TableFooter from './TableFooter'
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
- }
47
-
48
- type Order = 'asc' | 'desc' | ''
49
- type Sort = {}
50
-
51
- export default function Table({
52
- columns,
53
- dataSource,
54
- onRowClick,
55
- pagination,
56
- loading,
57
- onSort,
58
- dense = false,
59
- }: TableProps) {
60
- const [sort, setSort] = useState<Sort>({})
61
-
62
- const handleSortClick = (sortBykey) => {
63
- setSort((prev) => {
64
- if (prev[sortBykey]) {
65
- if (prev[sortBykey] === 'desc') return { ...prev, [sortBykey]: 'asc' }
66
- if (prev[sortBykey] === 'asc') {
67
- delete prev[sortBykey]
68
- return { ...prev }
69
- }
70
- } else {
71
- return {
72
- ...prev,
73
- [sortBykey]: 'desc',
74
- }
75
- }
76
- })
77
- }
78
-
79
- useEffect(() => {
80
- if (!onSort) return
81
-
82
- onSort({
83
- sortBy: Object.keys(sort).join(','),
84
- sortOrder: Object.keys(sort)
85
- .map((item) => sort[item])
86
- .join(','),
87
- })
88
- }, [sort])
89
-
90
- return (
91
- <TableContainer>
92
- <>
93
- <MuiTable>
94
- <TableHead>
95
- <TableRow>
96
- {columns.map((col, index) => (
97
- <TableCell
98
- key={index}
99
- sx={{
100
- ...(col?.width && {
101
- width: col?.width,
102
- }),
103
- }}
104
- >
105
- <>
106
- <Box sx={{ fontWeight: 600, fontSize: '14px' }}>
107
- {' '}
108
- {col.title}
109
- </Box>
110
- </>
111
- {col.sort && (
112
- <IconButton onClick={() => handleSortClick(col.dataIndex)}>
113
- <ListItemIcon>
114
- {sort[col.dataIndex] === 'asc' ? (
115
- <SortAscIcon />
116
- ) : sort[col.dataIndex] === 'desc' ? (
117
- <SortDescIcon />
118
- ) : (
119
- <SortIcon />
120
- )}
121
- </ListItemIcon>
122
- </IconButton>
123
- )}
124
- </TableCell>
125
- ))}
126
- </TableRow>
127
- </TableHead>
128
- {!loading ? (
129
- <>
130
- {dataSource?.length ? (
131
- <TableBody>
132
- {dataSource?.map((row, index) => (
133
- <StyledTableRow
134
- canRowClick={!!onRowClick}
135
- hover={!!onRowClick}
136
- key={index}
137
- onClick={() => {
138
- return onRowClick && onRowClick(row)
139
- }}
140
- >
141
- {columns.map((col, colIndex) => (
142
- <TableCell
143
- sx={{
144
- color: col.textColor,
145
- padding: dense ? '10px' : '15px',
146
- font: 'avenir',
147
- fontSize: '14px',
148
- }}
149
- key={colIndex}
150
- >
151
- <>
152
- {col?.render
153
- ? col.render(row[col.dataIndex], row, index)
154
- : _.get(row, col.dataIndex)}
155
- </>
156
- </TableCell>
157
- ))}
158
- </StyledTableRow>
159
- ))}
160
- </TableBody>
161
- ) : (
162
- <Box>
163
- {dataSource && (
164
- <Typography sx={{ padding: '10px' }}>
165
- No Records Found !..
166
- </Typography>
167
- )}
168
- </Box>
169
- )}
170
- </>
171
- ) : (
172
- <Spinner />
173
- )}
174
- </MuiTable>
175
- </>
176
- <>
177
- {pagination && (
178
- <TableFooter
179
- page={pagination.page}
180
- limit={pagination.limit}
181
- totalCount={pagination.totalCount}
182
- handlePagination={pagination.onChange}
183
- handlePageLimit={pagination.onChangeLimit}
184
- />
185
- )}
186
- </>
187
- </TableContainer>
188
- )
189
- }
190
-
191
- // const StyledSortButton = styled(IconButton)<{
192
- // sortOrder: Order
193
- // dataIndex: string
194
- // }>(({ theme, sortOrder, dataIndex }) => ({
195
- // marginLeft: '10px',
196
- // ...(sortOrder === '' && {
197
- // '& .MuiSvgIcon-root': {
198
- // // visibility: 'hidden',
199
- // },
200
- // // '&:hover .MuiSvgIcon-root': {
201
- // // visibility: 'visible',
202
- // // opacity: 0.4,
203
- // // },
204
- // transition: 'transform 1s ease-in-out',
205
- // }),
206
- // ...(sortOrder === 'asc' && {
207
- // transition: 'transform 1s ease-in-out',
208
- // }),
209
- // ...(sortOrder === 'desc' && {
210
- // '& .MuiSvgIcon-root': {
211
- // transform: 'rotate(180deg)',
212
- // },
213
- // transition: 'transform 1s ease-in-out',
214
- // }),
215
- // }))
216
-
217
- const StyledTableRow = styled(TableRow)<{ canRowClick: boolean }>(
218
- ({ theme, canRowClick }) => ({
219
- ...(canRowClick && {
220
- cursor: 'pointer',
221
- '&.MuiTableRow-hover:hover': {
222
- backgroundColor: alpha('#f2f2f2', 0.4),
223
- },
224
- }),
225
- }),
226
- )
1
+ export { default } from './Table'
@@ -37,11 +37,11 @@ export const StyledPagination = styled(Pagination)(({ theme }) => ({
37
37
  },
38
38
  }))
39
39
 
40
- export const StyledTableRow = styled(TableRow)<{ isSelected?: boolean }>(
41
- ({ theme, isSelected }) => ({
42
- background: isSelected && alpha(theme.palette.primary.main, 0.07),
43
- }),
44
- )
40
+ export const StyledTableRow = styled(TableRow, {
41
+ shouldForwardProp: (prop) => prop !== 'onRowClick',
42
+ })<{ isSelected?: boolean }>(({ theme, isSelected }) => ({
43
+ background: isSelected && alpha(theme.palette.primary.main, 0.07),
44
+ }))
45
45
 
46
46
  export const StyledActionsRow = styled(Box)(({ theme }) => ({
47
47
  display: 'flex',
@@ -108,10 +108,7 @@ export const StyledLimitMenu = styled((props: MenuProps) => (
108
108
  padding: '0',
109
109
  },
110
110
  '& .MuiMenuItem-root': {
111
- fontFamily: 'Avenir',
112
- fontSize: '14px',
113
- fontWeight: 'bold',
114
- height: '35px',
111
+ height: '40px',
115
112
  borderBottom: theme.borders.grayLight,
116
113
  align: 'center',
117
114
  '& .MuiSvgIcon-root': {
@@ -1,5 +1,4 @@
1
1
  import { alpha, darken, lighten } from '@mui/material'
2
- import { red } from '@mui/material/colors'
3
2
  import { createTheme } from '@mui/material/styles'
4
3
  import { customCssBaseline } from './customCssBaseline'
5
4
 
@@ -90,7 +89,7 @@ const muiTheme = createTheme({
90
89
  blue: themeColors.offsetBlue,
91
90
  },
92
91
  error: {
93
- main: red.A400,
92
+ main: '#BC2C3D',
94
93
  },
95
94
  text: {
96
95
  primary: '#121212',
@@ -157,12 +156,13 @@ const muiTheme = createTheme({
157
156
  styleOverrides: {
158
157
  root: {
159
158
  fontFamily: SECONDARY_FONT,
160
- height: '50px',
159
+ height: '40px',
161
160
  fontSize: '14px',
162
161
  padding: '10px 40px',
163
162
  textTransform: 'capitalize',
164
163
  fontWeight: 600,
165
164
  borderRadius: borderRadius.small,
165
+ flexShrink: 0,
166
166
  '&.MuiButton-sizeSmall': {
167
167
  padding: '6px 8px',
168
168
  height: '40px',
@@ -172,6 +172,10 @@ const muiTheme = createTheme({
172
172
  },
173
173
  },
174
174
  MuiButtonBase: {
175
+ defaultProps: {
176
+ disableRipple: true,
177
+ disableTouchRipple: true,
178
+ },
175
179
  styleOverrides: {
176
180
  root: {
177
181
  fontFamily: SECONDARY_FONT,
@@ -180,19 +184,36 @@ const muiTheme = createTheme({
180
184
  },
181
185
  },
182
186
  },
183
- MuiOutlinedInput: {
187
+ MuiInputBase: {
184
188
  styleOverrides: {
185
189
  root: {
186
- fontSize: '14px',
187
- minHeight: '50px',
188
- borderRadius: borderRadius.large,
190
+ height: '50px',
191
+ borderRadius: '10px',
192
+ '& input': {
193
+ padding: '10px 14px',
194
+ fontSize: '15px',
195
+ boxSizing: 'border-box',
196
+ height: '50px',
197
+ },
189
198
  '&.MuiInputBase-sizeSmall': {
190
- minHeight: '30px',
199
+ borderRadius: '6px',
200
+ height: '40px',
201
+ '& input': { height: '40px' },
202
+ '& fieldset': { height: '40px' },
191
203
  },
204
+ },
205
+ },
206
+ },
207
+ MuiOutlinedInput: {
208
+ styleOverrides: {
209
+ root: {
210
+ borderRadius: borderRadius.large,
192
211
  '& .MuiInputAdornment-positionEnd.MuiInputAdornment-outlined': {
193
212
  paddingRight: 2,
194
213
  },
195
214
  '& .MuiOutlinedInput-notchedOutline': {
215
+ top: 1,
216
+ height: '50px',
196
217
  borderColor: alpha(colors.common.black, 0.15),
197
218
  '& legend': {
198
219
  '& > span': {
@@ -214,6 +235,32 @@ const muiTheme = createTheme({
214
235
  },
215
236
  },
216
237
  },
238
+ MuiCheckbox: {
239
+ defaultProps: {
240
+ disableRipple: true,
241
+ },
242
+ styleOverrides: {
243
+ root: {
244
+ '& .MuiSvgIcon-root': {
245
+ width: '18px',
246
+ height: '18px',
247
+ },
248
+ },
249
+ },
250
+ },
251
+ MuiFormControl: {
252
+ styleOverrides: {
253
+ root: {
254
+ '& .MuiFormHelperText-root': {
255
+ fontStyle: 'oblique',
256
+ marginTop: '10px',
257
+ fontSize: '13px',
258
+ fontWeight: 600,
259
+ textAlign: 'right',
260
+ },
261
+ },
262
+ },
263
+ },
217
264
  MuiAutocomplete: {
218
265
  styleOverrides: {
219
266
  tag: {
@@ -404,6 +451,26 @@ const muiTheme = createTheme({
404
451
  },
405
452
  },
406
453
  },
454
+ MuiMenuItem: {
455
+ styleOverrides: {
456
+ root: {
457
+ fontWeight: 500,
458
+ fontFamily: SECONDARY_FONT,
459
+ fontSize: '14px',
460
+ },
461
+ },
462
+ },
463
+ MuiListItemText: {
464
+ styleOverrides: {
465
+ root: {
466
+ '& .MuiTypography-root': {
467
+ fontWeight: 500,
468
+ fontFamily: SECONDARY_FONT,
469
+ fontSize: '14px',
470
+ },
471
+ },
472
+ },
473
+ },
407
474
  MuiCardHeader: {
408
475
  styleOverrides: {
409
476
  root: {
@@ -479,10 +546,7 @@ const muiTheme = createTheme({
479
546
  },
480
547
  MuiRadio: {
481
548
  defaultProps: {
482
- size: 'small',
483
- },
484
- styleOverrides: {
485
- root: {},
549
+ disableRipple: true,
486
550
  },
487
551
  },
488
552
  MuiCssBaseline: {