@campxdev/shared 1.3.2 → 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.
@@ -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',
@@ -184,19 +184,36 @@ const muiTheme = createTheme({
184
184
  },
185
185
  },
186
186
  },
187
- MuiOutlinedInput: {
187
+ MuiInputBase: {
188
188
  styleOverrides: {
189
189
  root: {
190
- fontSize: '14px',
191
- minHeight: '50px',
192
- 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
+ },
193
198
  '&.MuiInputBase-sizeSmall': {
194
- minHeight: '30px',
199
+ borderRadius: '6px',
200
+ height: '40px',
201
+ '& input': { height: '40px' },
202
+ '& fieldset': { height: '40px' },
195
203
  },
204
+ },
205
+ },
206
+ },
207
+ MuiOutlinedInput: {
208
+ styleOverrides: {
209
+ root: {
210
+ borderRadius: borderRadius.large,
196
211
  '& .MuiInputAdornment-positionEnd.MuiInputAdornment-outlined': {
197
212
  paddingRight: 2,
198
213
  },
199
214
  '& .MuiOutlinedInput-notchedOutline': {
215
+ top: 1,
216
+ height: '50px',
200
217
  borderColor: alpha(colors.common.black, 0.15),
201
218
  '& legend': {
202
219
  '& > span': {
@@ -218,6 +235,32 @@ const muiTheme = createTheme({
218
235
  },
219
236
  },
220
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
+ },
221
264
  MuiAutocomplete: {
222
265
  styleOverrides: {
223
266
  tag: {
@@ -408,6 +451,26 @@ const muiTheme = createTheme({
408
451
  },
409
452
  },
410
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
+ },
411
474
  MuiCardHeader: {
412
475
  styleOverrides: {
413
476
  root: {
@@ -483,10 +546,7 @@ const muiTheme = createTheme({
483
546
  },
484
547
  MuiRadio: {
485
548
  defaultProps: {
486
- size: 'small',
487
- },
488
- styleOverrides: {
489
- root: {},
549
+ disableRipple: true,
490
550
  },
491
551
  },
492
552
  MuiCssBaseline: {