@gpa-gemstone/react-forms 1.1.64 → 1.1.66

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.
@@ -1,14 +1,45 @@
1
1
  interface IProps<T> {
2
+ /**
3
+ * Record to be used in form
4
+ * @type {T}
5
+ */
2
6
  Record: T;
7
+ /**
8
+ * Field of the record to be edited
9
+ * @type {keyof T}
10
+ */
3
11
  Field: keyof T;
12
+ /**
13
+ * Setter function to update the Record
14
+ * @param record - Updated Record
15
+ */
4
16
  Setter: (record: T) => void;
17
+ /**
18
+ * Help message or element to display
19
+ * @type {string | JSX.Element}
20
+ * @optional
21
+ */
5
22
  Help?: string | JSX.Element;
23
+ /**
24
+ * Position to display radion buttons in
25
+ * @type {'vertical' | 'horizontal'}
26
+ * @optional
27
+ */
6
28
  Position?: ('vertical' | 'horizontal');
29
+ /**
30
+ * Options for the radion buttons
31
+ * @type {{ Value: string | number; Label: string, Disabled?: boolean }[]}
32
+ */
7
33
  Options: {
8
- Value: string;
34
+ Value: string | number;
9
35
  Label: string;
10
36
  Disabled?: boolean;
11
37
  }[];
38
+ /**
39
+ * Label to display for the form, defaults to the Field prop
40
+ * @type {string}
41
+ * @optional
42
+ */
12
43
  Label?: string;
13
44
  }
14
45
  export default function RadioButtons<T>(props: IProps<T>): JSX.Element;
package/lib/Select.d.ts CHANGED
@@ -14,7 +14,7 @@ interface IProps<T> {
14
14
  * @type {{ Value: string; Label: string }[]}
15
15
  */
16
16
  Options: {
17
- Value: string;
17
+ Value: string | number;
18
18
  Label: string;
19
19
  }[];
20
20
  /**
package/lib/Select.js CHANGED
@@ -51,7 +51,7 @@ function Select(props) {
51
51
  React.useEffect(function () {
52
52
  var _a;
53
53
  var currentValue = GetRecordValue();
54
- if (!((_a = props.EmptyOption) !== null && _a !== void 0 ? _a : false) && props.Options.length > 0 && props.Options.findIndex(function (option) { return option.Value === currentValue; }) === -1) {
54
+ if (!((_a = props.EmptyOption) !== null && _a !== void 0 ? _a : false) && props.Options.length > 0 && props.Options.findIndex(function (option) { return option.Value == currentValue; }) === -1) {
55
55
  SetRecord(props.Options[0].Value);
56
56
  // tslint:disable-next-line
57
57
  console.warn("The current value is not available as an option. Specify EmptyOption=true if the value should be allowed.");
@@ -59,23 +59,31 @@ function Select(props) {
59
59
  }, [props.Options]);
60
60
  // Update the parent component's state with the new value.
61
61
  function SetRecord(value) {
62
+ var _a, _b;
62
63
  var record = __assign({}, props.Record);
63
- if (value !== '')
64
- record[props.Field] = value;
64
+ if (value !== '') {
65
+ var val = (_b = (_a = props.Options.find(function (op) { return op.Value == value; })) === null || _a === void 0 ? void 0 : _a.Value) !== null && _b !== void 0 ? _b : value;
66
+ record[props.Field] = val;
67
+ }
65
68
  else
66
69
  record[props.Field] = null;
67
- props.Setter(record);
70
+ if (record[props.Field] != props.Record[props.Field])
71
+ props.Setter(record);
68
72
  }
69
73
  // Rretrieve the current value of the select field from the record.
70
74
  function GetRecordValue() {
71
- return props.Record[props.Field] == null ? '' : props.Record[props.Field].toString();
75
+ return props.Record[props.Field] == null ? '' : props.Record[props.Field];
72
76
  }
77
+ // Variables to control the rendering of label and help icon.
78
+ var showLabel = props.Label !== "";
79
+ var showHelpIcon = props.Help !== undefined;
80
+ var label = props.Label === undefined ? props.Field : props.Label;
73
81
  return (React.createElement("div", { className: "form-group" },
74
- (props.Label !== "") ?
82
+ showHelpIcon || showLabel ?
75
83
  React.createElement("label", null,
76
- props.Label === undefined ? props.Field : props.Label,
77
- props.Help !== undefined ? React.createElement("div", { style: { width: 20, height: 20, borderRadius: '50%', display: 'inline-block', background: '#0D6EFD', marginLeft: 10, textAlign: 'center', fontWeight: 'bold' }, onMouseEnter: function () { return setShowHelp(true); }, onMouseLeave: function () { return setShowHelp(false); } }, " ? ") : null) : null,
78
- props.Help !== undefined ?
84
+ showLabel ? label : '',
85
+ showHelpIcon ? React.createElement("div", { style: { width: 20, height: 20, borderRadius: '50%', display: 'inline-block', background: '#0D6EFD', marginLeft: 10, textAlign: 'center', fontWeight: 'bold' }, onMouseEnter: function () { return setShowHelp(true); }, onMouseLeave: function () { return setShowHelp(false); } }, " ? ") : null) : null,
86
+ showHelpIcon ?
79
87
  React.createElement(HelperMessage_1.default, { Show: showHelp, Target: guid }, props.Help)
80
88
  : null,
81
89
  React.createElement("select", { "data-help": guid, className: "form-control", onChange: function (evt) { return SetRecord(evt.target.value); }, value: GetRecordValue(), disabled: props.Disabled == null ? false : props.Disabled },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gpa-gemstone/react-forms",
3
- "version": "1.1.64",
3
+ "version": "1.1.66",
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.72",
48
+ "@gpa-gemstone/application-typings": "0.0.73",
49
49
  "@gpa-gemstone/helper-functions": "0.0.32",
50
50
  "@types/react": "^17.0.14",
51
51
  "@types/styled-components": "^5.1.11",