allaw-ui 0.1.58 → 0.1.60
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.
|
@@ -44,11 +44,14 @@
|
|
|
44
44
|
}
|
|
45
45
|
|
|
46
46
|
.select-list {
|
|
47
|
-
|
|
47
|
+
position: absolute;
|
|
48
|
+
top: 100%;
|
|
49
|
+
left: 0;
|
|
50
|
+
right: 0;
|
|
51
|
+
display: flex;
|
|
48
52
|
flex-direction: column;
|
|
49
53
|
background: var(--secondary-light-grey, #f4f7fb);
|
|
50
54
|
border-radius: 8px;
|
|
51
|
-
margin-top: 8px;
|
|
52
55
|
padding: 8px 0;
|
|
53
56
|
color: var(--Primary-Mid-black, var(--primary-black, #171e25));
|
|
54
57
|
font-family: "Open Sans";
|
|
@@ -56,23 +59,14 @@
|
|
|
56
59
|
font-style: normal;
|
|
57
60
|
font-weight: 500;
|
|
58
61
|
line-height: normal;
|
|
59
|
-
max-height:
|
|
62
|
+
max-height: 300px;
|
|
60
63
|
overflow-y: auto;
|
|
61
|
-
|
|
62
|
-
top: 100%;
|
|
63
|
-
left: 0;
|
|
64
|
-
z-index: 1000;
|
|
64
|
+
z-index: 9999;
|
|
65
65
|
border: 1px solid var(--grey-venom, #e6edf5);
|
|
66
66
|
box-shadow: 0px 4px 8px 0px rgba(9, 30, 66, 0.15);
|
|
67
67
|
scroll-behavior: auto;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
.select-pressed .select-list {
|
|
71
|
-
display: flex;
|
|
72
|
-
opacity: 1;
|
|
73
|
-
transform: translateY(0) scale(1);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
70
|
.select-item {
|
|
77
71
|
display: flex;
|
|
78
72
|
align-items: center;
|
|
@@ -8,6 +8,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
8
8
|
return to.concat(ar || Array.prototype.slice.call(from));
|
|
9
9
|
};
|
|
10
10
|
import React, { useState, useEffect, useRef, useImperativeHandle, forwardRef, } from "react";
|
|
11
|
+
import ReactDOM from "react-dom";
|
|
11
12
|
import "./Select.css";
|
|
12
13
|
import "../../../styles/global.css";
|
|
13
14
|
import TinyInfo from "../typography/TinyInfo";
|
|
@@ -19,6 +20,11 @@ function Select(_a, ref) {
|
|
|
19
20
|
var _k = useState(""), error = _k[0], setError = _k[1];
|
|
20
21
|
var selectRef = useRef(null);
|
|
21
22
|
var listRef = useRef(null);
|
|
23
|
+
var _l = useState({
|
|
24
|
+
top: 0,
|
|
25
|
+
left: 0,
|
|
26
|
+
width: 0,
|
|
27
|
+
}), listPosition = _l[0], setListPosition = _l[1];
|
|
22
28
|
useEffect(function () {
|
|
23
29
|
setSelected((multiple ? selectedItem || [] : selectedItem || ""));
|
|
24
30
|
}, [selectedItem, multiple]);
|
|
@@ -57,21 +63,50 @@ function Select(_a, ref) {
|
|
|
57
63
|
onError === null || onError === void 0 ? void 0 : onError(errorMessage);
|
|
58
64
|
return !errorMessage;
|
|
59
65
|
};
|
|
66
|
+
var updateListPosition = function () {
|
|
67
|
+
if (selectRef.current) {
|
|
68
|
+
var rect = selectRef.current.getBoundingClientRect();
|
|
69
|
+
setListPosition({
|
|
70
|
+
top: rect.bottom + window.scrollY,
|
|
71
|
+
left: rect.left + window.scrollX,
|
|
72
|
+
width: rect.width,
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
};
|
|
60
76
|
var toggleOpen = function () {
|
|
77
|
+
if (!isOpen) {
|
|
78
|
+
updateListPosition();
|
|
79
|
+
}
|
|
61
80
|
setIsOpen(!isOpen);
|
|
62
81
|
};
|
|
63
82
|
var handleClickOutside = function (event) {
|
|
64
83
|
if (selectRef.current &&
|
|
65
|
-
!selectRef.current.contains(event.target)
|
|
84
|
+
!selectRef.current.contains(event.target) &&
|
|
85
|
+
listRef.current &&
|
|
86
|
+
!listRef.current.contains(event.target)) {
|
|
66
87
|
setIsOpen(false);
|
|
67
88
|
}
|
|
68
89
|
};
|
|
69
90
|
useEffect(function () {
|
|
70
|
-
|
|
91
|
+
if (isOpen) {
|
|
92
|
+
document.addEventListener("mousedown", handleClickOutside);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
document.removeEventListener("mousedown", handleClickOutside);
|
|
96
|
+
}
|
|
71
97
|
return function () {
|
|
72
98
|
document.removeEventListener("mousedown", handleClickOutside);
|
|
73
99
|
};
|
|
74
|
-
}, []);
|
|
100
|
+
}, [isOpen]);
|
|
101
|
+
var renderList = function () { return (React.createElement("div", { ref: listRef, className: "select-list ".concat(isOpen ? "visible" : ""), style: {
|
|
102
|
+
top: "".concat(listPosition.top, "px"),
|
|
103
|
+
left: "".concat(listPosition.left, "px"),
|
|
104
|
+
width: "".concat(listPosition.width, "px"),
|
|
105
|
+
} }, items.map(function (item) { return (React.createElement("div", { key: item.value, "data-value": item.value, className: "select-item ".concat(Array.isArray(selected) && selected.includes(item.value)
|
|
106
|
+
? "selected"
|
|
107
|
+
: "", " ").concat(!multiple && item.value === selectedItem ? "highlighted" : "", " ").concat(!multiple ? "single-select" : ""), onClick: function () { return handleSelect(item); } },
|
|
108
|
+
multiple && React.createElement("span", { className: "select-item-icon allaw-icon-check" }),
|
|
109
|
+
React.createElement("span", { className: "select-item-text" }, item.label))); }))); };
|
|
75
110
|
useImperativeHandle(ref, function () { return ({
|
|
76
111
|
validate: function () { return validateSelect(selected); },
|
|
77
112
|
}); });
|
|
@@ -85,11 +120,7 @@ function Select(_a, ref) {
|
|
|
85
120
|
? (_b = items.find(function (item) { return item.value === selected; })) === null || _b === void 0 ? void 0 : _b.label
|
|
86
121
|
: placeholder),
|
|
87
122
|
React.createElement("span", { className: "select-icon ".concat(isOpen ? "allaw-icon-chevron-up" : "allaw-icon-chevron-down") })),
|
|
88
|
-
isOpen &&
|
|
89
|
-
? "selected"
|
|
90
|
-
: "", " ").concat(!multiple && item.value === selectedItem ? "highlighted" : "", " ").concat(!multiple ? "single-select" : ""), onClick: function () { return handleSelect(item); } },
|
|
91
|
-
multiple && (React.createElement("span", { className: "select-item-icon allaw-icon-check" })),
|
|
92
|
-
React.createElement("span", { className: "select-item-text" }, item.label))); }))),
|
|
123
|
+
isOpen && ReactDOM.createPortal(renderList(), document.body),
|
|
93
124
|
isRequired && showError && error && (React.createElement("div", { className: "error-message" },
|
|
94
125
|
React.createElement(TinyInfo, { variant: "medium12", color: "actions-error", text: error })))));
|
|
95
126
|
}
|