@gpa-gemstone/react-forms 1.1.111 → 1.1.113
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/AutoCompleteInput.d.ts +24 -0
- package/lib/AutoCompleteInput.js +214 -0
- package/lib/AutoCompleteTextArea.d.ts +6 -0
- package/lib/AutoCompleteTextArea.js +151 -0
- package/lib/CheckBox.d.ts +2 -1
- package/lib/CheckBox.js +7 -20
- package/lib/ColorPicker.d.ts +2 -2
- package/lib/ColorPicker.js +13 -18
- package/lib/DateTimeUI/DateTimePicker.js +8 -15
- package/lib/HelpIcon.d.ts +29 -0
- package/lib/HelpIcon.js +44 -0
- package/lib/Input.d.ts +7 -2
- package/lib/Input.js +5 -17
- package/lib/InputWithButton.js +5 -18
- package/lib/MultiInput.js +9 -18
- package/lib/MultiSearchableSelect.js +9 -18
- package/lib/MutliCheckBoxSelect.js +5 -14
- package/lib/RadioButtons.js +2 -13
- package/lib/SearchableSelect.js +15 -0
- package/lib/Select.js +3 -12
- package/lib/StylableSelect.d.ts +2 -0
- package/lib/StylableSelect.js +18 -22
- package/lib/TextArea.d.ts +14 -2
- package/lib/TextArea.js +7 -12
- package/lib/TimePicker.js +3 -10
- package/lib/ToggleSwitch.js +2 -11
- package/lib/index.d.ts +4 -1
- package/lib/index.js +7 -1
- package/package.json +1 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { IProps as IInputProps } from './Input';
|
|
2
|
+
interface IProps<T> extends Omit<IInputProps<T>, 'Type'> {
|
|
3
|
+
Options: string[];
|
|
4
|
+
}
|
|
5
|
+
export interface IVariable {
|
|
6
|
+
Start: number;
|
|
7
|
+
End: number;
|
|
8
|
+
Variable: string | null;
|
|
9
|
+
}
|
|
10
|
+
export default function AutoCompleteInput<T>(props: IProps<T>): JSX.Element;
|
|
11
|
+
export declare const getSuggestions: (variable: IVariable, text: string, options: string[]) => {
|
|
12
|
+
Label: string;
|
|
13
|
+
Value: string;
|
|
14
|
+
}[];
|
|
15
|
+
export declare const getCurrentVariable: (text: string, selection: number) => {
|
|
16
|
+
Start: number;
|
|
17
|
+
End: number;
|
|
18
|
+
Variable: null;
|
|
19
|
+
} | {
|
|
20
|
+
Start: number;
|
|
21
|
+
End: number;
|
|
22
|
+
Variable: string;
|
|
23
|
+
};
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ******************************************************************************************************
|
|
3
|
+
// AutoCompleteInput.tsx - Gbtc
|
|
4
|
+
//
|
|
5
|
+
// Copyright © 2024, Grid Protection Alliance. All Rights Reserved.
|
|
6
|
+
//
|
|
7
|
+
// Licensed to the Grid Protection Alliance (GPA) under one or more contributor license agreements. See
|
|
8
|
+
// the NOTICE file distributed with this work for additional information regarding copyright ownership.
|
|
9
|
+
// The GPA licenses this file to you under the MIT License (MIT), the "License"; you may not use this
|
|
10
|
+
// file except in compliance with the License. You may obtain a copy of the License at:
|
|
11
|
+
//
|
|
12
|
+
// http://opensource.org/licenses/MIT
|
|
13
|
+
//
|
|
14
|
+
// Unless agreed to in writing, the subject software distributed under the License is distributed on an
|
|
15
|
+
// "AS-IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. Refer to the
|
|
16
|
+
// License for the specific language governing permissions and limitations.
|
|
17
|
+
//
|
|
18
|
+
// Code Modification History:
|
|
19
|
+
// ----------------------------------------------------------------------------------------------------
|
|
20
|
+
// 01/21/2026 - Natalie Beatty
|
|
21
|
+
// Generated original version of source code.
|
|
22
|
+
//
|
|
23
|
+
// ******************************************************************************************************
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.getCurrentVariable = exports.getSuggestions = void 0;
|
|
26
|
+
exports.default = AutoCompleteInput;
|
|
27
|
+
var React = require("react");
|
|
28
|
+
var Input_1 = require("./Input");
|
|
29
|
+
var react_portal_1 = require("react-portal");
|
|
30
|
+
var _ = require("lodash");
|
|
31
|
+
function AutoCompleteInput(props) {
|
|
32
|
+
var autoCompleteInput = React.useRef(null);
|
|
33
|
+
var inputElement = React.useRef(null);
|
|
34
|
+
var tableContainer = React.useRef(null);
|
|
35
|
+
var selectTable = React.useRef(null);
|
|
36
|
+
var _a = React.useState([]), suggestions = _a[0], setSuggestions = _a[1];
|
|
37
|
+
var _b = React.useState(null), position = _b[0], setPosition = _b[1];
|
|
38
|
+
var _c = React.useState(true), show = _c[0], setShow = _c[1];
|
|
39
|
+
// Handle showing and hiding of the dropdown.
|
|
40
|
+
var HandleShow = React.useCallback(function (evt) {
|
|
41
|
+
var _a;
|
|
42
|
+
// Ignore if disabled or not a mousedown event
|
|
43
|
+
if ((props.Disabled === undefined ? false : props.Disabled)
|
|
44
|
+
|| evt.type !== 'mousedown') {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
//ignore the click if it was inside the table or table container
|
|
48
|
+
if ((selectTable.current != null && selectTable.current.contains(evt.target)) || (tableContainer.current != null && tableContainer.current.contains(evt.target))) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (inputElement.current !== null && !((_a = inputElement.current) === null || _a === void 0 ? void 0 : _a.contains(evt.target))) {
|
|
52
|
+
setShow(false);
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
setShow(true);
|
|
56
|
+
}
|
|
57
|
+
}, [props.Disabled]);
|
|
58
|
+
// update dropdown position
|
|
59
|
+
React.useLayoutEffect(function () {
|
|
60
|
+
if ((suggestions === null || suggestions === void 0 ? void 0 : suggestions.length) == 0) {
|
|
61
|
+
setPosition(null);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
var updatePosition = _.debounce(function () {
|
|
65
|
+
if (inputElement.current == null) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
var rect = inputElement.current.getBoundingClientRect();
|
|
69
|
+
setPosition({ Top: rect.bottom, Left: rect.left, Width: rect.width, Height: rect.height });
|
|
70
|
+
}, 200);
|
|
71
|
+
var handleScroll = function () {
|
|
72
|
+
if (tableContainer.current == null)
|
|
73
|
+
return;
|
|
74
|
+
updatePosition();
|
|
75
|
+
};
|
|
76
|
+
updatePosition();
|
|
77
|
+
window.addEventListener('scroll', handleScroll, true);
|
|
78
|
+
window.addEventListener('resize', updatePosition);
|
|
79
|
+
return function () {
|
|
80
|
+
window.removeEventListener('scroll', handleScroll, true);
|
|
81
|
+
window.removeEventListener('resize', updatePosition);
|
|
82
|
+
updatePosition.cancel();
|
|
83
|
+
};
|
|
84
|
+
}, [suggestions]);
|
|
85
|
+
// listen for changes in input caret position
|
|
86
|
+
React.useEffect(function () {
|
|
87
|
+
var autoComplete = inputElement.current;
|
|
88
|
+
if (autoComplete == null)
|
|
89
|
+
return;
|
|
90
|
+
autoComplete.addEventListener("keyup", handleCaretPosition);
|
|
91
|
+
autoComplete.addEventListener("click", handleCaretPosition);
|
|
92
|
+
window.addEventListener('mousedown', HandleShow, false);
|
|
93
|
+
return function () {
|
|
94
|
+
autoComplete.removeEventListener("keyup", handleCaretPosition);
|
|
95
|
+
autoComplete.removeEventListener("click", handleCaretPosition);
|
|
96
|
+
window.removeEventListener('mousedown', HandleShow, false);
|
|
97
|
+
};
|
|
98
|
+
}, [HandleShow]);
|
|
99
|
+
// edit input text when suggestion is selected
|
|
100
|
+
var handleOptionClick = function (option) {
|
|
101
|
+
var _a, _b, _c, _d, _e;
|
|
102
|
+
if (inputElement.current == null)
|
|
103
|
+
return;
|
|
104
|
+
var currentPos = (_a = inputElement.current.selectionStart) !== null && _a !== void 0 ? _a : 0;
|
|
105
|
+
var optionLength = option.Value.length;
|
|
106
|
+
props.Record[props.Field] = option.Value;
|
|
107
|
+
props.Setter(props.Record);
|
|
108
|
+
var textLength = (_c = (_b = inputElement.current.textContent) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0;
|
|
109
|
+
var newCaretPos = (optionLength > textLength ? textLength - 1 : optionLength + currentPos);
|
|
110
|
+
(_d = inputElement.current) === null || _d === void 0 ? void 0 : _d.focus();
|
|
111
|
+
(_e = inputElement.current) === null || _e === void 0 ? void 0 : _e.setSelectionRange(newCaretPos, newCaretPos);
|
|
112
|
+
setSuggestions([]);
|
|
113
|
+
};
|
|
114
|
+
// update variable when caret position changes
|
|
115
|
+
var handleCaretPosition = function () {
|
|
116
|
+
var _a, _b, _c, _d, _e;
|
|
117
|
+
if (inputElement.current !== null) {
|
|
118
|
+
var selection = ((_a = inputElement.current.selectionStart) !== null && _a !== void 0 ? _a : 0);
|
|
119
|
+
var variable = (0, exports.getCurrentVariable)((_c = (_b = inputElement.current) === null || _b === void 0 ? void 0 : _b.getAttribute('value')) !== null && _c !== void 0 ? _c : "", selection);
|
|
120
|
+
var suggests = (0, exports.getSuggestions)(variable, (_e = (_d = inputElement.current) === null || _d === void 0 ? void 0 : _d.getAttribute('value')) !== null && _e !== void 0 ? _e : "", props.Options);
|
|
121
|
+
setSuggestions(suggests);
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
return (React.createElement("div", { ref: autoCompleteInput },
|
|
125
|
+
React.createElement(Input_1.default, { Valid: props.Valid, Record: props.Record, Setter: props.Setter, Field: props.Field, Feedback: props.Feedback, Style: props.Style, AllowNull: props.AllowNull, Size: props.Size, DefaultValue: props.DefaultValue, InputRef: inputElement }),
|
|
126
|
+
position == null || !show ? null :
|
|
127
|
+
React.createElement(react_portal_1.Portal, null,
|
|
128
|
+
React.createElement("div", { ref: tableContainer, className: 'popover', style: {
|
|
129
|
+
maxHeight: window.innerHeight - position.Top,
|
|
130
|
+
overflowY: 'auto',
|
|
131
|
+
padding: '10 5',
|
|
132
|
+
display: 'block',
|
|
133
|
+
position: 'absolute',
|
|
134
|
+
zIndex: 9999,
|
|
135
|
+
top: "".concat(position.Top, "px"),
|
|
136
|
+
left: "".concat(position.Left, "px"),
|
|
137
|
+
minWidth: "".concat(position.Width, "px"),
|
|
138
|
+
maxWidth: '100%'
|
|
139
|
+
} },
|
|
140
|
+
React.createElement("table", { className: "table table-hover", style: { margin: 0 }, ref: selectTable },
|
|
141
|
+
React.createElement("tbody", null, suggestions.map(function (f, i) { return (f.Value === props.Record[props.Field] ? null :
|
|
142
|
+
React.createElement("tr", { key: i, onMouseDown: function (_) { return handleOptionClick(f); } },
|
|
143
|
+
React.createElement("td", null, f.Label))); })))))));
|
|
144
|
+
}
|
|
145
|
+
var getSuggestions = function (variable, text, options) {
|
|
146
|
+
if (!(variable.Variable != null)) {
|
|
147
|
+
return [];
|
|
148
|
+
}
|
|
149
|
+
// if variable is valid option and hasEndBracket, assume it doesn't need autocompletion.
|
|
150
|
+
if (options.includes(variable.Variable)) {
|
|
151
|
+
return [];
|
|
152
|
+
}
|
|
153
|
+
if (text === "") {
|
|
154
|
+
return [];
|
|
155
|
+
}
|
|
156
|
+
// Find suggestions for the variable
|
|
157
|
+
var possibleVariables = options.filter(function (v) { var _a; return v.toLowerCase().includes(((_a = variable.Variable) !== null && _a !== void 0 ? _a : "").toLowerCase()); });
|
|
158
|
+
var before = text.substring(0, (variable.Start) - 1);
|
|
159
|
+
var after = text.substring(variable.End);
|
|
160
|
+
var hasEndBracket = (text[variable.End] === '}');
|
|
161
|
+
// Generate suggestions
|
|
162
|
+
var suggestions = possibleVariables.map(function (pv) {
|
|
163
|
+
// Ensure we have braces around the variable and add closing '}' if it was missing
|
|
164
|
+
var variableWithBraces = hasEndBracket ? "{".concat(pv) : "{".concat(pv, "}");
|
|
165
|
+
return { Label: "".concat(variableWithBraces).concat(hasEndBracket ? '}' : ''), Value: "".concat(before).concat(variableWithBraces).concat(after) };
|
|
166
|
+
});
|
|
167
|
+
return suggestions;
|
|
168
|
+
};
|
|
169
|
+
exports.getSuggestions = getSuggestions;
|
|
170
|
+
var getCurrentVariable = function (text, selection) {
|
|
171
|
+
var thisVariable = {
|
|
172
|
+
Start: 0,
|
|
173
|
+
End: 0,
|
|
174
|
+
Variable: null
|
|
175
|
+
};
|
|
176
|
+
if (text === "") {
|
|
177
|
+
return thisVariable;
|
|
178
|
+
}
|
|
179
|
+
// easy returns if selection start could not have a curly bracket before it
|
|
180
|
+
if (selection === null || selection < 0 || selection > text.length) {
|
|
181
|
+
return thisVariable;
|
|
182
|
+
}
|
|
183
|
+
// check backwards from the caret to find the nearest open curly bracket or space
|
|
184
|
+
var start = selection;
|
|
185
|
+
while (start > 0) {
|
|
186
|
+
// check for open curly bracket. if found, assign and break as start of valid variable expression
|
|
187
|
+
if (/{/g.test(text[start - 1])) {
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
// if space is encountered first, return
|
|
191
|
+
if (/[\s}]/g.test(text[start - 1])) {
|
|
192
|
+
return thisVariable;
|
|
193
|
+
}
|
|
194
|
+
start--;
|
|
195
|
+
}
|
|
196
|
+
// if no variable found, return
|
|
197
|
+
if (start == 0) {
|
|
198
|
+
return thisVariable;
|
|
199
|
+
}
|
|
200
|
+
thisVariable.Start = start;
|
|
201
|
+
// then, get the rest of the word.
|
|
202
|
+
var end = start !== null && start !== void 0 ? start : 0;
|
|
203
|
+
while (end < text.length) {
|
|
204
|
+
if (/[}{\s}]/.test(text[end])) {
|
|
205
|
+
break;
|
|
206
|
+
}
|
|
207
|
+
end++;
|
|
208
|
+
}
|
|
209
|
+
thisVariable.End = end;
|
|
210
|
+
// get variable as substring of text
|
|
211
|
+
var variable = text.substring(start, end);
|
|
212
|
+
return { Start: thisVariable.Start, End: thisVariable.End, Variable: variable };
|
|
213
|
+
};
|
|
214
|
+
exports.getCurrentVariable = getCurrentVariable;
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.default = AutoCompleteTextArea;
|
|
4
|
+
var React = require("react");
|
|
5
|
+
var TextArea_1 = require("./TextArea");
|
|
6
|
+
var react_portal_1 = require("react-portal");
|
|
7
|
+
var _ = require("lodash");
|
|
8
|
+
var AutoCompleteInput_1 = require("./AutoCompleteInput");
|
|
9
|
+
function AutoCompleteTextArea(props) {
|
|
10
|
+
var autoCompleteTextArea = React.useRef(null);
|
|
11
|
+
var tableContainer = React.useRef(null);
|
|
12
|
+
var selectTable = React.useRef(null);
|
|
13
|
+
var textAreaElement = React.useRef(null);
|
|
14
|
+
var _a = React.useState([]), suggestions = _a[0], setSuggestions = _a[1];
|
|
15
|
+
var _b = React.useState(null), position = _b[0], setPosition = _b[1];
|
|
16
|
+
var _c = React.useState({ Start: 0, End: 0, Variable: "" }), variable = _c[0], setVariable = _c[1];
|
|
17
|
+
var _d = React.useState(true), show = _d[0], setShow = _d[1];
|
|
18
|
+
// Handle showing and hiding of the dropdown.
|
|
19
|
+
var HandleShow = React.useCallback(function (evt) {
|
|
20
|
+
var _a;
|
|
21
|
+
// Ignore if disabled or not a mousedown event
|
|
22
|
+
if ((props.Disabled === undefined ? false : props.Disabled)
|
|
23
|
+
|| evt.type !== 'mousedown') {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
//ignore the click if it was inside the table or table container
|
|
27
|
+
if ((selectTable.current != null && selectTable.current.contains(evt.target)) || (tableContainer.current != null && tableContainer.current.contains(evt.target))) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (textAreaElement.current !== null && !((_a = textAreaElement.current) === null || _a === void 0 ? void 0 : _a.contains(evt.target))) {
|
|
31
|
+
setShow(false);
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
setShow(true);
|
|
35
|
+
}
|
|
36
|
+
}, [props.Disabled]);
|
|
37
|
+
// add listeners to follow caret
|
|
38
|
+
React.useEffect(function () {
|
|
39
|
+
var autoComplete = textAreaElement.current;
|
|
40
|
+
if (autoComplete == null)
|
|
41
|
+
return;
|
|
42
|
+
autoComplete.addEventListener("keyup", handleCaretPosition);
|
|
43
|
+
autoComplete.addEventListener("click", handleCaretPosition);
|
|
44
|
+
return function () {
|
|
45
|
+
autoComplete.removeEventListener("keyup", handleCaretPosition);
|
|
46
|
+
autoComplete.removeEventListener("click", handleCaretPosition);
|
|
47
|
+
};
|
|
48
|
+
}, []);
|
|
49
|
+
// set position of the suggestion dropdown
|
|
50
|
+
React.useLayoutEffect(function () {
|
|
51
|
+
if ((suggestions === null || suggestions === void 0 ? void 0 : suggestions.length) == 0) {
|
|
52
|
+
setPosition(null);
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
var updatePosition = _.debounce(function () {
|
|
56
|
+
if (textAreaElement.current == null) {
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
var rect = textAreaElement.current.getBoundingClientRect();
|
|
60
|
+
var _a = getTextDimensions(textAreaElement, variable.Start - 1, "\n"), caret_X = _a[0], caret_Y = _a[1];
|
|
61
|
+
setPosition({ Top: rect.top + caret_Y, Left: rect.left + caret_X, Width: rect.width, Height: rect.height });
|
|
62
|
+
}, 200);
|
|
63
|
+
var handleScroll = function () {
|
|
64
|
+
if (tableContainer.current == null)
|
|
65
|
+
return;
|
|
66
|
+
updatePosition();
|
|
67
|
+
};
|
|
68
|
+
updatePosition();
|
|
69
|
+
window.addEventListener('scroll', handleScroll, true);
|
|
70
|
+
window.addEventListener('resize', updatePosition);
|
|
71
|
+
window.addEventListener('mousedown', HandleShow, false);
|
|
72
|
+
return function () {
|
|
73
|
+
window.removeEventListener('scroll', handleScroll, true);
|
|
74
|
+
window.removeEventListener('resize', updatePosition);
|
|
75
|
+
window.removeEventListener('mousedown', HandleShow, false);
|
|
76
|
+
updatePosition.cancel();
|
|
77
|
+
};
|
|
78
|
+
}, [suggestions, HandleShow]);
|
|
79
|
+
// update variable and suggestions when caret position changes
|
|
80
|
+
var handleCaretPosition = function () {
|
|
81
|
+
var _a, _b, _c, _d;
|
|
82
|
+
if (textAreaElement.current !== null) {
|
|
83
|
+
var selection = textAreaElement.current.selectionStart;
|
|
84
|
+
var variable_1 = (0, AutoCompleteInput_1.getCurrentVariable)((_b = (_a = textAreaElement.current) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : "", selection);
|
|
85
|
+
setVariable(variable_1);
|
|
86
|
+
var suggests = (0, AutoCompleteInput_1.getSuggestions)(variable_1, (_d = (_c = textAreaElement.current) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : "", props.Options);
|
|
87
|
+
setSuggestions(suggests);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
// edit text area contents with selected suggestion
|
|
91
|
+
var handleOptionClick = function (option) {
|
|
92
|
+
var _a, _b, _c, _d;
|
|
93
|
+
var currentPos = textAreaElement.current !== null ? textAreaElement.current.selectionStart : 0;
|
|
94
|
+
var optionLength = option.Value.length;
|
|
95
|
+
props.Record[props.Field] = option.Value;
|
|
96
|
+
props.Setter(props.Record);
|
|
97
|
+
var textLength = textAreaElement.current !== null ? (_b = (_a = textAreaElement.current.textContent) === null || _a === void 0 ? void 0 : _a.length) !== null && _b !== void 0 ? _b : 0 : 0;
|
|
98
|
+
var newCaretPos = (optionLength > textLength ? textLength - 1 : optionLength + currentPos);
|
|
99
|
+
(_c = textAreaElement.current) === null || _c === void 0 ? void 0 : _c.focus();
|
|
100
|
+
(_d = textAreaElement.current) === null || _d === void 0 ? void 0 : _d.setSelectionRange(newCaretPos, newCaretPos);
|
|
101
|
+
setSuggestions([]);
|
|
102
|
+
};
|
|
103
|
+
return (React.createElement("div", { ref: autoCompleteTextArea },
|
|
104
|
+
React.createElement(TextArea_1.default, { Valid: props.Valid, Record: props.Record, Setter: props.Setter, Field: props.Field, Rows: props.Rows, TextAreaRef: textAreaElement, SpellCheck: false }),
|
|
105
|
+
position == null || !show ? React.createElement(React.Fragment, null) :
|
|
106
|
+
React.createElement(react_portal_1.Portal, null,
|
|
107
|
+
React.createElement("div", { ref: tableContainer, className: 'popover', style: {
|
|
108
|
+
maxHeight: window.innerHeight - position.Top,
|
|
109
|
+
overflowY: 'auto',
|
|
110
|
+
padding: '10 5',
|
|
111
|
+
display: 'block',
|
|
112
|
+
position: 'absolute',
|
|
113
|
+
zIndex: 9999,
|
|
114
|
+
maxWidth: '100%',
|
|
115
|
+
top: "".concat(position.Top, "px"),
|
|
116
|
+
left: "".concat(position.Left, "px"),
|
|
117
|
+
minWidth: "".concat(position.Width, "px")
|
|
118
|
+
} },
|
|
119
|
+
React.createElement("table", { className: "table table-hover", style: { margin: 0 }, ref: selectTable },
|
|
120
|
+
React.createElement("tbody", null, suggestions.map(function (f, i) { return (f.Value === props.Record[props.Field] ? null :
|
|
121
|
+
React.createElement("tr", { key: i, onMouseDown: function (_) { return handleOptionClick(f); } },
|
|
122
|
+
React.createElement("td", null, f.Label))); })))))));
|
|
123
|
+
}
|
|
124
|
+
var getTextDimensions = function (textArea, selection, prefix) {
|
|
125
|
+
var _a;
|
|
126
|
+
if (textArea.current == null)
|
|
127
|
+
return [0, 0];
|
|
128
|
+
var textarea = textArea.current;
|
|
129
|
+
if (textarea.parentNode == null)
|
|
130
|
+
return [0, 0];
|
|
131
|
+
var hiddenDiv = document.createElement('div');
|
|
132
|
+
var style = getComputedStyle(textarea);
|
|
133
|
+
Array.from(style).forEach(function (propertyName) {
|
|
134
|
+
var value = style.getPropertyValue(propertyName);
|
|
135
|
+
hiddenDiv.style.setProperty(propertyName, value);
|
|
136
|
+
});
|
|
137
|
+
// Set text content up to caret
|
|
138
|
+
var beforeSelection = textarea.value.substring(0, selection);
|
|
139
|
+
var afterSelection = (_a = textarea.value.substring(selection)) !== null && _a !== void 0 ? _a : '.';
|
|
140
|
+
hiddenDiv.textContent = (prefix !== null && prefix !== void 0 ? prefix : "") + beforeSelection;
|
|
141
|
+
// Create a span to mark caret position
|
|
142
|
+
var span = document.createElement('span');
|
|
143
|
+
span.textContent = afterSelection[0];
|
|
144
|
+
hiddenDiv.appendChild(span);
|
|
145
|
+
textarea.parentNode.appendChild(hiddenDiv);
|
|
146
|
+
// Get caret's vertical position relative to textarea
|
|
147
|
+
var caretX = span.offsetLeft - hiddenDiv.offsetLeft - hiddenDiv.scrollLeft;
|
|
148
|
+
var caretY = span.offsetTop - hiddenDiv.offsetTop - textarea.scrollTop;
|
|
149
|
+
textarea.parentNode.removeChild(hiddenDiv);
|
|
150
|
+
return [caretX, caretY];
|
|
151
|
+
};
|
package/lib/CheckBox.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import { Gemstone } from '@gpa-gemstone/application-typings';
|
|
2
|
-
|
|
2
|
+
declare const CheckBox: <T>(props: Gemstone.TSX.Interfaces.IBaseFormProps<T>) => JSX.Element;
|
|
3
|
+
export default CheckBox;
|
package/lib/CheckBox.js
CHANGED
|
@@ -33,20 +33,10 @@ var __assign = (this && this.__assign) || function () {
|
|
|
33
33
|
return __assign.apply(this, arguments);
|
|
34
34
|
};
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.default = CheckBox;
|
|
37
36
|
var React = require("react");
|
|
38
|
-
var
|
|
39
|
-
var
|
|
40
|
-
var gpa_symbols_1 = require("@gpa-gemstone/gpa-symbols");
|
|
41
|
-
function CheckBox(props) {
|
|
42
|
-
var _a = React.useState(""), guid = _a[0], setGuid = _a[1];
|
|
43
|
-
var _b = React.useState(false), showHelp = _b[0], setShowHelp = _b[1];
|
|
44
|
-
// Runs once, setting a unique GUID for each checkbox instance.
|
|
45
|
-
React.useEffect(function () {
|
|
46
|
-
setGuid((0, helper_functions_1.CreateGuid)());
|
|
47
|
-
}, []);
|
|
37
|
+
var HelpIcon_1 = require("./HelpIcon");
|
|
38
|
+
var CheckBox = function (props) {
|
|
48
39
|
var showLabel = props.Label !== "";
|
|
49
|
-
var showHelpIcon = props.Help !== undefined;
|
|
50
40
|
var label = props.Label === undefined ? props.Field : props.Label;
|
|
51
41
|
return (React.createElement("div", { className: "form-check" },
|
|
52
42
|
React.createElement("input", { type: "checkbox", className: "form-check-input", style: { zIndex: 1 }, onChange: function (evt) {
|
|
@@ -54,13 +44,10 @@ function CheckBox(props) {
|
|
|
54
44
|
record[props.Field] = evt.target.checked;
|
|
55
45
|
props.Setter(record);
|
|
56
46
|
}, value: props.Record[props.Field] ? 'on' : 'off', checked: props.Record[props.Field], disabled: props.Disabled == null ? false : props.Disabled }),
|
|
57
|
-
|
|
58
|
-
React.createElement("label", { className: "
|
|
47
|
+
showLabel ?
|
|
48
|
+
React.createElement("label", { className: "d-flex align-items-center" },
|
|
59
49
|
React.createElement("span", null, showLabel ? label : ''),
|
|
60
|
-
|
|
61
|
-
React.createElement(gpa_symbols_1.ReactIcons.QuestionMark, { Color: "var(--info)", Size: 20 }))))
|
|
62
|
-
: null,
|
|
63
|
-
showHelpIcon ?
|
|
64
|
-
React.createElement(ToolTip_1.default, { Show: showHelp, Target: guid, Class: "info", Position: "top" }, props.Help)
|
|
50
|
+
React.createElement(HelpIcon_1.default, { Help: props.Help }))
|
|
65
51
|
: null));
|
|
66
|
-
}
|
|
52
|
+
};
|
|
53
|
+
exports.default = CheckBox;
|
package/lib/ColorPicker.d.ts
CHANGED
|
@@ -40,5 +40,5 @@ interface IProps<T> extends Omit<Gemstone.TSX.Interfaces.IBaseFormProps<T>, "Set
|
|
|
40
40
|
*/
|
|
41
41
|
Triangle?: 'hide' | 'top';
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
export
|
|
43
|
+
declare const ColorPicker: <T>(props: IProps<T>) => JSX.Element;
|
|
44
|
+
export default ColorPicker;
|
package/lib/ColorPicker.js
CHANGED
|
@@ -37,26 +37,22 @@ var __assign = (this && this.__assign) || function () {
|
|
|
37
37
|
return __assign.apply(this, arguments);
|
|
38
38
|
};
|
|
39
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
-
exports.default = ColorPicker;
|
|
41
40
|
var React = require("react");
|
|
42
41
|
var react_color_1 = require("react-color");
|
|
43
42
|
var styled_components_1 = require("styled-components");
|
|
44
43
|
var helper_functions_1 = require("@gpa-gemstone/helper-functions");
|
|
45
44
|
var react_portal_1 = require("react-portal");
|
|
46
45
|
var lodash_1 = require("lodash");
|
|
47
|
-
var
|
|
48
|
-
var ToolTip_1 = require("./ToolTip");
|
|
46
|
+
var HelpIcon_1 = require("./HelpIcon");
|
|
49
47
|
var WrapperDiv = styled_components_1.default.div(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n & {\n border-radius: 3px;\n display: inline-block;\n font-size: 13px;\n padding: 8px;\n position: fixed;\n transition: opacity 0.3s ease-out;\n z-index: 99999;\n pointer-events: ", ";\n opacity: ", ";\n color: currentColor;\n top: ", ";\n left: ", ";\n border: 1px solid transparent;\n }\n"], ["\n & {\n border-radius: 3px;\n display: inline-block;\n font-size: 13px;\n padding: 8px;\n position: fixed;\n transition: opacity 0.3s ease-out;\n z-index: 99999;\n pointer-events: ", ";\n opacity: ", ";\n color: currentColor;\n top: ", ";\n left: ", ";\n border: 1px solid transparent;\n }\n"])), function (props) { return props.Show ? 'auto' : 'none'; }, function (props) { return props.Show ? "0.9" : "0"; }, function (props) { return "".concat(props.Top, "px"); }, function (props) { return "".concat(props.Left, "px"); });
|
|
50
|
-
function
|
|
48
|
+
var ColorPicker = function (props) {
|
|
51
49
|
var _a, _b, _c, _d, _e;
|
|
52
|
-
var guid = React.useState(helper_functions_1.CreateGuid)[0];
|
|
53
|
-
var _f = React.useState(false), showHelp = _f[0], setShowHelp = _f[1];
|
|
54
50
|
var toolTipRef = React.useRef(null);
|
|
55
51
|
var buttonRef = React.useRef(null);
|
|
56
|
-
var
|
|
57
|
-
var
|
|
58
|
-
var
|
|
59
|
-
var
|
|
52
|
+
var _f = React.useState(0), top = _f[0], setTop = _f[1];
|
|
53
|
+
var _g = React.useState(0), left = _g[0], setLeft = _g[1];
|
|
54
|
+
var _h = React.useState({ Top: -999, Left: -999, Width: 0, Height: 0 }), targetPosition = _h[0], setTargetPosition = _h[1];
|
|
55
|
+
var _j = React.useState(false), show = _j[0], setShow = _j[1];
|
|
60
56
|
var colors = (_a = props.Colors) !== null && _a !== void 0 ? _a : [
|
|
61
57
|
"#A30000", "#0029A3", "#007A29", "#d3d3d3", "#FF0000",
|
|
62
58
|
"#0066CC", "#33CC33", "#4287f5", "#edc240", "#afd8f8",
|
|
@@ -76,16 +72,14 @@ function ColorPicker(props) {
|
|
|
76
72
|
setLeft(l);
|
|
77
73
|
}
|
|
78
74
|
});
|
|
75
|
+
// Variables to control the rendering of label and help icon.
|
|
76
|
+
var showLabel = props.Label !== "";
|
|
79
77
|
var label = props.Label === undefined ? props.Field : props.Label;
|
|
80
78
|
return (React.createElement("div", { className: "form-group ", style: props.Style },
|
|
81
|
-
|
|
79
|
+
showLabel ?
|
|
82
80
|
React.createElement("label", { className: "d-flex align-items-center" },
|
|
83
|
-
React.createElement("span", null,
|
|
84
|
-
|
|
85
|
-
React.createElement(gpa_symbols_1.ReactIcons.QuestionMark, { Color: "var(--info)", Size: 20 }))))
|
|
86
|
-
: null,
|
|
87
|
-
props.Help !== undefined ?
|
|
88
|
-
React.createElement(ToolTip_1.default, { Show: showHelp, Target: guid, Class: "info", Position: "top" }, props.Help)
|
|
81
|
+
React.createElement("span", null, showLabel ? label : ''),
|
|
82
|
+
React.createElement(HelpIcon_1.default, { Help: props.Help }))
|
|
89
83
|
: null,
|
|
90
84
|
React.createElement("button", { disabled: (_b = props.Disabled) !== null && _b !== void 0 ? _b : false, ref: buttonRef, className: "btn btn-block form-control".concat(props.Valid == null || props.Valid(props.Field) ? '' : ' is-invalid'), "data-tooltip": "color-picker", onMouseOver: function () { return setShow(true); }, onMouseOut: function () { return setShow(false); }, style: __assign(__assign({}, props.Style), { backgroundColor: props.Record[props.Field], color: "#ffffff" }) }, (_c = props.Record[props.Field]) !== null && _c !== void 0 ? _c : ""),
|
|
91
85
|
React.createElement(react_portal_1.Portal, null, !((_d = props.Disabled) !== null && _d !== void 0 ? _d : false) ?
|
|
@@ -97,7 +91,7 @@ function ColorPicker(props) {
|
|
|
97
91
|
}, triangle: (_e = props.Triangle) !== null && _e !== void 0 ? _e : 'hide' }))
|
|
98
92
|
: React.createElement(React.Fragment, null)),
|
|
99
93
|
React.createElement("div", { className: "invalid-feedback" }, props.Feedback == null ? props.Field.toString() + ' is a required field.' : props.Feedback)));
|
|
100
|
-
}
|
|
94
|
+
};
|
|
101
95
|
var GetBestPosition = function (ref, targetTop, targetHeight, targetLeft, targetWidth) {
|
|
102
96
|
if (ref.current === null)
|
|
103
97
|
return [-999, -999];
|
|
@@ -127,4 +121,5 @@ var GetBestPosition = function (ref, targetTop, targetHeight, targetLeft, target
|
|
|
127
121
|
}
|
|
128
122
|
return result;
|
|
129
123
|
};
|
|
124
|
+
exports.default = ColorPicker;
|
|
130
125
|
var templateObject_1;
|
|
@@ -41,7 +41,7 @@ var moment = require("moment");
|
|
|
41
41
|
var DateTimePopup_1 = require("./DateTimePopup");
|
|
42
42
|
var helper_functions_1 = require("@gpa-gemstone/helper-functions");
|
|
43
43
|
var ToolTip_1 = require("../ToolTip");
|
|
44
|
-
var
|
|
44
|
+
var HelpIcon_1 = require("../HelpIcon");
|
|
45
45
|
/**
|
|
46
46
|
* Component that allows a user to pick a date or datetime.
|
|
47
47
|
*/
|
|
@@ -59,14 +59,12 @@ function DateTimePickerBase(props) {
|
|
|
59
59
|
var recordFormat = props.Format !== undefined ? props.Format : "YYYY-MM-DD" + (props.Type === undefined || props.Type === 'date' ? "" : "[T]HH:mm:ss.SSS[Z]");
|
|
60
60
|
// Parse the date from the record.
|
|
61
61
|
var parse = function (r) { return moment(props.Record[props.Field], recordFormat); };
|
|
62
|
-
var helpGuid = React.useState((0, helper_functions_1.CreateGuid)())[0];
|
|
63
|
-
var _d = React.useState(false), showHelp = _d[0], setShowHelp = _d[1];
|
|
64
62
|
// Adds a buffer between the outside props and what the box is reading to prevent box overwriting every render with a keystroke
|
|
65
|
-
var
|
|
66
|
-
var
|
|
67
|
-
var
|
|
68
|
-
var
|
|
69
|
-
var
|
|
63
|
+
var _d = React.useState(parse(props.Record).format(boxFormat)), boxRecord = _d[0], setBoxRecord = _d[1];
|
|
64
|
+
var _e = React.useState(parse(props.Record)), pickerRecord = _e[0], setPickerRecord = _e[1];
|
|
65
|
+
var _f = React.useState(""), feedbackMessage = _f[0], setFeedbackMessage = _f[1];
|
|
66
|
+
var _g = React.useState(0), top = _g[0], setTop = _g[1];
|
|
67
|
+
var _h = React.useState(0), left = _h[0], setLeft = _h[1];
|
|
70
68
|
var allowNull = React.useMemo(function () { var _a; return (_a = props.AllowEmpty) !== null && _a !== void 0 ? _a : false; }, [props.AllowEmpty]);
|
|
71
69
|
React.useEffect(function () {
|
|
72
70
|
if (props.Record[props.Field] != null) {
|
|
@@ -170,7 +168,6 @@ function DateTimePickerBase(props) {
|
|
|
170
168
|
}
|
|
171
169
|
// Variables for rendering labels and help icons.
|
|
172
170
|
var showLabel = props.Label !== "";
|
|
173
|
-
var showHelpIcon = props.Help !== undefined;
|
|
174
171
|
var label = props.Label === undefined ? props.Field : props.Label;
|
|
175
172
|
var step = props.Accuracy === 'millisecond' ? '0.001' : (props.Accuracy === 'minute' ? '60' : '1');
|
|
176
173
|
var IsValid = function () {
|
|
@@ -199,14 +196,10 @@ function DateTimePickerBase(props) {
|
|
|
199
196
|
setIsTextOverflowing(inputWidth > width);
|
|
200
197
|
}, [width, boxRecord, step]);
|
|
201
198
|
return (React.createElement("div", { className: "form-group", ref: divRef },
|
|
202
|
-
|
|
199
|
+
showLabel ?
|
|
203
200
|
React.createElement("label", { className: "d-flex align-items-center" },
|
|
204
201
|
React.createElement("span", null, showLabel ? label : ''),
|
|
205
|
-
|
|
206
|
-
React.createElement(gpa_symbols_1.ReactIcons.QuestionMark, { Color: "var(--info)", Size: 20 }))))
|
|
207
|
-
: null,
|
|
208
|
-
showHelpIcon ?
|
|
209
|
-
React.createElement(ToolTip_1.default, { Show: showHelp, Target: helpGuid, Class: "info", Position: "top" }, props.Help)
|
|
202
|
+
React.createElement(HelpIcon_1.default, { Help: props.Help }))
|
|
210
203
|
: null,
|
|
211
204
|
React.createElement("input", { className: "gpa-gemstone-datetime form-control ".concat(IsValid() ? '' : 'is-invalid'), type: props.Type === undefined ? 'date' : props.Type, onChange: function (evt) {
|
|
212
205
|
valueChange(evt.target.value);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
interface IProps {
|
|
2
|
+
/**
|
|
3
|
+
* Help content to display in the tooltip.
|
|
4
|
+
* If undefined, nothing is rendered.
|
|
5
|
+
* @type {string | JSX.Element}
|
|
6
|
+
*/
|
|
7
|
+
Help?: string | JSX.Element;
|
|
8
|
+
/**
|
|
9
|
+
* Optional icon size in pixels. Defaults to 20.
|
|
10
|
+
* @type {number}
|
|
11
|
+
*/
|
|
12
|
+
Size?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Optional icon color. Defaults to 'var(--info)'.
|
|
15
|
+
* @type {string}
|
|
16
|
+
*/
|
|
17
|
+
Color?: string;
|
|
18
|
+
/**
|
|
19
|
+
* Optional CSS class for the icon.
|
|
20
|
+
* @type {string}
|
|
21
|
+
*/
|
|
22
|
+
Class?: string;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* HelpIcon component.
|
|
26
|
+
* Renders a question-mark icon that displays a tooltip on hover.
|
|
27
|
+
*/
|
|
28
|
+
declare const HelpIcon: (props: IProps) => JSX.Element | null;
|
|
29
|
+
export default HelpIcon;
|