rez-table-listing-mui 2.0.0 → 2.0.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rez-table-listing-mui",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "type": "module",
5
5
  "description": "A rez table listing component built on TanStack Table",
6
6
  "main": "dist/index.js",
@@ -4,7 +4,6 @@ import NavigateBeforeRounded from "@mui/icons-material/NavigateBeforeRounded";
4
4
  import NavigateNextRounded from "@mui/icons-material/NavigateNextRounded";
5
5
  import { MenuItem, Typography } from "@mui/material";
6
6
  import { CraftTablePaginationProps } from "../../../types/table";
7
-
8
7
  import {
9
8
  PaginationContainer,
10
9
  GoToPageContainer,
@@ -49,6 +48,7 @@ function DefaultPagination<T>({
49
48
  defaultValue={pageIndex}
50
49
  type="number"
51
50
  inputProps={{
51
+ name: "pagination-size",
52
52
  min: 1,
53
53
  max: pageCount,
54
54
  }}
@@ -95,6 +95,7 @@ export const RowsPerPageSelect = styled(Select)(({ theme }) => ({
95
95
  fontSize: theme.typography.pxToRem(12),
96
96
 
97
97
  "& .MuiSelect-select": {
98
+ fontSize: theme.typography.pxToRem(12),
98
99
  padding: theme.spacing(0.5, 0.75),
99
100
  },
100
101
  }));
@@ -108,6 +109,7 @@ export const GoToPageInput = styled(InputBase)(({ theme }) => ({
108
109
  fontSize: theme.typography.pxToRem(12),
109
110
 
110
111
  "& .MuiInputBase-input": {
112
+ fontSize: theme.typography.pxToRem(12),
111
113
  padding: theme.spacing(0.25, 0.75),
112
114
  },
113
115
  }));
@@ -58,11 +58,7 @@ export const TableSearch = ({
58
58
  <Box
59
59
  ref={searchContainerRef}
60
60
  className="search-container"
61
- sx={{
62
- display: "flex",
63
- position: "relative",
64
- top: "10px",
65
- }}
61
+ sx={{ position: "relative" }}
66
62
  >
67
63
  <TextField
68
64
  type="text"
@@ -87,7 +83,7 @@ export const TableSearch = ({
87
83
  }, 100);
88
84
  }
89
85
  }}
90
- sx={{ color: "black", fontSize: "14px" }}
86
+ sx={{ color: "black", fontSize: 14 }}
91
87
  edge="start"
92
88
  >
93
89
  <SearchIcon />
@@ -103,12 +99,12 @@ export const TableSearch = ({
103
99
  setLocalValue("");
104
100
  handleChange({ target: { value: "" } } as any);
105
101
  }}
106
- sx={{ color: "black", fontSize: "14px" }}
102
+ sx={{ color: "black", fontSize: 14 }}
107
103
  edge="end"
108
104
  >
109
105
  <CloseRoundedIcon
110
106
  fontSize="small"
111
- sx={{ color: "black", fontSize: "14px" }}
107
+ sx={{ color: "black", fontSize: 14 }}
112
108
  />
113
109
  </IconButton>
114
110
  </InputAdornment>
@@ -28,7 +28,6 @@ export const TableBodyRow = styled("tr", {
28
28
  ...(hoverable && {
29
29
  transition: "background-color 0.2s ease, box-shadow 0.2s ease",
30
30
  "&:hover": {
31
- backgroundColor: theme.palette.action.hover,
32
31
  boxShadow: `inset 0 2px 2px rgba(0,0,0,0.05),
33
32
  inset 0 -2px 2px rgba(0,0,0,0.05)`,
34
33
  },
@@ -97,9 +97,7 @@ export const TableHeadCell = styled("th", {
97
97
  }>(({ theme, compact, isDragging, isPinned, sticky }) => ({
98
98
  position: "relative",
99
99
  padding: compact ? theme.spacing(0.375, 0.675) : theme.spacing(0.75, 1),
100
- borderWidth: "0.5px",
101
- borderStyle: "solid",
102
- borderColor: theme.palette.grey[500],
100
+ border: `0.5px solid ${theme.palette.grey[300]}`,
103
101
  cursor: "pointer",
104
102
  backgroundColor: theme.palette.common.white,
105
103
  userSelect: "none",
@@ -6,14 +6,14 @@ import { TableTab, TableTabCount, TableTabsRoot } from "./tabs.styles";
6
6
  import { SettingsOutlined } from "@mui/icons-material";
7
7
 
8
8
  interface TabDataProps {
9
- tab_name: string | null;
10
- count?: string | number;
9
+ tab_value: string | null;
10
+ tab_value_count?: string | number;
11
11
  }
12
12
 
13
13
  interface TableTabsProps {
14
14
  loading?: boolean;
15
15
  tabsData?: TabDataProps[];
16
- activeTab?: TabDataProps;
16
+ activeTab?: string;
17
17
  tableStates: CraftTableOptionsProps;
18
18
  onClick: (state: string) => void;
19
19
  settingsOptions?: settingsOptionsProps;
@@ -22,7 +22,7 @@ interface TableTabsProps {
22
22
  export function TableTabs({
23
23
  loading = false,
24
24
  tabsData = [],
25
- activeTab = { tab_name: "All", count: 0 },
25
+ activeTab = "All",
26
26
  onClick,
27
27
  tableStates,
28
28
  settingsOptions,
@@ -39,22 +39,22 @@ export function TableTabs({
39
39
 
40
40
  const normalizedTabs = useMemo(() => {
41
41
  return tabsData
42
- ?.filter((tab) => tab.tab_name !== null)
42
+ ?.filter((tab) => tab.tab_value !== null)
43
43
  ?.map((tab) => ({
44
44
  ...tab,
45
- tab_name: tab.tab_name,
45
+ tab_value: tab.tab_value,
46
46
  }));
47
47
  }, [tabsData]);
48
48
 
49
49
  const defaultTab = useMemo(() => {
50
50
  return (
51
- normalizedTabs.find((t) => t.tab_name === "All")?.tab_name ||
52
- normalizedTabs[0]?.tab_name ||
51
+ normalizedTabs.find((t) => t.tab_value === "All")?.tab_value ||
52
+ normalizedTabs[0]?.tab_value ||
53
53
  ""
54
54
  );
55
55
  }, [normalizedTabs]);
56
56
 
57
- const selectedTab = activeTab?.tab_name || defaultTab;
57
+ const selectedTab = activeTab || defaultTab;
58
58
 
59
59
  return (
60
60
  <Box display="flex" alignItems="center" justifyContent="flex-start">
@@ -73,21 +73,21 @@ export function TableTabs({
73
73
  scrollButtons="auto"
74
74
  >
75
75
  {normalizedTabs.map((tab) => {
76
- const isSelected = activeTab?.tab_name === tab?.tab_name;
76
+ const isSelected = activeTab === tab?.tab_value;
77
77
 
78
78
  return (
79
79
  <TableTab
80
- key={tab?.tab_name}
81
- value={tab}
80
+ key={tab?.tab_value}
81
+ value={tab?.tab_value}
82
82
  label={
83
83
  <Box display="flex" alignItems="center" gap={1}>
84
84
  <Box sx={{ color: isSelected ? "#000" : "" }}>
85
- {tab?.tab_name}
85
+ {tab?.tab_value}
86
86
  </Box>
87
87
  <TableTabCount selected={isSelected}>
88
- {tab?.count == 0
88
+ {tab?.tab_value_count == 0
89
89
  ? "0"
90
- : String(tab?.count).padStart(2, "0")}
90
+ : String(tab?.tab_value_count).padStart(2, "0")}
91
91
  </TableTabCount>
92
92
  </Box>
93
93
  }
@@ -34,13 +34,11 @@
34
34
  }
35
35
  }
36
36
  .ts--button {
37
- margin-right: 0.6rem;
38
- margin-top: 1rem;
39
37
  cursor: pointer;
40
38
  }
41
39
 
42
40
  .change-layout {
43
- margin-top: 0.99rem;
41
+ margin-top: 0.4rem;
44
42
  cursor: pointer;
45
43
  }
46
44
 
@@ -54,7 +52,7 @@
54
52
  }
55
53
 
56
54
  .hide-column {
57
- margin-top: 0.9rem;
55
+ margin-top: 0.8rem;
58
56
  position: relative;
59
57
 
60
58
  .ts-dropdown {
@@ -5,9 +5,8 @@ import {
5
5
  FilterationIcon,
6
6
  HideColumnIcon,
7
7
  } from "../../../assets/svg.tsx";
8
- import { Popover } from "@mui/material";
8
+ import { Box, Popover } from "@mui/material";
9
9
  import LayoutSelector from "../table-change-layout.tsx";
10
- import useOutsideClick from "../../libs/hooks/useOutsideClick.tsx";
11
10
  import { Table } from "@tanstack/react-table";
12
11
  import { TopbarOptionsProps } from "../../types/table.ts";
13
12
  import "./index.scss";
@@ -48,7 +47,6 @@ function Topbar<T>({
48
47
  const [sortAnchorEl, setSortAnchorEl] = useState<HTMLElement | null>(null);
49
48
  const [groupBy, setGroupBy] = useState<string>("None");
50
49
 
51
- const [showColumnHiding, setShowColumnHiding] = useState(false);
52
50
  const [layoutAnchorEl, setLayoutAnchorEl] = useState<null | HTMLElement>(
53
51
  null
54
52
  );
@@ -60,10 +58,6 @@ function Topbar<T>({
60
58
  table.getAllLeafColumns().map((col) => col.id)
61
59
  );
62
60
 
63
- const { setShowTableFilter } = tableStates;
64
-
65
- // search
66
- const [showSearchInput, setShowSearchInput] = useState(false);
67
61
  const searchContainerRef = useRef<HTMLDivElement>(null);
68
62
 
69
63
  // sync column order with table instance
@@ -78,7 +72,6 @@ function Topbar<T>({
78
72
  setSortAnchorEl(null);
79
73
  setColumnAnchorEl(null);
80
74
  setViewMoreAnchorEl(null);
81
- setShowColumnHiding(false);
82
75
  }
83
76
  }, [isFullscreen]);
84
77
 
@@ -96,22 +89,11 @@ function Topbar<T>({
96
89
 
97
90
  const { container: fullscreenContainer } = useFullscreenPopoverContainer();
98
91
 
99
- const dropdownRef = useRef<HTMLDivElement>(null);
100
- useOutsideClick({
101
- ref: dropdownRef,
102
- handler: () => setShowColumnHiding(false),
103
- });
104
-
105
92
  const handleLayoutSelect = (layout: string) => {
106
93
  setSelectedLayout(layout);
107
94
  setLayoutAnchorEl(null);
108
95
  };
109
96
 
110
- useOutsideClick({
111
- ref: searchContainerRef,
112
- handler: () => setShowSearchInput(false),
113
- });
114
-
115
97
  useEffect(() => {
116
98
  const handleExternalLayoutTrigger = (e: Event) => {
117
99
  const target = (e as CustomEvent).detail?.target as HTMLElement;
@@ -128,7 +110,6 @@ function Topbar<T>({
128
110
  };
129
111
 
130
112
  const handleExternalSearchTrigger = () => {
131
- setShowSearchInput(true);
132
113
  setTimeout(() => {
133
114
  searchContainerRef.current?.querySelector("input")?.focus();
134
115
  }, 100);
@@ -180,96 +161,107 @@ function Topbar<T>({
180
161
  {rightSideComponent}
181
162
  {paginationComponent}
182
163
 
183
- {showSearch && (
184
- <div
185
- title="Search"
186
- className="external-search-trigger"
187
- onClick={() => {
188
- const customEvent = new CustomEvent("triggerSearchInput");
189
- window.dispatchEvent(customEvent);
164
+ <Box
165
+ sx={{
166
+ display: "flex",
167
+ alignItems: "center",
168
+ justifyContent: "center",
169
+ gap: 0.5,
170
+ }}
171
+ >
172
+ {showSearch && (
173
+ <Box
174
+ title="Search"
175
+ className="external-search-trigger"
176
+ onClick={() => {
177
+ const customEvent = new CustomEvent("triggerSearchInput");
178
+ window.dispatchEvent(customEvent);
179
+ }}
180
+ ref={searchContainerRef}
181
+ >
182
+ <TableSearch
183
+ value={searchValue ?? ""}
184
+ onChange={onSearchChange ?? (() => {})}
185
+ />
186
+ </Box>
187
+ )}
188
+
189
+ {showChangeLayoutToggle && (
190
+ <>
191
+ <div className="change-layout ts--button" title="Layout">
192
+ <div
193
+ onClick={(e) => {
194
+ const customEvent = new CustomEvent(
195
+ "triggerLayoutPopover",
196
+ {
197
+ detail: { target: e.currentTarget },
198
+ }
199
+ );
200
+ window.dispatchEvent(customEvent);
201
+ }}
202
+ className="external-layout-trigger"
203
+ >
204
+ <ChangeLayoutIcon />
205
+ </div>
206
+ </div>
207
+ </>
208
+ )}
209
+ <Popover
210
+ open={Boolean(layoutAnchorEl)}
211
+ anchorEl={layoutAnchorEl}
212
+ onClose={() => setLayoutAnchorEl(null)}
213
+ anchorOrigin={{ vertical: "bottom", horizontal: "left" }}
214
+ container={fullscreenContainer}
215
+ sx={{
216
+ mt: 2.2,
190
217
  }}
191
- ref={searchContainerRef}
192
218
  >
193
- <TableSearch
194
- value={searchValue ?? ""}
195
- onChange={onSearchChange ?? (() => {})}
219
+ <LayoutSelector
220
+ onSelect={handleLayoutSelect}
221
+ selectedLayout={selectedLayout}
196
222
  />
197
- </div>
198
- )}
199
-
200
- {showChangeLayoutToggle && (
201
- <>
202
- <div className="change-layout ts--button" title="Layout">
223
+ </Popover>
224
+ {showColumnToggle && (
225
+ <>
203
226
  <div
204
- onClick={(e) => {
205
- const customEvent = new CustomEvent("triggerLayoutPopover", {
206
- detail: { target: e.currentTarget },
207
- });
208
- window.dispatchEvent(customEvent);
209
- }}
210
- className="external-layout-trigger"
227
+ className="hide-column ts--button"
228
+ onClick={(e) => setColumnAnchorEl(e.currentTarget)}
229
+ title="Column"
211
230
  >
212
- <ChangeLayoutIcon />
231
+ <HideColumnIcon />
213
232
  </div>
214
- </div>
215
- </>
216
- )}
217
- <Popover
218
- open={Boolean(layoutAnchorEl)}
219
- anchorEl={layoutAnchorEl}
220
- onClose={() => setLayoutAnchorEl(null)}
221
- anchorOrigin={{ vertical: "bottom", horizontal: "left" }}
222
- container={fullscreenContainer}
223
- sx={{
224
- mt: 2.2,
225
- }}
226
- >
227
- <LayoutSelector
228
- onSelect={handleLayoutSelect}
229
- selectedLayout={selectedLayout}
230
- />
231
- </Popover>
232
- {showColumnToggle && (
233
- <>
234
- <div
235
- className="hide-column ts--button"
236
- onClick={(e) => setColumnAnchorEl(e.currentTarget)}
237
- title="Column"
238
- >
239
- <HideColumnIcon />
240
- </div>
241
- <ColumnToggle
242
- anchorEl={columnAnchorEl}
243
- onClose={() => setColumnAnchorEl(null)}
244
- table={table}
245
- columnOrder={columnOrder}
246
- setColumnOrder={setColumnOrder}
247
- />
248
- </>
249
- )}
233
+ <ColumnToggle
234
+ anchorEl={columnAnchorEl}
235
+ onClose={() => setColumnAnchorEl(null)}
236
+ table={table}
237
+ columnOrder={columnOrder}
238
+ setColumnOrder={setColumnOrder}
239
+ />
240
+ </>
241
+ )}
250
242
 
251
- {showSortingToggle && (
252
- <>
253
- <div
254
- className="filter ts--button"
255
- title="Sort"
256
- onClick={(e) => setSortAnchorEl(e.currentTarget)}
257
- >
258
- <SortingIcon />
259
- </div>
260
- <SortPopover
261
- anchorEl={sortAnchorEl}
262
- onClose={() => setSortAnchorEl(null)}
263
- columns={table.getAllLeafColumns().map((col) => ({
264
- id: col.id,
265
- label: (col.columnDef.meta as any)?.label || col.id,
266
- }))}
267
- onChange={(sortingRules) => table.setSorting(sortingRules)}
268
- />
269
- </>
270
- )}
243
+ {showSortingToggle && (
244
+ <>
245
+ <div
246
+ className="filter ts--button"
247
+ title="Sort"
248
+ onClick={(e) => setSortAnchorEl(e.currentTarget)}
249
+ >
250
+ <SortingIcon />
251
+ </div>
252
+ <SortPopover
253
+ anchorEl={sortAnchorEl}
254
+ onClose={() => setSortAnchorEl(null)}
255
+ columns={table.getAllLeafColumns().map((col) => ({
256
+ id: col.id,
257
+ label: (col.columnDef.meta as any)?.label || col.id,
258
+ }))}
259
+ onChange={(sortingRules) => table.setSorting(sortingRules)}
260
+ />
261
+ </>
262
+ )}
271
263
 
272
- {/* {showFilterToggle && (
264
+ {/* {showFilterToggle && (
273
265
  <div
274
266
  className="filter ts--button"
275
267
  title="Filter"
@@ -298,51 +290,52 @@ function Topbar<T>({
298
290
  </div>
299
291
  )} */}
300
292
 
301
- {showFilterToggle && (
302
- <div
303
- className="filter ts--button"
304
- title="Filter"
305
- onClick={onFilterButtonClick}
306
- style={{
307
- position: "relative",
308
- display: "flex",
309
- justifyContent: "center",
310
- alignItems: "center",
311
- backgroundColor:
312
- tableStates.showTableFilter || tableStates.filters.length > 0
313
- ? "#eae4fe"
314
- : "transparent",
315
- height: "25px",
316
- width: "25px",
317
- borderRadius: "6px",
318
- cursor: "pointer",
319
- }}
320
- >
321
- <FilterationIcon
322
- color={
323
- tableStates.showTableFilter || tableStates.filters.length > 0
324
- ? "#7A5AF8"
325
- : "#1C1B1F"
326
- }
327
- />
328
-
329
- {tableStates.filters.length > 0 && !tableStates.showTableFilter && (
330
- <span
331
- style={{
332
- position: "absolute",
333
- top: "1px",
334
- right: "1px",
335
- width: "6px",
336
- height: "6px",
337
- borderRadius: "50%",
338
- backgroundColor: "#F63D68",
339
- }}
293
+ {showFilterToggle && (
294
+ <div
295
+ className="filter ts--button"
296
+ title="Filter"
297
+ onClick={onFilterButtonClick}
298
+ style={{
299
+ position: "relative",
300
+ display: "flex",
301
+ justifyContent: "center",
302
+ alignItems: "center",
303
+ backgroundColor:
304
+ tableStates.showTableFilter || tableStates.filters.length > 0
305
+ ? "#eae4fe"
306
+ : "transparent",
307
+ height: "25px",
308
+ width: "25px",
309
+ borderRadius: "6px",
310
+ cursor: "pointer",
311
+ }}
312
+ >
313
+ <FilterationIcon
314
+ color={
315
+ tableStates.showTableFilter || tableStates.filters.length > 0
316
+ ? "#7A5AF8"
317
+ : "#1C1B1F"
318
+ }
340
319
  />
341
- )}
342
- </div>
343
- )}
344
320
 
345
- {/* {viewMoreToggle && (
321
+ {tableStates.filters.length > 0 &&
322
+ !tableStates.showTableFilter && (
323
+ <span
324
+ style={{
325
+ position: "absolute",
326
+ top: "1px",
327
+ right: "1px",
328
+ width: "6px",
329
+ height: "6px",
330
+ borderRadius: "50%",
331
+ backgroundColor: "#F63D68",
332
+ }}
333
+ />
334
+ )}
335
+ </div>
336
+ )}
337
+
338
+ {/* {viewMoreToggle && (
346
339
  <div className="view-more ts--button" title="View More">
347
340
  <ViewMore
348
341
  compactMode={isCompactTable}
@@ -357,7 +350,7 @@ function Topbar<T>({
357
350
  />
358
351
  </div>
359
352
  )} */}
360
- {/* {viewMoreToggle && (
353
+ {/* {viewMoreToggle && (
361
354
  <div
362
355
  className="view-more ts--button view-more-trigger"
363
356
  title="View More"
@@ -375,36 +368,37 @@ function Topbar<T>({
375
368
  />
376
369
  </div>
377
370
  )} */}
378
- <Popover
379
- open={isViewMoreOpen}
380
- anchorEl={viewMoreAnchorEl}
381
- onClose={() => setViewMoreAnchorEl(null)}
382
- anchorOrigin={{ vertical: "bottom", horizontal: "left" }}
383
- transformOrigin={{ vertical: "top", horizontal: "left" }}
384
- container={fullscreenContainer}
385
- // PaperProps={{
386
- // sx: {
387
- // mt: 2,
388
- // padding: 0,
389
- // width: 380,
390
- // borderRadius: 1,
391
- // boxShadow: 4,
392
- // },
393
- // }}
394
- >
395
- <ViewMore
396
- compactMode={isCompactTable}
397
- onCompactToggle={(value: string) =>
398
- setIsCompactTable(value === "Compact")
399
- }
400
- isFullscreen={isFullscreen}
401
- onFullscreenToggle={fullscreenToggle}
402
- groupBy={groupBy}
403
- onGroupByChange={(value: string) => setGroupBy(value)}
404
- tableStates={tableStates}
371
+ <Popover
372
+ open={isViewMoreOpen}
373
+ anchorEl={viewMoreAnchorEl}
405
374
  onClose={() => setViewMoreAnchorEl(null)}
406
- />
407
- </Popover>
375
+ anchorOrigin={{ vertical: "bottom", horizontal: "left" }}
376
+ transformOrigin={{ vertical: "top", horizontal: "left" }}
377
+ container={fullscreenContainer}
378
+ // PaperProps={{
379
+ // sx: {
380
+ // mt: 2,
381
+ // padding: 0,
382
+ // width: 380,
383
+ // borderRadius: 1,
384
+ // boxShadow: 4,
385
+ // },
386
+ // }}
387
+ >
388
+ <ViewMore
389
+ compactMode={isCompactTable}
390
+ onCompactToggle={(value: string) =>
391
+ setIsCompactTable(value === "Compact")
392
+ }
393
+ isFullscreen={isFullscreen}
394
+ onFullscreenToggle={fullscreenToggle}
395
+ groupBy={groupBy}
396
+ onGroupByChange={(value: string) => setGroupBy(value)}
397
+ tableStates={tableStates}
398
+ onClose={() => setViewMoreAnchorEl(null)}
399
+ />
400
+ </Popover>
401
+ </Box>
408
402
  </div>
409
403
  </div>
410
404
  );
@@ -518,13 +518,13 @@ function ListingView() {
518
518
  ),
519
519
  searchValue: searchTerm,
520
520
  onSearchChange: (val) => setSearchTerm(val),
521
- showFilterToggle: false,
521
+ showFilterToggle: true,
522
522
  onFilterButtonClick: () =>
523
523
  tableStates.setShowTableFilter(!tableStates.showTableFilter),
524
- showColumnToggle: false,
525
- showSearch: false,
526
- showChangeLayoutToggle: false,
527
- showSortingToggle: false,
524
+ // showColumnToggle: false,
525
+ // showSearch: false,
526
+ // showChangeLayoutToggle: false,
527
+ // showSortingToggle: false,
528
528
  // viewMoreToggle: true,
529
529
  // showCompactTableToggle: false,
530
530
  }}