@neo4j-ndl/react
Version:
React implementation of Neo4j Design System
45 lines • 1.88 kB
JavaScript
;
/**
*
* Copyright (c) "Neo4j"
* Neo4j Sweden AB [http://neo4j.com]
*
* This file is part of Neo4j.
*
* Neo4j is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.useDataGridCellStyle = useDataGridCellStyle;
const react_1 = require("react");
const data_grid_context_1 = require("../data-grid-context");
const evaluate_1 = require("./evaluate");
/**
* Returns computed inline style for a specific cell based on style rules in context.
* Use this in custom BodyCell overrides to apply rule-based styling.
*/
function useDataGridCellStyle(cell) {
const { styleRules, styleRuleValueConverters } = (0, data_grid_context_1.useDataGridContext)();
return (0, react_1.useMemo)(() => {
if (!styleRules || styleRules.length === 0) {
return undefined;
}
const original = cell.row.original;
const rowData = typeof original === 'object' && original !== null
? original
: {};
const { cellStyles } = (0, evaluate_1.computeDataGridRowStyles)(styleRules, rowData, styleRuleValueConverters);
return cellStyles[cell.column.id];
}, [styleRules, styleRuleValueConverters, cell]);
}
//# sourceMappingURL=hooks.js.map