@nethru/ui 1.0.31 → 1.0.33

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