@visns-studio/visns-components 6.25.0 → 6.27.0

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/README.md CHANGED
@@ -9,6 +9,51 @@ A comprehensive React component library used by the VISNS Studio team for CRM an
9
9
 
10
10
  VISNS Components is a React-based UI component library that provides a set of reusable, consistent, and customizable components for building web applications. It includes components for authentication, data grids, forms, navigation, and more, designed to work seamlessly together.
11
11
 
12
+ ## Recent Updates (v6.27.0)
13
+
14
+ ### A tint on one column: `cellColours`
15
+
16
+ A DataGrid could already tint a whole ROW from its data —
17
+ `ajaxSetting.rowColours`, first match wins:
18
+
19
+ ```js
20
+ ajaxSetting: {
21
+ rowColours: [{ id: 'priority', value: 'high', colour: '#FFCDD2' }],
22
+ }
23
+ ```
24
+
25
+ Which is the right instrument for "this record needs attention" and the wrong
26
+ one for "these are Sam's". A grid where every row is coloured has no signal
27
+ left in colour at all — the eye stops reading it after the second full-width
28
+ band. `cellColours` is the same rule shape declared on a COLUMN, painted onto
29
+ that one cell:
30
+
31
+ ```js
32
+ {
33
+ id: ['owner'],
34
+ label: 'Owner',
35
+ type: 'relation',
36
+ nameFrom: 'name',
37
+ cellColours: [
38
+ { id: 'owner_id', value: 19, colour: '#E1BEE7' },
39
+ { id: 'owner_id', value: 30, colour: '#BBDEFB' },
40
+ ],
41
+ }
42
+ ```
43
+
44
+ - **`id` names a field on the ROW, not on the column.** The value worth
45
+ matching is usually the id sitting behind the label the column renders
46
+ (`owner_id` under an Owner relation column), and the cell never shows it.
47
+ - **Loose equality**, as `rowStyles` uses — a JSON config writes `19` and an
48
+ API hands back `"19"`, and a config author should not have to know which.
49
+ - **First match wins**, as `rowColours` does. A cell has one background.
50
+ - **Every column type**, because the rule is applied by the shared column
51
+ `style`, not by any one renderer — relation, text, date, currency alike.
52
+ - **It composes with `rowColours`.** The row tint is a background on the row
53
+ element and the cell's own paints on top of it, so a tinted cell reads as
54
+ itself on a tinted row, and keeps its colour under the hover surface (which
55
+ is also below the cell).
56
+
12
57
  ## Recent Updates (v6.17.0)
13
58
 
14
59
  ### A client's text messages, on the client's own page
package/package.json CHANGED
@@ -93,7 +93,7 @@
93
93
  "react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0"
94
94
  },
95
95
  "name": "@visns-studio/visns-components",
96
- "version": "6.25.0",
96
+ "version": "6.27.0",
97
97
  "description": "Various packages to assist in the development of our Custom Applications.",
98
98
  "main": "src/index.js",
99
99
  "files": [
@@ -128,6 +128,31 @@ const ROW_STYLE_CLASSES = {
128
128
  complete: styles.rowComplete,
129
129
  };
130
130
 
131
+ /**
132
+ * First matching per-column `cellColours` rule for a row.
133
+ *
134
+ * cellColours: [
135
+ * { id: 'owner_id', value: 19, colour: '#E1BEE7' }
136
+ * ]
137
+ *
138
+ * The column-level twin of `ajaxSetting.rowColours`: the same rule shape,
139
+ * painted onto ONE cell instead of the whole row. A grid where every row is
140
+ * tinted is a grid with no signal left, so a view that only needs to tell its
141
+ * owners apart tints the Owner column and leaves the rest of the row alone.
142
+ *
143
+ * `id` names a field on the ROW, not on the column, because the value worth
144
+ * matching is usually the id sitting behind the label the column renders
145
+ * (`owner_id` under an Owner relation column) and the cell never shows it.
146
+ *
147
+ * Loose equality, as `rowStyles` uses: a JSON config writes 19 and an API
148
+ * hands back "19", and a config author should not have to know which. First
149
+ * match wins, as `rowColours` does — a cell has exactly one background.
150
+ */
151
+ const findCellColour = (column, data) =>
152
+ Array.isArray(column?.cellColours) && data
153
+ ? column.cellColours.find((rule) => data[rule.id] == rule.value)
154
+ : undefined;
155
+
131
156
  import '@visns-studio/visns-datagrid-enterprise/index.css';
132
157
 
133
158
  import CustomFetch from './Fetch';
@@ -4438,6 +4463,26 @@ const DataGrid = forwardRef(
4438
4463
  columnsMetadata
4439
4464
  );
4440
4465
 
4466
+ // A `cellColours` tint is an inline background on the
4467
+ // cell, and global-datagrid.css paints every cell
4468
+ // `background: transparent !important` (it has to
4469
+ // outrank the vendored theme) — inline loses to
4470
+ // `!important`, so the tint would never be seen. The
4471
+ // literal class marks the cells that carry one and
4472
+ // that rule stands down for them, exactly as
4473
+ // `vs-datagrid--row-tinted` does a level up. The
4474
+ // hover and selected surfaces live on the ROW, so the
4475
+ // tint keeps painting over them and survives a hover.
4476
+ const cellColourClassName = (cellProps, extra = '') =>
4477
+ [
4478
+ findCellColour(column, cellProps?.data)
4479
+ ? 'vs-datagrid--cell-tinted'
4480
+ : '',
4481
+ extra,
4482
+ ]
4483
+ .filter(Boolean)
4484
+ .join(' ');
4485
+
4441
4486
  const commonProps = {
4442
4487
  header: column.label,
4443
4488
  defaultFlex: 1,
@@ -4481,7 +4526,7 @@ const DataGrid = forwardRef(
4481
4526
  ? style.text_vertical_align
4482
4527
  : 'center',
4483
4528
  style: (cellProps) => {
4484
- const { id, value } = cellProps;
4529
+ const { id, value, data } = cellProps;
4485
4530
  let columnStyle = {};
4486
4531
 
4487
4532
  if (
@@ -4501,8 +4546,24 @@ const DataGrid = forwardRef(
4501
4546
  };
4502
4547
  }
4503
4548
 
4549
+ // `cellColours` last, so a column's static
4550
+ // `style` cannot quietly outrank the rule the
4551
+ // view asked for. It paints over any
4552
+ // `rowColours` tint for this one cell without
4553
+ // touching it: the row tint is a background on
4554
+ // the ROW element and this one sits on the cell
4555
+ // above it.
4556
+ const cellColour = findCellColour(column, data);
4557
+
4558
+ if (cellColour) {
4559
+ columnStyle.backgroundColor =
4560
+ cellColour.colour;
4561
+ }
4562
+
4504
4563
  return columnStyle;
4505
4564
  },
4565
+ className: (cellProps) =>
4566
+ cellColourClassName(cellProps),
4506
4567
  type: column.type,
4507
4568
  };
4508
4569
 
@@ -4966,9 +5027,13 @@ const DataGrid = forwardRef(
4966
5027
  name: columnId,
4967
5028
  filterEditor: filterEditor,
4968
5029
  filterEditorProps: filterEditorProps,
4969
- className: finalWordWrap
4970
- ? 'cell-word-wrap'
4971
- : '',
5030
+ className: (cellProps) =>
5031
+ cellColourClassName(
5032
+ cellProps,
5033
+ finalWordWrap
5034
+ ? 'cell-word-wrap'
5035
+ : ''
5036
+ ),
4972
5037
  render: ({ data }) => {
4973
5038
  if (
4974
5039
  data &&