@gpa-gemstone/react-forms 1.1.78 → 1.1.80
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.d.ts +3 -4
- package/lib/SearchableSelect.js +45 -31
- package/lib/StylableSelect.d.ts +37 -5
- package/lib/StylableSelect.js +2 -2
- package/package.json +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { Gemstone } from '@gpa-gemstone/application-typings';
|
|
3
3
|
interface IOption {
|
|
4
|
-
Value: string;
|
|
4
|
+
Value: string | number;
|
|
5
5
|
Label: string;
|
|
6
6
|
}
|
|
7
7
|
interface IProps<T> extends Gemstone.TSX.Interfaces.IBaseFormProps<T> {
|
|
@@ -16,7 +16,7 @@ interface IProps<T> extends Gemstone.TSX.Interfaces.IBaseFormProps<T> {
|
|
|
16
16
|
* @param search - Search string
|
|
17
17
|
* @returns {[promise: Promise<IOption[]>, callback?: () => void]}
|
|
18
18
|
*/
|
|
19
|
-
Search: (search: string) => [
|
|
19
|
+
Search: (search: string) => [Promise<IOption[]>, () => void];
|
|
20
20
|
/**
|
|
21
21
|
* CSS styles to apply to the form group
|
|
22
22
|
* @type {React.CSSProperties}
|
|
@@ -27,10 +27,9 @@ interface IProps<T> extends Gemstone.TSX.Interfaces.IBaseFormProps<T> {
|
|
|
27
27
|
* CSS style to apply to the button holding the selected value
|
|
28
28
|
* @type {React.CSSProperties}
|
|
29
29
|
* @optional
|
|
30
|
-
*
|
|
31
30
|
*/
|
|
32
31
|
BtnStyle?: React.CSSProperties;
|
|
33
|
-
|
|
32
|
+
GetLabel?: () => [Promise<string>, () => void];
|
|
34
33
|
}
|
|
35
34
|
export default function SearchableSelect<T>(props: IProps<T>): JSX.Element;
|
|
36
35
|
export {};
|
package/lib/SearchableSelect.js
CHANGED
|
@@ -38,57 +38,71 @@ var React = require("react");
|
|
|
38
38
|
var StylableSelect_1 = require("./StylableSelect");
|
|
39
39
|
var gpa_symbols_1 = require("@gpa-gemstone/gpa-symbols");
|
|
40
40
|
function SearchableSelect(props) {
|
|
41
|
-
var _a,
|
|
42
|
-
var
|
|
43
|
-
var
|
|
44
|
-
var
|
|
41
|
+
var _a = React.useState(props.Record[props.Field].toString()), search = _a[0], setSearch = _a[1];
|
|
42
|
+
var _b = React.useState(props.Record[props.Field].toString()), label = _b[0], setLabel = _b[1];
|
|
43
|
+
var _c = React.useState([]), results = _c[0], setResults = _c[1];
|
|
44
|
+
var _d = React.useState(false), loading = _d[0], setLoading = _d[1];
|
|
45
|
+
React.useEffect(function () {
|
|
46
|
+
if (props.GetLabel === undefined)
|
|
47
|
+
setLabel(props.Record[props.Field].toString());
|
|
48
|
+
else {
|
|
49
|
+
setLoading(true);
|
|
50
|
+
var _a = props.GetLabel(), handle = _a[0], callback = _a[1];
|
|
51
|
+
handle.then(function (lab) {
|
|
52
|
+
setLabel(lab);
|
|
53
|
+
setSearch(lab);
|
|
54
|
+
setLoading(false);
|
|
55
|
+
});
|
|
56
|
+
return callback;
|
|
57
|
+
}
|
|
58
|
+
}, [props.GetLabel]);
|
|
45
59
|
React.useEffect(function () {
|
|
46
60
|
setLoading(true);
|
|
47
|
-
var _a = props.Search(search),
|
|
48
|
-
|
|
49
|
-
setResults(d.map(function (o) { return ({ Value: o.Value, Element:
|
|
61
|
+
var _a = props.Search(search), handle = _a[0], callback = _a[1];
|
|
62
|
+
handle.then(function (d) {
|
|
63
|
+
setResults(d.map(function (o) { return ({ Value: o.Value, Element: o.Label }); }));
|
|
50
64
|
setLoading(false);
|
|
51
65
|
});
|
|
52
|
-
return
|
|
66
|
+
return callback;
|
|
53
67
|
}, [search]);
|
|
54
|
-
React.
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
setSearch(props.SearchLabel);
|
|
58
|
-
}, [props.SearchLabel]);
|
|
68
|
+
var handleOnBlur = React.useCallback(function () {
|
|
69
|
+
setSearch(label);
|
|
70
|
+
}, [label]);
|
|
59
71
|
var options = React.useMemo(function () {
|
|
60
|
-
var _a
|
|
72
|
+
var _a;
|
|
61
73
|
var ops = [];
|
|
62
74
|
ops.push({
|
|
63
|
-
Value: props.Record[props.Field],
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
return props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = search, _a)));
|
|
67
|
-
} : function () { var _a; return setSearch((_a = props.SearchLabel) !== null && _a !== void 0 ? _a : props.Record[props.Field].toString()); }) }),
|
|
75
|
+
Value: props.Record[props.Field],
|
|
76
|
+
Element: React.createElement("div", { className: 'input-group' },
|
|
77
|
+
React.createElement("input", { type: "text", className: "form-control", value: search, onChange: function (d) { return setSearch(d.target.value); }, onBlur: handleOnBlur }),
|
|
68
78
|
loading ?
|
|
69
79
|
React.createElement("div", { className: "input-group-append" },
|
|
70
80
|
React.createElement("span", { className: "input-group-text" },
|
|
71
81
|
React.createElement(gpa_symbols_1.ReactIcons.SpiningIcon, null)))
|
|
72
82
|
: null)
|
|
73
83
|
});
|
|
74
|
-
if (!((
|
|
75
|
-
ops.push({ Value: 'search-' + props.Record[props.Field], Element:
|
|
76
|
-
|
|
77
|
-
ops.push({ Value: search, Element:
|
|
84
|
+
if (!((_a = props.AllowCustom) !== null && _a !== void 0 ? _a : false))
|
|
85
|
+
ops.push({ Value: 'search-' + props.Record[props.Field], Element: label });
|
|
86
|
+
else
|
|
87
|
+
ops.push({ Value: search, Element: search });
|
|
78
88
|
ops.push.apply(ops, results.filter(function (f) { return f.Value !== search && f.Value !== props.Record[props.Field]; }));
|
|
79
89
|
return ops;
|
|
80
|
-
}, [search, props.Record[props.Field], props.Disabled, loading, props.
|
|
81
|
-
var update = React.useCallback(function (record) {
|
|
90
|
+
}, [search, props.Record[props.Field], results, props.Disabled, loading, label, props.AllowCustom, handleOnBlur]);
|
|
91
|
+
var update = React.useCallback(function (record, selectedOption) {
|
|
82
92
|
var _a;
|
|
83
|
-
var
|
|
84
|
-
|
|
85
|
-
|
|
93
|
+
var stringVal = record[props.Field].toString();
|
|
94
|
+
var newLabel = stringVal;
|
|
95
|
+
if (!React.isValidElement(selectedOption.Element))
|
|
96
|
+
newLabel = selectedOption.Element;
|
|
97
|
+
setLabel(newLabel);
|
|
98
|
+
if (stringVal.startsWith('search-')) {
|
|
99
|
+
var value = stringVal.replace('search-', '');
|
|
86
100
|
props.Setter(__assign(__assign({}, record), (_a = {}, _a[props.Field] = value, _a)));
|
|
87
|
-
setSearch(
|
|
101
|
+
setSearch(newLabel !== null && newLabel !== void 0 ? newLabel : value);
|
|
88
102
|
return;
|
|
89
103
|
}
|
|
90
104
|
props.Setter(record);
|
|
91
|
-
setSearch(
|
|
92
|
-
}, [props.Setter, props.Field,
|
|
105
|
+
setSearch(newLabel);
|
|
106
|
+
}, [props.Setter, props.Field, label]);
|
|
93
107
|
return React.createElement(StylableSelect_1.default, { Record: props.Record, Field: props.Field, Setter: update, Label: props.Label, Disabled: props.Disabled, Help: props.Help, Style: props.Style, Options: options, BtnStyle: props.BtnStyle });
|
|
94
108
|
}
|
package/lib/StylableSelect.d.ts
CHANGED
|
@@ -1,13 +1,45 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { Gemstone } from '@gpa-gemstone/application-typings';
|
|
3
2
|
export interface IOption {
|
|
4
3
|
Value: any;
|
|
5
|
-
Element: React.ReactElement<any
|
|
4
|
+
Element: React.ReactElement<any> | string;
|
|
6
5
|
}
|
|
7
|
-
interface IProps<T>
|
|
6
|
+
interface IProps<T> {
|
|
8
7
|
/**
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
* Record to be used in form
|
|
9
|
+
* @type {T}
|
|
10
|
+
*/
|
|
11
|
+
Record: T;
|
|
12
|
+
/**
|
|
13
|
+
* Field of the record to be edited
|
|
14
|
+
* @type {keyof T}
|
|
15
|
+
*/
|
|
16
|
+
Field: keyof T;
|
|
17
|
+
/**
|
|
18
|
+
* Label to display for the form, defaults to the Field prop
|
|
19
|
+
* @type {string}
|
|
20
|
+
* @optional
|
|
21
|
+
*/
|
|
22
|
+
Label?: string;
|
|
23
|
+
/**
|
|
24
|
+
* Help message or element to display
|
|
25
|
+
* @type {string | JSX.Element}
|
|
26
|
+
* @optional
|
|
27
|
+
*/
|
|
28
|
+
Help?: string | JSX.Element;
|
|
29
|
+
/**
|
|
30
|
+
* Flag to disable the input field
|
|
31
|
+
* @type {boolean}
|
|
32
|
+
* @optional
|
|
33
|
+
*/
|
|
34
|
+
Disabled?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Setter function to update the Record
|
|
37
|
+
* @param record - Updated Record
|
|
38
|
+
*/
|
|
39
|
+
Setter: (record: T, option: IOption) => void;
|
|
40
|
+
/**
|
|
41
|
+
* Options for the select dropdown
|
|
42
|
+
* @type {{ Value: any, Element: React.ReactElement<any> }[]}
|
|
11
43
|
*/
|
|
12
44
|
Options: IOption[];
|
|
13
45
|
/**
|
package/lib/StylableSelect.js
CHANGED
|
@@ -98,7 +98,7 @@ function StylableSelect(props) {
|
|
|
98
98
|
record[props.Field] = selectedOption.Value;
|
|
99
99
|
else
|
|
100
100
|
record[props.Field] = null;
|
|
101
|
-
props.Setter(record);
|
|
101
|
+
props.Setter(record, selectedOption);
|
|
102
102
|
}
|
|
103
103
|
// Effect for initial setup and event listeners.
|
|
104
104
|
React.useEffect(function () {
|
|
@@ -145,6 +145,6 @@ function StylableSelect(props) {
|
|
|
145
145
|
} },
|
|
146
146
|
React.createElement("table", { className: "table table-hover", style: { margin: 0 }, ref: selectTable },
|
|
147
147
|
React.createElement("tbody", null, props.Options.map(function (f, i) { return (f.Value === props.Record[props.Field] ? null :
|
|
148
|
-
React.createElement("tr", { key: i,
|
|
148
|
+
React.createElement("tr", { key: i, onMouseDown: function (evt) { return handleOptionClick(evt, f); } },
|
|
149
149
|
React.createElement("td", null, f.Element))); })))))));
|
|
150
150
|
}
|
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.80",
|
|
4
4
|
"description": "React Form modules for gpa webapps",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -45,7 +45,7 @@
|
|
|
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.80",
|
|
49
49
|
"@gpa-gemstone/gpa-symbols": "0.0.46",
|
|
50
50
|
"@gpa-gemstone/helper-functions": "0.0.37",
|
|
51
51
|
"@types/react": "^17.0.14",
|