ehscan-react-components 0.1.25 → 0.1.26
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/DropDown.js
CHANGED
|
@@ -3,14 +3,12 @@ import { useEffect, useState, useRef, forwardRef, useImperativeHandle } from "re
|
|
|
3
3
|
export const DropDown = forwardRef(({ openDropDown, display, addItem, searchTerm, maxDropDownEntries }, ref) => {
|
|
4
4
|
const [position, setPosition] = useState({ top: 0, left: 0, width: 0, maxHeight: 0 });
|
|
5
5
|
const containerRef = useRef(null);
|
|
6
|
-
// Expose functions to parent
|
|
7
6
|
useImperativeHandle(ref, () => ({
|
|
8
7
|
calc: () => {
|
|
9
8
|
console.log("calc");
|
|
10
9
|
setTimeout(() => {
|
|
11
10
|
calcDropDown();
|
|
12
11
|
}, 50);
|
|
13
|
-
// parent will implement actual state change, this is just the hook
|
|
14
12
|
},
|
|
15
13
|
}));
|
|
16
14
|
const HighlightedText = ({ text, searchTerm, maxLength = 150 }) => {
|
|
@@ -26,7 +24,6 @@ export const DropDown = forwardRef(({ openDropDown, display, addItem, searchTerm
|
|
|
26
24
|
return _jsx("div", { children: text.slice(0, maxLength) });
|
|
27
25
|
}
|
|
28
26
|
const lowerText = text.toLowerCase();
|
|
29
|
-
// Find first match position
|
|
30
27
|
let firstMatchIndex = -1;
|
|
31
28
|
for (let word of searchWords) {
|
|
32
29
|
const index = lowerText.indexOf(word);
|
|
@@ -34,14 +31,12 @@ export const DropDown = forwardRef(({ openDropDown, display, addItem, searchTerm
|
|
|
34
31
|
firstMatchIndex = index;
|
|
35
32
|
}
|
|
36
33
|
}
|
|
37
|
-
// Determine slice window
|
|
38
34
|
let sliceStart = 0;
|
|
39
35
|
let sliceEnd = maxLength;
|
|
40
36
|
if (firstMatchIndex > -1) {
|
|
41
37
|
const foundWord = searchWords.find(w => lowerText.includes(w));
|
|
42
38
|
if (firstMatchIndex > -1 && foundWord) {
|
|
43
39
|
const matchEnd = firstMatchIndex + foundWord.length;
|
|
44
|
-
// const matchEnd = firstMatchIndex + searchWords.find(w => lowerText.includes(w)).length;
|
|
45
40
|
if (matchEnd > maxLength) {
|
|
46
41
|
sliceEnd = Math.min(text.length, matchEnd);
|
|
47
42
|
sliceStart = sliceEnd - maxLength;
|
|
@@ -49,7 +44,6 @@ export const DropDown = forwardRef(({ openDropDown, display, addItem, searchTerm
|
|
|
49
44
|
}
|
|
50
45
|
}
|
|
51
46
|
const displayText = text.slice(sliceStart, sliceEnd);
|
|
52
|
-
// Build a regex that matches all words
|
|
53
47
|
const highlightRegex = new RegExp(`(${searchWords.join('|')})`, 'gi');
|
|
54
48
|
const parts = displayText.split(highlightRegex);
|
|
55
49
|
return (_jsxs(_Fragment, { children: [sliceStart > 0 && '…', parts.map((part, i) => searchWords.includes(part.toLowerCase()) ? (_jsx("span", { className: "highlight-words", children: part }, i)) : (_jsx("span", { children: part }, i))), sliceEnd < text.length && '…'] }));
|
|
@@ -60,7 +54,7 @@ export const DropDown = forwardRef(({ openDropDown, display, addItem, searchTerm
|
|
|
60
54
|
const rect = containerRef.current.getBoundingClientRect();
|
|
61
55
|
const distanceToBottom = window.innerHeight - rect.bottom;
|
|
62
56
|
setPosition({
|
|
63
|
-
top: rect.bottom -
|
|
57
|
+
top: rect.bottom - 10,
|
|
64
58
|
left: rect.left,
|
|
65
59
|
width: rect.width,
|
|
66
60
|
maxHeight: distanceToBottom - 50
|
|
@@ -78,7 +72,7 @@ export const DropDown = forwardRef(({ openDropDown, display, addItem, searchTerm
|
|
|
78
72
|
calcDropDown();
|
|
79
73
|
}, 50);
|
|
80
74
|
};
|
|
81
|
-
return (_jsxs(_Fragment, { children: [_jsx("div", { className: "ext-window-dropdown-edge", ref: containerRef }), openDropDown && (_jsxs("div", { className: "ext-window-dropdown", style: {
|
|
75
|
+
return (_jsxs(_Fragment, { children: [_jsx("div", { className: "ext-window-dropdown-edge", ref: containerRef }), openDropDown && display.length > 0 && (_jsxs("div", { className: "ext-window-dropdown", style: {
|
|
82
76
|
top: position.top,
|
|
83
77
|
left: position.left,
|
|
84
78
|
width: position.width
|
|
@@ -295,6 +295,7 @@ input:-webkit-autofill:active {
|
|
|
295
295
|
text-align: end;
|
|
296
296
|
font-size: 80%;
|
|
297
297
|
font-weight: 600;
|
|
298
|
+
border-radius: var(--ext-dropdown-border-radius) var(--ext-dropdown-border-radius) 0 0;
|
|
298
299
|
}
|
|
299
300
|
|
|
300
301
|
.textarea-tag.input {
|
|
@@ -325,7 +326,6 @@ input:-webkit-autofill:active {
|
|
|
325
326
|
grid-template-columns: 1fr auto;
|
|
326
327
|
align-items: center;
|
|
327
328
|
justify-content: center;
|
|
328
|
-
gap: 10px;
|
|
329
329
|
}
|
|
330
330
|
|
|
331
331
|
.search-x-input {
|