rez-table-listing-mui 1.3.62 → 2.0.1

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.
Files changed (34) hide show
  1. package/dist/index.d.ts +5 -6
  2. package/dist/index.js +1 -1
  3. package/dist/index.js.map +1 -1
  4. package/dist/index.mjs +1 -1
  5. package/dist/index.mjs.map +1 -1
  6. package/package.json +1 -1
  7. package/src/listing/components/index.scss +0 -144
  8. package/src/listing/components/login/index.tsx +4 -4
  9. package/src/listing/components/pagination/default/index.tsx +108 -138
  10. package/src/listing/components/pagination/default/pagination.styles.ts +115 -0
  11. package/src/listing/components/search/index.tsx +4 -8
  12. package/src/listing/components/{table-body-dnd-cell.tsx → table-body/table-body-dnd-cell.tsx} +18 -25
  13. package/src/listing/components/table-body/table-body.styles.ts +64 -0
  14. package/src/listing/components/{table-body.tsx → table-body/table-body.tsx} +35 -32
  15. package/src/listing/components/table-head/table-head-dnd-cell.tsx +112 -0
  16. package/src/listing/components/table-head/table-head-pin.tsx +29 -0
  17. package/src/listing/components/{table-head-popover.tsx → table-head/table-head-popover.tsx} +4 -16
  18. package/src/listing/components/table-head/table-head-resizer.tsx +22 -0
  19. package/src/listing/components/table-head/table-head.styles.ts +113 -0
  20. package/src/listing/components/{table-head.tsx → table-head/table-head.tsx} +36 -69
  21. package/src/listing/components/table.tsx +2 -2
  22. package/src/listing/components/tabs/index.tsx +31 -49
  23. package/src/listing/components/tabs/tabs.styles.ts +49 -0
  24. package/src/listing/components/topbar/index.scss +2 -4
  25. package/src/listing/components/topbar/index.tsx +169 -175
  26. package/src/listing/libs/hooks/useEntityTableHooks.ts +3 -3
  27. package/src/listing/libs/utils/apiColumn.ts +7 -3
  28. package/src/listing/libs/utils/common.ts +44 -0
  29. package/src/listing/types/table.ts +2 -2
  30. package/src/view/ListingView.tsx +38 -87
  31. package/src/listing/components/table-head-dnd-cell.tsx +0 -150
  32. package/src/listing/components/table-head-pin.tsx +0 -22
  33. package/src/listing/components/tabs/index.scss +0 -42
  34. package/src/listing/components/tabs/styles.ts +0 -34
@@ -3,17 +3,25 @@ import {
3
3
  CraftTableFeatureProps,
4
4
  craftTableFilterSettingsOptionsProps,
5
5
  CraftTableOptionsProps,
6
- } from "../types/table-options";
7
- import { DownArrow, UpArrow } from "../../assets/svg";
8
- import { CSSProperties, useState } from "react";
9
- import { getColumnPinningStyles } from "../libs/utils/common";
6
+ } from "../../types/table-options";
7
+ import { DownArrow, UpArrow } from "../../../assets/svg";
8
+ import { useState } from "react";
9
+ import { getColumnPinningStyles } from "../../libs/utils/common";
10
10
  import {
11
11
  horizontalListSortingStrategy,
12
12
  SortableContext,
13
13
  } from "@dnd-kit/sortable";
14
14
  import DraggableTableHeader from "./table-head-dnd-cell";
15
15
  import TableHeadPin from "./table-head-pin";
16
- import Checkbox from "./inputs/checkbox";
16
+ import Checkbox from "../inputs/checkbox";
17
+ import TableColumnResizeHandle from "./table-head-resizer";
18
+ import {
19
+ TableHeadCell,
20
+ TableHeadContent,
21
+ TableHeadRoot,
22
+ TableHeadRow,
23
+ TableHeadSort,
24
+ } from "./table-head.styles";
17
25
 
18
26
  interface TableHeadProps<T> {
19
27
  table: Table<T>;
@@ -49,54 +57,26 @@ function TableHead<T>({
49
57
  };
50
58
 
51
59
  return (
52
- <thead className={`ts__head ${stickyHeader ? "ts--sticky" : ""}`.trim()}>
60
+ <TableHeadRoot sticky={stickyHeader}>
53
61
  {table.getHeaderGroups().map((headerGroup) => (
54
- <tr className="ts__head__tr" key={headerGroup?.id}>
62
+ <TableHeadRow striped={featureOptions.striped} key={headerGroup?.id}>
55
63
  {enableRowSelection && (
56
- <th
57
- className="ts__head__th ts__head__checkbox"
58
- style={{
59
- position: "sticky",
60
- left: 0,
61
- width: "50px",
62
- }}
64
+ <TableHeadCell
65
+ sticky
66
+ compact={featureOptions.compactTable}
67
+ style={{ width: 50 }}
63
68
  >
64
- <div className="ts__content">
69
+ <TableHeadContent>
65
70
  <Checkbox
66
71
  checked={table.getIsAllRowsSelected()}
67
72
  indeterminate={table.getIsSomeRowsSelected()}
68
73
  onChange={() => table.toggleAllRowsSelected()}
69
74
  />
70
- </div>
71
- </th>
75
+ </TableHeadContent>
76
+ </TableHeadCell>
72
77
  )}
73
78
 
74
79
  {headerGroup.headers.map((header) => {
75
- let sortProps: {
76
- className: string;
77
- title?: string;
78
- style?: CSSProperties;
79
- } = {
80
- className: "ts__content",
81
- // style: {
82
- // justifyContent: getColumnAlignment(
83
- // (header?.column?.columnDef?.meta as align)?.align
84
- // ),
85
- // },
86
- };
87
-
88
- // if (header.column.getCanSort()) {
89
- // sortProps = {
90
- // ...sortProps,
91
- // title:
92
- // header.column.getNextSortingOrder() === "asc"
93
- // ? "Sort ascending"
94
- // : header.column.getNextSortingOrder() === "desc"
95
- // ? "Sort descending"
96
- // : "Clear sort",
97
- // };
98
- // }
99
-
100
80
  return enableColumnReordering ? (
101
81
  <SortableContext
102
82
  key={header?.id}
@@ -113,36 +93,30 @@ function TableHead<T>({
113
93
  />
114
94
  </SortableContext>
115
95
  ) : (
116
- <th
96
+ <TableHeadCell
117
97
  key={header?.id}
118
- className="ts__head__th"
119
98
  colSpan={header.colSpan}
99
+ compact={featureOptions.compactTable}
100
+ onClick={handleHover}
120
101
  style={{
121
102
  ...getColumnPinningStyles(header.column),
122
103
  width: `${header.column.getSize()}px`,
123
104
  minWidth: `${header.column.columnDef.minSize}px`,
124
105
  maxWidth: `${header.column.columnDef.maxSize}px`,
125
106
  }}
126
- onClick={handleHover}
127
107
  >
128
108
  {header.isPlaceholder ? null : (
129
- <div {...sortProps}>
130
- <div
131
- className={`${
132
- header.column.getCanSort() ? "ts__content__sort" : ""
133
- }`.trim()}
134
- // onClick={header.column.getToggleSortingHandler()}
135
- >
109
+ <TableHeadContent>
110
+ <TableHeadSort sortable={header.column.getCanSort()}>
136
111
  {flexRender(
137
112
  header.column.columnDef.header,
138
113
  header.getContext()
139
114
  )}
140
115
 
141
- {{
142
- asc: <UpArrow />,
143
- desc: <DownArrow />,
144
- }[header.column.getIsSorted() as "asc" | "desc"] ?? null}
145
- </div>
116
+ {{ asc: <UpArrow />, desc: <DownArrow /> }[
117
+ header.column.getIsSorted() as "asc" | "desc"
118
+ ] ?? null}
119
+ </TableHeadSort>
146
120
 
147
121
  {enableColumnPinning && (
148
122
  <TableHeadPin
@@ -151,19 +125,12 @@ function TableHead<T>({
151
125
  tableStates={tableStates}
152
126
  />
153
127
  )}
154
- </div>
128
+ </TableHeadContent>
155
129
  )}
156
130
 
157
131
  {/* column resizing */}
158
132
  {header.column.getCanResize() ? (
159
- <div
160
- onDoubleClick={() => header.column.resetSize()}
161
- onMouseDown={header.getResizeHandler()}
162
- onTouchStart={header.getResizeHandler()}
163
- className={`column__resize ${
164
- header.column.getIsResizing() ? "is__resizing" : ""
165
- }`}
166
- />
133
+ <TableColumnResizeHandle header={header} />
167
134
  ) : null}
168
135
 
169
136
  {/* Popover */}
@@ -174,12 +141,12 @@ function TableHead<T>({
174
141
  wrap={wrap}
175
142
  tableStates={tableStates}
176
143
  /> */}
177
- </th>
144
+ </TableHeadCell>
178
145
  );
179
146
  })}
180
- </tr>
147
+ </TableHeadRow>
181
148
  ))}
182
- </thead>
149
+ </TableHeadRoot>
183
150
  );
184
151
  }
185
152
 
@@ -1,7 +1,7 @@
1
1
  import { formatClassName } from "../libs/utils/common";
2
2
  import { CraftTableComponentProps } from "../types/table";
3
- import TableBody from "./table-body";
4
- import TableHead from "./table-head";
3
+ import TableBody from "./table-body/table-body";
4
+ import TableHead from "./table-head/table-head";
5
5
 
6
6
  function Table<T>({
7
7
  table,
@@ -1,24 +1,21 @@
1
- import "./index.scss";
2
- import { Box, CircularProgress, IconButton, Tab, Tabs } from "@mui/material";
1
+ import { Box, CircularProgress, IconButton } from "@mui/material";
3
2
  import { CraftTableOptionsProps } from "../../types/table-options";
4
- import SettingsOutlinedIcon from "@mui/icons-material/SettingsOutlined";
5
3
  import { settingsOptionsProps } from "../../types/table";
6
- import { tableTabsStyles } from "./styles";
7
4
  import { useMemo } from "react";
8
- import { SettingIcon } from "../../../assets/svg";
5
+ import { TableTab, TableTabCount, TableTabsRoot } from "./tabs.styles";
6
+ import { SettingsOutlined } from "@mui/icons-material";
9
7
 
10
8
  interface TabDataProps {
11
- tab_name: string | null;
12
- count: string | number;
9
+ tab_value: string | null;
10
+ tab_value_count?: string | number;
13
11
  }
14
12
 
15
13
  interface TableTabsProps {
16
14
  loading?: boolean;
17
15
  tabsData?: TabDataProps[];
18
- activeTab?: any;
16
+ activeTab?: string;
19
17
  tableStates: CraftTableOptionsProps;
20
18
  onClick: (state: string) => void;
21
- columns?: any[];
22
19
  settingsOptions?: settingsOptionsProps;
23
20
  }
24
21
 
@@ -34,23 +31,25 @@ export function TableTabs({
34
31
 
35
32
  const handleTabClick = (tab: string) => {
36
33
  onClick(tab);
37
- tableStates.setPagination((prev) => ({ ...prev, pageIndex: 0 }));
34
+ tableStates.setPagination((prev) => ({
35
+ ...prev,
36
+ pageIndex: 0,
37
+ }));
38
38
  };
39
39
 
40
- // Normalize tab_name to uppercase for display + logic
41
40
  const normalizedTabs = useMemo(() => {
42
41
  return tabsData
43
- ?.filter((tab) => tab.tab_name !== null)
42
+ ?.filter((tab) => tab.tab_value !== null)
44
43
  ?.map((tab) => ({
45
44
  ...tab,
46
- tab_name: tab.tab_name,
45
+ tab_value: tab.tab_value,
47
46
  }));
48
47
  }, [tabsData]);
49
48
 
50
49
  const defaultTab = useMemo(() => {
51
50
  return (
52
- normalizedTabs.find((t) => t.tab_name === "All")?.tab_name ||
53
- normalizedTabs[0]?.tab_name ||
51
+ normalizedTabs.find((t) => t.tab_value === "All")?.tab_value ||
52
+ normalizedTabs[0]?.tab_value ||
54
53
  ""
55
54
  );
56
55
  }, [normalizedTabs]);
@@ -59,60 +58,43 @@ export function TableTabs({
59
58
 
60
59
  return (
61
60
  <Box display="flex" alignItems="center" justifyContent="flex-start">
62
- {/* Layout settings icon */}
61
+ {/* Settings icon */}
63
62
  {settingsOptions?.showIcon && (
64
- <IconButton
65
- onClick={settingsOptions?.onClick}
66
- sx={{ zIndex: 1000, mx: 0 }}
67
- >
68
- <SettingIcon />
63
+ <IconButton size="small" onClick={settingsOptions?.onClick}>
64
+ <SettingsOutlined fontSize="small" />
69
65
  </IconButton>
70
66
  )}
71
67
 
72
68
  {/* Tabs */}
73
- <Tabs
69
+ <TableTabsRoot
74
70
  value={selectedTab}
75
- onChange={(_, newValue) => {
76
- handleTabClick(newValue);
77
- }}
71
+ onChange={(_, newValue) => handleTabClick(newValue)}
78
72
  variant="scrollable"
79
73
  scrollButtons="auto"
80
- slotProps={{ indicator: { sx: { display: "none" } } }}
81
- sx={tableTabsStyles.tabs}
82
74
  >
83
75
  {normalizedTabs.map((tab) => {
84
- const isSelected = activeTab?.tab_name === tab?.tab_name;
76
+ const isSelected = activeTab === tab?.tab_value;
85
77
 
86
78
  return (
87
- <Tab
88
- key={tab?.tab_name}
89
- value={tab}
79
+ <TableTab
80
+ key={tab?.tab_value}
81
+ value={tab?.tab_value}
90
82
  label={
91
83
  <Box display="flex" alignItems="center" gap={1}>
92
- <Box>{tab?.tab_name}</Box>
93
- <Box
94
- sx={{
95
- ...tableTabsStyles.tabCount,
96
- ...(isSelected && {
97
- // backgroundColor: "#ced3da",
98
- // borderColor: "#ced3da",
99
- backgroundColor: "#000",
100
- color: "#fff",
101
- fontWeight: "500",
102
- }),
103
- }}
104
- >
105
- {tab?.count == 0
106
- ? "0"
107
- : String(tab?.count).padStart(2, "0")}
84
+ <Box sx={{ color: isSelected ? "#000" : "" }}>
85
+ {tab?.tab_value}
108
86
  </Box>
87
+ <TableTabCount selected={isSelected}>
88
+ {tab?.tab_value_count == 0
89
+ ? "0"
90
+ : String(tab?.tab_value_count).padStart(2, "0")}
91
+ </TableTabCount>
109
92
  </Box>
110
93
  }
111
- sx={tableTabsStyles.tab}
112
94
  />
113
95
  );
114
96
  })}
115
- </Tabs>
97
+ </TableTabsRoot>
116
98
  </Box>
117
99
  );
118
100
  }
@@ -0,0 +1,49 @@
1
+ // tableTabs.styles.ts
2
+ import { styled } from "@mui/material/styles";
3
+ import Tabs, { tabsClasses } from "@mui/material/Tabs";
4
+ import Tab, { tabClasses } from "@mui/material/Tab";
5
+ import Box from "@mui/material/Box";
6
+
7
+ export const TableTabsRoot = styled(Tabs)(({ theme }) => ({
8
+ minHeight: theme.spacing(3.5),
9
+
10
+ [`& .${tabsClasses.flexContainer}`]: {
11
+ minHeight: theme.spacing(3.5),
12
+ },
13
+
14
+ // hide indicator (instead of slotProps every time)
15
+ [`& .${tabsClasses.indicator}`]: {
16
+ display: "none",
17
+ },
18
+ }));
19
+
20
+ export const TableTab = styled(Tab)(({ theme }) => ({
21
+ color: theme.palette.grey[600],
22
+ padding: theme.spacing(1, 1.5),
23
+ minHeight: theme.spacing(3.5),
24
+ maxHeight: theme.spacing(3.5),
25
+ textTransform: "none",
26
+ minWidth: "unset",
27
+ whiteSpace: "nowrap",
28
+
29
+ [`&.${tabClasses.selected}`]: {
30
+ color: theme.palette.text.primary,
31
+ fontWeight: 700,
32
+ },
33
+ }));
34
+
35
+ export const TableTabCount = styled(Box, {
36
+ shouldForwardProp: (prop) => prop !== "selected",
37
+ })<{ selected?: boolean }>(({ theme, selected }) => ({
38
+ padding: theme.spacing(0.25),
39
+ borderRadius: theme.shape.borderRadius,
40
+ border: `1px solid ${
41
+ selected ? theme.palette.text.primary : theme.palette.grey[700]
42
+ }`,
43
+ color: selected ? theme.palette.common.white : theme.palette.text.primary,
44
+ backgroundColor: selected ? theme.palette.text.primary : "transparent",
45
+ fontWeight: selected ? 500 : 400,
46
+ lineHeight: 1,
47
+ minWidth: 20,
48
+ textAlign: "center",
49
+ }));
@@ -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 {