UNPKG

@carbon/react

Version:

React components for the Carbon Design System

32 lines (29 loc) 839 B
/** * Copyright IBM Corp. 2016, 2023 * * This source code is licensed under the Apache-2.0 license found in the * LICENSE file in the root directory of this source tree. */ /** * Filters row IDs based on whether any of the cell values in the row include * the input value as a substring. Boolean cell values are ignored. */ const defaultFilterRows = ({ rowIds, headers, cellsById, inputValue, getCellId }) => { const normalizedInput = inputValue.trim().toLowerCase(); if (!normalizedInput) return rowIds; return rowIds.filter(rowId => headers.some(({ key }) => { const cellId = getCellId(rowId, key); const cell = cellsById[cellId]; if (typeof cell.value === 'boolean') return false; return String(cell.value).toLowerCase().includes(normalizedInput); })); }; export { defaultFilterRows };