@linzjs/step-ag-grid 2.3.1 → 2.4.1

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.
Files changed (30) hide show
  1. package/dist/index.js +95 -16
  2. package/dist/index.js.map +1 -1
  3. package/dist/src/components/GridSubComponentTextArea.d.ts +4 -4
  4. package/dist/src/components/gridForm/GridFormDropDown.d.ts +2 -0
  5. package/dist/src/components/gridForm/GridFormSubComponentTextInput.d.ts +7 -0
  6. package/dist/src/components/gridForm/GridFormTextArea.d.ts +1 -1
  7. package/dist/src/components/gridForm/GridFormTextInput.d.ts +1 -1
  8. package/dist/src/contexts/GridSubComponentContext.d.ts +8 -0
  9. package/dist/src/index.d.ts +1 -0
  10. package/dist/step-ag-grid.esm.js +95 -17
  11. package/dist/step-ag-grid.esm.js.map +1 -1
  12. package/package.json +1 -1
  13. package/src/components/GridSubComponentTextArea.tsx +22 -10
  14. package/src/components/gridForm/GridFormDropDown.tsx +55 -11
  15. package/src/components/gridForm/GridFormMultiSelect.tsx +19 -15
  16. package/src/components/gridForm/GridFormSubComponentTextInput.tsx +34 -0
  17. package/src/components/gridForm/GridFormTextArea.tsx +3 -3
  18. package/src/components/gridForm/GridFormTextInput.tsx +3 -3
  19. package/src/contexts/GridSubComponentContext.ts +21 -0
  20. package/src/index.ts +1 -0
  21. package/src/stories/components/ActionButton.stories.tsx +1 -1
  22. package/src/stories/grid/FormTest.tsx +5 -6
  23. package/src/stories/grid/GridPopoutBearing.stories.tsx +1 -1
  24. package/src/stories/grid/GridPopoutEditDropDown.stories.tsx +42 -1
  25. package/src/stories/grid/GridPopoutEditGeneric.stories.tsx +1 -1
  26. package/src/stories/grid/GridPopoutEditGenericTextArea.stories.tsx +3 -3
  27. package/src/stories/grid/GridPopoutEditMultiSelect.stories.tsx +2 -2
  28. package/src/stories/grid/GridReadOnly.stories.tsx +1 -1
  29. package/dist/src/components/gridForm/GridSubComponentProps.d.ts +0 -6
  30. package/src/components/gridForm/GridSubComponentProps.ts +0 -6
package/dist/index.js CHANGED
@@ -2840,7 +2840,8 @@ var GridFormDropDown = function (_props) {
2840
2840
  var _c = react.useState([]), filteredValues = _c[0], setFilteredValues = _c[1];
2841
2841
  var optionsInitialising = react.useRef(false);
2842
2842
  var _d = react.useState(null), options = _d[0], setOptions = _d[1];
2843
- var selectItemHandler = react.useCallback(function (value) { return __awaiter(void 0, void 0, void 0, function () {
2843
+ var _e = react.useState([]), subComponentValues = _e[0], setSubComponentValues = _e[1];
2844
+ var selectItemHandler = react.useCallback(function (value, subComponentValue) { return __awaiter(void 0, void 0, void 0, function () {
2844
2845
  var field;
2845
2846
  return __generator(this, function (_a) {
2846
2847
  switch (_a.label) {
@@ -2854,7 +2855,7 @@ var GridFormDropDown = function (_props) {
2854
2855
  hasChanged = selectedRows.some(function (row) { return row[field] !== value; });
2855
2856
  if (!hasChanged) return [3 /*break*/, 3];
2856
2857
  if (!props.onSelectedItem) return [3 /*break*/, 2];
2857
- return [4 /*yield*/, props.onSelectedItem({ selectedRows: selectedRows, value: value })];
2858
+ return [4 /*yield*/, props.onSelectedItem({ selectedRows: selectedRows, value: value, subComponentValue: subComponentValue })];
2858
2859
  case 1:
2859
2860
  _a.sent();
2860
2861
  return [3 /*break*/, 3];
@@ -2996,10 +2997,59 @@ var GridFormDropDown = function (_props) {
2996
2997
  return (jsxRuntime.jsx("div", __assign({ style: { display: "flex", width: "100%" } }, { children: jsxRuntime.jsx("input", { autoFocus: true, className: "free-text-input", style: { border: "0px" }, ref: ref, type: "text", placeholder: (_b = props.filterPlaceholder) !== null && _b !== void 0 ? _b : "Placeholder", "data-testid": "filteredMenu-free-text-input", defaultValue: filter, onChange: function (e) { return setFilter(e.target.value.toLowerCase()); }, onKeyDown: function (e) { return onFilterKeyDown(e); } }) })));
2997
2998
  } })), jsxRuntime.jsx(MenuDivider, {}, "$$divider_filter")] }))), jsxRuntime.jsx(ComponentLoadingWrapper, __assign({ loading: !options, className: "GridFormDropDown-options" }, { children: jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [options && options.length == (filteredValues === null || filteredValues === void 0 ? void 0 : filteredValues.length) && jsxRuntime.jsx(MenuItem, { children: "[Empty]" }), options === null || options === void 0 ? void 0 : options.map(function (item, index) {
2998
2999
  var _a;
2999
- return item.value === MenuSeparatorString ? (jsxRuntime.jsx(MenuDivider, {}, "$$divider_".concat(index))) : item.value === MenuHeaderString ? (jsxRuntime.jsx(MenuHeader, { children: item.label })) : filteredValues.includes(item.value) ? null : (jsxRuntime.jsx(MenuItem, __assign({ disabled: !!item.disabled, title: item.disabled && typeof item.disabled !== "boolean" ? item.disabled : "", value: item.value, onClick: function () { return selectItemHandler(item.value); } }, { children: (_a = item.label) !== null && _a !== void 0 ? _a : (item.value == null ? "<".concat(item.value, ">") : "".concat(item.value)) }), "".concat(props.field, "-").concat(index)));
3000
+ return item.value === MenuSeparatorString ? (jsxRuntime.jsx(MenuDivider, {}, "$$divider_".concat(index))) : item.value === MenuHeaderString ? (jsxRuntime.jsx(MenuHeader, { children: item.label })) : filteredValues.includes(item.value) ? null : (jsxRuntime.jsx(jsxRuntime.Fragment, { children: !item.subComponent ? (jsxRuntime.jsx(MenuItem, __assign({ disabled: !!item.disabled, title: item.disabled && typeof item.disabled !== "boolean" ? item.disabled : "", value: item.value, onClick: function () {
3001
+ selectItemHandler(item.value);
3002
+ } }, { children: (_a = item.label) !== null && _a !== void 0 ? _a : (item.value == null ? "<".concat(item.value, ">") : "".concat(item.value)) }), "".concat(props.field, "-").concat(index))) : (jsxRuntime.jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (ref) {
3003
+ return item.subComponent &&
3004
+ item.subComponent({
3005
+ setValue: function (value) {
3006
+ var localSubComponentValues = __spreadArray([], subComponentValues, true);
3007
+ var subComponentValueIndex = localSubComponentValues.findIndex(function (_a) {
3008
+ var optionValue = _a.optionValue;
3009
+ return optionValue === item.value;
3010
+ });
3011
+ if (subComponentValueIndex !== -1) {
3012
+ localSubComponentValues[subComponentValueIndex].subComponentValue = value;
3013
+ }
3014
+ else {
3015
+ localSubComponentValues.push({
3016
+ subComponentValue: value,
3017
+ optionValue: item.value
3018
+ });
3019
+ }
3020
+ setSubComponentValues(localSubComponentValues);
3021
+ },
3022
+ keyDown: function (key) {
3023
+ var subComponentItem = subComponentValues.find(function (_a) {
3024
+ var optionValue = _a.optionValue;
3025
+ return optionValue === item.value;
3026
+ });
3027
+ if (key === "Enter" && subComponentItem) {
3028
+ selectItemHandler(item.value, subComponentItem.subComponentValue);
3029
+ ref.closeMenu();
3030
+ }
3031
+ }
3032
+ }, ref);
3033
+ } }), "".concat(props.field, "-").concat(index, "_subcomponent"))) }));
3000
3034
  })] }) }))] }));
3001
3035
  };
3002
3036
 
3037
+ var GridSubComponentContext = react.createContext({
3038
+ value: "GridSubComponentContext value no context",
3039
+ setValue: function () {
3040
+ console.error("GridSubComponentContext setValue no context");
3041
+ },
3042
+ setValid: function () {
3043
+ console.error("GridSubComponentContext setValid no context");
3044
+ },
3045
+ triggerSave: function () { return __awaiter(void 0, void 0, void 0, function () {
3046
+ return __generator(this, function (_a) {
3047
+ console.error("GridSubComponentContext triggerSave no context");
3048
+ return [2 /*return*/];
3049
+ });
3050
+ }); }
3051
+ });
3052
+
3003
3053
  var GridFormMultiSelect = function (props) {
3004
3054
  var selectedRows = props.selectedRows;
3005
3055
  var initialiseValues = react.useMemo(function () { return props.initialSelectedValues && props.initialSelectedValues(selectedRows); }, [props, selectedRows]);
@@ -3126,10 +3176,8 @@ var GridFormMultiSelect = function (props) {
3126
3176
  }
3127
3177
  }, onChange: function () {
3128
3178
  /*Do nothing, change handled by menuItem*/
3129
- } }) }), "".concat(index)), selectedValues.includes(item.value) && item.subComponent && (jsxRuntime.jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (ref) {
3130
- return item.subComponent &&
3131
- item.subComponent({
3132
- ref: ref,
3179
+ } }) }), "".concat(index)), selectedValues.includes(item.value) && item.subComponent && (jsxRuntime.jsx(FocusableItem, __assign({ className: "LuiDeprecatedForms" }, { children: function (_) {
3180
+ return item.subComponent && (jsxRuntime.jsx(GridSubComponentContext.Provider, __assign({ value: {
3133
3181
  value: subSelectedValues["".concat(item.value)],
3134
3182
  setValue: function (value) {
3135
3183
  subSelectedValues["".concat(item.value)] = value;
@@ -3139,7 +3187,7 @@ var GridFormMultiSelect = function (props) {
3139
3187
  subComponentIsValid.current["".concat(item.value)] = valid;
3140
3188
  },
3141
3189
  triggerSave: triggerSave
3142
- });
3190
+ } }, { children: jsxRuntime.jsx(item.subComponent, {}) })));
3143
3191
  } }), "".concat(item.value, "_subcomponent")))] }, "".concat(index)));
3144
3192
  }) }))] }) })));
3145
3193
  };
@@ -3515,8 +3563,8 @@ var GridFormTextArea = function (_props) {
3515
3563
  if (props.required && value.length == 0) {
3516
3564
  return "Some text is required";
3517
3565
  }
3518
- if (props.maxlength && value.length > props.maxlength) {
3519
- return "Text must be no longer than ".concat(props.maxlength, " characters");
3566
+ if (props.maxLength && value.length > props.maxLength) {
3567
+ return "Text must be no longer than ".concat(props.maxLength, " characters");
3520
3568
  }
3521
3569
  if (props.validate) {
3522
3570
  return props.validate(value);
@@ -3562,8 +3610,8 @@ var GridFormTextInput = function (_props) {
3562
3610
  if (props.required && trimmedValue.length == 0) {
3563
3611
  return "Some text is required";
3564
3612
  }
3565
- if (props.maxlength && trimmedValue.length > props.maxlength) {
3566
- return "Text must be no longer than ".concat(props.maxlength, " characters");
3613
+ if (props.maxLength && trimmedValue.length > props.maxLength) {
3614
+ return "Text must be no longer than ".concat(props.maxLength, " characters");
3567
3615
  }
3568
3616
  if (props.validate) {
3569
3617
  return props.validate(trimmedValue, props.data);
@@ -3613,14 +3661,44 @@ var GridPopoverTextInput = function (colDef, params) {
3613
3661
  return GridCell(colDef, __assign({ editor: GridFormTextInput }, params));
3614
3662
  };
3615
3663
 
3664
+ var GridFormSubComponentTextInput = function (_a) {
3665
+ var keyDown = _a.keyDown, placeholder = _a.placeholder, setValue = _a.setValue;
3666
+ var placeholderText = placeholder || "Other...";
3667
+ var _b = react.useState(""), inputValue = _b[0], setInputValue = _b[1];
3668
+ return (jsxRuntime.jsx(jsxRuntime.Fragment, { children: jsxRuntime.jsx(TextInputFormatted, { value: inputValue, onChange: function (e) {
3669
+ var value = e.target.value;
3670
+ setValue(value);
3671
+ setInputValue(value);
3672
+ }, inputProps: {
3673
+ onKeyDown: function (k) { return keyDown(k.key); },
3674
+ placeholder: placeholderText,
3675
+ onMouseEnter: function (e) {
3676
+ if (document.activeElement != e.currentTarget) {
3677
+ e.currentTarget.focus();
3678
+ }
3679
+ }
3680
+ } }) }));
3681
+ };
3682
+
3616
3683
  var GridSubComponentTextArea = function (props) {
3617
- var value = props.value, setValue = props.setValue, setValid = props.setValid, triggerSave = props.triggerSave;
3684
+ var _a = react.useContext(GridSubComponentContext), value = _a.value, setValue = _a.setValue, setValid = _a.setValid, triggerSave = _a.triggerSave;
3685
+ // If is not initialised yet as it's just been created then set the default value
3686
+ react.useEffect(function () {
3687
+ if (value == null)
3688
+ setValue(props.defaultValue);
3689
+ }, [props.defaultValue, setValue, value]);
3618
3690
  var validate = react.useCallback(function (value) {
3691
+ if (value == null)
3692
+ return null;
3693
+ // This can happen because subcomponent is invoked without type safety
3694
+ if (typeof value !== "string") {
3695
+ console.error("Value is not a string", value);
3696
+ }
3619
3697
  if (props.required && value.length === 0) {
3620
3698
  return "Some text is required";
3621
3699
  }
3622
- if (props.maxlength && value.length > props.maxlength) {
3623
- return "Text must be no longer than ".concat(props.maxlength, " characters");
3700
+ if (props.maxLength && value.length > props.maxLength) {
3701
+ return "Text must be no longer than ".concat(props.maxLength, " characters");
3624
3702
  }
3625
3703
  if (props.validate) {
3626
3704
  return props.validate(value);
@@ -3628,7 +3706,7 @@ var GridSubComponentTextArea = function (props) {
3628
3706
  return null;
3629
3707
  }, [props]);
3630
3708
  react.useEffect(function () {
3631
- setValid(validate(value) == null);
3709
+ setValid(value != null && validate(value) == null);
3632
3710
  }, [setValid, validate, value]);
3633
3711
  return (jsxRuntime.jsx("div", __assign({ className: "FreeTextInput LuiDeprecatedForms" }, { children: jsxRuntime.jsx(TextInputFormatted, { className: "free-text-input", value: value, onMouseEnter: function (e) {
3634
3712
  if (document.activeElement != e.currentTarget) {
@@ -3749,6 +3827,7 @@ exports.GridContextProvider = GridContextProvider;
3749
3827
  exports.GridFormDropDown = GridFormDropDown;
3750
3828
  exports.GridFormMultiSelect = GridFormMultiSelect;
3751
3829
  exports.GridFormPopoutMenu = GridFormPopoutMenu;
3830
+ exports.GridFormSubComponentTextInput = GridFormSubComponentTextInput;
3752
3831
  exports.GridHeaderSelect = GridHeaderSelect;
3753
3832
  exports.GridIcon = GridIcon;
3754
3833
  exports.GridLoadableCell = GridLoadableCell;