shadcn-zod-formkit 1.13.0 → 1.14.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.d.mts CHANGED
@@ -80,6 +80,8 @@ declare const inputFieldComp: InputTypes[];
80
80
  interface FieldProps<T = Record<string, any>> {
81
81
  name: keyof T;
82
82
  label: string;
83
+ childrenPosition?: 'up' | 'down';
84
+ children?: ReactNode | ((item: any, index: number) => ReactNode);
83
85
  defaultValue?: any;
84
86
  repeaterFields?: Array<FieldProps | FieldProps[]>;
85
87
  minItems?: number;
@@ -173,12 +175,11 @@ declare enum TextInputType {
173
175
  PASSWORD = "password"
174
176
  }
175
177
 
176
- declare abstract class BaseInput<T = unknown> {
178
+ declare abstract class BaseInput {
177
179
  protected readonly input: FieldProps;
178
180
  protected readonly form: UseFormReturn;
179
181
  protected readonly isSubmitting?: boolean | undefined;
180
- protected readonly children?: ReactNode | ((item: T, index: number) => ReactNode);
181
- constructor(input: FieldProps, form: UseFormReturn, isSubmitting?: boolean | undefined, children?: ReactNode | ((item: T, index: number) => ReactNode));
182
+ constructor(input: FieldProps, form: UseFormReturn, isSubmitting?: boolean | undefined);
182
183
  abstract render(): JSX.Element;
183
184
  }
184
185
  declare const entityToInputOption: (entitiy: any, name?: string, description?: string, groupedLabel?: string) => InputOption;
package/dist/index.d.ts CHANGED
@@ -80,6 +80,8 @@ declare const inputFieldComp: InputTypes[];
80
80
  interface FieldProps<T = Record<string, any>> {
81
81
  name: keyof T;
82
82
  label: string;
83
+ childrenPosition?: 'up' | 'down';
84
+ children?: ReactNode | ((item: any, index: number) => ReactNode);
83
85
  defaultValue?: any;
84
86
  repeaterFields?: Array<FieldProps | FieldProps[]>;
85
87
  minItems?: number;
@@ -173,12 +175,11 @@ declare enum TextInputType {
173
175
  PASSWORD = "password"
174
176
  }
175
177
 
176
- declare abstract class BaseInput<T = unknown> {
178
+ declare abstract class BaseInput {
177
179
  protected readonly input: FieldProps;
178
180
  protected readonly form: UseFormReturn;
179
181
  protected readonly isSubmitting?: boolean | undefined;
180
- protected readonly children?: ReactNode | ((item: T, index: number) => ReactNode);
181
- constructor(input: FieldProps, form: UseFormReturn, isSubmitting?: boolean | undefined, children?: ReactNode | ((item: T, index: number) => ReactNode));
182
+ constructor(input: FieldProps, form: UseFormReturn, isSubmitting?: boolean | undefined);
182
183
  abstract render(): JSX.Element;
183
184
  }
184
185
  declare const entityToInputOption: (entitiy: any, name?: string, description?: string, groupedLabel?: string) => InputOption;
package/dist/index.mjs CHANGED
@@ -159,11 +159,10 @@ var validationMessages = {
159
159
 
160
160
  // src/components/custom/form/inputs/base/base-input.ts
161
161
  var BaseInput = class {
162
- constructor(input, form, isSubmitting, children) {
162
+ constructor(input, form, isSubmitting) {
163
163
  this.input = input;
164
164
  this.form = form;
165
165
  this.isSubmitting = isSubmitting;
166
- this.children = children;
167
166
  }
168
167
  };
169
168
  var entityToInputOption = (entitiy, name = "name", description = "description", groupedLabel) => ({
@@ -5366,6 +5365,7 @@ var getFieldLabel = (fieldErrorKey, fields) => {
5366
5365
  const foundField = fields.find((field) => field.name === fieldErrorKey);
5367
5366
  return foundField?.label ?? fieldErrorKey;
5368
5367
  };
5368
+ var isRenderableChild = (c) => c !== void 0 && c !== null && typeof c !== "function";
5369
5369
  var FormFieldsGrid = ({
5370
5370
  fields,
5371
5371
  form,
@@ -5375,23 +5375,44 @@ var FormFieldsGrid = ({
5375
5375
  gap = "gap-2"
5376
5376
  }) => {
5377
5377
  return /* @__PURE__ */ jsx("div", { className: `w-full grid grid-cols-1 ${gap} ${className}`, children: fields.map(
5378
- (input, idx) => Array.isArray(input) ? /* @__PURE__ */ jsx(
5379
- "span",
5378
+ (inputOrGroup, idx) => Array.isArray(inputOrGroup) ? /* @__PURE__ */ jsx(
5379
+ "div",
5380
5380
  {
5381
- className: "w-full flex flex-row justify-between py-3",
5382
- children: input.map((field, subIdx) => {
5383
- if (readOnly) field.disabled = true;
5384
- return /* @__PURE__ */ jsx("div", { className: "w-full px-2", children: InputFactory.create(field, form, isPending) }, subIdx);
5381
+ className: "w-full flex flex-row items-start gap-4 py-3",
5382
+ children: inputOrGroup.map((field, subIdx) => {
5383
+ const fieldCopy = {
5384
+ ...field,
5385
+ disabled: readOnly ? true : field.disabled
5386
+ };
5387
+ const renderInlineChild = fieldCopy.childrenPosition !== "down" && isRenderableChild(fieldCopy.children);
5388
+ const renderInlineChildDown = fieldCopy.childrenPosition === "down" && isRenderableChild(fieldCopy.children);
5389
+ return /* @__PURE__ */ jsxs("div", { className: "w-full px-2", children: [
5390
+ renderInlineChild && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy.children }),
5391
+ InputFactory.create(fieldCopy, form, isPending),
5392
+ renderInlineChildDown && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy.children })
5393
+ ] }, `field-${idx}-${subIdx}`);
5385
5394
  })
5386
5395
  },
5387
5396
  `field-group-${idx}`
5388
5397
  ) : /* @__PURE__ */ jsx(
5389
- "span",
5398
+ "div",
5390
5399
  {
5391
5400
  className: "flex flex-col justify-between py-3 w-full px-2",
5392
- children: InputFactory.create(input, form, isPending)
5401
+ children: (() => {
5402
+ const fieldCopy = {
5403
+ ...inputOrGroup,
5404
+ disabled: readOnly ? true : inputOrGroup.disabled
5405
+ };
5406
+ const renderUp = fieldCopy.childrenPosition !== "down" && isRenderableChild(fieldCopy.children);
5407
+ const renderDown = fieldCopy.childrenPosition === "down" && isRenderableChild(fieldCopy.children);
5408
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
5409
+ renderUp && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy.children }),
5410
+ InputFactory.create(fieldCopy, form, isPending),
5411
+ renderDown && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy.children })
5412
+ ] });
5413
+ })()
5393
5414
  },
5394
- `field-group-${idx}`
5415
+ `field-single-${idx}`
5395
5416
  )
5396
5417
  ) });
5397
5418
  };