@neo4j-ndl/react 4.14.1 → 4.14.3
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/lib/cjs/_common/component-docs-page.js +72 -0
- package/lib/cjs/_common/component-docs-page.js.map +1 -0
- package/lib/cjs/data-grid/Components.js +3 -1
- package/lib/cjs/data-grid/Components.js.map +1 -1
- package/lib/cjs/data-grid/DataGrid.js +2 -1
- package/lib/cjs/data-grid/DataGrid.js.map +1 -1
- package/lib/cjs/data-grid/data-grid-context.js.map +1 -1
- package/lib/cjs/data-grid/index.js +14 -1
- package/lib/cjs/data-grid/index.js.map +1 -1
- package/lib/cjs/data-grid/stories/datagrid-custom-cell-with-style-rules.story.js +142 -0
- package/lib/cjs/data-grid/stories/datagrid-custom-cell-with-style-rules.story.js.map +1 -0
- package/lib/cjs/data-grid/stories/datagrid-rule-based-styling.story.js +133 -0
- package/lib/cjs/data-grid/stories/datagrid-rule-based-styling.story.js.map +1 -0
- package/lib/cjs/data-grid/stories/index.js +9 -1
- package/lib/cjs/data-grid/stories/index.js.map +1 -1
- package/lib/cjs/data-grid/style-rules/evaluate.js +283 -0
- package/lib/cjs/data-grid/style-rules/evaluate.js.map +1 -0
- package/lib/cjs/data-grid/style-rules/hooks.js +45 -0
- package/lib/cjs/data-grid/style-rules/hooks.js.map +1 -0
- package/lib/cjs/data-grid/style-rules/index.js +37 -0
- package/lib/cjs/data-grid/style-rules/index.js.map +1 -0
- package/lib/cjs/data-grid/style-rules/types.js +158 -0
- package/lib/cjs/data-grid/style-rules/types.js.map +1 -0
- package/lib/cjs/graph-label/GraphLabel.js +9 -8
- package/lib/cjs/graph-label/GraphLabel.js.map +1 -1
- package/lib/cjs/index.js +3 -8
- package/lib/cjs/index.js.map +1 -1
- package/lib/esm/_common/component-docs-page.js +69 -0
- package/lib/esm/_common/component-docs-page.js.map +1 -0
- package/lib/esm/data-grid/Components.js +3 -1
- package/lib/esm/data-grid/Components.js.map +1 -1
- package/lib/esm/data-grid/DataGrid.js +2 -1
- package/lib/esm/data-grid/DataGrid.js.map +1 -1
- package/lib/esm/data-grid/data-grid-context.js.map +1 -1
- package/lib/esm/data-grid/index.js +3 -0
- package/lib/esm/data-grid/index.js.map +1 -1
- package/lib/esm/data-grid/stories/datagrid-custom-cell-with-style-rules.story.js +140 -0
- package/lib/esm/data-grid/stories/datagrid-custom-cell-with-style-rules.story.js.map +1 -0
- package/lib/esm/data-grid/stories/datagrid-rule-based-styling.story.js +131 -0
- package/lib/esm/data-grid/stories/datagrid-rule-based-styling.story.js.map +1 -0
- package/lib/esm/data-grid/stories/index.js +6 -0
- package/lib/esm/data-grid/stories/index.js.map +1 -1
- package/lib/esm/data-grid/style-rules/evaluate.js +279 -0
- package/lib/esm/data-grid/style-rules/evaluate.js.map +1 -0
- package/lib/esm/data-grid/style-rules/hooks.js +42 -0
- package/lib/esm/data-grid/style-rules/hooks.js.map +1 -0
- package/lib/esm/data-grid/style-rules/index.js +24 -0
- package/lib/esm/data-grid/style-rules/index.js.map +1 -0
- package/lib/esm/data-grid/style-rules/types.js +155 -0
- package/lib/esm/data-grid/style-rules/types.js.map +1 -0
- package/lib/esm/graph-label/GraphLabel.js +9 -8
- package/lib/esm/graph-label/GraphLabel.js.map +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/types/_common/{readme-docs-page.d.ts → component-docs-page.d.ts} +2 -2
- package/lib/types/_common/component-docs-page.d.ts.map +1 -0
- package/lib/types/data-grid/Components.d.ts.map +1 -1
- package/lib/types/data-grid/DataGrid.d.ts +4 -1
- package/lib/types/data-grid/DataGrid.d.ts.map +1 -1
- package/lib/types/data-grid/data-grid-context.d.ts +2 -0
- package/lib/types/data-grid/data-grid-context.d.ts.map +1 -1
- package/lib/types/data-grid/index.d.ts +4 -0
- package/lib/types/data-grid/index.d.ts.map +1 -1
- package/lib/types/data-grid/stories/datagrid-custom-cell-with-style-rules.story.d.ts +24 -0
- package/lib/types/data-grid/stories/datagrid-custom-cell-with-style-rules.story.d.ts.map +1 -0
- package/lib/types/data-grid/stories/datagrid-pinned-columns.stories.d.ts +2 -2
- package/lib/types/data-grid/stories/datagrid-rule-based-styling.story.d.ts +24 -0
- package/lib/types/data-grid/stories/datagrid-rule-based-styling.story.d.ts.map +1 -0
- package/lib/types/data-grid/stories/datagrid-search-and-filters.stories.d.ts +2 -2
- package/lib/types/data-grid/stories/index.d.ts +4 -0
- package/lib/types/data-grid/stories/index.d.ts.map +1 -1
- package/lib/types/data-grid/style-rules/evaluate.d.ts +41 -0
- package/lib/types/data-grid/style-rules/evaluate.d.ts.map +1 -0
- package/lib/types/data-grid/style-rules/hooks.d.ts +27 -0
- package/lib/types/data-grid/style-rules/hooks.d.ts.map +1 -0
- package/lib/types/data-grid/style-rules/index.d.ts +25 -0
- package/lib/types/data-grid/style-rules/index.d.ts.map +1 -0
- package/lib/types/data-grid/style-rules/types.d.ts +161 -0
- package/lib/types/data-grid/style-rules/types.d.ts.map +1 -0
- package/lib/types/graph-label/GraphLabel.d.ts.map +1 -1
- package/lib/types/index.d.ts +1 -1
- package/lib/types/index.d.ts.map +1 -1
- package/package.json +4 -3
- package/lib/cjs/_common/readme-docs-page.js +0 -55
- package/lib/cjs/_common/readme-docs-page.js.map +0 -1
- package/lib/esm/_common/readme-docs-page.js +0 -52
- package/lib/esm/_common/readme-docs-page.js.map +0 -1
- package/lib/types/_common/readme-docs-page.d.ts.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datagrid-custom-cell-with-style-rules.story.js","sourceRoot":"","sources":["../../../../src/data-grid/stories/datagrid-custom-cell-with-style-rules.story.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,yCAAyC,CAAC;AAEjD,OAAO,EACL,QAAQ,EAER,oBAAoB,GACrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAEL,kBAAkB,EAClB,UAAU,EACV,eAA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ClC,MAAM,EAAE,GAAG,EAAE,CAAC,KAAK;YACnB,OAAO,EAAE,EAAE;SACZ,CAAC;QACF,YAAY,CAAC,QAAQ,CAAC,eAAe,EAAE;YACrC,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,QAAQ,EAAE;YAC/B,MAAM,EAAE,GAAG,EAAE,CAAC,gBAAgB;YAC9B,OAAO,EAAE,GAAG;YACZ,IAAI,EAAE,GAAG;SACV,CAAC;KACH,CAAC;IAEF,MAAM,KAAK,GAAG,aAAa,CAAC;QAC1B,gBAAgB,EAAE,UAAU;QAC5B,OAAO;QACP,IAAI,EAAE,eAAe;QACrB,aAAa,EAAE;YACb,OAAO,EAAE,GAAG;YACZ,OAAO,EAAE,EAAE;SACZ;QACD,aAAa,EAAE,IAAI;QACnB,eAAe,EAAE,eAAe,EAAE;QAClC,qBAAqB,EAAE,qBAAqB,EAAE;QAC9C,iBAAiB,EAAE,iBAAiB,EAAE;QACtC,YAAY,EAAE;YACZ,UAAU,EAAE;gBACV,QAAQ,EAAE,EAAE;aACb;SACF;KACF,CAAC,CAAC;IAEH,OAAO,CACL,cAAK,SAAS,EAAC,0CAA0C,YACvD,KAAC,QAAQ,IACP,WAAW,EAAE,KAAK,EAClB,aAAa,EAAE,KAAK,EACpB,mBAAmB,EAAE,KAAK,EAC1B,UAAU,EAAE,UAAU,EACtB,UAAU,EAAE;gBACV,QAAQ,EAAE,cAAc;aACzB,EACD,OAAO,EAAE;gBACP,WAAW,EAAE,WAAW;gBACxB,eAAe,EAAE,IAAI;gBACrB,gBAAgB,EAAE,KAAK;aACxB,GACD,GACE,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,SAAS,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport '@neo4j-ndl/base/lib/neo4j-ds-styles.css';\n\nimport {\n DataGrid,\n type DataGridStyleRule,\n useDataGridCellStyle,\n} from '@neo4j-ndl/react';\nimport {\n type Cell,\n createColumnHelper,\n flexRender,\n getCoreRowModel,\n getPaginationRowModel,\n getSortedRowModel,\n type RowData,\n useReactTable,\n} from '@tanstack/react-table';\n\nimport { TABLE_DEMO_DATA, type TestDataFormat } from './staticData';\n\nconst styleRules: DataGridStyleRule[] = [\n // Row coloring: all cells styled when name contains \"Alicia\"\n {\n apply: {\n color: { value: '#000000' },\n textColor: { value: '#ffffff' },\n },\n column: null,\n priority: 3,\n where: { contains: [{ column: 'name' }, 'Alicia'] },\n },\n // Cell coloring: cells in the \"age\" column with value 51 get green\n {\n apply: { color: { value: '#00bb00' } },\n column: 'age',\n priority: 3,\n where: { equal: [{ column: 'age' }, 51] },\n },\n // Dual color ranges on the \"age\" column: independent gradients for background\n // (driven by age, full 0-100 range) and text color (driven by age too, but\n // with a narrower 20-80 band so the text contrast is calibrated separately).\n {\n apply: {\n colorRange: {\n maxColor: '#f00000',\n maxValue: 100,\n midColor: '#a00000',\n midValue: 50,\n minColor: '#800000',\n minValue: 0,\n onColumn: 'age',\n },\n textColorRange: {\n maxColor: '#aaaaaa',\n maxValue: 80,\n minColor: '#ffffff',\n minValue: 20,\n onColumn: 'age',\n },\n },\n column: 'age',\n priority: 2, // Lower priority so explicit green rule overrides\n },\n // Multi-column rule: all cells styled when age > 50 AND name contains \"o\"\n {\n apply: {\n color: { value: '#fef3c7' },\n textColor: { value: '#000000' },\n },\n column: null,\n priority: 0, // Lower priority so other rules take precedence\n where: {\n and: [\n { greaterThan: [{ column: 'age' }, 50] },\n { contains: [{ column: 'name' }, 'o'] },\n ],\n },\n },\n];\n\n/**\n * A custom BodyCell that uses the `useDataGridCellStyle` hook to manually apply style rules to the cell.\n */\nconst CustomBodyCell = <T extends RowData>({\n cell,\n}: {\n cell: Cell<T, unknown>;\n}) => {\n const ruleStyle = useDataGridCellStyle(cell);\n\n return (\n <div\n className=\"ndl-data-grid-td\"\n role=\"cell\"\n style={{\n ...ruleStyle,\n width: cell.column.getSize(),\n }}\n >\n {flexRender(cell.column.columnDef.cell, cell.getContext())}\n </div>\n );\n};\n\nconst Component = () => {\n const columnHelper = createColumnHelper<TestDataFormat>();\n\n const columns = [\n columnHelper.accessor('name', {\n cell: (info) => info.getValue(),\n header: () => 'Name',\n minSize: 180,\n size: 220,\n }),\n columnHelper.accessor('age', {\n cell: (info) => info.renderValue(),\n header: () => 'Age',\n minSize: 80,\n }),\n columnHelper.accessor('cypherCommand', {\n cell: (info) => info.getValue(),\n header: () => 'Cypher Command',\n minSize: 400,\n size: 400,\n }),\n ];\n\n const table = useReactTable({\n columnResizeMode: 'onChange',\n columns,\n data: TABLE_DEMO_DATA,\n defaultColumn: {\n maxSize: 800,\n minSize: 80,\n },\n enableSorting: true,\n getCoreRowModel: getCoreRowModel(),\n getPaginationRowModel: getPaginationRowModel(),\n getSortedRowModel: getSortedRowModel(),\n initialState: {\n pagination: {\n pageSize: 10,\n },\n },\n });\n\n return (\n <div className=\"n-w-full n-bg-light-neutral-text-weakest\">\n <DataGrid\n isResizable={false}\n tableInstance={table}\n isKeyboardNavigable={false}\n styleRules={styleRules}\n components={{\n BodyCell: CustomBodyCell,\n }}\n styling={{\n borderStyle: 'all-sides',\n hasHoverEffects: true,\n hasZebraStriping: false,\n }}\n />\n </div>\n );\n};\n\nexport default Component;\n"]}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) "Neo4j"
|
|
5
|
+
* Neo4j Sweden AB [http://neo4j.com]
|
|
6
|
+
*
|
|
7
|
+
* This file is part of Neo4j.
|
|
8
|
+
*
|
|
9
|
+
* Neo4j is free software: you can redistribute it and/or modify
|
|
10
|
+
* it under the terms of the GNU General Public License as published by
|
|
11
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
12
|
+
* (at your option) any later version.
|
|
13
|
+
*
|
|
14
|
+
* This program is distributed in the hope that it will be useful,
|
|
15
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17
|
+
* GNU General Public License for more details.
|
|
18
|
+
*
|
|
19
|
+
* You should have received a copy of the GNU General Public License
|
|
20
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
21
|
+
*/
|
|
22
|
+
import '@neo4j-ndl/base/lib/neo4j-ds-styles.css';
|
|
23
|
+
import { DataGrid } from '@neo4j-ndl/react';
|
|
24
|
+
import { createColumnHelper, getCoreRowModel, getPaginationRowModel, getSortedRowModel, useReactTable, } from '@tanstack/react-table';
|
|
25
|
+
import { TABLE_DEMO_DATA } from './staticData';
|
|
26
|
+
const styleRules = [
|
|
27
|
+
// Row coloring: all cells styled when name contains "Alicia"
|
|
28
|
+
{
|
|
29
|
+
apply: {
|
|
30
|
+
color: { value: '#000000' },
|
|
31
|
+
textColor: { value: '#ffffff' },
|
|
32
|
+
},
|
|
33
|
+
column: null,
|
|
34
|
+
priority: 3,
|
|
35
|
+
where: { contains: [{ column: 'name' }, 'Alicia'] },
|
|
36
|
+
},
|
|
37
|
+
// Cell coloring: cells in the "age" column with value 51 get green
|
|
38
|
+
{
|
|
39
|
+
apply: { color: { value: '#00bb00' } },
|
|
40
|
+
column: 'age',
|
|
41
|
+
priority: 3,
|
|
42
|
+
where: { equal: [{ column: 'age' }, 51] },
|
|
43
|
+
},
|
|
44
|
+
// Dual color ranges on the "age" column: independent gradients for background
|
|
45
|
+
// (driven by age, full 0-100 range) and text color (driven by age too, but
|
|
46
|
+
// with a narrower 20-80 band so the text contrast is calibrated separately).
|
|
47
|
+
{
|
|
48
|
+
apply: {
|
|
49
|
+
colorRange: {
|
|
50
|
+
maxColor: '#f00000',
|
|
51
|
+
maxValue: 100,
|
|
52
|
+
midColor: '#a00000',
|
|
53
|
+
midValue: 50,
|
|
54
|
+
minColor: '#800000',
|
|
55
|
+
minValue: 0,
|
|
56
|
+
onColumn: 'age',
|
|
57
|
+
},
|
|
58
|
+
textColorRange: {
|
|
59
|
+
maxColor: '#aaaaaa',
|
|
60
|
+
maxValue: 80,
|
|
61
|
+
minColor: '#ffffff',
|
|
62
|
+
minValue: 20,
|
|
63
|
+
onColumn: 'age',
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
column: 'age',
|
|
67
|
+
priority: 2, // Lower priority so explicit green rule overrides
|
|
68
|
+
},
|
|
69
|
+
// Multi-column rule: all cells styled when age > 50 AND name contains "o"
|
|
70
|
+
{
|
|
71
|
+
apply: {
|
|
72
|
+
color: { value: '#fef3c7' },
|
|
73
|
+
textColor: { value: '#000000' },
|
|
74
|
+
},
|
|
75
|
+
column: null,
|
|
76
|
+
priority: 0, // Lower priority so other rules take precedence
|
|
77
|
+
where: {
|
|
78
|
+
and: [
|
|
79
|
+
{ greaterThan: [{ column: 'age' }, 50] },
|
|
80
|
+
{ contains: [{ column: 'name' }, 'o'] },
|
|
81
|
+
],
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
];
|
|
85
|
+
const Component = () => {
|
|
86
|
+
const columnHelper = createColumnHelper();
|
|
87
|
+
const columns = [
|
|
88
|
+
columnHelper.accessor('name', {
|
|
89
|
+
cell: (info) => info.getValue(),
|
|
90
|
+
header: () => 'Name',
|
|
91
|
+
minSize: 180,
|
|
92
|
+
size: 220,
|
|
93
|
+
}),
|
|
94
|
+
columnHelper.accessor('age', {
|
|
95
|
+
cell: (info) => info.renderValue(),
|
|
96
|
+
header: () => 'Age',
|
|
97
|
+
minSize: 80,
|
|
98
|
+
}),
|
|
99
|
+
columnHelper.accessor('cypherCommand', {
|
|
100
|
+
cell: (info) => info.getValue(),
|
|
101
|
+
header: () => 'Cypher Command',
|
|
102
|
+
minSize: 400,
|
|
103
|
+
size: 400,
|
|
104
|
+
}),
|
|
105
|
+
];
|
|
106
|
+
const table = useReactTable({
|
|
107
|
+
columnResizeMode: 'onChange',
|
|
108
|
+
columns,
|
|
109
|
+
data: TABLE_DEMO_DATA,
|
|
110
|
+
defaultColumn: {
|
|
111
|
+
maxSize: 800,
|
|
112
|
+
minSize: 80,
|
|
113
|
+
},
|
|
114
|
+
enableSorting: true,
|
|
115
|
+
getCoreRowModel: getCoreRowModel(),
|
|
116
|
+
getPaginationRowModel: getPaginationRowModel(),
|
|
117
|
+
getSortedRowModel: getSortedRowModel(),
|
|
118
|
+
initialState: {
|
|
119
|
+
pagination: {
|
|
120
|
+
pageSize: 10,
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
});
|
|
124
|
+
return (_jsx("div", { className: "n-w-full n-bg-light-neutral-text-weakest", children: _jsx(DataGrid, { isResizable: false, tableInstance: table, isKeyboardNavigable: false, styleRules: styleRules, styling: {
|
|
125
|
+
borderStyle: 'all-sides',
|
|
126
|
+
hasHoverEffects: true,
|
|
127
|
+
hasZebraStriping: false,
|
|
128
|
+
} }) }));
|
|
129
|
+
};
|
|
130
|
+
export default Component;
|
|
131
|
+
//# sourceMappingURL=datagrid-rule-based-styling.story.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datagrid-rule-based-styling.story.js","sourceRoot":"","sources":["../../../../src/data-grid/stories/datagrid-rule-based-styling.story.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,yCAAyC,CAAC;AAEjD,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EACL,kB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AI,EAAE,eAAe;QACrB,aAAa,EAAE;YACb,OAAO,EAAE,GAAG;YACZ,OAAO,EAAE,EAAE;SACZ;QACD,aAAa,EAAE,IAAI;QACnB,eAAe,EAAE,eAAe,EAAE;QAClC,qBAAqB,EAAE,qBAAqB,EAAE;QAC9C,iBAAiB,EAAE,iBAAiB,EAAE;QACtC,YAAY,EAAE;YACZ,UAAU,EAAE;gBACV,QAAQ,EAAE,EAAE;aACb;SACF;KACF,CAAC,CAAC;IAEH,OAAO,CACL,cAAK,SAAS,EAAC,0CAA0C,YACvD,KAAC,QAAQ,IACP,WAAW,EAAE,KAAK,EAClB,aAAa,EAAE,KAAK,EACpB,mBAAmB,EAAE,KAAK,EAC1B,UAAU,EAAE,UAAU,EACtB,OAAO,EAAE;gBACP,WAAW,EAAE,WAAW;gBACxB,eAAe,EAAE,IAAI;gBACrB,gBAAgB,EAAE,KAAK;aACxB,GACD,GACE,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,SAAS,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport '@neo4j-ndl/base/lib/neo4j-ds-styles.css';\n\nimport { DataGrid } from '@neo4j-ndl/react';\nimport {\n createColumnHelper,\n getCoreRowModel,\n getPaginationRowModel,\n getSortedRowModel,\n useReactTable,\n} from '@tanstack/react-table';\n\nimport { type DataGridStyleRule } from '../style-rules/types';\nimport { TABLE_DEMO_DATA, type TestDataFormat } from './staticData';\n\nconst styleRules: DataGridStyleRule[] = [\n // Row coloring: all cells styled when name contains \"Alicia\"\n {\n apply: {\n color: { value: '#000000' },\n textColor: { value: '#ffffff' },\n },\n column: null,\n priority: 3,\n where: { contains: [{ column: 'name' }, 'Alicia'] },\n },\n // Cell coloring: cells in the \"age\" column with value 51 get green\n {\n apply: { color: { value: '#00bb00' } },\n column: 'age',\n priority: 3,\n where: { equal: [{ column: 'age' }, 51] },\n },\n // Dual color ranges on the \"age\" column: independent gradients for background\n // (driven by age, full 0-100 range) and text color (driven by age too, but\n // with a narrower 20-80 band so the text contrast is calibrated separately).\n {\n apply: {\n colorRange: {\n maxColor: '#f00000',\n maxValue: 100,\n midColor: '#a00000',\n midValue: 50,\n minColor: '#800000',\n minValue: 0,\n onColumn: 'age',\n },\n textColorRange: {\n maxColor: '#aaaaaa',\n maxValue: 80,\n minColor: '#ffffff',\n minValue: 20,\n onColumn: 'age',\n },\n },\n column: 'age',\n priority: 2, // Lower priority so explicit green rule overrides\n },\n // Multi-column rule: all cells styled when age > 50 AND name contains \"o\"\n {\n apply: {\n color: { value: '#fef3c7' },\n textColor: { value: '#000000' },\n },\n column: null,\n priority: 0, // Lower priority so other rules take precedence\n where: {\n and: [\n { greaterThan: [{ column: 'age' }, 50] },\n { contains: [{ column: 'name' }, 'o'] },\n ],\n },\n },\n];\n\nconst Component = () => {\n const columnHelper = createColumnHelper<TestDataFormat>();\n\n const columns = [\n columnHelper.accessor('name', {\n cell: (info) => info.getValue(),\n header: () => 'Name',\n minSize: 180,\n size: 220,\n }),\n columnHelper.accessor('age', {\n cell: (info) => info.renderValue(),\n header: () => 'Age',\n minSize: 80,\n }),\n columnHelper.accessor('cypherCommand', {\n cell: (info) => info.getValue(),\n header: () => 'Cypher Command',\n minSize: 400,\n size: 400,\n }),\n ];\n\n const table = useReactTable({\n columnResizeMode: 'onChange',\n columns,\n data: TABLE_DEMO_DATA,\n defaultColumn: {\n maxSize: 800,\n minSize: 80,\n },\n enableSorting: true,\n getCoreRowModel: getCoreRowModel(),\n getPaginationRowModel: getPaginationRowModel(),\n getSortedRowModel: getSortedRowModel(),\n initialState: {\n pagination: {\n pageSize: 10,\n },\n },\n });\n\n return (\n <div className=\"n-w-full n-bg-light-neutral-text-weakest\">\n <DataGrid\n isResizable={false}\n tableInstance={table}\n isKeyboardNavigable={false}\n styleRules={styleRules}\n styling={{\n borderStyle: 'all-sides',\n hasHoverEffects: true,\n hasZebraStriping: false,\n }}\n />\n </div>\n );\n};\n\nexport default Component;\n"]}
|
|
@@ -36,10 +36,13 @@ export { PinnedBothSides as DataGridPinnedBothSides, PinnedLeftSide as DataGridP
|
|
|
36
36
|
export { default as DataGridNoPaginationTable } from './datagrid-no-pagination-table.story';
|
|
37
37
|
export { default as DataGridSingleSelectable } from './datagrid-single-selectable.story';
|
|
38
38
|
export { default as DataGridUsingEditableCells } from './datagrid-using-editable-cells.story';
|
|
39
|
+
export { default as DataGridRuleBasedStyling } from './datagrid-rule-based-styling.story';
|
|
40
|
+
export { default as DataGridCustomCellWithStyleRules } from './datagrid-custom-cell-with-style-rules.story';
|
|
39
41
|
import { removeLicenseHeader } from '../../_common/export-stories-utils';
|
|
40
42
|
import DataGridColumnFilteringSourceRaw from './datagrid-column-filtering.story?raw';
|
|
41
43
|
import DataGridCompactModeSourceRaw from './datagrid-compact-mode.story?raw';
|
|
42
44
|
import DataGridComponentOverridingSourceRaw from './datagrid-component-overriding.story?raw';
|
|
45
|
+
import DataGridCustomCellWithStyleRulesSourceRaw from './datagrid-custom-cell-with-style-rules.story?raw';
|
|
43
46
|
import DataGridInDialogSourceRaw from './datagrid-in-dialog.story?raw';
|
|
44
47
|
import DataGridKeyboardNavigationSourceRaw from './datagrid-keyboard-navigation.story?raw';
|
|
45
48
|
import DataGridKitchenSinkSourceRaw from './datagrid-kitchen-sink.story?raw';
|
|
@@ -48,6 +51,7 @@ import DataGridPercentageWidthColumnsSourceRaw from './datagrid-percentage-width
|
|
|
48
51
|
import DataGridPinnedColumnsSourceRaw from './datagrid-pinned-columns.stories?raw';
|
|
49
52
|
import DataGridPlaceholderStatesSourceRaw from './datagrid-placeholder-states.story?raw';
|
|
50
53
|
import DataGridResizableColumnSourceRaw from './datagrid-resizable-column.story?raw';
|
|
54
|
+
import DataGridRuleBasedStylingSourceRaw from './datagrid-rule-based-styling.story?raw';
|
|
51
55
|
import DataGridSearchableSourceRaw from './datagrid-search-and-filters.stories?raw';
|
|
52
56
|
import DataGridSelectableSourceRaw from './datagrid-selectable.story?raw';
|
|
53
57
|
import DataGridSimpleSourceRaw from './datagrid-simple.story?raw';
|
|
@@ -56,6 +60,8 @@ import DataGridSkeletonLoadingSourceRaw from './datagrid-skeleton-loading.story?
|
|
|
56
60
|
import DataGridSortableSourceRaw from './datagrid-sortable.story?raw';
|
|
57
61
|
import DataGridUsingEditableCellsSourceRaw from './datagrid-using-editable-cells.story?raw';
|
|
58
62
|
import DataGridVirtualizationSourceRaw from './datagrid-virtualization.story?raw';
|
|
63
|
+
export const DataGridCustomCellWithStyleRulesSource = removeLicenseHeader(DataGridCustomCellWithStyleRulesSourceRaw);
|
|
64
|
+
export const DataGridRuleBasedStylingSource = removeLicenseHeader(DataGridRuleBasedStylingSourceRaw);
|
|
59
65
|
export const DataGridSimpleSource = removeLicenseHeader(DataGridSimpleSourceRaw);
|
|
60
66
|
export const DataGridCompactModeSource = removeLicenseHeader(DataGridCompactModeSourceRaw);
|
|
61
67
|
export const DataGridSortableSource = removeLicenseHeader(DataGridSortableSourceRaw);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/data-grid/stories/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAC/E,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,OAAO,IAAI,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,CAAC,MAAM,4BAA4B,GAAG,mBAAmB,CAC7D,+BAA+B,CAChC,CAAC;AACF,MAAM,CAAC,MAAM,6BAA6B,GAAG,mBAAmB,CAC9D,gCAAgC,CACjC,CAAC;AACF,MAAM,CAAC,MAAM,+BAA+B,GAAG,mBAAmB,CAChE,kCAAkC,CACnC,CAAC;AACF,MAAM,CAAC,MAAM,6BAA6B,GAAG,mBAAmB,CAC9D,gCAAgC,CACjC,CAAC;AACF,MAAM,CAAC,MAAM,6BAA6B,GAAG,mBAAmB,CAC9D,gCAAgC,CACjC,CAAC;AACF,MAAM,CAAC,MAAM,iCAAiC,GAAG,mBAAmB,CAClE,oCAAoC,CACrC,CAAC;AACF,MAAM,CAAC,MAAM,gCAAgC,GAAG,mBAAmB,CACjE,mCAAmC,CACpC,CAAC;AACF,MAAM,CAAC,MAAM,oCAAoC,GAAG,mBAAmB,CACrE,uCAAuC,CACxC,CAAC;AACF,MAAM,CAAC,MAAM,2BAA2B,GAAG,mBAAmB,CAC5D,8BAA8B,CAC/B,CAAC;AACF,MAAM,CAAC,MAAM,+BAA+B,GAAG,mBAAmB,CAChE,4BAA4B,CAC7B,CAAC;AACF,MAAM,CAAC,MAAM,8BAA8B,GAAG,mBAAmB,CAC/D,iCAAiC,CAClC,CAAC;AACF,MAAM,CAAC,MAAM,gCAAgC,GAAG,mBAAmB,CACjE,mCAAmC,CACpC,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nexport { default as DataGridCompactMode } from './datagrid-compact-mode.story';\nexport { default as DataGridSimple } from './datagrid-simple.story';\nexport { default as DataGridSortable } from './datagrid-sortable.story';\nexport { default as DataGridSelectable } from './datagrid-selectable.story';\nexport {\n Searchable as DataGridSearchable,\n ColumnFiltering as DataGridColumnFiltering,\n} from './datagrid-search-and-filters.stories';\nexport { default as DataGridInDialog } from './datagrid-in-dialog.story';\nexport { default as DataGridKitchenSink } from './datagrid-kitchen-sink.story';\nexport { default as DataGridVirtualization } from './datagrid-virtualization.story';\nexport { default as DataGridSkeletonLoading } from './datagrid-skeleton-loading.story';\nexport { default as DataGridPlaceholderStates } from './datagrid-placeholder-states.story';\nexport { default as DataGridResizableColumn } from './datagrid-resizable-column.story';\nexport { default as DataGridComponentOverriding } from './datagrid-component-overriding.story';\nexport { default as DataGridKeyboardNavigation } from './datagrid-keyboard-navigation.story';\nexport { default as DataGridPercentageWidthColumns } from './datagrid-percentage-width-columns.story';\nexport {\n PinnedBothSides as DataGridPinnedBothSides,\n PinnedLeftSide as DataGridPinnedLeftSide,\n PinnedRightSide as DataGridPinnedRightSide,\n} from './datagrid-pinned-columns.stories';\nexport { default as DataGridNoPaginationTable } from './datagrid-no-pagination-table.story';\nexport { default as DataGridSingleSelectable } from './datagrid-single-selectable.story';\nexport { default as DataGridUsingEditableCells } from './datagrid-using-editable-cells.story';\n\nimport { removeLicenseHeader } from '../../_common/export-stories-utils';\nimport DataGridColumnFilteringSourceRaw from './datagrid-column-filtering.story?raw';\nimport DataGridCompactModeSourceRaw from './datagrid-compact-mode.story?raw';\nimport DataGridComponentOverridingSourceRaw from './datagrid-component-overriding.story?raw';\nimport DataGridInDialogSourceRaw from './datagrid-in-dialog.story?raw';\nimport DataGridKeyboardNavigationSourceRaw from './datagrid-keyboard-navigation.story?raw';\nimport DataGridKitchenSinkSourceRaw from './datagrid-kitchen-sink.story?raw';\nimport DataGridNoPaginationTableRaw from './datagrid-no-pagination-table.story?raw';\nimport DataGridPercentageWidthColumnsSourceRaw from './datagrid-percentage-width-columns.story?raw';\nimport DataGridPinnedColumnsSourceRaw from './datagrid-pinned-columns.stories?raw';\nimport DataGridPlaceholderStatesSourceRaw from './datagrid-placeholder-states.story?raw';\nimport DataGridResizableColumnSourceRaw from './datagrid-resizable-column.story?raw';\nimport DataGridSearchableSourceRaw from './datagrid-search-and-filters.stories?raw';\nimport DataGridSelectableSourceRaw from './datagrid-selectable.story?raw';\nimport DataGridSimpleSourceRaw from './datagrid-simple.story?raw';\nimport DataGridSingleSelectableSourceRaw from './datagrid-single-selectable.story?raw';\nimport DataGridSkeletonLoadingSourceRaw from './datagrid-skeleton-loading.story?raw';\nimport DataGridSortableSourceRaw from './datagrid-sortable.story?raw';\nimport DataGridUsingEditableCellsSourceRaw from './datagrid-using-editable-cells.story?raw';\nimport DataGridVirtualizationSourceRaw from './datagrid-virtualization.story?raw';\n\nexport const DataGridSimpleSource = removeLicenseHeader(\n DataGridSimpleSourceRaw,\n);\nexport const DataGridCompactModeSource = removeLicenseHeader(\n DataGridCompactModeSourceRaw,\n);\nexport const DataGridSortableSource = removeLicenseHeader(\n DataGridSortableSourceRaw,\n);\nexport const DataGridSelectableSource = removeLicenseHeader(\n DataGridSelectableSourceRaw,\n);\nexport const DataGridSearchableSource = removeLicenseHeader(\n DataGridSearchableSourceRaw,\n);\nexport const DataGridInDialogSource = removeLicenseHeader(\n DataGridInDialogSourceRaw,\n);\nexport const DataGridKitchenSinkSource = removeLicenseHeader(\n DataGridKitchenSinkSourceRaw,\n);\nexport const DataGridVirtualizationSource = removeLicenseHeader(\n DataGridVirtualizationSourceRaw,\n);\nexport const DataGridSkeletonLoadingSource = removeLicenseHeader(\n DataGridSkeletonLoadingSourceRaw,\n);\nexport const DataGridPlaceholderStatesSource = removeLicenseHeader(\n DataGridPlaceholderStatesSourceRaw,\n);\nexport const DataGridResizableColumnSource = removeLicenseHeader(\n DataGridResizableColumnSourceRaw,\n);\nexport const DataGridColumnFilteringSource = removeLicenseHeader(\n DataGridColumnFilteringSourceRaw,\n);\nexport const DataGridComponentOverridingSource = removeLicenseHeader(\n DataGridComponentOverridingSourceRaw,\n);\nexport const DataGridKeyboardNavigationSource = removeLicenseHeader(\n DataGridKeyboardNavigationSourceRaw,\n);\nexport const DataGridPercentageWidthColumnsSource = removeLicenseHeader(\n DataGridPercentageWidthColumnsSourceRaw,\n);\nexport const DataGridPinnedColumnsSource = removeLicenseHeader(\n DataGridPinnedColumnsSourceRaw,\n);\nexport const DataGridNoPaginationTableSource = removeLicenseHeader(\n DataGridNoPaginationTableRaw,\n);\nexport const DataGridSingleSelectableSource = removeLicenseHeader(\n DataGridSingleSelectableSourceRaw,\n);\nexport const DataGridUsingEditableCellsSource = removeLicenseHeader(\n DataGridUsingEditableCellsSourceRaw,\n);\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/data-grid/stories/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAC/E,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AAC5E,OAAO,EACL,UAAU,IAAI,kBAAkB,EAChC,eAAe,IAAI,uBAAuB,GAC3C,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AACzE,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,+BAA+B,CAAC;AAC/E,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACpF,OAAO,EAAE,OAAO,IAAI,uBAAuB,EAAE,MAAM,mCAAmC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,6BAA6B,GAAG,mBAAmB,CAC9D,gCAAgC,CACjC,CAAC;AACF,MAAM,CAAC,MAAM,+BAA+B,GAAG,mBAAmB,CAChE,kCAAkC,CACnC,CAAC;AACF,MAAM,CAAC,MAAM,6BAA6B,GAAG,mBAAmB,CAC9D,gCAAgC,CACjC,CAAC;AACF,MAAM,CAAC,MAAM,6BAA6B,GAAG,mBAAmB,CAC9D,gCAAgC,CACjC,CAAC;AACF,MAAM,CAAC,MAAM,iCAAiC,GAAG,mBAAmB,CAClE,oCAAoC,CACrC,CAAC;AACF,MAAM,CAAC,MAAM,gCAAgC,GAAG,mBAAmB,CACjE,mCAAmC,CACpC,CAAC;AACF,MAAM,CAAC,MAAM,oCAAoC,GAAG,mBAAmB,CACrE,uCAAuC,CACxC,CAAC;AACF,MAAM,CAAC,MAAM,2BAA2B,GAAG,mBAAmB,CAC5D,8BAA8B,CAC/B,CAAC;AACF,MAAM,CAAC,MAAM,+BAA+B,GAAG,mBAAmB,CAChE,4BAA4B,CAC7B,CAAC;AACF,MAAM,CAAC,MAAM,8BAA8B,GAAG,mBAAmB,CAC/D,iCAAiC,CAClC,CAAC;AACF,MAAM,CAAC,MAAM,gCAAgC,GAAG,mBAAmB,CACjE,mCAAmC,CACpC,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nexport { default as DataGridCompactMode } from './datagrid-compact-mode.story';\nexport { default as DataGridSimple } from './datagrid-simple.story';\nexport { default as DataGridSortable } from './datagrid-sortable.story';\nexport { default as DataGridSelectable } from './datagrid-selectable.story';\nexport {\n Searchable as DataGridSearchable,\n ColumnFiltering as DataGridColumnFiltering,\n} from './datagrid-search-and-filters.stories';\nexport { default as DataGridInDialog } from './datagrid-in-dialog.story';\nexport { default as DataGridKitchenSink } from './datagrid-kitchen-sink.story';\nexport { default as DataGridVirtualization } from './datagrid-virtualization.story';\nexport { default as DataGridSkeletonLoading } from './datagrid-skeleton-loading.story';\nexport { default as DataGridPlaceholderStates } from './datagrid-placeholder-states.story';\nexport { default as DataGridResizableColumn } from './datagrid-resizable-column.story';\nexport { default as DataGridComponentOverriding } from './datagrid-component-overriding.story';\nexport { default as DataGridKeyboardNavigation } from './datagrid-keyboard-navigation.story';\nexport { default as DataGridPercentageWidthColumns } from './datagrid-percentage-width-columns.story';\nexport {\n PinnedBothSides as DataGridPinnedBothSides,\n PinnedLeftSide as DataGridPinnedLeftSide,\n PinnedRightSide as DataGridPinnedRightSide,\n} from './datagrid-pinned-columns.stories';\nexport { default as DataGridNoPaginationTable } from './datagrid-no-pagination-table.story';\nexport { default as DataGridSingleSelectable } from './datagrid-single-selectable.story';\nexport { default as DataGridUsingEditableCells } from './datagrid-using-editable-cells.story';\nexport { default as DataGridRuleBasedStyling } from './datagrid-rule-based-styling.story';\nexport { default as DataGridCustomCellWithStyleRules } from './datagrid-custom-cell-with-style-rules.story';\n\nimport { removeLicenseHeader } from '../../_common/export-stories-utils';\nimport DataGridColumnFilteringSourceRaw from './datagrid-column-filtering.story?raw';\nimport DataGridCompactModeSourceRaw from './datagrid-compact-mode.story?raw';\nimport DataGridComponentOverridingSourceRaw from './datagrid-component-overriding.story?raw';\nimport DataGridCustomCellWithStyleRulesSourceRaw from './datagrid-custom-cell-with-style-rules.story?raw';\nimport DataGridInDialogSourceRaw from './datagrid-in-dialog.story?raw';\nimport DataGridKeyboardNavigationSourceRaw from './datagrid-keyboard-navigation.story?raw';\nimport DataGridKitchenSinkSourceRaw from './datagrid-kitchen-sink.story?raw';\nimport DataGridNoPaginationTableRaw from './datagrid-no-pagination-table.story?raw';\nimport DataGridPercentageWidthColumnsSourceRaw from './datagrid-percentage-width-columns.story?raw';\nimport DataGridPinnedColumnsSourceRaw from './datagrid-pinned-columns.stories?raw';\nimport DataGridPlaceholderStatesSourceRaw from './datagrid-placeholder-states.story?raw';\nimport DataGridResizableColumnSourceRaw from './datagrid-resizable-column.story?raw';\nimport DataGridRuleBasedStylingSourceRaw from './datagrid-rule-based-styling.story?raw';\nimport DataGridSearchableSourceRaw from './datagrid-search-and-filters.stories?raw';\nimport DataGridSelectableSourceRaw from './datagrid-selectable.story?raw';\nimport DataGridSimpleSourceRaw from './datagrid-simple.story?raw';\nimport DataGridSingleSelectableSourceRaw from './datagrid-single-selectable.story?raw';\nimport DataGridSkeletonLoadingSourceRaw from './datagrid-skeleton-loading.story?raw';\nimport DataGridSortableSourceRaw from './datagrid-sortable.story?raw';\nimport DataGridUsingEditableCellsSourceRaw from './datagrid-using-editable-cells.story?raw';\nimport DataGridVirtualizationSourceRaw from './datagrid-virtualization.story?raw';\n\nexport const DataGridCustomCellWithStyleRulesSource = removeLicenseHeader(\n DataGridCustomCellWithStyleRulesSourceRaw,\n);\nexport const DataGridRuleBasedStylingSource = removeLicenseHeader(\n DataGridRuleBasedStylingSourceRaw,\n);\nexport const DataGridSimpleSource = removeLicenseHeader(\n DataGridSimpleSourceRaw,\n);\nexport const DataGridCompactModeSource = removeLicenseHeader(\n DataGridCompactModeSourceRaw,\n);\nexport const DataGridSortableSource = removeLicenseHeader(\n DataGridSortableSourceRaw,\n);\nexport const DataGridSelectableSource = removeLicenseHeader(\n DataGridSelectableSourceRaw,\n);\nexport const DataGridSearchableSource = removeLicenseHeader(\n DataGridSearchableSourceRaw,\n);\nexport const DataGridInDialogSource = removeLicenseHeader(\n DataGridInDialogSourceRaw,\n);\nexport const DataGridKitchenSinkSource = removeLicenseHeader(\n DataGridKitchenSinkSourceRaw,\n);\nexport const DataGridVirtualizationSource = removeLicenseHeader(\n DataGridVirtualizationSourceRaw,\n);\nexport const DataGridSkeletonLoadingSource = removeLicenseHeader(\n DataGridSkeletonLoadingSourceRaw,\n);\nexport const DataGridPlaceholderStatesSource = removeLicenseHeader(\n DataGridPlaceholderStatesSourceRaw,\n);\nexport const DataGridResizableColumnSource = removeLicenseHeader(\n DataGridResizableColumnSourceRaw,\n);\nexport const DataGridColumnFilteringSource = removeLicenseHeader(\n DataGridColumnFilteringSourceRaw,\n);\nexport const DataGridComponentOverridingSource = removeLicenseHeader(\n DataGridComponentOverridingSourceRaw,\n);\nexport const DataGridKeyboardNavigationSource = removeLicenseHeader(\n DataGridKeyboardNavigationSourceRaw,\n);\nexport const DataGridPercentageWidthColumnsSource = removeLicenseHeader(\n DataGridPercentageWidthColumnsSourceRaw,\n);\nexport const DataGridPinnedColumnsSource = removeLicenseHeader(\n DataGridPinnedColumnsSourceRaw,\n);\nexport const DataGridNoPaginationTableSource = removeLicenseHeader(\n DataGridNoPaginationTableRaw,\n);\nexport const DataGridSingleSelectableSource = removeLicenseHeader(\n DataGridSingleSelectableSourceRaw,\n);\nexport const DataGridUsingEditableCellsSource = removeLicenseHeader(\n DataGridUsingEditableCellsSourceRaw,\n);\n"]}
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Copyright (c) "Neo4j"
|
|
4
|
+
* Neo4j Sweden AB [http://neo4j.com]
|
|
5
|
+
*
|
|
6
|
+
* This file is part of Neo4j.
|
|
7
|
+
*
|
|
8
|
+
* Neo4j is free software: you can redistribute it and/or modify
|
|
9
|
+
* it under the terms of the GNU General Public License as published by
|
|
10
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
11
|
+
* (at your option) any later version.
|
|
12
|
+
*
|
|
13
|
+
* This program is distributed in the hope that it will be useful,
|
|
14
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
* GNU General Public License for more details.
|
|
17
|
+
*
|
|
18
|
+
* You should have received a copy of the GNU General Public License
|
|
19
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
+
*/
|
|
21
|
+
import { color, rgbToHex, validHex } from '@uiw/react-color';
|
|
22
|
+
// --- Color interpolation (duplicated from react-graph to avoid cross-package coupling) ---
|
|
23
|
+
function getWeight(startValue, endValue, value) {
|
|
24
|
+
return (value - startValue) / (endValue - startValue);
|
|
25
|
+
}
|
|
26
|
+
function lerpColor(startColor, endColor, weight) {
|
|
27
|
+
return {
|
|
28
|
+
b: Math.round(startColor.b * (1 - weight) + endColor.b * weight),
|
|
29
|
+
g: Math.round(startColor.g * (1 - weight) + endColor.g * weight),
|
|
30
|
+
r: Math.round(startColor.r * (1 - weight) + endColor.r * weight),
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
function getInterpolatedColor(colorRange, rowData) {
|
|
34
|
+
const { onColumn, minValue, minColor, maxValue, maxColor, midValue, midColor, } = colorRange;
|
|
35
|
+
if (!validHex(minColor) || !validHex(maxColor)) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
const minRgb = color(minColor).rgb;
|
|
39
|
+
const maxRgb = color(maxColor).rgb;
|
|
40
|
+
const actualMinValue = Math.min(minValue, maxValue);
|
|
41
|
+
const actualMaxValue = Math.max(minValue, maxValue);
|
|
42
|
+
let midRgb = undefined;
|
|
43
|
+
if (midValue !== undefined && midColor !== undefined) {
|
|
44
|
+
const isMidInRange = actualMinValue <= midValue && midValue <= actualMaxValue;
|
|
45
|
+
if (!isMidInRange || !validHex(midColor)) {
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
midRgb = color(midColor).rgb;
|
|
49
|
+
}
|
|
50
|
+
const rawValue = rowData[onColumn];
|
|
51
|
+
if (typeof rawValue !== 'number') {
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
const clampedValue = Math.max(actualMinValue, Math.min(actualMaxValue, rawValue));
|
|
55
|
+
let rgb;
|
|
56
|
+
if (midRgb !== undefined && midValue !== undefined) {
|
|
57
|
+
const t = getWeight(minValue, midValue, clampedValue);
|
|
58
|
+
const isBetweenMinAndMid = t <= 1;
|
|
59
|
+
if (isBetweenMinAndMid) {
|
|
60
|
+
rgb = lerpColor(minRgb, midRgb, t);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
const t2 = getWeight(midValue, maxValue, clampedValue);
|
|
64
|
+
rgb = lerpColor(midRgb, maxRgb, t2);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
const t = getWeight(minValue, maxValue, clampedValue);
|
|
69
|
+
rgb = lerpColor(minRgb, maxRgb, t);
|
|
70
|
+
}
|
|
71
|
+
return rgbToHex(rgb);
|
|
72
|
+
}
|
|
73
|
+
function resolveValue(value, rowData) {
|
|
74
|
+
if (typeof value === 'object' && value !== null && 'column' in value) {
|
|
75
|
+
const cellVal = rowData[value.column];
|
|
76
|
+
if (cellVal === undefined) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
if (typeof cellVal === 'string' ||
|
|
80
|
+
typeof cellVal === 'number' ||
|
|
81
|
+
typeof cellVal === 'boolean') {
|
|
82
|
+
return cellVal;
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
return value;
|
|
87
|
+
}
|
|
88
|
+
function safeCompare(left, right, rowData, compareFn) {
|
|
89
|
+
const leftVal = resolveValue(left, rowData);
|
|
90
|
+
const rightVal = resolveValue(right, rowData);
|
|
91
|
+
if (leftVal === null || rightVal === null) {
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
return compareFn(leftVal, rightVal);
|
|
95
|
+
}
|
|
96
|
+
function safeStringCompare(left, right, rowData, compareFn) {
|
|
97
|
+
const leftVal = resolveValue(left, rowData);
|
|
98
|
+
const rightVal = resolveValue(right, rowData);
|
|
99
|
+
if (leftVal === null ||
|
|
100
|
+
rightVal === null ||
|
|
101
|
+
typeof leftVal !== 'string' ||
|
|
102
|
+
typeof rightVal !== 'string') {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
return compareFn(leftVal, rightVal);
|
|
106
|
+
}
|
|
107
|
+
function evaluateWhere(rowData, where) {
|
|
108
|
+
if (!where) {
|
|
109
|
+
return true;
|
|
110
|
+
}
|
|
111
|
+
if ('equal' in where) {
|
|
112
|
+
const [left, right] = where.equal;
|
|
113
|
+
const leftVal = resolveValue(left, rowData);
|
|
114
|
+
const rightVal = resolveValue(right, rowData);
|
|
115
|
+
if (leftVal === null || rightVal === null) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
return leftVal === rightVal;
|
|
119
|
+
}
|
|
120
|
+
if ('not' in where) {
|
|
121
|
+
const isMatch = evaluateWhere(rowData, where.not);
|
|
122
|
+
return isMatch === null ? null : !isMatch;
|
|
123
|
+
}
|
|
124
|
+
if ('lessThan' in where) {
|
|
125
|
+
return safeCompare(where.lessThan[0], where.lessThan[1], rowData, (a, b) => a < b);
|
|
126
|
+
}
|
|
127
|
+
if ('lessThanOrEqual' in where) {
|
|
128
|
+
return safeCompare(where.lessThanOrEqual[0], where.lessThanOrEqual[1], rowData, (a, b) => a <= b);
|
|
129
|
+
}
|
|
130
|
+
if ('greaterThan' in where) {
|
|
131
|
+
return safeCompare(where.greaterThan[0], where.greaterThan[1], rowData, (a, b) => a > b);
|
|
132
|
+
}
|
|
133
|
+
if ('greaterThanOrEqual' in where) {
|
|
134
|
+
return safeCompare(where.greaterThanOrEqual[0], where.greaterThanOrEqual[1], rowData, (a, b) => a >= b);
|
|
135
|
+
}
|
|
136
|
+
if ('contains' in where) {
|
|
137
|
+
return safeStringCompare(where.contains[0], where.contains[1], rowData, (a, b) => a.includes(b));
|
|
138
|
+
}
|
|
139
|
+
if ('startsWith' in where) {
|
|
140
|
+
return safeStringCompare(where.startsWith[0], where.startsWith[1], rowData, (a, b) => a.startsWith(b));
|
|
141
|
+
}
|
|
142
|
+
if ('endsWith' in where) {
|
|
143
|
+
return safeStringCompare(where.endsWith[0], where.endsWith[1], rowData, (a, b) => a.endsWith(b));
|
|
144
|
+
}
|
|
145
|
+
if ('isNull' in where) {
|
|
146
|
+
const value = resolveValue(where.isNull, rowData);
|
|
147
|
+
return value === null;
|
|
148
|
+
}
|
|
149
|
+
if ('and' in where) {
|
|
150
|
+
let hasNull = false;
|
|
151
|
+
for (const clause of where.and) {
|
|
152
|
+
const isMatch = evaluateWhere(rowData, clause);
|
|
153
|
+
if (isMatch === false) {
|
|
154
|
+
return false;
|
|
155
|
+
}
|
|
156
|
+
if (isMatch === null) {
|
|
157
|
+
hasNull = true;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return hasNull ? null : true;
|
|
161
|
+
}
|
|
162
|
+
if ('or' in where) {
|
|
163
|
+
let hasNull = false;
|
|
164
|
+
for (const clause of where.or) {
|
|
165
|
+
const isMatch = evaluateWhere(rowData, clause);
|
|
166
|
+
if (isMatch === true) {
|
|
167
|
+
return true;
|
|
168
|
+
}
|
|
169
|
+
if (isMatch === null) {
|
|
170
|
+
hasNull = true;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return hasNull ? null : false;
|
|
174
|
+
}
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
// --- Style resolution ---
|
|
178
|
+
function resolveAppliedStyle(apply, rowData) {
|
|
179
|
+
const result = {};
|
|
180
|
+
let hasStyle = false;
|
|
181
|
+
if (apply.color && !apply.color.isDisabled) {
|
|
182
|
+
result.backgroundColor = apply.color.value;
|
|
183
|
+
hasStyle = true;
|
|
184
|
+
}
|
|
185
|
+
if (apply.textColor && !apply.textColor.isDisabled) {
|
|
186
|
+
result.color = apply.textColor.value;
|
|
187
|
+
hasStyle = true;
|
|
188
|
+
}
|
|
189
|
+
if (apply.colorRange && !apply.colorRange.isDisabled) {
|
|
190
|
+
const interpolated = getInterpolatedColor(apply.colorRange, rowData);
|
|
191
|
+
if (interpolated !== null) {
|
|
192
|
+
result.backgroundColor = interpolated;
|
|
193
|
+
hasStyle = true;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (apply.textColorRange && !apply.textColorRange.isDisabled) {
|
|
197
|
+
const interpolated = getInterpolatedColor(apply.textColorRange, rowData);
|
|
198
|
+
if (interpolated !== null) {
|
|
199
|
+
result.color = interpolated;
|
|
200
|
+
hasStyle = true;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
return hasStyle ? result : undefined;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Computes styles for all cells in a row based on the given style rules.
|
|
207
|
+
* When a rule's `column` is `null`, its style is applied to every cell.
|
|
208
|
+
*
|
|
209
|
+
* Used internally by hooks, but exported for context-free usage.
|
|
210
|
+
*/
|
|
211
|
+
export function computeDataGridRowStyles(rules, rowData) {
|
|
212
|
+
const enabledRules = rules.filter((r) => !r.isDisabled);
|
|
213
|
+
const totalRules = enabledRules.length;
|
|
214
|
+
const sortedRules = enabledRules
|
|
215
|
+
.map((rule, index) => {
|
|
216
|
+
var _a;
|
|
217
|
+
if (rule.priority !== undefined && rule.priority < 0) {
|
|
218
|
+
throw new Error(`DataGridStyleRule priority must be >= 0, got ${rule.priority}. Negative values are reserved for internal use.`);
|
|
219
|
+
}
|
|
220
|
+
return Object.assign(Object.assign({}, rule), { _order: index, _priority: (_a = rule.priority) !== null && _a !== void 0 ? _a : index - totalRules });
|
|
221
|
+
})
|
|
222
|
+
.sort((a, b) => {
|
|
223
|
+
if (a._priority !== b._priority) {
|
|
224
|
+
return a._priority - b._priority;
|
|
225
|
+
}
|
|
226
|
+
return a._order - b._order;
|
|
227
|
+
});
|
|
228
|
+
const cellPriorityMap = {};
|
|
229
|
+
for (const rule of sortedRules) {
|
|
230
|
+
const isMatching = evaluateWhere(rowData, rule.where) === true;
|
|
231
|
+
if (!isMatching) {
|
|
232
|
+
continue;
|
|
233
|
+
}
|
|
234
|
+
const style = resolveAppliedStyle(rule.apply, rowData);
|
|
235
|
+
if (!style) {
|
|
236
|
+
continue;
|
|
237
|
+
}
|
|
238
|
+
const effectivePriority = rule._priority;
|
|
239
|
+
const affectedColumns = rule.column === null ? Object.keys(rowData) : [rule.column];
|
|
240
|
+
for (const col of affectedColumns) {
|
|
241
|
+
if (!cellPriorityMap[col]) {
|
|
242
|
+
cellPriorityMap[col] = {};
|
|
243
|
+
}
|
|
244
|
+
for (const [prop, value] of Object.entries(style)) {
|
|
245
|
+
const existing = cellPriorityMap[col][prop];
|
|
246
|
+
if (!existing || effectivePriority >= existing.priority) {
|
|
247
|
+
cellPriorityMap[col][prop] = {
|
|
248
|
+
priority: effectivePriority,
|
|
249
|
+
value: value,
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
const cellStyles = {};
|
|
256
|
+
for (const [col, propMap] of Object.entries(cellPriorityMap)) {
|
|
257
|
+
const style = {};
|
|
258
|
+
let hasProp = false;
|
|
259
|
+
for (const [prop, entry] of Object.entries(propMap)) {
|
|
260
|
+
style[prop] = entry.value;
|
|
261
|
+
hasProp = true;
|
|
262
|
+
}
|
|
263
|
+
cellStyles[col] = hasProp ? style : undefined;
|
|
264
|
+
}
|
|
265
|
+
return { cellStyles };
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Evaluate style rules for a single cell.
|
|
269
|
+
* Pure function -- no React context needed.
|
|
270
|
+
*
|
|
271
|
+
* @param rules - Array of style rules to evaluate
|
|
272
|
+
* @param rowData - The row's data as a record (column id -> value)
|
|
273
|
+
* @param columnId - Returns the computed style for this specific cell.
|
|
274
|
+
*/
|
|
275
|
+
export function evaluateDataGridStyleRules(rules, rowData, columnId) {
|
|
276
|
+
const { cellStyles } = computeDataGridRowStyles(rules, rowData);
|
|
277
|
+
return cellStyles[columnId];
|
|
278
|
+
}
|
|
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I,CAAC,GAAG;wBAC3B,QAAQ,EAAE,iBAAiB;wBAC3B,KAAK,EAAE,KAAe;qBACvB,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;IAED,MAAM,UAAU,GAAoD,EAAE,CAAC;IACvE,KAAK,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,EAAE,CAAC;QAC7D,MAAM,KAAK,GAAwB,EAAE,CAAC;QACtC,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;YACnD,KAAgC,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC;YACtD,OAAO,GAAG,IAAI,CAAC;QACjB,CAAC;QACD,UAAU,CAAC,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;IAChD,CAAC;IAED,OAAO,EAAE,UAAU,EAAE,CAAC;AACxB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,0BAA0B,CACxC,KAA0B,EAC1B,OAAgC,EAChC,QAAgB;IAEhB,MAAM,EAAE,UAAU,EAAE,GAAG,wBAAwB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IAChE,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport { color, type RgbColor, rgbToHex, validHex } from '@uiw/react-color';\n\nimport {\n type DataGridCellStyle,\n type DataGridColorRange,\n type DataGridStyleRule,\n type DataGridStyleRuleLiteral,\n type DataGridStyleRuleOperand,\n type DataGridStyleRuleWhere,\n} from './types';\n\n// --- Color interpolation (duplicated from react-graph to avoid cross-package coupling) ---\n\nfunction getWeight(\n startValue: number,\n endValue: number,\n value: number,\n): number {\n return (value - startValue) / (endValue - startValue);\n}\n\nfunction lerpColor(\n startColor: RgbColor,\n endColor: RgbColor,\n weight: number,\n): RgbColor {\n return {\n b: Math.round(startColor.b * (1 - weight) + endColor.b * weight),\n g: Math.round(startColor.g * (1 - weight) + endColor.g * weight),\n r: Math.round(startColor.r * (1 - weight) + endColor.r * weight),\n };\n}\n\nfunction getInterpolatedColor(\n colorRange: DataGridColorRange,\n rowData: Record<string, unknown>,\n): string | null {\n const {\n onColumn,\n minValue,\n minColor,\n maxValue,\n maxColor,\n midValue,\n midColor,\n } = colorRange;\n\n if (!validHex(minColor) || !validHex(maxColor)) {\n return null;\n }\n\n const minRgb = color(minColor).rgb;\n const maxRgb = color(maxColor).rgb;\n const actualMinValue = Math.min(minValue, maxValue);\n const actualMaxValue = Math.max(minValue, maxValue);\n\n let midRgb: RgbColor | undefined = undefined;\n if (midValue !== undefined && midColor !== undefined) {\n const isMidInRange =\n actualMinValue <= midValue && midValue <= actualMaxValue;\n if (!isMidInRange || !validHex(midColor)) {\n return null;\n }\n midRgb = color(midColor).rgb;\n }\n\n const rawValue = rowData[onColumn];\n if (typeof rawValue !== 'number') {\n return null;\n }\n\n const clampedValue = Math.max(\n actualMinValue,\n Math.min(actualMaxValue, rawValue),\n );\n\n let rgb: RgbColor;\n\n if (midRgb !== undefined && midValue !== undefined) {\n const t = getWeight(minValue, midValue, clampedValue);\n const isBetweenMinAndMid = t <= 1;\n if (isBetweenMinAndMid) {\n rgb = lerpColor(minRgb, midRgb, t);\n } else {\n const t2 = getWeight(midValue, maxValue, clampedValue);\n rgb = lerpColor(midRgb, maxRgb, t2);\n }\n } else {\n const t = getWeight(minValue, maxValue, clampedValue);\n rgb = lerpColor(minRgb, maxRgb, t);\n }\n\n return rgbToHex(rgb);\n}\n\n// --- Where clause evaluation ---\n\ntype Ternary = boolean | null;\n\nfunction resolveValue(\n value: DataGridStyleRuleOperand,\n rowData: Record<string, unknown>,\n): DataGridStyleRuleLiteral {\n if (typeof value === 'object' && value !== null && 'column' in value) {\n const cellVal = rowData[value.column];\n if (cellVal === undefined) {\n return null;\n }\n if (\n typeof cellVal === 'string' ||\n typeof cellVal === 'number' ||\n typeof cellVal === 'boolean'\n ) {\n return cellVal;\n }\n return null;\n }\n return value;\n}\n\nfunction safeCompare(\n left: DataGridStyleRuleOperand,\n right: DataGridStyleRuleOperand,\n rowData: Record<string, unknown>,\n compareFn: (\n a: NonNullable<DataGridStyleRuleLiteral>,\n b: NonNullable<DataGridStyleRuleLiteral>,\n ) => boolean,\n): Ternary {\n const leftVal = resolveValue(left, rowData);\n const rightVal = resolveValue(right, rowData);\n if (leftVal === null || rightVal === null) {\n return null;\n }\n return compareFn(leftVal, rightVal);\n}\n\nfunction safeStringCompare(\n left: DataGridStyleRuleOperand,\n right: DataGridStyleRuleOperand,\n rowData: Record<string, unknown>,\n compareFn: (a: string, b: string) => boolean,\n): Ternary {\n const leftVal = resolveValue(left, rowData);\n const rightVal = resolveValue(right, rowData);\n if (\n leftVal === null ||\n rightVal === null ||\n typeof leftVal !== 'string' ||\n typeof rightVal !== 'string'\n ) {\n return null;\n }\n return compareFn(leftVal, rightVal);\n}\n\nfunction evaluateWhere(\n rowData: Record<string, unknown>,\n where?: DataGridStyleRuleWhere,\n): Ternary {\n if (!where) {\n return true;\n }\n\n if ('equal' in where) {\n const [left, right] = where.equal;\n const leftVal = resolveValue(left, rowData);\n const rightVal = resolveValue(right, rowData);\n if (leftVal === null || rightVal === null) {\n return null;\n }\n return leftVal === rightVal;\n }\n\n if ('not' in where) {\n const isMatch = evaluateWhere(rowData, where.not);\n return isMatch === null ? null : !isMatch;\n }\n\n if ('lessThan' in where) {\n return safeCompare(\n where.lessThan[0],\n where.lessThan[1],\n rowData,\n (a, b) => a < b,\n );\n }\n\n if ('lessThanOrEqual' in where) {\n return safeCompare(\n where.lessThanOrEqual[0],\n where.lessThanOrEqual[1],\n rowData,\n (a, b) => a <= b,\n );\n }\n\n if ('greaterThan' in where) {\n return safeCompare(\n where.greaterThan[0],\n where.greaterThan[1],\n rowData,\n (a, b) => a > b,\n );\n }\n\n if ('greaterThanOrEqual' in where) {\n return safeCompare(\n where.greaterThanOrEqual[0],\n where.greaterThanOrEqual[1],\n rowData,\n (a, b) => a >= b,\n );\n }\n\n if ('contains' in where) {\n return safeStringCompare(\n where.contains[0],\n where.contains[1],\n rowData,\n (a, b) => a.includes(b),\n );\n }\n\n if ('startsWith' in where) {\n return safeStringCompare(\n where.startsWith[0],\n where.startsWith[1],\n rowData,\n (a, b) => a.startsWith(b),\n );\n }\n\n if ('endsWith' in where) {\n return safeStringCompare(\n where.endsWith[0],\n where.endsWith[1],\n rowData,\n (a, b) => a.endsWith(b),\n );\n }\n\n if ('isNull' in where) {\n const value = resolveValue(where.isNull, rowData);\n return value === null;\n }\n\n if ('and' in where) {\n let hasNull = false;\n for (const clause of where.and) {\n const isMatch = evaluateWhere(rowData, clause);\n if (isMatch === false) {\n return false;\n }\n if (isMatch === null) {\n hasNull = true;\n }\n }\n return hasNull ? null : true;\n }\n\n if ('or' in where) {\n let hasNull = false;\n for (const clause of where.or) {\n const isMatch = evaluateWhere(rowData, clause);\n if (isMatch === true) {\n return true;\n }\n if (isMatch === null) {\n hasNull = true;\n }\n }\n return hasNull ? null : false;\n }\n\n return false;\n}\n\n// --- Style resolution ---\n\nfunction resolveAppliedStyle(\n apply: DataGridCellStyle,\n rowData: Record<string, unknown>,\n): React.CSSProperties | undefined {\n const result: React.CSSProperties = {};\n let hasStyle = false;\n\n if (apply.color && !apply.color.isDisabled) {\n result.backgroundColor = apply.color.value;\n hasStyle = true;\n }\n\n if (apply.textColor && !apply.textColor.isDisabled) {\n result.color = apply.textColor.value;\n hasStyle = true;\n }\n\n if (apply.colorRange && !apply.colorRange.isDisabled) {\n const interpolated = getInterpolatedColor(apply.colorRange, rowData);\n if (interpolated !== null) {\n result.backgroundColor = interpolated;\n hasStyle = true;\n }\n }\n\n if (apply.textColorRange && !apply.textColorRange.isDisabled) {\n const interpolated = getInterpolatedColor(apply.textColorRange, rowData);\n if (interpolated !== null) {\n result.color = interpolated;\n hasStyle = true;\n }\n }\n\n return hasStyle ? result : undefined;\n}\n\nexport type ComputedDataGridStyles = {\n cellStyles: Record<string, React.CSSProperties | undefined>;\n};\n\ntype PriorityEntry = { value: string; priority: number };\ntype PropPriorityMap = Record<string, PriorityEntry>;\n\n/**\n * Computes styles for all cells in a row based on the given style rules.\n * When a rule's `column` is `null`, its style is applied to every cell.\n *\n * Used internally by hooks, but exported for context-free usage.\n */\nexport function computeDataGridRowStyles(\n rules: DataGridStyleRule[],\n rowData: Record<string, unknown>,\n): ComputedDataGridStyles {\n const enabledRules = rules.filter((r) => !r.isDisabled);\n const totalRules = enabledRules.length;\n\n const sortedRules = enabledRules\n .map((rule, index) => {\n if (rule.priority !== undefined && rule.priority < 0) {\n throw new Error(\n `DataGridStyleRule priority must be >= 0, got ${rule.priority}. Negative values are reserved for internal use.`,\n );\n }\n\n return {\n ...rule,\n _order: index,\n _priority: rule.priority ?? index - totalRules,\n };\n })\n .sort((a, b) => {\n if (a._priority !== b._priority) {\n return a._priority - b._priority;\n }\n return a._order - b._order;\n });\n\n const cellPriorityMap: Record<string, PropPriorityMap> = {};\n\n for (const rule of sortedRules) {\n const isMatching = evaluateWhere(rowData, rule.where) === true;\n if (!isMatching) {\n continue;\n }\n\n const style = resolveAppliedStyle(rule.apply, rowData);\n if (!style) {\n continue;\n }\n\n const effectivePriority = rule._priority;\n const affectedColumns =\n rule.column === null ? Object.keys(rowData) : [rule.column];\n\n for (const col of affectedColumns) {\n if (!cellPriorityMap[col]) {\n cellPriorityMap[col] = {};\n }\n for (const [prop, value] of Object.entries(style)) {\n const existing = cellPriorityMap[col][prop];\n if (!existing || effectivePriority >= existing.priority) {\n cellPriorityMap[col][prop] = {\n priority: effectivePriority,\n value: value as string,\n };\n }\n }\n }\n }\n\n const cellStyles: Record<string, React.CSSProperties | undefined> = {};\n for (const [col, propMap] of Object.entries(cellPriorityMap)) {\n const style: React.CSSProperties = {};\n let hasProp = false;\n for (const [prop, entry] of Object.entries(propMap)) {\n (style as Record<string, string>)[prop] = entry.value;\n hasProp = true;\n }\n cellStyles[col] = hasProp ? style : undefined;\n }\n\n return { cellStyles };\n}\n\n/**\n * Evaluate style rules for a single cell.\n * Pure function -- no React context needed.\n *\n * @param rules - Array of style rules to evaluate\n * @param rowData - The row's data as a record (column id -> value)\n * @param columnId - Returns the computed style for this specific cell.\n */\nexport function evaluateDataGridStyleRules(\n rules: DataGridStyleRule[],\n rowData: Record<string, unknown>,\n columnId: string,\n): React.CSSProperties | undefined {\n const { cellStyles } = computeDataGridRowStyles(rules, rowData);\n return cellStyles[columnId];\n}\n"]}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
*
|
|
3
|
+
* Copyright (c) "Neo4j"
|
|
4
|
+
* Neo4j Sweden AB [http://neo4j.com]
|
|
5
|
+
*
|
|
6
|
+
* This file is part of Neo4j.
|
|
7
|
+
*
|
|
8
|
+
* Neo4j is free software: you can redistribute it and/or modify
|
|
9
|
+
* it under the terms of the GNU General Public License as published by
|
|
10
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
11
|
+
* (at your option) any later version.
|
|
12
|
+
*
|
|
13
|
+
* This program is distributed in the hope that it will be useful,
|
|
14
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
* GNU General Public License for more details.
|
|
17
|
+
*
|
|
18
|
+
* You should have received a copy of the GNU General Public License
|
|
19
|
+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
20
|
+
*/
|
|
21
|
+
import { useMemo } from 'react';
|
|
22
|
+
import { useDataGridContext } from '../data-grid-context';
|
|
23
|
+
import { computeDataGridRowStyles } from './evaluate';
|
|
24
|
+
/**
|
|
25
|
+
* Returns computed inline style for a specific cell based on style rules in context.
|
|
26
|
+
* Use this in custom BodyCell overrides to apply rule-based styling.
|
|
27
|
+
*/
|
|
28
|
+
export function useDataGridCellStyle(cell) {
|
|
29
|
+
const { styleRules } = useDataGridContext();
|
|
30
|
+
return useMemo(() => {
|
|
31
|
+
if (!styleRules || styleRules.length === 0) {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
const original = cell.row.original;
|
|
35
|
+
const rowData = typeof original === 'object' && original !== null
|
|
36
|
+
? original
|
|
37
|
+
: {};
|
|
38
|
+
const { cellStyles } = computeDataGridRowStyles(styleRules, rowData);
|
|
39
|
+
return cellStyles[cell.column.id];
|
|
40
|
+
}, [styleRules, cell]);
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../../../src/data-grid/style-rules/hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAGH,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEhC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAEtD;;;GAGG;AACH,MAAM,UAAU,oBAAoB,CAClC,IAAsB;IAEtB,MAAM,EAAE,UAAU,EAAE,GAAG,kBAAkB,EAAK,CAAC;IAE/C,OAAO,OAAO,CAAC,GAAG,EAAE;QAClB,IAAI,CAAC,UAAU,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC3C,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,MAAM,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC;QACnC,MAAM,OAAO,GACX,OAAO,QAAQ,KAAK,QAAQ,IAAI,QAAQ,KAAK,IAAI;YAC/C,CAAC,CAAE,QAAoC;YACvC,CAAC,CAAC,EAAE,CAAC;QACT,MAAM,EAAE,UAAU,EAAE,GAAG,wBAAwB,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QACrE,OAAO,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC;IACpC,CAAC,EAAE,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC,CAAC;AACzB,CAAC","sourcesContent":["/**\n *\n * Copyright (c) \"Neo4j\"\n * Neo4j Sweden AB [http://neo4j.com]\n *\n * This file is part of Neo4j.\n *\n * Neo4j is free software: you can redistribute it and/or modify\n * it under the terms of the GNU General Public License as published by\n * the Free Software Foundation, either version 3 of the License, or\n * (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU General Public License for more details.\n *\n * You should have received a copy of the GNU General Public License\n * along with this program. If not, see <http://www.gnu.org/licenses/>.\n */\n\nimport { type Cell, type RowData } from '@tanstack/react-table';\nimport { useMemo } from 'react';\n\nimport { useDataGridContext } from '../data-grid-context';\nimport { computeDataGridRowStyles } from './evaluate';\n\n/**\n * Returns computed inline style for a specific cell based on style rules in context.\n * Use this in custom BodyCell overrides to apply rule-based styling.\n */\nexport function useDataGridCellStyle<T extends RowData>(\n cell: Cell<T, unknown>,\n): React.CSSProperties | undefined {\n const { styleRules } = useDataGridContext<T>();\n\n return useMemo(() => {\n if (!styleRules || styleRules.length === 0) {\n return undefined;\n }\n const original = cell.row.original;\n const rowData =\n typeof original === 'object' && original !== null\n ? (original as Record<string, unknown>)\n : {};\n const { cellStyles } = computeDataGridRowStyles(styleRules, rowData);\n return cellStyles[cell.column.id];\n }, [styleRules, cell]);\n}\n"]}
|