@gpa-gemstone/react-forms 1.1.110 → 1.1.112
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/lib/SearchableSelect.js +15 -0
- package/lib/StylableSelect.d.ts +2 -0
- package/lib/StylableSelect.js +15 -13
- package/lib/ToolTip.js +46 -9
- package/package.json +3 -3
package/lib/SearchableSelect.js
CHANGED
|
@@ -21,6 +21,17 @@
|
|
|
21
21
|
// Generated original version of source code.
|
|
22
22
|
//
|
|
23
23
|
// ******************************************************************************************************
|
|
24
|
+
var __assign = (this && this.__assign) || function () {
|
|
25
|
+
__assign = Object.assign || function(t) {
|
|
26
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
27
|
+
s = arguments[i];
|
|
28
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
29
|
+
t[p] = s[p];
|
|
30
|
+
}
|
|
31
|
+
return t;
|
|
32
|
+
};
|
|
33
|
+
return __assign.apply(this, arguments);
|
|
34
|
+
};
|
|
24
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
36
|
exports.default = SearchableSelect;
|
|
26
37
|
var React = require("react");
|
|
@@ -98,6 +109,10 @@ function SearchableSelect(props) {
|
|
|
98
109
|
ops.push({ Value: search, Element: React.createElement(React.Fragment, null,
|
|
99
110
|
search,
|
|
100
111
|
" (Entered Value)"), Label: search });
|
|
112
|
+
//Ensure selectedOption is always at top of the list
|
|
113
|
+
var selected = searchOptions.find(function (f) { return f.Value === props.Record[props.Field]; });
|
|
114
|
+
if (selected != null)
|
|
115
|
+
ops.push(__assign(__assign({}, selected), { RowClass: 'table-primary' }));
|
|
101
116
|
ops.push.apply(ops, searchOptions.filter(function (f) { return f.Value !== search && f.Value !== props.Record[props.Field]; }));
|
|
102
117
|
return ops;
|
|
103
118
|
}, [search, props.Record[props.Field], props.Field, searchOptions, props.Disabled, loading, props.Valid, handleSetSearch]);
|
package/lib/StylableSelect.d.ts
CHANGED
package/lib/StylableSelect.js
CHANGED
|
@@ -42,16 +42,16 @@ var react_portal_1 = require("react-portal");
|
|
|
42
42
|
var _ = require("lodash");
|
|
43
43
|
var gpa_symbols_1 = require("@gpa-gemstone/gpa-symbols");
|
|
44
44
|
function StylableSelect(props) {
|
|
45
|
-
var _a, _b, _c;
|
|
45
|
+
var _a, _b, _c, _d;
|
|
46
46
|
// State hooks and ref for managing component state and interactions.
|
|
47
47
|
var stylableSelect = React.useRef(null);
|
|
48
48
|
var selectTable = React.useRef(null);
|
|
49
49
|
var tableContainer = React.useRef(null);
|
|
50
|
-
var
|
|
51
|
-
var
|
|
52
|
-
var
|
|
53
|
-
var
|
|
54
|
-
var
|
|
50
|
+
var _e = React.useState(false), show = _e[0], setShow = _e[1];
|
|
51
|
+
var _f = React.useState(0), selectedOptionIndex = _f[0], setSelectedOptionIndex = _f[1];
|
|
52
|
+
var _g = React.useState(""), guid = _g[0], setGuid = _g[1];
|
|
53
|
+
var _h = React.useState(false), showHelp = _h[0], setShowHelp = _h[1];
|
|
54
|
+
var _j = React.useState({ Top: 0, Left: 0, Width: 0, Height: 0 }), position = _j[0], setPosition = _j[1];
|
|
55
55
|
React.useLayoutEffect(function () {
|
|
56
56
|
var updatePosition = _.debounce(function () {
|
|
57
57
|
if (stylableSelect.current != null) {
|
|
@@ -102,7 +102,7 @@ function StylableSelect(props) {
|
|
|
102
102
|
}, [props.Disabled, show]);
|
|
103
103
|
// Update the parent component's state with the selected option.
|
|
104
104
|
function SetRecord(selectedOption) {
|
|
105
|
-
|
|
105
|
+
setSelectedOptionIndex(props.Options.findIndex(function (e) { return (0, lodash_1.isEqual)(e.Value, selectedOption.Value); }));
|
|
106
106
|
var record = __assign({}, props.Record);
|
|
107
107
|
if (selectedOption.Value !== '')
|
|
108
108
|
record[props.Field] = selectedOption.Value;
|
|
@@ -120,8 +120,8 @@ function StylableSelect(props) {
|
|
|
120
120
|
}, [HandleShow]);
|
|
121
121
|
// Effect to handle changes to the record's field value.
|
|
122
122
|
React.useEffect(function () {
|
|
123
|
-
var
|
|
124
|
-
|
|
123
|
+
var elementIndex = props.Options.findIndex(function (e) { return (0, lodash_1.isEqual)(e.Value, props.Record[props.Field]); });
|
|
124
|
+
setSelectedOptionIndex(elementIndex !== -1 ? elementIndex : 0);
|
|
125
125
|
}, [props.Record, props.Options]);
|
|
126
126
|
var handleOptionClick = function (evt, option) {
|
|
127
127
|
SetRecord(option);
|
|
@@ -142,7 +142,7 @@ function StylableSelect(props) {
|
|
|
142
142
|
React.createElement(ToolTip_1.default, { Show: showHelp, Target: guid, Class: "info", Position: "top" }, props.Help)
|
|
143
143
|
: null,
|
|
144
144
|
React.createElement("button", { type: "button", style: __assign({ padding: '.375rem .75rem' }, ((_a = props.BtnStyle) !== null && _a !== void 0 ? _a : {})), className: "dropdown-toggle form-control ".concat(((_c = (_b = props.Valid) === null || _b === void 0 ? void 0 : _b.call(props, props.Field)) !== null && _c !== void 0 ? _c : true) ? '' : 'is-invalid'), onClick: HandleShow, disabled: props.Disabled === undefined ? false : props.Disabled },
|
|
145
|
-
React.createElement("div", { style: props.Style },
|
|
145
|
+
React.createElement("div", { style: props.Style }, (_d = props.Options[selectedOptionIndex]) === null || _d === void 0 ? void 0 : _d.Element)),
|
|
146
146
|
React.createElement("div", { className: "invalid-feedback" }, props.Feedback == null ? props.Field.toString() + ' is a required field.' : props.Feedback),
|
|
147
147
|
React.createElement(react_portal_1.Portal, null,
|
|
148
148
|
React.createElement("div", { ref: tableContainer, className: 'popover', style: {
|
|
@@ -158,7 +158,9 @@ function StylableSelect(props) {
|
|
|
158
158
|
maxWidth: '100%'
|
|
159
159
|
} },
|
|
160
160
|
React.createElement("table", { className: "table table-hover", style: { margin: 0 }, ref: selectTable },
|
|
161
|
-
React.createElement("tbody", null, props.Options.map(function (f, i) {
|
|
162
|
-
|
|
163
|
-
|
|
161
|
+
React.createElement("tbody", null, props.Options.map(function (f, i) {
|
|
162
|
+
var _a;
|
|
163
|
+
return i === selectedOptionIndex ? null : ((React.createElement("tr", { key: "".concat(i, "-").concat(JSON.stringify(f.Value)), className: (_a = f.RowClass) !== null && _a !== void 0 ? _a : '', style: f.RowStyle, onMouseDown: function (evt) { return handleOptionClick(evt, f); } },
|
|
164
|
+
React.createElement("td", null, f.Element))));
|
|
165
|
+
})))))));
|
|
164
166
|
}
|
package/lib/ToolTip.js
CHANGED
|
@@ -86,6 +86,7 @@ var Tooltip = function (props) {
|
|
|
86
86
|
closeTimer.current = window.setTimeout(function () { return setDelayedShow(false); }, 250);
|
|
87
87
|
}
|
|
88
88
|
}, [props.Show, isTooltipHovered]);
|
|
89
|
+
//Effect to get colors from alert class
|
|
89
90
|
React.useLayoutEffect(function () {
|
|
90
91
|
if (alertRef.current == null)
|
|
91
92
|
return;
|
|
@@ -93,17 +94,49 @@ var Tooltip = function (props) {
|
|
|
93
94
|
setBackgroundColor(style.backgroundColor);
|
|
94
95
|
setColor(style.color);
|
|
95
96
|
});
|
|
97
|
+
//effect to get target element position
|
|
96
98
|
React.useEffect(function () {
|
|
97
|
-
var
|
|
98
|
-
|
|
99
|
-
|
|
99
|
+
var updateTargetPosition = function () {
|
|
100
|
+
var target = getTarget(props.Target);
|
|
101
|
+
if (target == null) {
|
|
102
|
+
setTargetElementPosition(defaultTargetPosition);
|
|
103
|
+
setDelayedShow(false);
|
|
104
|
+
setIsTooltipHovered(false);
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
var targetLocation = (0, helper_functions_1.GetNodeSize)(target);
|
|
108
|
+
var newPosition = {
|
|
109
|
+
Height: targetLocation.height,
|
|
110
|
+
Top: targetLocation.top,
|
|
111
|
+
Left: targetLocation.left,
|
|
112
|
+
Width: targetLocation.width
|
|
113
|
+
};
|
|
114
|
+
setTargetElementPosition(function (prev) {
|
|
115
|
+
if (!(0, lodash_1.isEqual)(newPosition, prev))
|
|
116
|
+
return newPosition;
|
|
117
|
+
return prev;
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
// Initial position calculation
|
|
121
|
+
updateTargetPosition();
|
|
122
|
+
// Only set up observers when tooltip is visible
|
|
123
|
+
if (!shouldShow)
|
|
100
124
|
return;
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
125
|
+
var target = getTarget(props.Target);
|
|
126
|
+
if (target == null)
|
|
127
|
+
return;
|
|
128
|
+
window.addEventListener('scroll', updateTargetPosition, true);
|
|
129
|
+
window.addEventListener('resize', updateTargetPosition);
|
|
130
|
+
var resizeObserver = new ResizeObserver(updateTargetPosition);
|
|
131
|
+
resizeObserver.observe(document.body);
|
|
132
|
+
resizeObserver.observe(target);
|
|
133
|
+
return function () {
|
|
134
|
+
window.removeEventListener('scroll', updateTargetPosition, true);
|
|
135
|
+
window.removeEventListener('resize', updateTargetPosition);
|
|
136
|
+
resizeObserver.disconnect();
|
|
137
|
+
};
|
|
138
|
+
}, [shouldShow, props.Target]);
|
|
139
|
+
//Effect to position tooltip
|
|
107
140
|
React.useLayoutEffect(function () {
|
|
108
141
|
var _a = getPosition(toolTip, targetElementPosition, targetPosition), t = _a[0], l = _a[1], arrowLeft = _a[2], actPosition = _a[3];
|
|
109
142
|
setTop(t);
|
|
@@ -185,5 +218,9 @@ var getPosition = function (toolTip, targetPosition, position) {
|
|
|
185
218
|
}
|
|
186
219
|
return [top, left, arrowPositionPercent, effectivePosition];
|
|
187
220
|
};
|
|
221
|
+
var getTarget = function (target) {
|
|
222
|
+
var targets = document.querySelectorAll("[data-tooltip".concat(target === undefined ? '' : "=\"".concat(target, "\""), "]"));
|
|
223
|
+
return targets.length > 0 ? targets[0] : null;
|
|
224
|
+
};
|
|
188
225
|
exports.default = exports.Tooltip;
|
|
189
226
|
var templateObject_1, templateObject_2;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gpa-gemstone/react-forms",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.112",
|
|
4
4
|
"description": "React Form modules for gpa webapps",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -45,9 +45,9 @@
|
|
|
45
45
|
"typescript": "5.5.3"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@gpa-gemstone/application-typings": "0.0.
|
|
48
|
+
"@gpa-gemstone/application-typings": "0.0.96",
|
|
49
49
|
"@gpa-gemstone/gpa-symbols": "0.0.59",
|
|
50
|
-
"@gpa-gemstone/helper-functions": "0.0.
|
|
50
|
+
"@gpa-gemstone/helper-functions": "0.0.55",
|
|
51
51
|
"@types/react": "^17.0.14",
|
|
52
52
|
"@types/styled-components": "^5.1.11",
|
|
53
53
|
"lodash": "^4.17.21",
|