@arturton/react-form-constructor 0.1.3 → 0.2.0

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/dist/index.js CHANGED
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,22 +17,362 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
 
20
30
  // src/index.ts
21
31
  var index_exports = {};
22
32
  __export(index_exports, {
33
+ FormButton: () => FormButton_default,
34
+ FormCheckbox: () => FormCheckbox_default,
35
+ FormDate: () => FormDate_default,
36
+ FormError: () => FormError_default,
37
+ FormFileInput: () => FormFileInput_default,
38
+ FormInput: () => FormInput_default,
39
+ FormInputLayout: () => FormInputLayout_default,
40
+ FormLabel: () => FormLabel_default,
23
41
  FormLayout: () => FormLayout,
42
+ FormMaskedInput: () => FormMaskedInput_default,
43
+ FormNumber: () => FormNumber_default,
44
+ FormPasswordInput: () => FormPasswordInput_default,
45
+ FormProvider: () => FormProvider,
46
+ FormRadio: () => FormRadio_default,
47
+ FormRange: () => FormRange_default,
48
+ FormSelect: () => FormSelect_default,
49
+ FormTextarea: () => FormTextarea_default,
24
50
  InputForm: () => InputForm_default,
25
51
  useFormContext: () => useFormContext
26
52
  });
27
53
  module.exports = __toCommonJS(index_exports);
28
54
 
29
- // src/FormLayout.tsx
30
- var import_react_hook_form2 = require("react-hook-form");
55
+ // src/JsonMethod/FormLayout.tsx
56
+ var import_react_hook_form = require("react-hook-form");
57
+ var import_react_number_format = require("react-number-format");
58
+ var import_jsx_runtime = require("react/jsx-runtime");
59
+ function FieldRenderer({
60
+ field,
61
+ register,
62
+ control,
63
+ errors,
64
+ globalClasses
65
+ }) {
66
+ const fieldName = String(field.key);
67
+ const error = errors[fieldName];
68
+ const errorMessage = error?.message;
69
+ const hasError = !!error;
70
+ const labelFieldClassName = field.labelClass || globalClasses.label;
71
+ const inputFieldClassName = `${field.inputClass || globalClasses.input || ""} ${hasError ? field.classNameError || "" : ""}`.trim();
72
+ const errorFieldClassName = field.errorClass || globalClasses.error;
73
+ if (field.render) {
74
+ return field.render({
75
+ register,
76
+ control,
77
+ errors,
78
+ field
79
+ });
80
+ }
81
+ const renderField = () => {
82
+ switch (field.type) {
83
+ // Text inputs
84
+ case "text":
85
+ case "email":
86
+ case "password":
87
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
88
+ "input",
89
+ {
90
+ ...register(fieldName, {
91
+ required: field.required,
92
+ minLength: field.minLength,
93
+ maxLength: field.maxLength,
94
+ pattern: field.pattern,
95
+ validate: field.validate
96
+ }),
97
+ type: field.type,
98
+ placeholder: field.placeholder,
99
+ className: inputFieldClassName,
100
+ disabled: field.disabled
101
+ }
102
+ );
103
+ // Number input
104
+ case "number":
105
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
106
+ "input",
107
+ {
108
+ ...register(fieldName, {
109
+ required: field.required,
110
+ minLength: field.minLength,
111
+ maxLength: field.maxLength,
112
+ validate: field.validate
113
+ }),
114
+ type: "number",
115
+ min: field.min,
116
+ max: field.max,
117
+ step: field.step || 1,
118
+ placeholder: field.placeholder,
119
+ className: inputFieldClassName,
120
+ disabled: field.disabled
121
+ }
122
+ );
123
+ // Date input
124
+ case "date":
125
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
126
+ "input",
127
+ {
128
+ ...register(fieldName, {
129
+ required: field.required,
130
+ validate: field.validate
131
+ }),
132
+ type: "date",
133
+ className: inputFieldClassName,
134
+ disabled: field.disabled
135
+ }
136
+ );
137
+ // Textarea
138
+ case "textarea":
139
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
140
+ "textarea",
141
+ {
142
+ ...register(fieldName, {
143
+ required: field.required,
144
+ minLength: field.minLength,
145
+ maxLength: field.maxLength,
146
+ validate: field.validate
147
+ }),
148
+ placeholder: field.placeholder,
149
+ className: inputFieldClassName,
150
+ disabled: field.disabled,
151
+ rows: field.rows || 4
152
+ }
153
+ );
154
+ // Select
155
+ case "select":
156
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
157
+ "select",
158
+ {
159
+ ...register(fieldName, {
160
+ required: field.required,
161
+ validate: field.validate
162
+ }),
163
+ className: inputFieldClassName,
164
+ disabled: field.disabled,
165
+ multiple: field.multiple,
166
+ children: [
167
+ field.placeholder && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "", children: field.placeholder }),
168
+ field.options?.map((option) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: option.value, children: option.label }, option.value))
169
+ ]
170
+ }
171
+ );
172
+ // Masked input
173
+ case "mask":
174
+ return field.maska ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
175
+ import_react_hook_form.Controller,
176
+ {
177
+ name: fieldName,
178
+ control,
179
+ rules: {
180
+ required: field.maska.required || field.required,
181
+ minLength: field.minLength,
182
+ maxLength: field.maxLength,
183
+ validate: field.validate
184
+ },
185
+ render: ({ field: fieldProps }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
186
+ import_react_number_format.PatternFormat,
187
+ {
188
+ ...fieldProps,
189
+ format: field.maska.format,
190
+ mask: field.maska.mask,
191
+ placeholder: field.placeholder,
192
+ className: inputFieldClassName,
193
+ disabled: field.disabled
194
+ }
195
+ )
196
+ }
197
+ ) : null;
198
+ // File input
199
+ case "file":
200
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
201
+ "input",
202
+ {
203
+ ...register(fieldName, {
204
+ required: field.required,
205
+ validate: field.validate
206
+ }),
207
+ type: "file",
208
+ accept: field.accept,
209
+ className: inputFieldClassName,
210
+ disabled: field.disabled,
211
+ multiple: field.multiple
212
+ }
213
+ );
214
+ // Checkbox
215
+ case "checkbox":
216
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: field.containerClass, children: [
217
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
218
+ "input",
219
+ {
220
+ ...register(fieldName, {
221
+ required: field.required,
222
+ validate: field.validate
223
+ }),
224
+ type: "checkbox",
225
+ id: fieldName,
226
+ className: inputFieldClassName,
227
+ disabled: field.disabled,
228
+ defaultChecked: field.defaultChecked
229
+ }
230
+ ),
231
+ field.label && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: fieldName, className: labelFieldClassName, children: field.label })
232
+ ] });
233
+ // Radio buttons
234
+ case "radio":
235
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: field.containerClass, children: field.radioOptions?.map((option) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", { className: labelFieldClassName, children: [
236
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
237
+ "input",
238
+ {
239
+ ...register(fieldName, {
240
+ required: field.required,
241
+ validate: field.validate
242
+ }),
243
+ type: "radio",
244
+ value: option.value,
245
+ className: inputFieldClassName,
246
+ disabled: field.disabled,
247
+ defaultChecked: field.defaultChecked
248
+ }
249
+ ),
250
+ option.label
251
+ ] }, option.value)) });
252
+ // Range/Slider
253
+ case "range":
254
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: field.containerClass, children: [
255
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
256
+ "input",
257
+ {
258
+ ...register(fieldName, {
259
+ required: field.required,
260
+ validate: field.validate
261
+ }),
262
+ type: "range",
263
+ min: field.min || 0,
264
+ max: field.max || 100,
265
+ step: field.step || 1,
266
+ className: inputFieldClassName,
267
+ disabled: field.disabled
268
+ }
269
+ ),
270
+ field.showValue && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: errors[fieldName]?.message || "Value" })
271
+ ] });
272
+ default:
273
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
274
+ "input",
275
+ {
276
+ ...register(fieldName, {
277
+ required: field.required,
278
+ minLength: field.minLength,
279
+ maxLength: field.maxLength,
280
+ pattern: field.pattern,
281
+ validate: field.validate
282
+ }),
283
+ type: "text",
284
+ placeholder: field.placeholder,
285
+ className: inputFieldClassName,
286
+ disabled: field.disabled
287
+ }
288
+ );
289
+ }
290
+ };
291
+ return renderField();
292
+ }
293
+ function FormLayout({
294
+ formData,
295
+ funSubmit,
296
+ defaultValues,
297
+ onError,
298
+ formClass,
299
+ containerClass,
300
+ buttonClass,
301
+ buttonName = "Submit",
302
+ labelClass,
303
+ inputClass,
304
+ errorClass,
305
+ submitButtonProps,
306
+ disabledOnError = false
307
+ }) {
308
+ const {
309
+ register,
310
+ handleSubmit,
311
+ control,
312
+ formState: { errors }
313
+ } = (0, import_react_hook_form.useForm)({
314
+ mode: "onChange",
315
+ defaultValues
316
+ });
317
+ const onSubmit = (data) => {
318
+ funSubmit(data);
319
+ };
320
+ const onSubmitError = (formErrors) => {
321
+ onError?.(formErrors);
322
+ };
323
+ const globalClasses = {
324
+ label: labelClass,
325
+ input: inputClass,
326
+ error: errorClass
327
+ };
328
+ const hasErrors = Object.keys(errors).length > 0;
329
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
330
+ "form",
331
+ {
332
+ onSubmit: handleSubmit(onSubmit, onSubmitError),
333
+ className: formClass,
334
+ children: [
335
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: containerClass, children: formData.map((field) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: field.containerClass, children: [
336
+ field.type !== "checkbox" && field.label && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
337
+ "label",
338
+ {
339
+ htmlFor: String(field.key),
340
+ className: field.labelClass || globalClasses.label,
341
+ children: [
342
+ field.label,
343
+ field.required && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: "text-red-500", children: "*" })
344
+ ]
345
+ }
346
+ ),
347
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
348
+ FieldRenderer,
349
+ {
350
+ field,
351
+ register,
352
+ control,
353
+ errors,
354
+ globalClasses
355
+ }
356
+ ),
357
+ errors[String(field.key)] && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: field.errorClass || globalClasses.error, children: errors[String(field.key)]?.message })
358
+ ] }, String(field.key))) }),
359
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
360
+ "button",
361
+ {
362
+ type: "submit",
363
+ className: buttonClass,
364
+ disabled: disabledOnError && hasErrors,
365
+ ...submitButtonProps,
366
+ children: buttonName
367
+ }
368
+ )
369
+ ]
370
+ }
371
+ );
372
+ }
31
373
 
32
374
  // src/InputForm/layouts/mainLayout.tsx
33
- var import_jsx_runtime = require("react/jsx-runtime");
375
+ var import_jsx_runtime2 = require("react/jsx-runtime");
34
376
  function MainLayout({
35
377
  children,
36
378
  label,
@@ -40,22 +382,22 @@ function MainLayout({
40
382
  labelClass,
41
383
  errorClass
42
384
  }) {
43
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { children: [
44
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", { className: labelClass, children: [
385
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { children: [
386
+ label && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("label", { className: labelClass, children: [
45
387
  label,
46
388
  " ",
47
- required ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "*" }) : null
389
+ required ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { children: "*" }) : null
48
390
  ] }),
49
391
  children,
50
- error?.[name] && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { className: errorClass, children: error?.[name]?.message })
392
+ error?.[name] && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { className: errorClass, children: error?.[name]?.message })
51
393
  ] });
52
394
  }
53
395
  var mainLayout_default = MainLayout;
54
396
 
55
397
  // src/InputForm/components/MaskedField.tsx
56
- var import_react_hook_form = require("react-hook-form");
57
- var import_react_number_format = require("react-number-format");
58
- var import_jsx_runtime2 = require("react/jsx-runtime");
398
+ var import_react_hook_form2 = require("react-hook-form");
399
+ var import_react_number_format2 = require("react-number-format");
400
+ var import_jsx_runtime3 = require("react/jsx-runtime");
59
401
  function MaskedField({
60
402
  placeholder,
61
403
  name,
@@ -63,14 +405,14 @@ function MaskedField({
63
405
  maska,
64
406
  inputClass
65
407
  }) {
66
- return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
67
- import_react_hook_form.Controller,
408
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
409
+ import_react_hook_form2.Controller,
68
410
  {
69
411
  name: name || "",
70
412
  control,
71
413
  rules: { required: maska.required },
72
- render: ({ field }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
73
- import_react_number_format.PatternFormat,
414
+ render: ({ field }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
415
+ import_react_number_format2.PatternFormat,
74
416
  {
75
417
  ...field,
76
418
  format: maska.format,
@@ -85,7 +427,7 @@ function MaskedField({
85
427
  var MaskedField_default = MaskedField;
86
428
 
87
429
  // src/InputForm/components/InputField.tsx
88
- var import_jsx_runtime3 = require("react/jsx-runtime");
430
+ var import_jsx_runtime4 = require("react/jsx-runtime");
89
431
  function InputField({
90
432
  register,
91
433
  type,
@@ -93,7 +435,7 @@ function InputField({
93
435
  inputClass,
94
436
  name
95
437
  }) {
96
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
438
+ return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
97
439
  "input",
98
440
  {
99
441
  id: name,
@@ -107,7 +449,7 @@ function InputField({
107
449
  var InputField_default = InputField;
108
450
 
109
451
  // src/InputForm/InputForm.tsx
110
- var import_jsx_runtime4 = require("react/jsx-runtime");
452
+ var import_jsx_runtime5 = require("react/jsx-runtime");
111
453
  function InputForm({
112
454
  register,
113
455
  type,
@@ -124,7 +466,7 @@ function InputForm({
124
466
  }) {
125
467
  const renderChildren = () => {
126
468
  if (maska) {
127
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
469
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
128
470
  MaskedField_default,
129
471
  {
130
472
  name,
@@ -135,7 +477,7 @@ function InputForm({
135
477
  }
136
478
  );
137
479
  } else {
138
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
480
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
139
481
  InputField_default,
140
482
  {
141
483
  name,
@@ -147,7 +489,7 @@ function InputForm({
147
489
  );
148
490
  }
149
491
  };
150
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
492
+ return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
151
493
  mainLayout_default,
152
494
  {
153
495
  label,
@@ -162,67 +504,664 @@ function InputForm({
162
504
  }
163
505
  var InputForm_default = InputForm;
164
506
 
165
- // src/FormContext.tsx
166
- var import_react = require("react");
167
- var FormContext = (0, import_react.createContext)(null);
168
- var FormProvider = FormContext.Provider;
507
+ // src/ProviderMethod/layouts/FormProvider.tsx
508
+ var import_react_hook_form3 = require("react-hook-form");
509
+
510
+ // src/ProviderMethod/context/FormContext.tsx
511
+ var import_react = __toESM(require("react"));
512
+ var FormContext = import_react.default.createContext(void 0);
169
513
  function useFormContext() {
170
- const context = (0, import_react.useContext)(FormContext);
514
+ const context = import_react.default.useContext(FormContext);
171
515
  if (!context) {
172
- throw new Error("useFormContext must be used within FormLayout");
516
+ throw new Error("useFormContext \u0434\u043E\u043B\u0436\u0435\u043D \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u044C\u0441\u044F \u0432\u043D\u0443\u0442\u0440\u0438 FormProvider");
173
517
  }
174
518
  return context;
175
519
  }
176
520
 
177
- // src/FormLayout.tsx
178
- var import_jsx_runtime5 = require("react/jsx-runtime");
179
- function FormLayout({
180
- formData,
521
+ // src/ProviderMethod/layouts/FormProvider.tsx
522
+ var import_react2 = require("react");
523
+ var import_jsx_runtime6 = require("react/jsx-runtime");
524
+ function FormProvider({
525
+ setFormApi,
526
+ children,
181
527
  funSubmit,
182
- formClass,
183
- buttonClass,
184
- children
528
+ className
185
529
  }) {
186
530
  const {
187
531
  control,
188
532
  register,
189
533
  handleSubmit,
190
534
  formState: { errors }
191
- } = (0, import_react_hook_form2.useForm)();
535
+ } = (0, import_react_hook_form3.useForm)();
192
536
  const onSubmit = (data) => {
193
537
  funSubmit(data);
194
538
  };
195
- return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(FormProvider, { value: { control, register, errors }, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("form", { onSubmit: handleSubmit(onSubmit), className: formClass, children: [
196
- formData ? formData.map((item) => /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
197
- InputForm_default,
198
- {
199
- type: item.type,
200
- placeholder: item.placeholder,
201
- error: errors,
202
- name: String(item.key),
203
- label: item.label,
204
- control,
205
- maska: item.maska,
206
- register: register(item.key, {
207
- required: item.required,
208
- minLength: item.minLength,
209
- maxLength: item.maxLength,
210
- pattern: item.pattern,
211
- validate: item.validate
212
- }),
213
- required: item.required,
214
- inputClass: item.inputClass,
215
- errorClass: item.errorClass,
216
- labelClass: item.labelClass
539
+ const values = (0, import_react_hook_form3.useWatch)({ control });
540
+ const contextValue = {
541
+ register,
542
+ errors,
543
+ control,
544
+ values
545
+ };
546
+ (0, import_react2.useEffect)(() => {
547
+ setFormApi && setFormApi({ control, register, errors, values });
548
+ }, [setFormApi, control, register, errors, values]);
549
+ return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(FormContext.Provider, { value: contextValue, children: /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("form", { onSubmit: handleSubmit(onSubmit), className, children }) });
550
+ }
551
+
552
+ // src/ProviderMethod/layouts/FormInputLayout.tsx
553
+ var import_react3 = __toESM(require("react"));
554
+ var import_jsx_runtime7 = require("react/jsx-runtime");
555
+ var FormInputLayoutContext = import_react3.default.createContext(void 0);
556
+ function useInputLayoutContext() {
557
+ const context = import_react3.default.useContext(FormInputLayoutContext);
558
+ if (!context) {
559
+ throw new Error(
560
+ "useInputLayoutContext \u0434\u043E\u043B\u0436\u0435\u043D \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u043E\u0432\u0430\u0442\u044C\u0441\u044F \u0432\u043D\u0443\u0442\u0440\u0438 FormInputLayout"
561
+ );
562
+ }
563
+ return context;
564
+ }
565
+ function useOptionalInputLayoutContext() {
566
+ return import_react3.default.useContext(FormInputLayoutContext);
567
+ }
568
+ function FormInputLayout({
569
+ name,
570
+ minLength,
571
+ maxLength,
572
+ pattern,
573
+ required,
574
+ validate,
575
+ children,
576
+ className,
577
+ maska
578
+ }) {
579
+ const contextValue = {
580
+ name,
581
+ minLength,
582
+ maxLength,
583
+ pattern,
584
+ required,
585
+ validate,
586
+ maska
587
+ };
588
+ return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(FormInputLayoutContext.Provider, { value: contextValue, children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className, children }) });
589
+ }
590
+ var FormInputLayout_default = FormInputLayout;
591
+
592
+ // src/ProviderMethod/components/FormInput.tsx
593
+ var import_jsx_runtime8 = require("react/jsx-runtime");
594
+ function FormInput({
595
+ placeholder,
596
+ className,
597
+ classNameError,
598
+ type
599
+ }) {
600
+ const { register, errors } = useFormContext();
601
+ const { name, required, minLength, maxLength, pattern, validate } = useInputLayoutContext();
602
+ const isErrorMessage = !!errors[name]?.message;
603
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
604
+ "input",
605
+ {
606
+ id: name,
607
+ ...register(name, {
608
+ required,
609
+ minLength,
610
+ maxLength,
611
+ pattern,
612
+ validate
613
+ }),
614
+ type: type ? type : "text",
615
+ placeholder: placeholder ? placeholder : "",
616
+ className: `${className} ${isErrorMessage ? classNameError : ""}`
617
+ }
618
+ );
619
+ }
620
+ var FormInput_default = FormInput;
621
+
622
+ // src/ProviderMethod/components/FormPasswordInput.tsx
623
+ var import_react4 = require("react");
624
+ var import_jsx_runtime9 = require("react/jsx-runtime");
625
+ var EyeIcon = ({ className }) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
626
+ "svg",
627
+ {
628
+ width: "20",
629
+ height: "20",
630
+ viewBox: "0 0 24 24",
631
+ fill: "none",
632
+ stroke: "currentColor",
633
+ strokeWidth: "2",
634
+ strokeLinecap: "round",
635
+ strokeLinejoin: "round",
636
+ className,
637
+ children: [
638
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("path", { d: "M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" }),
639
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("circle", { cx: "12", cy: "12", r: "3" })
640
+ ]
641
+ }
642
+ );
643
+ var EyeOffIcon = ({ className }) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
644
+ "svg",
645
+ {
646
+ width: "20",
647
+ height: "20",
648
+ viewBox: "0 0 24 24",
649
+ fill: "none",
650
+ stroke: "currentColor",
651
+ strokeWidth: "2",
652
+ strokeLinecap: "round",
653
+ strokeLinejoin: "round",
654
+ className,
655
+ children: [
656
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("path", { d: "M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24" }),
657
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("line", { x1: "1", y1: "1", x2: "23", y2: "23" })
658
+ ]
659
+ }
660
+ );
661
+ function FormPasswordInput({
662
+ placeholder,
663
+ className,
664
+ inputClassName,
665
+ classNameError,
666
+ visibleIcon = /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(EyeIcon, {}),
667
+ hiddenIcon = /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(EyeOffIcon, {}),
668
+ iconClassName,
669
+ iconWrapperClassName = "cursor-pointer"
670
+ }) {
671
+ const [isVisible, setIsVisible] = (0, import_react4.useState)(false);
672
+ const { register, errors } = useFormContext();
673
+ const { name, required, minLength, maxLength, pattern, validate } = useInputLayoutContext();
674
+ const isErrorMessage = !!errors[name]?.message;
675
+ const toggleVisibility = () => {
676
+ setIsVisible(!isVisible);
677
+ };
678
+ return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
679
+ "div",
680
+ {
681
+ className,
682
+ style: { display: "flex", alignItems: "center", gap: "8px" },
683
+ children: [
684
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
685
+ "input",
686
+ {
687
+ id: name,
688
+ ...register(name, {
689
+ required,
690
+ minLength,
691
+ maxLength,
692
+ pattern,
693
+ validate
694
+ }),
695
+ type: isVisible ? "text" : "password",
696
+ placeholder: placeholder ? placeholder : "",
697
+ className: `${inputClassName} ${isErrorMessage ? classNameError : ""}`,
698
+ style: { flex: 1 }
699
+ }
700
+ ),
701
+ /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
702
+ "div",
703
+ {
704
+ onClick: toggleVisibility,
705
+ className: `${iconClassName ? iconClassName : iconWrapperClassName}`,
706
+ style: {
707
+ cursor: "pointer",
708
+ userSelect: "none",
709
+ display: "flex",
710
+ alignItems: "center"
711
+ },
712
+ title: isVisible ? "\u0421\u043A\u0440\u044B\u0442\u044C \u043F\u0430\u0440\u043E\u043B\u044C" : "\u041F\u043E\u043A\u0430\u0437\u0430\u0442\u044C \u043F\u0430\u0440\u043E\u043B\u044C",
713
+ children: isVisible ? visibleIcon : hiddenIcon
714
+ }
715
+ )
716
+ ]
717
+ }
718
+ );
719
+ }
720
+ var FormPasswordInput_default = FormPasswordInput;
721
+
722
+ // src/ProviderMethod/components/FormTextarea.tsx
723
+ var import_jsx_runtime10 = require("react/jsx-runtime");
724
+ function FormTextarea({
725
+ placeholder,
726
+ className,
727
+ classNameError,
728
+ rows,
729
+ cols
730
+ }) {
731
+ const { register, errors } = useFormContext();
732
+ const { name, required, minLength, maxLength, pattern, validate } = useInputLayoutContext();
733
+ const isErrorMessage = !!errors[name]?.message;
734
+ return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
735
+ "textarea",
736
+ {
737
+ id: name,
738
+ ...register(name, {
739
+ required,
740
+ minLength,
741
+ maxLength,
742
+ pattern,
743
+ validate
744
+ }),
745
+ placeholder: placeholder ? placeholder : "",
746
+ className: `${className} ${isErrorMessage ? classNameError : ""}`,
747
+ rows,
748
+ cols
749
+ }
750
+ );
751
+ }
752
+ var FormTextarea_default = FormTextarea;
753
+
754
+ // src/ProviderMethod/components/FormMaskedInput.tsx
755
+ var import_react_hook_form4 = require("react-hook-form");
756
+ var import_react_number_format3 = require("react-number-format");
757
+ var import_jsx_runtime11 = require("react/jsx-runtime");
758
+ function FormMaskedInput({
759
+ placeholder,
760
+ className,
761
+ classNameError
762
+ }) {
763
+ const { control, errors } = useFormContext();
764
+ const { name, required, minLength, maxLength, pattern, validate, maska } = useInputLayoutContext();
765
+ const isErrorMessage = !!errors[name]?.message;
766
+ if (!maska) {
767
+ return null;
768
+ }
769
+ return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
770
+ import_react_hook_form4.Controller,
771
+ {
772
+ name: name || "",
773
+ control,
774
+ rules: {
775
+ required: maska.required ?? required,
776
+ minLength,
777
+ maxLength,
778
+ pattern,
779
+ validate
217
780
  },
218
- String(item.key)
219
- )) : children,
220
- /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("button", { type: "submit", className: buttonClass, children: "\u041E\u0442\u043F\u0440\u0430\u0432\u0438\u0442\u044C" })
221
- ] }) });
781
+ render: ({ field }) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
782
+ import_react_number_format3.PatternFormat,
783
+ {
784
+ ...field,
785
+ format: maska.format,
786
+ mask: maska.mask,
787
+ placeholder: placeholder ? placeholder : "",
788
+ className: `${className} ${isErrorMessage ? classNameError : ""}`
789
+ }
790
+ )
791
+ }
792
+ );
793
+ }
794
+ var FormMaskedInput_default = FormMaskedInput;
795
+
796
+ // src/ProviderMethod/components/FormSelect.tsx
797
+ var import_jsx_runtime12 = require("react/jsx-runtime");
798
+ function FormSelect({
799
+ options,
800
+ className,
801
+ classNameError,
802
+ multiple,
803
+ placeholder
804
+ }) {
805
+ const { register, errors } = useFormContext();
806
+ const { name, required, validate } = useInputLayoutContext();
807
+ const isErrorMessage = !!errors[name]?.message;
808
+ return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(
809
+ "select",
810
+ {
811
+ id: name,
812
+ ...register(name, {
813
+ required,
814
+ validate
815
+ }),
816
+ className: `${className} ${isErrorMessage ? classNameError : ""}`,
817
+ multiple,
818
+ children: [
819
+ placeholder && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("option", { value: "", children: placeholder }),
820
+ options.map((option) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)("option", { value: option.value, children: option.label }, option.value))
821
+ ]
822
+ }
823
+ );
824
+ }
825
+ var FormSelect_default = FormSelect;
826
+
827
+ // src/ProviderMethod/components/FormNumber.tsx
828
+ var import_jsx_runtime13 = require("react/jsx-runtime");
829
+ function FormNumber({
830
+ placeholder,
831
+ className,
832
+ classNameError,
833
+ min,
834
+ max,
835
+ step
836
+ }) {
837
+ const { register, errors } = useFormContext();
838
+ const { name, required, validate } = useInputLayoutContext();
839
+ const isErrorMessage = !!errors[name]?.message;
840
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
841
+ "input",
842
+ {
843
+ id: name,
844
+ type: "number",
845
+ ...register(name, {
846
+ required,
847
+ validate,
848
+ valueAsNumber: true
849
+ }),
850
+ placeholder: placeholder ? placeholder : "",
851
+ className: `${className} ${isErrorMessage ? classNameError : ""}`,
852
+ min,
853
+ max,
854
+ step
855
+ }
856
+ );
857
+ }
858
+ var FormNumber_default = FormNumber;
859
+
860
+ // src/ProviderMethod/components/FormDate.tsx
861
+ var import_jsx_runtime14 = require("react/jsx-runtime");
862
+ function FormDate({
863
+ placeholder,
864
+ className,
865
+ classNameError,
866
+ min,
867
+ max,
868
+ type = "date"
869
+ }) {
870
+ const { register, errors } = useFormContext();
871
+ const { name, required, validate } = useInputLayoutContext();
872
+ const isErrorMessage = !!errors[name]?.message;
873
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
874
+ "input",
875
+ {
876
+ id: name,
877
+ type,
878
+ ...register(name, {
879
+ required,
880
+ validate
881
+ }),
882
+ placeholder: placeholder ? placeholder : "",
883
+ className: `${className} ${isErrorMessage ? classNameError : ""}`,
884
+ min,
885
+ max
886
+ }
887
+ );
888
+ }
889
+ var FormDate_default = FormDate;
890
+
891
+ // src/ProviderMethod/components/FormRange.tsx
892
+ var import_react5 = require("react");
893
+ var import_jsx_runtime15 = require("react/jsx-runtime");
894
+ function FormRange({
895
+ className,
896
+ classNameError,
897
+ min = 0,
898
+ max = 100,
899
+ step = 1,
900
+ range = "single",
901
+ showValue,
902
+ containerClassName
903
+ }) {
904
+ const { register, control, errors } = useFormContext();
905
+ const { name, required, validate } = useInputLayoutContext();
906
+ const [value, setValue] = (0, import_react5.useState)(min);
907
+ const [maxValue, setMaxValue] = (0, import_react5.useState)(max);
908
+ const isErrorMessage = !!errors[name]?.message;
909
+ return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { className: containerClassName, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
910
+ "div",
911
+ {
912
+ style: {
913
+ display: "flex",
914
+ gap: "16px",
915
+ alignItems: "flex-start",
916
+ flexWrap: "wrap"
917
+ },
918
+ children: [
919
+ range === "single" && /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { style: { flex: 1, minWidth: "200px" }, children: [
920
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
921
+ "input",
922
+ {
923
+ id: name,
924
+ type: "range",
925
+ ...register(name, {
926
+ required,
927
+ validate
928
+ }),
929
+ className: `${className} w-full ${isErrorMessage ? classNameError : ""}`,
930
+ min,
931
+ max,
932
+ step,
933
+ onChange: (e) => setValue(Number(e.target.value)),
934
+ style: { cursor: "pointer" }
935
+ }
936
+ ),
937
+ showValue && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { style: { marginTop: "8px", fontSize: "14px" }, children: value })
938
+ ] }),
939
+ range === "double" && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { style: { flex: 1, minWidth: "200px" }, children: /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)(
940
+ "div",
941
+ {
942
+ style: {
943
+ display: "flex",
944
+ flexDirection: "column",
945
+ gap: "12px"
946
+ },
947
+ children: [
948
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { children: [
949
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("label", { style: { fontSize: "12px", marginRight: "8px" }, children: "\u041E\u0442:" }),
950
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
951
+ "input",
952
+ {
953
+ type: "range",
954
+ ...register(`${name}_min`, {
955
+ required,
956
+ validate
957
+ }),
958
+ className: `${className} w-full ${isErrorMessage ? classNameError : ""}`,
959
+ min,
960
+ max: maxValue,
961
+ step,
962
+ onChange: (e) => setValue(Number(e.target.value)),
963
+ style: { cursor: "pointer" }
964
+ }
965
+ ),
966
+ showValue && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { style: { marginTop: "4px", fontSize: "12px" }, children: value })
967
+ ] }),
968
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { children: [
969
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("label", { style: { fontSize: "12px", marginRight: "8px" }, children: "\u0414\u043E:" }),
970
+ /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(
971
+ "input",
972
+ {
973
+ type: "range",
974
+ ...register(`${name}_max`, {
975
+ required,
976
+ validate
977
+ }),
978
+ className: `${className} w-full ${isErrorMessage ? classNameError : ""}`,
979
+ min: value,
980
+ max,
981
+ step,
982
+ onChange: (e) => setMaxValue(Number(e.target.value)),
983
+ style: { cursor: "pointer" }
984
+ }
985
+ ),
986
+ showValue && /* @__PURE__ */ (0, import_jsx_runtime15.jsx)("div", { style: { marginTop: "4px", fontSize: "12px" }, children: maxValue })
987
+ ] }),
988
+ showValue && /* @__PURE__ */ (0, import_jsx_runtime15.jsxs)("div", { style: { fontSize: "14px", fontWeight: "bold" }, children: [
989
+ "\u0414\u0438\u0430\u043F\u0430\u0437\u043E\u043D: ",
990
+ value,
991
+ " - ",
992
+ maxValue
993
+ ] })
994
+ ]
995
+ }
996
+ ) })
997
+ ]
998
+ }
999
+ ) });
1000
+ }
1001
+ var FormRange_default = FormRange;
1002
+
1003
+ // src/ProviderMethod/components/FormFileInput.tsx
1004
+ var import_jsx_runtime16 = require("react/jsx-runtime");
1005
+ function FormFileInput({
1006
+ className,
1007
+ classNameError,
1008
+ accept,
1009
+ multiple
1010
+ }) {
1011
+ const { register, errors } = useFormContext();
1012
+ const { name, required, validate } = useInputLayoutContext();
1013
+ const isErrorMessage = !!errors[name]?.message;
1014
+ return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(
1015
+ "input",
1016
+ {
1017
+ id: name,
1018
+ type: "file",
1019
+ ...register(name, {
1020
+ required,
1021
+ validate
1022
+ }),
1023
+ className: `${className} ${isErrorMessage ? classNameError : ""}`,
1024
+ accept,
1025
+ multiple
1026
+ }
1027
+ );
1028
+ }
1029
+ var FormFileInput_default = FormFileInput;
1030
+
1031
+ // src/ProviderMethod/components/FormCheckbox.tsx
1032
+ var import_jsx_runtime17 = require("react/jsx-runtime");
1033
+ function FormCheckbox({
1034
+ className,
1035
+ classNameError,
1036
+ value,
1037
+ defaultChecked,
1038
+ disabled
1039
+ }) {
1040
+ const { register, errors } = useFormContext();
1041
+ const { name, required, validate } = useInputLayoutContext();
1042
+ const isErrorMessage = !!errors[name]?.message;
1043
+ return /* @__PURE__ */ (0, import_jsx_runtime17.jsx)(
1044
+ "input",
1045
+ {
1046
+ id: name,
1047
+ type: "checkbox",
1048
+ ...register(name, {
1049
+ required,
1050
+ validate
1051
+ }),
1052
+ className: `${className} ${isErrorMessage ? classNameError : ""}`,
1053
+ value,
1054
+ defaultChecked,
1055
+ disabled
1056
+ }
1057
+ );
1058
+ }
1059
+ var FormCheckbox_default = FormCheckbox;
1060
+
1061
+ // src/ProviderMethod/components/FormRadio.tsx
1062
+ var import_jsx_runtime18 = require("react/jsx-runtime");
1063
+ function FormRadio({
1064
+ className,
1065
+ classNameError,
1066
+ value,
1067
+ defaultChecked,
1068
+ disabled
1069
+ }) {
1070
+ const { register, errors } = useFormContext();
1071
+ const { name, required, validate } = useInputLayoutContext();
1072
+ const isErrorMessage = !!errors[name]?.message;
1073
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(
1074
+ "input",
1075
+ {
1076
+ id: `${name}-${value}`,
1077
+ type: "radio",
1078
+ ...register(name, {
1079
+ required,
1080
+ validate
1081
+ }),
1082
+ className: `${className} ${isErrorMessage ? classNameError : ""}`,
1083
+ value,
1084
+ defaultChecked,
1085
+ disabled
1086
+ }
1087
+ );
1088
+ }
1089
+ var FormRadio_default = FormRadio;
1090
+
1091
+ // src/ProviderMethod/components/FormButton.tsx
1092
+ var import_jsx_runtime19 = require("react/jsx-runtime");
1093
+ function FormButton({
1094
+ children,
1095
+ className,
1096
+ disabledError,
1097
+ ...props
1098
+ }) {
1099
+ const { errors } = useFormContext();
1100
+ const errorMessage = errors && Object.keys(errors).length > 0;
1101
+ return /* @__PURE__ */ (0, import_jsx_runtime19.jsx)(
1102
+ "button",
1103
+ {
1104
+ type: "submit",
1105
+ className: `${className}`,
1106
+ ...props,
1107
+ disabled: errorMessage && disabledError,
1108
+ children
1109
+ }
1110
+ );
1111
+ }
1112
+ var FormButton_default = FormButton;
1113
+
1114
+ // src/ProviderMethod/components/FormError.tsx
1115
+ var import_jsx_runtime20 = require("react/jsx-runtime");
1116
+ function FormError({ ...props }) {
1117
+ const { errors } = useFormContext();
1118
+ const { name } = useInputLayoutContext();
1119
+ const layout = useOptionalInputLayoutContext();
1120
+ const resolvedName = name ?? layout?.name;
1121
+ if (!resolvedName) {
1122
+ return null;
1123
+ }
1124
+ const errorMessage = errors[resolvedName]?.message;
1125
+ return /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("span", { ...props, children: typeof errorMessage === "string" ? errorMessage : null });
1126
+ }
1127
+ var FormError_default = FormError;
1128
+
1129
+ // src/ProviderMethod/components/FormLabel.tsx
1130
+ var import_jsx_runtime21 = require("react/jsx-runtime");
1131
+ function FormLabel({
1132
+ children,
1133
+ className,
1134
+ classNameError
1135
+ }) {
1136
+ const { required } = useInputLayoutContext();
1137
+ const { errors } = useFormContext();
1138
+ const { name } = useInputLayoutContext();
1139
+ const isErrorMessage = !!errors[name]?.message;
1140
+ return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("label", { className: `${className} ${isErrorMessage ? classNameError : ""}`, children: [
1141
+ children,
1142
+ !!required && "*"
1143
+ ] });
222
1144
  }
1145
+ var FormLabel_default = FormLabel;
223
1146
  // Annotate the CommonJS export names for ESM import in node:
224
1147
  0 && (module.exports = {
1148
+ FormButton,
1149
+ FormCheckbox,
1150
+ FormDate,
1151
+ FormError,
1152
+ FormFileInput,
1153
+ FormInput,
1154
+ FormInputLayout,
1155
+ FormLabel,
225
1156
  FormLayout,
1157
+ FormMaskedInput,
1158
+ FormNumber,
1159
+ FormPasswordInput,
1160
+ FormProvider,
1161
+ FormRadio,
1162
+ FormRange,
1163
+ FormSelect,
1164
+ FormTextarea,
226
1165
  InputForm,
227
1166
  useFormContext
228
1167
  });