@gpa-gemstone/react-forms 1.1.79 → 1.1.81
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/FileUpload.js +2 -2
- package/lib/SearchableSelect.d.ts +2 -7
- package/lib/SearchableSelect.js +41 -30
- package/lib/StylableSelect.d.ts +37 -5
- package/lib/StylableSelect.js +1 -1
- package/package.json +3 -3
package/lib/FileUpload.js
CHANGED
|
@@ -62,11 +62,11 @@ var FileUpload = function (props) {
|
|
|
62
62
|
};
|
|
63
63
|
return (React.createElement(React.Fragment, null,
|
|
64
64
|
React.createElement("div", { className: 'row' },
|
|
65
|
-
React.createElement("div", { className: 'col-auto mt-2' },
|
|
65
|
+
React.createElement("div", { className: 'col-auto mt-2 pl-0' },
|
|
66
66
|
React.createElement("label", { style: { cursor: 'pointer' } },
|
|
67
67
|
React.createElement(gpa_symbols_1.ReactIcons.ShareArrow, { Color: 'var(--info)' }),
|
|
68
68
|
React.createElement("input", { type: "file", onChange: handleFileUpload, accept: props.FileTypeAttribute, style: { display: 'none' } }))),
|
|
69
|
-
React.createElement("div", { className: 'col-auto' },
|
|
69
|
+
React.createElement("div", { className: 'col-auto pl-0' },
|
|
70
70
|
React.createElement("button", { className: 'btn', onClick: handleOnClear },
|
|
71
71
|
React.createElement(gpa_symbols_1.ReactIcons.CircledX, { Color: 'red' })))),
|
|
72
72
|
isFileUpload ?
|
|
@@ -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> {
|
|
@@ -29,12 +29,7 @@ interface IProps<T> extends Gemstone.TSX.Interfaces.IBaseFormProps<T> {
|
|
|
29
29
|
* @optional
|
|
30
30
|
*/
|
|
31
31
|
BtnStyle?: React.CSSProperties;
|
|
32
|
-
|
|
33
|
-
* Custom label to display instead of the default record[field] value. Useful when having a field like an ID.
|
|
34
|
-
* @type {string}
|
|
35
|
-
* @optional
|
|
36
|
-
*/
|
|
37
|
-
SearchLabel?: string;
|
|
32
|
+
GetLabel?: () => [Promise<string>, () => void];
|
|
38
33
|
}
|
|
39
34
|
export default function SearchableSelect<T>(props: IProps<T>): JSX.Element;
|
|
40
35
|
export {};
|
package/lib/SearchableSelect.js
CHANGED
|
@@ -38,63 +38,74 @@ 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, _b, _c, _d;
|
|
42
|
+
var _e = React.useState((_b = (_a = props.Record[props.Field]) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : ''), search = _e[0], setSearch = _e[1];
|
|
43
|
+
var _f = React.useState((_d = (_c = props.Record[props.Field]) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _d !== void 0 ? _d : ''), label = _f[0], setLabel = _f[1];
|
|
44
|
+
var _g = React.useState([]), results = _g[0], setResults = _g[1];
|
|
45
|
+
var _h = React.useState(false), loading = _h[0], setLoading = _h[1];
|
|
46
|
+
React.useEffect(function () {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
if (props.GetLabel === undefined)
|
|
49
|
+
setLabel((_b = (_a = props.Record[props.Field]) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : '');
|
|
50
|
+
else {
|
|
51
|
+
setLoading(true);
|
|
52
|
+
var _c = props.GetLabel(), handle = _c[0], callback = _c[1];
|
|
53
|
+
handle.then(function (lab) {
|
|
54
|
+
setLabel(lab);
|
|
55
|
+
setSearch(lab);
|
|
56
|
+
setLoading(false);
|
|
57
|
+
});
|
|
58
|
+
return callback;
|
|
59
|
+
}
|
|
60
|
+
}, [props.GetLabel]);
|
|
45
61
|
React.useEffect(function () {
|
|
46
62
|
setLoading(true);
|
|
47
63
|
var _a = props.Search(search), handle = _a[0], callback = _a[1];
|
|
48
64
|
handle.then(function (d) {
|
|
49
|
-
setResults(d.map(function (o) { return ({ Value: o.Value, Element:
|
|
65
|
+
setResults(d.map(function (o) { return ({ Value: o.Value, Element: o.Label }); }));
|
|
50
66
|
setLoading(false);
|
|
51
67
|
});
|
|
52
68
|
return callback;
|
|
53
69
|
}, [search]);
|
|
54
|
-
React.useEffect(function () {
|
|
55
|
-
if (props.SearchLabel == null)
|
|
56
|
-
return;
|
|
57
|
-
setSearch(props.SearchLabel);
|
|
58
|
-
}, [props.SearchLabel]);
|
|
59
70
|
var handleOnBlur = React.useCallback(function () {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if ((_b = props.AllowCustom) !== null && _b !== void 0 ? _b : false)
|
|
63
|
-
props.Setter(__assign(__assign({}, props.Record), (_a = {}, _a[props.Field] = search, _a)));
|
|
64
|
-
else
|
|
65
|
-
setSearch(props.Record[props.Field].toString());
|
|
66
|
-
}, [props.AllowCustom, props.Record, props.Field, search]);
|
|
71
|
+
setSearch(label);
|
|
72
|
+
}, [label]);
|
|
67
73
|
var options = React.useMemo(function () {
|
|
68
|
-
var _a, _b
|
|
74
|
+
var _a, _b;
|
|
69
75
|
var ops = [];
|
|
70
76
|
ops.push({
|
|
71
77
|
Value: props.Record[props.Field],
|
|
72
78
|
Element: React.createElement("div", { className: 'input-group' },
|
|
73
|
-
React.createElement("input", { type: "text", className: "form-control", value: search, onChange: function (d) { return setSearch(d.target.value); }, onBlur: handleOnBlur }),
|
|
79
|
+
React.createElement("input", { type: "text", className: "form-control", value: search, onChange: function (d) { return setSearch(d.target.value); }, onBlur: handleOnBlur, disabled: (_a = props.Disabled) !== null && _a !== void 0 ? _a : false }),
|
|
74
80
|
loading ?
|
|
75
81
|
React.createElement("div", { className: "input-group-append" },
|
|
76
82
|
React.createElement("span", { className: "input-group-text" },
|
|
77
83
|
React.createElement(gpa_symbols_1.ReactIcons.SpiningIcon, null)))
|
|
78
84
|
: null)
|
|
79
85
|
});
|
|
80
|
-
if (!((
|
|
81
|
-
ops.push({ Value: 'search-' + props.Record[props.Field], Element:
|
|
82
|
-
|
|
83
|
-
ops.push({ Value: search, Element:
|
|
86
|
+
if (!((_b = props.AllowCustom) !== null && _b !== void 0 ? _b : false))
|
|
87
|
+
ops.push({ Value: 'search-' + props.Record[props.Field], Element: label });
|
|
88
|
+
else
|
|
89
|
+
ops.push({ Value: search, Element: search });
|
|
84
90
|
ops.push.apply(ops, results.filter(function (f) { return f.Value !== search && f.Value !== props.Record[props.Field]; }));
|
|
85
91
|
return ops;
|
|
86
|
-
}, [search, props.Record[props.Field], results, props.Disabled, loading,
|
|
87
|
-
var update = React.useCallback(function (record) {
|
|
92
|
+
}, [search, props.Record[props.Field], results, props.Disabled, loading, label, props.AllowCustom, handleOnBlur]);
|
|
93
|
+
var update = React.useCallback(function (record, selectedOption) {
|
|
88
94
|
var _a;
|
|
89
95
|
var _b, _c;
|
|
90
|
-
|
|
91
|
-
|
|
96
|
+
var stringVal = (_c = (_b = record[props.Field]) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _c !== void 0 ? _c : '';
|
|
97
|
+
var newLabel = stringVal;
|
|
98
|
+
if (!React.isValidElement(selectedOption.Element))
|
|
99
|
+
newLabel = selectedOption.Element;
|
|
100
|
+
setLabel(newLabel);
|
|
101
|
+
if (stringVal.startsWith('search-')) {
|
|
102
|
+
var value = stringVal.replace('search-', '');
|
|
92
103
|
props.Setter(__assign(__assign({}, record), (_a = {}, _a[props.Field] = value, _a)));
|
|
93
|
-
setSearch(
|
|
104
|
+
setSearch(newLabel !== null && newLabel !== void 0 ? newLabel : value);
|
|
94
105
|
return;
|
|
95
106
|
}
|
|
96
107
|
props.Setter(record);
|
|
97
|
-
setSearch(
|
|
98
|
-
}, [props.Setter, props.Field,
|
|
108
|
+
setSearch(newLabel);
|
|
109
|
+
}, [props.Setter, props.Field, label]);
|
|
99
110
|
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 });
|
|
100
111
|
}
|
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 () {
|
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.81",
|
|
4
4
|
"description": "React Form modules for gpa webapps",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"typescript": "5.5.3"
|
|
46
46
|
},
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@gpa-gemstone/application-typings": "0.0.
|
|
49
|
-
"@gpa-gemstone/gpa-symbols": "0.0.
|
|
48
|
+
"@gpa-gemstone/application-typings": "0.0.81",
|
|
49
|
+
"@gpa-gemstone/gpa-symbols": "0.0.47",
|
|
50
50
|
"@gpa-gemstone/helper-functions": "0.0.37",
|
|
51
51
|
"@types/react": "^17.0.14",
|
|
52
52
|
"@types/styled-components": "^5.1.11",
|