@nethru/ui 1.0.32 → 1.0.34

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/dist/Editor.js CHANGED
@@ -7,7 +7,7 @@ import { useMemo, useState } from "react";
7
7
  import { jsx as _jsx } from "react/jsx-runtime";
8
8
  import { jsxs as _jsxs } from "react/jsx-runtime";
9
9
  export default function Editor({
10
- editable = true,
10
+ readOnly = false,
11
11
  error = false,
12
12
  helperText,
13
13
  basicSetup,
@@ -20,23 +20,23 @@ export default function Editor({
20
20
  const [focused, setFocused] = useState(false);
21
21
  const styles = useMemo(() => {
22
22
  return {
23
- borderBottom: focused ? `3px solid ${error ? '#d32f2f' : '#1976d2'}` : `${editable ? '2px' : '0px'} solid rgba(0, 0, 0, 0.42)`
23
+ borderBottom: focused ? `3px solid ${error ? '#d32f2f' : '#1976d2'}` : `${!readOnly ? '2px' : '0px'} solid rgba(0, 0, 0, 0.42)`
24
24
  };
25
- }, [editable, error, focused]);
25
+ }, [readOnly, error, focused]);
26
26
  const handleUpdate = viewUpdate => {
27
27
  setFocused(viewUpdate.view.hasFocus);
28
28
  if (onUpdate) onUpdate(viewUpdate);
29
29
  };
30
30
  return /*#__PURE__*/_jsxs(Box, {
31
31
  children: [/*#__PURE__*/_jsx(CodeMirror, {
32
- editable: editable,
32
+ editable: !readOnly,
33
33
  extensions: [jsonFormat ? json() : javascript({
34
34
  jsx: true
35
35
  }), EditorView.lineWrapping, ...extensions],
36
36
  basicSetup: {
37
37
  ...basicSetup,
38
38
  highlightActiveLineGutter: false,
39
- highlightActiveLine: editable
39
+ highlightActiveLine: !readOnly
40
40
  },
41
41
  onUpdate: handleUpdate,
42
42
  style: {
@@ -5,15 +5,48 @@ export default function PropertyTable({
5
5
  columns,
6
6
  rows,
7
7
  onUpdate,
8
+ readOnly,
8
9
  sx,
9
10
  ...props
10
11
  }) {
11
- const [updatedRows, setUpdatedRows] = useState(rows);
12
- const columnsWithClassName = useMemo(() => {
12
+ const styles = useMemo(() => {
13
+ const result = {
14
+ '&.MuiDataGrid-root': {
15
+ borderBottom: 'none'
16
+ },
17
+ '.MuiDataGrid-columnHeaders': {
18
+ backgroundColor: '#f8f9fa'
19
+ },
20
+ '.MuiDataGrid-columnSeparator': {
21
+ visibility: 'hidden !important'
22
+ },
23
+ '&.MuiDataGrid-root .MuiDataGrid-columnHeader:focus': {
24
+ outline: 'none !important'
25
+ },
26
+ '.MuiDataGrid-cell.fixed': {
27
+ fontWeight: 'bold'
28
+ },
29
+ '.MuiDataGrid-cell.dimmed': {
30
+ color: '#666'
31
+ },
32
+ '& .Mui-error': {
33
+ backgroundColor: 'rgb(126,10,15, 0.1)',
34
+ color: '#750f0f'
35
+ }
36
+ };
37
+ if (readOnly) {
38
+ result['&.MuiDataGrid-root .MuiDataGrid-cell:focus'] = {
39
+ outline: 'none !important'
40
+ };
41
+ }
42
+ return result;
43
+ }, [readOnly]);
44
+ const arrangedColumns = useMemo(() => {
13
45
  return columns.map(column => {
14
46
  const newColumn = {
15
47
  ...column
16
48
  };
49
+ if (readOnly) newColumn.editable = false;
17
50
  if (column.fixed) {
18
51
  newColumn.cellClassName = params => {
19
52
  return !params.row.deletable ? 'fixed' : '';
@@ -21,7 +54,8 @@ export default function PropertyTable({
21
54
  } else if (column.dimmed) newColumn.cellClassName = 'dimmed';
22
55
  return newColumn;
23
56
  });
24
- }, [columns]);
57
+ }, [columns, readOnly]);
58
+ const [updatedRows, setUpdatedRows] = useState(rows);
25
59
  const processRowUpdate = row => {
26
60
  const newRows = updatedRows.filter(r => r.id !== row.id);
27
61
  newRows.push(row);
@@ -30,7 +64,7 @@ export default function PropertyTable({
30
64
  return row;
31
65
  };
32
66
  return /*#__PURE__*/_jsx(DataGrid, {
33
- columns: columnsWithClassName,
67
+ columns: arrangedColumns,
34
68
  rows: rows,
35
69
  columnHeaderHeight: 35,
36
70
  rowHeight: 30,
@@ -40,6 +74,7 @@ export default function PropertyTable({
40
74
  processRowUpdate: processRowUpdate,
41
75
  onProcessRowUpdateError: error => console.log(error),
42
76
  disableColumnMenu: true,
77
+ disableRowSelectionOnClick: readOnly,
43
78
  hideFooter: true,
44
79
  sx: {
45
80
  ...styles,
@@ -47,22 +82,4 @@ export default function PropertyTable({
47
82
  },
48
83
  ...props
49
84
  });
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
- };
85
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nethru/ui",
3
- "version": "1.0.32",
3
+ "version": "1.0.34",
4
4
  "main": "dist/index.js",
5
5
  "files": [
6
6
  "/dist"