@bluemarble/bm-components 0.0.81 → 0.0.82

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/esm/index.js CHANGED
@@ -15129,7 +15129,7 @@ function createFilter(filters) {
15129
15129
  };
15130
15130
  }
15131
15131
 
15132
- function useGrid({ columns, filters = [], rowsPerPageOptions = [30, 60, 100] }) {
15132
+ function useGrid({ columns, filters = [], search, rowsPerPageOptions = [30, 60, 100] }) {
15133
15133
  const [defaultData, setDefaultData] = useState([]);
15134
15134
  const [sortedBy, setSortedBy] = useState('');
15135
15135
  const [sortedDirection, setSortedDirection] = useState('desc');
@@ -15192,10 +15192,14 @@ function useGrid({ columns, filters = [], rowsPerPageOptions = [30, 60, 100] })
15192
15192
  setRowsPerPage(rows);
15193
15193
  };
15194
15194
  const filteredData = useMemo(() => {
15195
- const newData = defaultData.slice(0);
15195
+ let newData = defaultData.slice(0);
15196
+ if (search && search.value !== '') {
15197
+ const searchBy = createSearch(search);
15198
+ newData = newData.filter(searchBy);
15199
+ }
15196
15200
  const newFilter = createFilter(filters);
15197
15201
  return newData.filter(newFilter.apply);
15198
- }, [defaultData, filters]);
15202
+ }, [defaultData, filters, search]);
15199
15203
  const displayData = useMemo(() => {
15200
15204
  const sortedData = sortData(filteredData);
15201
15205
  const startPage = currentPage * rowsPerPage;
@@ -15220,6 +15224,44 @@ function useGrid({ columns, filters = [], rowsPerPageOptions = [30, 60, 100] })
15220
15224
  setSort
15221
15225
  };
15222
15226
  }
15227
+ function searchKeysForValue(row, compare) {
15228
+ const rowKeys = Object.keys(row);
15229
+ let match = false;
15230
+ const isNumberOrString = (value) => ['number', 'string'].includes(typeof value);
15231
+ for (const key of rowKeys) {
15232
+ const objValue = row[key];
15233
+ if (objValue) {
15234
+ if (Array.isArray(objValue))
15235
+ match = objValue.some((obj) => isNumberOrString(obj)
15236
+ ? compare(obj)
15237
+ : searchKeysForValue(obj, compare));
15238
+ else if (typeof objValue === 'object')
15239
+ match = searchKeysForValue(objValue, compare);
15240
+ else
15241
+ match = compare(row[key]);
15242
+ if (match)
15243
+ return match;
15244
+ }
15245
+ }
15246
+ return match;
15247
+ }
15248
+ function createSearch(options) {
15249
+ const searchValue = options.caseSensitive
15250
+ ? options.value
15251
+ : String(options.value).toLowerCase();
15252
+ function compare(objValue) {
15253
+ const value = options.caseSensitive
15254
+ ? String(objValue)
15255
+ : String(objValue).toLowerCase();
15256
+ if (options.exact)
15257
+ return value === searchValue;
15258
+ return value.includes(searchValue);
15259
+ }
15260
+ return (row) => {
15261
+ const match = searchKeysForValue(row, compare);
15262
+ return match;
15263
+ };
15264
+ }
15223
15265
 
15224
15266
  /* eslint no-undef: "off" */
15225
15267
  function useEvent(event, handler, passive = false) {