@nethru/ui 1.0.30 → 1.0.32

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.
@@ -0,0 +1,68 @@
1
+ import { useMemo, useState } from "react";
2
+ import { DataGrid } from "@mui/x-data-grid";
3
+ import { jsx as _jsx } from "react/jsx-runtime";
4
+ export default function PropertyTable({
5
+ columns,
6
+ rows,
7
+ onUpdate,
8
+ sx,
9
+ ...props
10
+ }) {
11
+ const [updatedRows, setUpdatedRows] = useState(rows);
12
+ const columnsWithClassName = useMemo(() => {
13
+ return columns.map(column => {
14
+ const newColumn = {
15
+ ...column
16
+ };
17
+ if (column.fixed) {
18
+ newColumn.cellClassName = params => {
19
+ return !params.row.deletable ? 'fixed' : '';
20
+ };
21
+ } else if (column.dimmed) newColumn.cellClassName = 'dimmed';
22
+ return newColumn;
23
+ });
24
+ }, [columns]);
25
+ const processRowUpdate = row => {
26
+ const newRows = updatedRows.filter(r => r.id !== row.id);
27
+ newRows.push(row);
28
+ setUpdatedRows(newRows);
29
+ if (onUpdate) onUpdate(row, newRows);
30
+ return row;
31
+ };
32
+ return /*#__PURE__*/_jsx(DataGrid, {
33
+ columns: columnsWithClassName,
34
+ rows: rows,
35
+ columnHeaderHeight: 35,
36
+ rowHeight: 30,
37
+ isCellEditable: params => {
38
+ return params.row.deletable || !params.colDef.fixed;
39
+ },
40
+ processRowUpdate: processRowUpdate,
41
+ onProcessRowUpdateError: error => console.log(error),
42
+ disableColumnMenu: true,
43
+ hideFooter: true,
44
+ sx: {
45
+ ...styles,
46
+ ...sx
47
+ },
48
+ ...props
49
+ });
50
+ }
51
+ const styles = {
52
+ '.MuiDataGrid-columnHeaders': {
53
+ backgroundColor: '#f8f9fa'
54
+ },
55
+ '.MuiDataGrid-columnSeparator': {
56
+ visibility: 'hidden !important'
57
+ },
58
+ '.MuiDataGrid-cell.fixed': {
59
+ fontWeight: 'bold'
60
+ },
61
+ '.MuiDataGrid-cell.dimmed': {
62
+ color: '#666'
63
+ },
64
+ '& .Mui-error': {
65
+ backgroundColor: 'rgb(126,10,15, 0.1)',
66
+ color: '#750f0f'
67
+ }
68
+ };
package/dist/index.js CHANGED
@@ -20,6 +20,7 @@ export { default as ListItemDivider } from "./ListItemDivider";
20
20
  export { default as ListItemGrid } from "./ListItemGrid";
21
21
  export { default as ListItemText } from "./ListItemText";
22
22
  export { default as MainHeader } from "./MainHeader";
23
+ export { default as PropertyTable } from "./PropertyTable";
23
24
  export { default as ReferenceChipList } from "./ReferenceChipList";
24
25
  export { default as SearchTextField } from "./SearchTextField";
25
26
  export { default as Section } from "./Section";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nethru/ui",
3
- "version": "1.0.30",
3
+ "version": "1.0.32",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "/dist"