albinasoft-ui-package 1.0.93 → 1.0.94

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,5 +1,8 @@
1
1
  import React from "react";
2
- interface AlbinaFormProps {
2
+ export interface AlbinaFormHandles {
3
+ getFormValues: () => Record<string, any>;
4
+ }
5
+ export interface AlbinaFormProps {
3
6
  /** Başlangıç form değerleri */
4
7
  initialValues?: Record<string, any>;
5
8
  /** Form elemanları konfigürasyonu (CustomForm’un elements prop’una verilecek) */
@@ -15,9 +18,9 @@ interface AlbinaFormProps {
15
18
  /** İptal butonu görünürlüğü */
16
19
  showCancelButton?: boolean;
17
20
  /** Form gönderme işlemi */
18
- onSubmit: (values: Record<string, any>) => void;
21
+ onSubmit: (values: Record<string, any>) => Promise<any> | void;
19
22
  /** İptal işlemi */
20
23
  onCancel?: () => void;
21
24
  }
22
- declare const AlbinaForm: React.FC<AlbinaFormProps>;
25
+ declare const AlbinaForm: React.ForwardRefExoticComponent<AlbinaFormProps & React.RefAttributes<AlbinaFormHandles>>;
23
26
  export default AlbinaForm;
@@ -36,9 +36,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
36
36
  Object.defineProperty(exports, "__esModule", { value: true });
37
37
  var react_1 = __importStar(require("react"));
38
38
  var CustomForm_1 = __importStar(require("./CustomForm"));
39
- var AlbinaForm = function (_a) {
39
+ var AlbinaForm = (0, react_1.forwardRef)(function (_a, ref) {
40
40
  var _b = _a.initialValues, initialValues = _b === void 0 ? {} : _b, elements = _a.elements, _c = _a.innerRowCustomClass, innerRowCustomClass = _c === void 0 ? "justify-content-evenly" : _c, _d = _a.confirmLabel, confirmLabel = _d === void 0 ? "Gönder" : _d, _e = _a.cancelLabel, cancelLabel = _e === void 0 ? "İptal" : _e, _f = _a.showConfirmButton, showConfirmButton = _f === void 0 ? true : _f, _g = _a.showCancelButton, showCancelButton = _g === void 0 ? false : _g, onSubmit = _a.onSubmit, onCancel = _a.onCancel;
41
41
  var _h = (0, react_1.useState)(initialValues), formValues = _h[0], setFormValues = _h[1];
42
+ // Her input için onChange eventini içeren ortak handler
42
43
  var handleInputChange = function (id) { return function (e) {
43
44
  if (e instanceof Date || e === null) {
44
45
  setFormValues(function (prev) {
@@ -60,6 +61,7 @@ var AlbinaForm = function (_a) {
60
61
  });
61
62
  }
62
63
  }; };
64
+ // Elemana ait onChange handler ile formValues state'ini update ediyoruz.
63
65
  var enhancedElements = elements.map(function (element) {
64
66
  if (element.id && element.type === CustomForm_1.ElementType.SELECT) {
65
67
  return __assign(__assign({}, element), { value: formValues[element.id] || [], onChange: handleInputChange(element.id) });
@@ -72,6 +74,14 @@ var AlbinaForm = function (_a) {
72
74
  var handleFormSubmit = function (values) {
73
75
  onSubmit(formValues);
74
76
  };
77
+ // Ref üzerinden dışarıya sunulacak metod
78
+ var getFormValues = function () {
79
+ return formValues;
80
+ };
81
+ // useImperativeHandle ile ref üzerinden sunulan metotları belirtiyoruz.
82
+ (0, react_1.useImperativeHandle)(ref, function () { return ({
83
+ getFormValues: getFormValues,
84
+ }); });
75
85
  return (react_1.default.createElement(CustomForm_1.default, { elements: enhancedElements, innerRowCustomClass: innerRowCustomClass, confirmLabel: confirmLabel, cancelLabel: cancelLabel, showConfirmButton: showConfirmButton, showCancelButton: showCancelButton, onSubmit: handleFormSubmit, handleCancel: onCancel }));
76
- };
86
+ });
77
87
  exports.default = AlbinaForm;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "albinasoft-ui-package",
3
- "version": "1.0.93",
3
+ "version": "1.0.94",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {