shadcn-zod-formkit 1.14.0 → 1.16.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/README.md CHANGED
@@ -26,7 +26,7 @@ yarn add shadcn-zod-formkit
26
26
  You need installa shadcn basic components
27
27
  ```typescript
28
28
  # Add Shadcn Basics
29
- npx shadcn@latest add accordion alert badge button calendar card checkbox dialog popover form input label select sonner tooltip switch textarea input-otp collapsible input-group radio-group slider button-group command
29
+ npx shadcn@latest add accordion alert badge button calendar card checkbox dialog popover form input label select sonner tooltip switch textarea input-otp collapsible input-group radio-group slider button-group command tabs
30
30
  ```
31
31
 
32
32
 
package/dist/index.cjs CHANGED
@@ -27,6 +27,7 @@ var sonner = require('sonner');
27
27
  var SwitchPrimitive = require('@radix-ui/react-switch');
28
28
  var TooltipPrimitive = require('@radix-ui/react-tooltip');
29
29
  var cmdk = require('cmdk');
30
+ var TabsPrimitive = require('@radix-ui/react-tabs');
30
31
  var SliderPrimitive = require('@radix-ui/react-slider');
31
32
  var core = require('@dnd-kit/core');
32
33
  var sortable = require('@dnd-kit/sortable');
@@ -67,6 +68,7 @@ var ScrollAreaPrimitive__namespace = /*#__PURE__*/_interopNamespace(ScrollAreaPr
67
68
  var SelectPrimitive__namespace = /*#__PURE__*/_interopNamespace(SelectPrimitive);
68
69
  var SwitchPrimitive__namespace = /*#__PURE__*/_interopNamespace(SwitchPrimitive);
69
70
  var TooltipPrimitive__namespace = /*#__PURE__*/_interopNamespace(TooltipPrimitive);
71
+ var TabsPrimitive__namespace = /*#__PURE__*/_interopNamespace(TabsPrimitive);
70
72
  var SliderPrimitive__namespace = /*#__PURE__*/_interopNamespace(SliderPrimitive);
71
73
  var z2__default = /*#__PURE__*/_interopDefault(z2);
72
74
 
@@ -273,9 +275,11 @@ var InputTypes = /* @__PURE__ */ ((InputTypes2) => {
273
275
  InputTypes2["MULTI_SELECT"] = "multi_select";
274
276
  InputTypes2["COMBOBOX"] = "COMBO_BOX";
275
277
  InputTypes2["SORTABLE_LIST"] = "sortable_list";
278
+ InputTypes2["REPEATER_TABS"] = "repeater_tabs";
276
279
  return InputTypes2;
277
280
  })(InputTypes || {});
278
281
  var inputFieldComp = [
282
+ "repeater_tabs" /* REPEATER_TABS */,
279
283
  "sortable_list" /* SORTABLE_LIST */,
280
284
  "COMBO_BOX" /* COMBOBOX */,
281
285
  "multi_select" /* MULTI_SELECT */,
@@ -4620,6 +4624,161 @@ var FieldRepeater = ({ form, input, isSubmitting }) => {
4620
4624
  }
4621
4625
  );
4622
4626
  };
4627
+ function Tabs({
4628
+ className,
4629
+ ...props
4630
+ }) {
4631
+ return /* @__PURE__ */ jsxRuntime.jsx(
4632
+ TabsPrimitive__namespace.Root,
4633
+ {
4634
+ "data-slot": "tabs",
4635
+ className: cn("flex flex-col gap-2", className),
4636
+ ...props
4637
+ }
4638
+ );
4639
+ }
4640
+ function TabsList({
4641
+ className,
4642
+ ...props
4643
+ }) {
4644
+ return /* @__PURE__ */ jsxRuntime.jsx(
4645
+ TabsPrimitive__namespace.List,
4646
+ {
4647
+ "data-slot": "tabs-list",
4648
+ className: cn(
4649
+ "bg-muted text-muted-foreground inline-flex h-9 w-fit items-center justify-center rounded-lg p-[3px]",
4650
+ className
4651
+ ),
4652
+ ...props
4653
+ }
4654
+ );
4655
+ }
4656
+ function TabsTrigger({
4657
+ className,
4658
+ ...props
4659
+ }) {
4660
+ return /* @__PURE__ */ jsxRuntime.jsx(
4661
+ TabsPrimitive__namespace.Trigger,
4662
+ {
4663
+ "data-slot": "tabs-trigger",
4664
+ className: cn(
4665
+ "data-[state=active]:bg-background dark:data-[state=active]:text-foreground focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:outline-ring dark:data-[state=active]:border-input dark:data-[state=active]:bg-input/30 text-foreground dark:text-muted-foreground inline-flex h-[calc(100%-1px)] flex-1 items-center justify-center gap-1.5 rounded-md border border-transparent px-2 py-1 text-sm font-medium whitespace-nowrap transition-[color,box-shadow] focus-visible:ring-[3px] focus-visible:outline-1 disabled:pointer-events-none disabled:opacity-50 data-[state=active]:shadow-sm [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",
4666
+ className
4667
+ ),
4668
+ ...props
4669
+ }
4670
+ );
4671
+ }
4672
+ function TabsContent({
4673
+ className,
4674
+ ...props
4675
+ }) {
4676
+ return /* @__PURE__ */ jsxRuntime.jsx(
4677
+ TabsPrimitive__namespace.Content,
4678
+ {
4679
+ "data-slot": "tabs-content",
4680
+ className: cn("flex-1 outline-none", className),
4681
+ ...props
4682
+ }
4683
+ );
4684
+ }
4685
+ var RepeaterTabsInput = class extends BaseInput {
4686
+ render() {
4687
+ const { input, form, isSubmitting } = this;
4688
+ return /* @__PURE__ */ jsxRuntime.jsx(FieldRepeaterTabs, { form, input, isSubmitting });
4689
+ }
4690
+ };
4691
+ var FieldRepeaterTabs = ({ form, input, isSubmitting }) => {
4692
+ const { control } = form;
4693
+ const { fields, append, remove } = reactHookForm.useFieldArray({
4694
+ control,
4695
+ name: input.name
4696
+ });
4697
+ const [activeTab, setActiveTab] = React3.useState(fields[0]?.id ?? "");
4698
+ const canAdd = !input.maxItems || fields.length < input.maxItems;
4699
+ const canRemove = fields.length > (input.minItems ?? 0);
4700
+ const handleAdd = () => {
4701
+ const newItem = { id: `tab-${Date.now()}` };
4702
+ append(newItem);
4703
+ setActiveTab(newItem.id);
4704
+ };
4705
+ const handleRemove = (index) => {
4706
+ const removedId = fields[index].id;
4707
+ remove(index);
4708
+ if (activeTab === removedId && fields.length > 1) {
4709
+ const nextTab = fields[index - 1] ?? fields[0];
4710
+ if (nextTab) setActiveTab(nextTab.id);
4711
+ }
4712
+ };
4713
+ return /* @__PURE__ */ jsxRuntime.jsx(
4714
+ FormField,
4715
+ {
4716
+ control,
4717
+ name: input.name,
4718
+ render: () => /* @__PURE__ */ jsxRuntime.jsxs(FormItem, { className: input.className, children: [
4719
+ input.label && /* @__PURE__ */ jsxRuntime.jsx(FormLabel, { children: /* @__PURE__ */ jsxRuntime.jsx("b", { children: input.label }) }),
4720
+ /* @__PURE__ */ jsxRuntime.jsx(FormControl, { children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: "space-y-3", children: /* @__PURE__ */ jsxRuntime.jsxs(Tabs, { value: activeTab, onValueChange: setActiveTab, className: "w-full", children: [
4721
+ /* @__PURE__ */ jsxRuntime.jsxs(TabsList, { className: "flex w-full justify-start overflow-x-auto", children: [
4722
+ fields.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center", children: [
4723
+ /* @__PURE__ */ jsxRuntime.jsx(TabsTrigger, { value: item.id, className: "flex items-center gap-1", children: input.tabLabelField ? form.watch(`${input.name}.${index}.${input.tabLabelField}`) || `Item ${index + 1}` : `Item ${index + 1}` }),
4724
+ canRemove && /* @__PURE__ */ jsxRuntime.jsx(
4725
+ Button,
4726
+ {
4727
+ type: "button",
4728
+ size: "icon",
4729
+ variant: "ghost",
4730
+ onClick: () => handleRemove(index),
4731
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Trash2, { size: 14 })
4732
+ }
4733
+ )
4734
+ ] }, item.id)),
4735
+ canAdd && /* @__PURE__ */ jsxRuntime.jsxs(
4736
+ Button,
4737
+ {
4738
+ type: "button",
4739
+ variant: "secondary",
4740
+ size: "sm",
4741
+ onClick: handleAdd,
4742
+ disabled: isSubmitting,
4743
+ className: "ml-2",
4744
+ children: [
4745
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Plus, { size: 14, className: "mr-1" }),
4746
+ " Agregar"
4747
+ ]
4748
+ }
4749
+ )
4750
+ ] }),
4751
+ fields.map((item, index) => /* @__PURE__ */ jsxRuntime.jsx(TabsContent, { value: item.id, className: "mt-4", children: input.repeaterFields?.map((fieldGroup, groupIndex) => {
4752
+ const group = Array.isArray(fieldGroup) ? fieldGroup : [fieldGroup];
4753
+ const cols = group.length;
4754
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className: `grid gap-3 grid-cols-${cols}`, children: group.map((subField) => /* @__PURE__ */ jsxRuntime.jsx(
4755
+ FormField,
4756
+ {
4757
+ control,
4758
+ name: `${input.name}.${index}.${subField.name}`,
4759
+ render: ({ field, fieldState }) => /* @__PURE__ */ jsxRuntime.jsxs(FormItem, { className: "flex-1", children: [
4760
+ /* @__PURE__ */ jsxRuntime.jsx(FormLabel, { children: subField.label }),
4761
+ /* @__PURE__ */ jsxRuntime.jsx(FormControl, { children: /* @__PURE__ */ jsxRuntime.jsx(
4762
+ Input,
4763
+ {
4764
+ placeholder: subField.placeHolder,
4765
+ disabled: subField.disabled || isSubmitting,
4766
+ ...field
4767
+ }
4768
+ ) }),
4769
+ /* @__PURE__ */ jsxRuntime.jsx(FormMessage, { children: fieldState.error?.message })
4770
+ ] })
4771
+ },
4772
+ `${input.name}.${index}.${subField.name}`
4773
+ )) }, groupIndex);
4774
+ }) }, item.id))
4775
+ ] }) }) }),
4776
+ input.description && /* @__PURE__ */ jsxRuntime.jsx(FormDescription, { children: input.description }),
4777
+ /* @__PURE__ */ jsxRuntime.jsx(FormMessage, {})
4778
+ ] })
4779
+ }
4780
+ );
4781
+ };
4623
4782
  var SelectInput = class extends BaseInput {
4624
4783
  render() {
4625
4784
  const { input, form, isSubmitting } = this;
@@ -5299,6 +5458,7 @@ var inputMap = {
5299
5458
  ["multi_select" /* MULTI_SELECT */]: MultiSelectInput,
5300
5459
  ["COMBO_BOX" /* COMBOBOX */]: ComboboxInput,
5301
5460
  ["sortable_list" /* SORTABLE_LIST */]: SortableListInput,
5461
+ ["repeater_tabs" /* REPEATER_TABS */]: RepeaterTabsInput,
5302
5462
  //ToDos: ============================================================
5303
5463
  ["slider" /* SLIDER */]: SliderInput,
5304
5464
  //ToDo: // PENDIENTE ... VISUALMENTE NO SE VE BIEN.!!!
@@ -5461,6 +5621,10 @@ var DynamicForm = ({
5461
5621
  record = {},
5462
5622
  onSubmit,
5463
5623
  extraValidations,
5624
+ children,
5625
+ childrenHeader,
5626
+ showIcon = true,
5627
+ showFormHeader = true,
5464
5628
  withErrorsAlert = true,
5465
5629
  errorAlertPosition = "up",
5466
5630
  withCard = false,
@@ -5490,12 +5654,18 @@ var DynamicForm = ({
5490
5654
  }
5491
5655
  };
5492
5656
  const formContent = /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
5493
- /* @__PURE__ */ jsxRuntime.jsxs(CardTitle, { className: "flex items-center gap-2 p-2 border-b", children: [
5494
- /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Pencil, { className: "h-5 w-5" }),
5495
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
5496
- /* @__PURE__ */ jsxRuntime.jsx("p", { children: formTitle }),
5497
- formSubTitle && /* @__PURE__ */ jsxRuntime.jsx(CardDescription, { children: formSubTitle })
5498
- ] })
5657
+ showFormHeader && /* @__PURE__ */ jsxRuntime.jsxs(CardTitle, { className: "flex flex-row items-center gap-2 p-2 border-b", children: [
5658
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-row items-center gap-2 w-full", children: [
5659
+ showIcon && /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Pencil, { className: "h-5 w-5" }),
5660
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col", children: [
5661
+ /* @__PURE__ */ jsxRuntime.jsxs(CardTitle, { className: "text-xl", children: [
5662
+ formTitle,
5663
+ " "
5664
+ ] }),
5665
+ formSubTitle && /* @__PURE__ */ jsxRuntime.jsx(CardDescription, { children: formSubTitle })
5666
+ ] })
5667
+ ] }),
5668
+ childrenHeader && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-row items-center gap-2 w-full h-full", children: childrenHeader })
5499
5669
  ] }),
5500
5670
  withErrorsAlert && errorAlertPosition === "up" && /* @__PURE__ */ jsxRuntime.jsx(FormErrorsAlert, { formState: form.formState, fields }),
5501
5671
  /* @__PURE__ */ jsxRuntime.jsx(Form, { ...form, children: /* @__PURE__ */ jsxRuntime.jsxs(
@@ -5504,7 +5674,10 @@ var DynamicForm = ({
5504
5674
  onSubmit: form.handleSubmit(handleSubmit),
5505
5675
  className: `flex flex-col gap-2 ${readOnly ? "opacity-70 pointer-events-none select-none" : ""}`,
5506
5676
  children: [
5507
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "w-full grid grid-cols-1", children: /* @__PURE__ */ jsxRuntime.jsx(FormFieldsGrid, { fields, form, readOnly }) }),
5677
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "w-full grid grid-cols-1", children: [
5678
+ /* @__PURE__ */ jsxRuntime.jsx(FormFieldsGrid, { fields, form, readOnly }),
5679
+ children && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-row items-center gap-2 w-full h-full", children })
5680
+ ] }),
5508
5681
  !readOnly && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-row gap-2 justify-end items-end", children: /* @__PURE__ */ jsxRuntime.jsx(Button, { type: "submit", size: "lg", className: submitBtnClass, disabled: isPending, children: isPending ? /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5509
5682
  /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "h-4 w-4 mr-2 animate-spin" }),
5510
5683
  "Guardando..."