shadcn-zod-formkit 1.24.0 → 1.25.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.cjs CHANGED
@@ -294,9 +294,11 @@ var InputTypes = /* @__PURE__ */ ((InputTypes2) => {
294
294
  InputTypes2["COMBOBOX"] = "COMBO_BOX";
295
295
  InputTypes2["SORTABLE_LIST"] = "sortable_list";
296
296
  InputTypes2["REPEATER_TABS"] = "repeater_tabs";
297
+ InputTypes2["STRING_LIST"] = "string_list";
297
298
  return InputTypes2;
298
299
  })(InputTypes || {});
299
300
  var inputFieldComp = [
301
+ "string_list" /* STRING_LIST */,
300
302
  "repeater_tabs" /* REPEATER_TABS */,
301
303
  "sortable_list" /* SORTABLE_LIST */,
302
304
  "COMBO_BOX" /* COMBOBOX */,
@@ -4220,7 +4222,7 @@ var FieldKeyValueList = ({ form, input, isSubmitting }) => {
4220
4222
  return /* @__PURE__ */ jsxRuntime.jsxs(FormItem, { className: input.className, children: [
4221
4223
  /* @__PURE__ */ jsxRuntime.jsx(FormLabel, { children: /* @__PURE__ */ jsxRuntime.jsx("b", { children: input.label }) }),
4222
4224
  /* @__PURE__ */ jsxRuntime.jsx(FormMessage, {}),
4223
- /* @__PURE__ */ jsxRuntime.jsx(FormControl, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3 shadow-lg rounded-xl p-3 bg-white", children: [
4225
+ /* @__PURE__ */ jsxRuntime.jsx(FormControl, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3 rounded-xl p-3 ", children: [
4224
4226
  pairs.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: "No pairs have been added yet." }),
4225
4227
  pairs.map((pair, index) => /* @__PURE__ */ jsxRuntime.jsxs(
4226
4228
  "div",
@@ -5198,6 +5200,102 @@ function SortableWrapper({
5198
5200
  }
5199
5201
  );
5200
5202
  }
5203
+ var StringValueListInput = class extends BaseInput {
5204
+ render() {
5205
+ const { input, form, isSubmitting } = this;
5206
+ return /* @__PURE__ */ jsxRuntime.jsx(
5207
+ FieldStringValueList,
5208
+ {
5209
+ input,
5210
+ form,
5211
+ isSubmitting
5212
+ }
5213
+ );
5214
+ }
5215
+ };
5216
+ var FieldStringValueList = ({ form, input, isSubmitting }) => {
5217
+ const fieldName = input.name;
5218
+ React3.useEffect(() => {
5219
+ const current = form.getValues(fieldName);
5220
+ if (!Array.isArray(current)) {
5221
+ form.setValue(fieldName, []);
5222
+ }
5223
+ }, [form, fieldName]);
5224
+ const handleAddItem = () => {
5225
+ const current = form.getValues(fieldName) || [];
5226
+ form.setValue(fieldName, [...current, ""]);
5227
+ };
5228
+ const handleRemoveItem = (index) => {
5229
+ const current = form.getValues(fieldName) || [];
5230
+ const updated = current.filter((_, i) => i !== index);
5231
+ form.setValue(fieldName, updated);
5232
+ };
5233
+ const handleChange = (index, newValue) => {
5234
+ const current = form.getValues(fieldName) || [];
5235
+ const updated = current.map(
5236
+ (item, i) => i === index ? newValue : item
5237
+ );
5238
+ form.setValue(fieldName, updated);
5239
+ };
5240
+ return /* @__PURE__ */ jsxRuntime.jsx(
5241
+ FormField,
5242
+ {
5243
+ control: form.control,
5244
+ name: fieldName,
5245
+ render: () => {
5246
+ const items = form.watch(fieldName) || [];
5247
+ return /* @__PURE__ */ jsxRuntime.jsxs(FormItem, { className: input.className, children: [
5248
+ /* @__PURE__ */ jsxRuntime.jsx(FormLabel, { children: /* @__PURE__ */ jsxRuntime.jsx("b", { children: input.label }) }),
5249
+ /* @__PURE__ */ jsxRuntime.jsx(FormMessage, {}),
5250
+ /* @__PURE__ */ jsxRuntime.jsx(FormControl, { children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col gap-3 rounded-xl ", children: [
5251
+ items.length === 0 && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-sm text-muted-foreground", children: "No items have been added yet." }),
5252
+ items.map((value, index) => /* @__PURE__ */ jsxRuntime.jsxs(
5253
+ "div",
5254
+ {
5255
+ className: "flex gap-2 items-center",
5256
+ children: [
5257
+ /* @__PURE__ */ jsxRuntime.jsx(
5258
+ Input,
5259
+ {
5260
+ placeholder: `Item ${index + 1}`,
5261
+ value,
5262
+ disabled: isSubmitting,
5263
+ onChange: (e) => handleChange(index, e.target.value)
5264
+ }
5265
+ ),
5266
+ input.isRemovebleOption && /* @__PURE__ */ jsxRuntime.jsx(
5267
+ Button,
5268
+ {
5269
+ type: "button",
5270
+ variant: "destructive",
5271
+ size: "icon",
5272
+ onClick: () => handleRemoveItem(index),
5273
+ disabled: isSubmitting,
5274
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Trash2, { size: 18 })
5275
+ }
5276
+ )
5277
+ ]
5278
+ },
5279
+ index
5280
+ )),
5281
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex justify-end mt-2", children: /* @__PURE__ */ jsxRuntime.jsx(
5282
+ Button,
5283
+ {
5284
+ type: "button",
5285
+ variant: "outline",
5286
+ size: "sm",
5287
+ onClick: handleAddItem,
5288
+ disabled: isSubmitting,
5289
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Plus, { size: 18, className: "mr-1" })
5290
+ }
5291
+ ) })
5292
+ ] }) }),
5293
+ input.description && /* @__PURE__ */ jsxRuntime.jsx(FormDescription, { children: input.description })
5294
+ ] });
5295
+ }
5296
+ }
5297
+ );
5298
+ };
5201
5299
  var SwitchInput = class extends BaseInput {
5202
5300
  render() {
5203
5301
  const { input, form, isSubmitting } = this;
@@ -5509,6 +5607,7 @@ var inputMap = {
5509
5607
  ["COMBO_BOX" /* COMBOBOX */]: ComboboxInput,
5510
5608
  ["sortable_list" /* SORTABLE_LIST */]: SortableListInput,
5511
5609
  ["repeater_tabs" /* REPEATER_TABS */]: RepeaterTabsInput,
5610
+ ["string_list" /* STRING_LIST */]: StringValueListInput,
5512
5611
  //ToDos: ============================================================
5513
5612
  ["slider" /* SLIDER */]: SliderInput,
5514
5613
  //ToDo: // PENDIENTE ... VISUALMENTE NO SE VE BIEN.!!!