@xeplr/ui-table 1.1.4 → 1.1.6
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/package.json
CHANGED
|
@@ -15,14 +15,21 @@ import { createPortal } from 'react-dom';
|
|
|
15
15
|
* cannot read is a filter you cannot use.
|
|
16
16
|
*
|
|
17
17
|
* A portal has no ancestors to be clipped by. The cost is that it no longer
|
|
18
|
-
* moves with the page on its own, so
|
|
19
|
-
*
|
|
18
|
+
* moves with the page on its own, so a scroll of the page or the table moves
|
|
19
|
+
* it after its trigger (and closes it once the trigger is out of view); a
|
|
20
|
+
* scroll INSIDE the panel — its own list of values — is just reading it.
|
|
20
21
|
*
|
|
21
22
|
* @param {object} props
|
|
22
23
|
* @param {boolean} props.isActive - Whether filter is currently applied
|
|
23
24
|
* @param {React.ReactNode} props.children - Filter UI content
|
|
24
25
|
* @param {Function} props.onClear - Called when user clears the filter
|
|
25
26
|
*/
|
|
27
|
+
/** Where the panel is put: the nearest themed ancestor (class xeplr-theme-…), else <body>. */
|
|
28
|
+
function themeRoot(el) {
|
|
29
|
+
var themed = el && el.closest ? el.closest('[class*="xeplr-theme-"]') : null;
|
|
30
|
+
return themed || document.body;
|
|
31
|
+
}
|
|
32
|
+
|
|
26
33
|
export default function FilterWrapper({ isActive, children, onClear }) {
|
|
27
34
|
var [open, setOpen] = useState(false);
|
|
28
35
|
var [rect, setRect] = useState(null);
|
|
@@ -54,19 +61,29 @@ export default function FilterWrapper({ isActive, children, onClear }) {
|
|
|
54
61
|
var inPanel = panelRef.current && panelRef.current.contains(e.target);
|
|
55
62
|
if (!inTrigger && !inPanel) setOpen(false);
|
|
56
63
|
}
|
|
57
|
-
// A portalled panel does not travel with what it is anchored to, so
|
|
58
|
-
//
|
|
59
|
-
//
|
|
60
|
-
//
|
|
61
|
-
|
|
64
|
+
// A portalled panel does not travel with what it is anchored to, so a
|
|
65
|
+
// scroll moves it after its trigger. `true` catches scrolling in the
|
|
66
|
+
// TABLE, not just the window — the scroll event does not bubble, so a
|
|
67
|
+
// listener without capture never hears it. Scrolling the panel's own list
|
|
68
|
+
// is not a reason to move or close it: it used to close the panel the
|
|
69
|
+
// moment anyone scrolled down its values.
|
|
70
|
+
function handleScroll(e) {
|
|
71
|
+
if (panelRef.current && e && e.target instanceof Node && panelRef.current.contains(e.target)) return;
|
|
72
|
+
var el = wrapperRef.current;
|
|
73
|
+
if (!el) return;
|
|
74
|
+
var r = el.getBoundingClientRect();
|
|
75
|
+
// The trigger scrolled out of view: nothing left to hang from.
|
|
76
|
+
if (r.bottom < 0 || r.top > window.innerHeight || r.right < 0 || r.left > window.innerWidth) { setOpen(false); return; }
|
|
77
|
+
place();
|
|
78
|
+
}
|
|
62
79
|
|
|
63
80
|
document.addEventListener('mousedown', handleClick);
|
|
64
81
|
window.addEventListener('scroll', handleScroll, true);
|
|
65
|
-
window.addEventListener('resize',
|
|
82
|
+
window.addEventListener('resize', place);
|
|
66
83
|
return function() {
|
|
67
84
|
document.removeEventListener('mousedown', handleClick);
|
|
68
85
|
window.removeEventListener('scroll', handleScroll, true);
|
|
69
|
-
window.removeEventListener('resize',
|
|
86
|
+
window.removeEventListener('resize', place);
|
|
70
87
|
};
|
|
71
88
|
}, [open, place]);
|
|
72
89
|
|
|
@@ -94,7 +111,10 @@ export default function FilterWrapper({ isActive, children, onClear }) {
|
|
|
94
111
|
</button>
|
|
95
112
|
</div>
|
|
96
113
|
</div>,
|
|
97
|
-
|
|
114
|
+
// Inside the app's theme (@xeplr/ui-account's .xeplr-theme-* wrapper), not
|
|
115
|
+
// bare in <body>: there its --xeplr-* colours are not set and the panel
|
|
116
|
+
// fell back to this package's dark palette on a light page.
|
|
117
|
+
themeRoot(wrapperRef.current)
|
|
98
118
|
) : null;
|
|
99
119
|
|
|
100
120
|
return (
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, { useState, useMemo } from 'react';
|
|
2
2
|
import FilterWrapper from './FilterWrapper.jsx';
|
|
3
|
+
import { NONE, toggleSelection, passesString } from './stringSelection.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* Excel-like string filter: searchable multi-select of unique values + null checks.
|
|
@@ -36,14 +37,9 @@ export default function StringFilter({ column }) {
|
|
|
36
37
|
var selectedSet = new Set(currentFilter.selected);
|
|
37
38
|
var isActive = currentFilter.selected.length > 0 || currentFilter.isNull !== null;
|
|
38
39
|
|
|
40
|
+
// As the boxes read: untick one of all to hide it; after Clear All, tick to show (stringSelection).
|
|
39
41
|
function toggleValue(val) {
|
|
40
|
-
|
|
41
|
-
if (next.has(val)) {
|
|
42
|
-
next.delete(val);
|
|
43
|
-
} else {
|
|
44
|
-
next.add(val);
|
|
45
|
-
}
|
|
46
|
-
column.setFilterValue({ selected: Array.from(next), isNull: currentFilter.isNull });
|
|
42
|
+
column.setFilterValue({ selected: toggleSelection(currentFilter.selected, val, uniqueValues), isNull: currentFilter.isNull });
|
|
47
43
|
}
|
|
48
44
|
|
|
49
45
|
function selectAll() {
|
|
@@ -53,7 +49,7 @@ export default function StringFilter({ column }) {
|
|
|
53
49
|
function selectNone() {
|
|
54
50
|
// Selecting "none" means selecting all visible as the filter — i.e. show nothing
|
|
55
51
|
// Actually, set selected to a sentinel empty-but-active state
|
|
56
|
-
column.setFilterValue({ selected: [
|
|
52
|
+
column.setFilterValue({ selected: [NONE], isNull: currentFilter.isNull });
|
|
57
53
|
}
|
|
58
54
|
|
|
59
55
|
function setNullMode(mode) {
|
|
@@ -126,17 +122,5 @@ export default function StringFilter({ column }) {
|
|
|
126
122
|
* Custom filter function for string columns.
|
|
127
123
|
*/
|
|
128
124
|
export function stringFilterFn(row, columnId, filterValue) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
var val = row.getValue(columnId);
|
|
132
|
-
var isNullish = val === null || val === undefined || val === '';
|
|
133
|
-
|
|
134
|
-
// Null mode check
|
|
135
|
-
if (filterValue.isNull === true) return isNullish;
|
|
136
|
-
if (filterValue.isNull === false && isNullish) return false;
|
|
137
|
-
|
|
138
|
-
// Selected values check
|
|
139
|
-
if (filterValue.selected.length === 0) return true; // no selection = show all
|
|
140
|
-
if (filterValue.selected[0] === '__xeplr_none__') return false;
|
|
141
|
-
return filterValue.selected.includes(String(val));
|
|
125
|
+
return passesString(row.getValue(columnId), filterValue);
|
|
142
126
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
// WHAT A STRING FILTER'S TICKS MEAN — pure, so it can be tested.
|
|
2
|
+
//
|
|
3
|
+
// The filter value is { selected: string[], isNull: true|false|null }:
|
|
4
|
+
// selected [] nothing chosen: every row shows (all ticked)
|
|
5
|
+
// selected ['__xeplr_none__'] "Clear All": no row shows (none ticked)
|
|
6
|
+
// selected [a, b] only rows whose value is a or b
|
|
7
|
+
export var NONE = '__xeplr_none__';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The selection after one value's tick is toggled — as the boxes read. With
|
|
11
|
+
* everything ticked, unticking one leaves all the others; after Clear All,
|
|
12
|
+
* ticking one shows that one; ticking the last one back is "all" again.
|
|
13
|
+
* @param {string[]} selected the current selection
|
|
14
|
+
* @param {string} value the value toggled
|
|
15
|
+
* @param {string[]} all every value the column has
|
|
16
|
+
* @returns {string[]}
|
|
17
|
+
*/
|
|
18
|
+
export function toggleSelection(selected, value, all) {
|
|
19
|
+
var current = (selected || []).filter(function(v) { return v !== NONE; });
|
|
20
|
+
var everything = !selected || selected.length === 0;
|
|
21
|
+
var ticked = new Set(everything ? all : current);
|
|
22
|
+
if (ticked.has(value)) ticked.delete(value); else ticked.add(value);
|
|
23
|
+
if (ticked.size === 0) return [NONE];
|
|
24
|
+
var allTicked = all.length > 0 && all.every(function(v) { return ticked.has(v); });
|
|
25
|
+
return allTicked ? [] : Array.from(ticked);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** Whether a row's value passes a string filter. */
|
|
29
|
+
export function passesString(val, filterValue) {
|
|
30
|
+
if (!filterValue) return true;
|
|
31
|
+
var isNullish = val === null || val === undefined || val === '';
|
|
32
|
+
if (filterValue.isNull === true) return isNullish;
|
|
33
|
+
if (filterValue.isNull === false && isNullish) return false;
|
|
34
|
+
var selected = filterValue.selected || [];
|
|
35
|
+
if (selected.length === 0) return true;
|
|
36
|
+
var chosen = selected.filter(function(v) { return v !== NONE; });
|
|
37
|
+
if (!chosen.length) return false;
|
|
38
|
+
return chosen.includes(String(val));
|
|
39
|
+
}
|
package/src/xeplr-table.css
CHANGED
|
@@ -286,6 +286,8 @@
|
|
|
286
286
|
max-height: 60vh;
|
|
287
287
|
overflow: auto;
|
|
288
288
|
background: var(--xeplr-bg-tertiary, #1e1e38);
|
|
289
|
+
/* Its own text colour: it is not inside the table, so it inherits none. */
|
|
290
|
+
color: var(--xeplr-text-primary, #e0e0e0);
|
|
289
291
|
border: 1px solid var(--xeplr-border-primary, #3a3a5a);
|
|
290
292
|
border-radius: 6px;
|
|
291
293
|
box-shadow: var(--xeplr-shadow-lg, 0 8px 24px rgba(0, 0, 0, 0.4));
|