shadcn-zod-formkit 1.22.3 → 1.22.4

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
@@ -79,8 +79,8 @@ declare enum InputTypes {
79
79
  declare const inputFieldComp: InputTypes[];
80
80
 
81
81
  declare const flattenFields: <T extends Record<string, any>>(fields: FieldConfig<T>[]) => FieldProps<T>[];
82
- type FieldConfig<T> = FieldProps<T> | FieldConfig<T>[];
83
- interface FieldProps<T = Record<string, any>> {
82
+ type FieldConfig<T, RT = Record<string, any>> = FieldProps<T, RT> | FieldConfig<T, RT>[];
83
+ interface FieldProps<T = Record<string, any>, RT = Record<string, any>> {
84
84
  name: keyof T;
85
85
  label: string;
86
86
  onChange?: (...event: any[]) => void;
@@ -89,7 +89,7 @@ interface FieldProps<T = Record<string, any>> {
89
89
  children?: ReactNode | ((item: any, index: number) => ReactNode);
90
90
  defaultValue?: any;
91
91
  direction?: 'row' | 'col';
92
- repeaterFields?: Array<FieldProps | FieldProps[]>;
92
+ repeaterFields?: FieldConfig<RT>;
93
93
  minItems?: number;
94
94
  maxItems?: number;
95
95
  currencyFormat?: Intl.NumberFormatOptions;
package/dist/index.d.ts CHANGED
@@ -79,8 +79,8 @@ declare enum InputTypes {
79
79
  declare const inputFieldComp: InputTypes[];
80
80
 
81
81
  declare const flattenFields: <T extends Record<string, any>>(fields: FieldConfig<T>[]) => FieldProps<T>[];
82
- type FieldConfig<T> = FieldProps<T> | FieldConfig<T>[];
83
- interface FieldProps<T = Record<string, any>> {
82
+ type FieldConfig<T, RT = Record<string, any>> = FieldProps<T, RT> | FieldConfig<T, RT>[];
83
+ interface FieldProps<T = Record<string, any>, RT = Record<string, any>> {
84
84
  name: keyof T;
85
85
  label: string;
86
86
  onChange?: (...event: any[]) => void;
@@ -89,7 +89,7 @@ interface FieldProps<T = Record<string, any>> {
89
89
  children?: ReactNode | ((item: any, index: number) => ReactNode);
90
90
  defaultValue?: any;
91
91
  direction?: 'row' | 'col';
92
- repeaterFields?: Array<FieldProps | FieldProps[]>;
92
+ repeaterFields?: FieldConfig<RT>;
93
93
  minItems?: number;
94
94
  maxItems?: number;
95
95
  currencyFormat?: Intl.NumberFormatOptions;
package/dist/index.mjs CHANGED
@@ -5551,49 +5551,55 @@ var getFieldLabel = (fieldErrorKey, fields) => {
5551
5551
  return foundField?.label ?? fieldErrorKey;
5552
5552
  };
5553
5553
  var isRenderableChild = (c) => c !== void 0 && c !== null && typeof c !== "function";
5554
- var isFieldProps = (f) => !Array.isArray(f);
5555
5554
  var FormFieldsGrid = ({
5556
5555
  fields,
5557
5556
  form,
5558
5557
  isPending,
5559
5558
  readOnly,
5560
5559
  className = "",
5561
- gap = "gap-4"
5560
+ gap = "gap-2"
5562
5561
  }) => {
5563
- const renderField = (field) => {
5564
- const fieldCopy = { ...field, disabled: readOnly ? true : field.disabled };
5565
- const renderUp = fieldCopy.childrenPosition !== "down" && isRenderableChild(fieldCopy.children);
5566
- const renderDown = fieldCopy.childrenPosition === "down" && isRenderableChild(fieldCopy.children);
5567
- const dirClass = fieldCopy.direction === "row" ? "flex flex-col sm:flex-row sm:items-center sm:gap-x-4 gap-y-2 flex-wrap" : "flex flex-col gap-2";
5568
- return /* @__PURE__ */ jsxs("div", { className: dirClass, children: [
5569
- renderUp && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy.children }),
5570
- InputFactory.create(fieldCopy, form, isPending),
5571
- renderDown && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy.children })
5572
- ] });
5573
- };
5574
- const renderColumn = (col, parentKey = "") => {
5575
- if (col.length === 0) return null;
5576
- const colDirection = isFieldProps(col[0]) && col[0].direction === "row" ? "flex flex-col sm:flex-row sm:items-center sm:gap-x-4 gap-y-2 flex-wrap" : "flex flex-col w-full";
5577
- return /* @__PURE__ */ jsx("div", { className: colDirection, children: col.map((item, idx) => {
5578
- if (isFieldProps(item))
5579
- return /* @__PURE__ */ jsx("div", { className: "flex-1 min-w-[200px]", children: renderField(item) }, `${parentKey}${item.name.toString()}-${idx}`);
5580
- if (Array.isArray(item)) return renderColumn(item, `${parentKey}col${idx}-`);
5581
- return null;
5582
- }) });
5583
- };
5584
- const renderRow = (row, parentKey = "") => {
5585
- if (row.length === 0) return null;
5586
- return /* @__PURE__ */ jsx("div", { className: "w-full flex flex-col sm:flex-row sm:gap-x-4 gap-y-2 py-2 flex-wrap gap-4", children: row.map((col, idx) => {
5587
- if (isFieldProps(col)) return renderColumn([col], `${parentKey}row${idx}-`);
5588
- if (Array.isArray(col)) return renderColumn(col, `${parentKey}row${idx}-`);
5589
- return null;
5590
- }) });
5591
- };
5592
- return /* @__PURE__ */ jsx("div", { className: `w-full flex flex-col ${gap} ${className}`, children: fields.map((f, idx) => {
5593
- if (isFieldProps(f)) return /* @__PURE__ */ jsx("div", { children: renderField(f) }, `field-${f.name.toString()}-${idx}`);
5594
- if (Array.isArray(f)) return /* @__PURE__ */ jsx("div", { children: renderRow(f, `row-${idx}-`) }, `row-${idx}`);
5595
- return null;
5596
- }) });
5562
+ return /* @__PURE__ */ jsx("div", { className: `w-full grid grid-cols-1 ${gap} ${className}`, children: fields.map(
5563
+ (inputOrGroup, idx) => Array.isArray(inputOrGroup) ? /* @__PURE__ */ jsx(
5564
+ "div",
5565
+ {
5566
+ className: "w-full flex flex-row items-start gap-4 py-3",
5567
+ children: inputOrGroup.map((field, subIdx) => {
5568
+ const fieldCopy = {
5569
+ ...field,
5570
+ disabled: readOnly ? true : field.disabled
5571
+ };
5572
+ const renderInlineChild = fieldCopy.childrenPosition !== "down" && isRenderableChild(fieldCopy.children);
5573
+ const renderInlineChildDown = fieldCopy.childrenPosition === "down" && isRenderableChild(fieldCopy.children);
5574
+ return /* @__PURE__ */ jsxs("div", { className: "w-full px-2", children: [
5575
+ renderInlineChild && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy.children }),
5576
+ InputFactory.create(fieldCopy, form, isPending),
5577
+ renderInlineChildDown && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy.children })
5578
+ ] }, `field-${idx}-${subIdx}`);
5579
+ })
5580
+ },
5581
+ `field-group-${idx}`
5582
+ ) : /* @__PURE__ */ jsx(
5583
+ "div",
5584
+ {
5585
+ className: "flex flex-col justify-between py-3 w-full px-2",
5586
+ children: (() => {
5587
+ const fieldCopy = {
5588
+ ...inputOrGroup,
5589
+ disabled: readOnly ? true : inputOrGroup.disabled
5590
+ };
5591
+ const renderUp = fieldCopy.childrenPosition !== "down" && isRenderableChild(fieldCopy.children);
5592
+ const renderDown = fieldCopy.childrenPosition === "down" && isRenderableChild(fieldCopy.children);
5593
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
5594
+ renderUp && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy.children }),
5595
+ InputFactory.create(fieldCopy, form, isPending),
5596
+ renderDown && /* @__PURE__ */ jsx(Fragment, { children: fieldCopy.children })
5597
+ ] });
5598
+ })()
5599
+ },
5600
+ `field-single-${idx}`
5601
+ )
5602
+ ) });
5597
5603
  };
5598
5604
  var DynamicForm = ({
5599
5605
  formTitle,