trotl-table 1.0.8 → 1.0.10
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 +3 -1
- package/dist/index.cjs.js +36 -8
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +36 -8
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,7 +25,8 @@ yarn add trotl-table
|
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
## Versions
|
|
28
|
-
|
|
28
|
+
```js
|
|
29
|
+
1.0.9 => fix readme, whatever
|
|
29
30
|
1.0.8 => fix readme
|
|
30
31
|
1.0.7 => removed context (better for npm consumers)
|
|
31
32
|
1.0.6 => ...
|
|
@@ -34,6 +35,7 @@ yarn add trotl-table
|
|
|
34
35
|
1.0.3 => ...
|
|
35
36
|
1.0.2 => prepare for npm consumers
|
|
36
37
|
1.0.1 => initial release
|
|
38
|
+
```
|
|
37
39
|
|
|
38
40
|
## ⚡ Quick Start
|
|
39
41
|
|
package/dist/index.cjs.js
CHANGED
|
@@ -9683,11 +9683,36 @@ function Table({
|
|
|
9683
9683
|
viewCallback = () => {},
|
|
9684
9684
|
deleteCallback = null,
|
|
9685
9685
|
buttons = ["view", "edit", "delete"],
|
|
9686
|
-
enableDragRow = false
|
|
9686
|
+
enableDragRow = false,
|
|
9687
|
+
enableSearchUrlParam = false
|
|
9687
9688
|
}) {
|
|
9688
9689
|
// Local selection & sorting state (removed TableContext dependency)
|
|
9689
9690
|
const [selectedRows, setSelectedRows] = React.useState([]);
|
|
9690
9691
|
const [sorting, setSorting] = React.useState(null);
|
|
9692
|
+
|
|
9693
|
+
// Option to read search param from URL
|
|
9694
|
+
const [searchTerm, setSearchTerm] = React.useState(extraSearchTerm);
|
|
9695
|
+
|
|
9696
|
+
// Recognize "entry" in URL search param and set as searchTerm if present
|
|
9697
|
+
// Extract window.location.search to a variable for useEffect dependency
|
|
9698
|
+
const locationSearch = typeof window !== "undefined" ? window.location.search : "";
|
|
9699
|
+
React.useEffect(() => {
|
|
9700
|
+
if (!enableSearchUrlParam) {
|
|
9701
|
+
setSearchTerm(extraSearchTerm);
|
|
9702
|
+
return;
|
|
9703
|
+
}
|
|
9704
|
+
const params = new URLSearchParams(locationSearch);
|
|
9705
|
+
const entrySearch = params.get("entry");
|
|
9706
|
+
const urlSearch = params.get("search");
|
|
9707
|
+
console.log(urlSearch);
|
|
9708
|
+
if (entrySearch) {
|
|
9709
|
+
setSearchTerm(entrySearch);
|
|
9710
|
+
} else if (urlSearch) {
|
|
9711
|
+
setSearchTerm(urlSearch);
|
|
9712
|
+
} else {
|
|
9713
|
+
setSearchTerm(extraSearchTerm);
|
|
9714
|
+
}
|
|
9715
|
+
}, [locationSearch, enableSearchUrlParam, extraSearchTerm]);
|
|
9691
9716
|
const toggleRowSelection = React.useCallback(rowId => {
|
|
9692
9717
|
setSelectedRows(prev => prev.includes(rowId) ? prev.filter(r => r !== rowId) : [...prev, rowId]);
|
|
9693
9718
|
}, []);
|
|
@@ -9705,7 +9730,9 @@ function Table({
|
|
|
9705
9730
|
return null;
|
|
9706
9731
|
});
|
|
9707
9732
|
};
|
|
9708
|
-
|
|
9733
|
+
|
|
9734
|
+
// console.log(extraSearchTerm)
|
|
9735
|
+
|
|
9709
9736
|
const [localData, setLocalData] = React.useState(data);
|
|
9710
9737
|
React.useEffect(() => setLocalData(data), [data]);
|
|
9711
9738
|
const listRef = React.useRef(null);
|
|
@@ -9713,14 +9740,14 @@ function Table({
|
|
|
9713
9740
|
return normalizeData(isGrouped ? localData : [], isGrouped ? [] : localData);
|
|
9714
9741
|
}, [localData, isGrouped]);
|
|
9715
9742
|
const filterRows = React.useCallback(rows => {
|
|
9716
|
-
if (!
|
|
9717
|
-
const query =
|
|
9743
|
+
if (!searchTerm) return rows;
|
|
9744
|
+
const query = searchTerm.toLowerCase();
|
|
9718
9745
|
return rows.filter(row => columns.some(col => {
|
|
9719
9746
|
const val = row[col.accessor];
|
|
9720
9747
|
if (val == null) return false;
|
|
9721
9748
|
return String(val).toLowerCase().includes(query);
|
|
9722
9749
|
}));
|
|
9723
|
-
}, [
|
|
9750
|
+
}, [searchTerm, columns]);
|
|
9724
9751
|
|
|
9725
9752
|
// Natural-ish comparator: handles nulls, numbers, strings, ISO dates
|
|
9726
9753
|
const compare = (x, y, dir = "asc") => {
|
|
@@ -9857,15 +9884,16 @@ function Table({
|
|
|
9857
9884
|
|
|
9858
9885
|
// RENDER CELL
|
|
9859
9886
|
const highlight = React.useCallback(text => {
|
|
9860
|
-
|
|
9887
|
+
// Use the actual searchTerm (from URL or prop) for highlighting
|
|
9888
|
+
if (!searchTerm || typeof text !== "string") return text;
|
|
9861
9889
|
const lower = text.toLowerCase();
|
|
9862
|
-
const query =
|
|
9890
|
+
const query = searchTerm.toLowerCase();
|
|
9863
9891
|
const idx = lower.indexOf(query);
|
|
9864
9892
|
if (idx === -1) return text;
|
|
9865
9893
|
return /*#__PURE__*/React.createElement(React.Fragment, null, text.slice(0, idx), /*#__PURE__*/React.createElement("span", {
|
|
9866
9894
|
className: "highlight"
|
|
9867
9895
|
}, text.slice(idx, idx + query.length)), text.slice(idx + query.length));
|
|
9868
|
-
}, [
|
|
9896
|
+
}, [searchTerm]);
|
|
9869
9897
|
const renderCell = React.useCallback((v, accessor) => {
|
|
9870
9898
|
if (accessor === "deadlineISO") {
|
|
9871
9899
|
return v ? new Date(v).toLocaleString("sl-SI", {
|