shadcn-zod-formkit 1.27.3 → 1.28.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
@@ -88,6 +88,7 @@ type FieldConfig<T, RT = Record<string, any>> = FieldProps<T, RT> | FieldConfig<
88
88
  interface FieldProps<T = Record<string, any>, RT = Record<string, any>> {
89
89
  name: keyof T;
90
90
  label: string;
91
+ withAddBtn?: boolean;
91
92
  form?: UseFormReturn<any>;
92
93
  isRemovebleOption?: boolean;
93
94
  withDuplicatTag?: boolean;
package/dist/index.d.ts CHANGED
@@ -88,6 +88,7 @@ type FieldConfig<T, RT = Record<string, any>> = FieldProps<T, RT> | FieldConfig<
88
88
  interface FieldProps<T = Record<string, any>, RT = Record<string, any>> {
89
89
  name: keyof T;
90
90
  label: string;
91
+ withAddBtn?: boolean;
91
92
  form?: UseFormReturn<any>;
92
93
  isRemovebleOption?: boolean;
93
94
  withDuplicatTag?: boolean;
package/dist/index.mjs CHANGED
@@ -4,7 +4,7 @@ import { cva } from 'class-variance-authority';
4
4
  import { twMerge } from 'tailwind-merge';
5
5
  import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
6
6
  import * as React3 from 'react';
7
- import React3__default, { useMemo, useState, useEffect, useRef, useTransition } from 'react';
7
+ import React3__default, { useState, useMemo, useEffect, useRef, useTransition } from 'react';
8
8
  import { FormProvider, Controller, useFormContext, useFormState, useFieldArray, useForm } from 'react-hook-form';
9
9
  import * as AccordionPrimitive from '@radix-ui/react-accordion';
10
10
  import { Slot } from '@radix-ui/react-slot';
@@ -2183,6 +2183,28 @@ var ColorInput = class extends BaseInput {
2183
2183
  return /* @__PURE__ */ jsx(FieldColor, { input, form, isSubmitting });
2184
2184
  }
2185
2185
  };
2186
+ var PRESET_COLORS = [
2187
+ "#ef4444",
2188
+ // red
2189
+ "#f97316",
2190
+ // orange
2191
+ "#eab308",
2192
+ // yellow
2193
+ "#22c55e",
2194
+ // green
2195
+ "#06b6d4",
2196
+ // cyan
2197
+ "#3b82f6",
2198
+ // blue
2199
+ "#8b5cf6",
2200
+ // purple
2201
+ "#ec4899",
2202
+ // pink
2203
+ "#64748b",
2204
+ // slate
2205
+ "#000000"
2206
+ // black
2207
+ ];
2186
2208
  var FieldColor = ({ form, input, isSubmitting }) => {
2187
2209
  const [ColorCmp, _setColorCmp] = useState(ColorComp);
2188
2210
  return /* @__PURE__ */ jsx(
@@ -2213,13 +2235,17 @@ var FieldColor = ({ form, input, isSubmitting }) => {
2213
2235
  var ColorComp = React3__default.forwardRef(
2214
2236
  ({ value = "#000000", onChange, onBlur, disabled, className, hideInput = ["hsv"] }, ref) => {
2215
2237
  const [color, setColor] = useColor(value);
2216
- const [open, setOpen] = React3__default.useState(false);
2238
+ const [open, setOpen] = useState(false);
2217
2239
  React3__default.useEffect(() => {
2218
2240
  if (value !== color.hex) {
2219
2241
  setColor({ ...color, hex: value });
2220
2242
  }
2221
- }, [color, setColor, value]);
2243
+ }, [value]);
2222
2244
  const handleColorChange = (newColor) => {
2245
+ setColor({ ...color, hex: newColor });
2246
+ onChange?.(newColor);
2247
+ };
2248
+ const handlePickerChange = (newColor) => {
2223
2249
  setColor(newColor);
2224
2250
  onChange?.(newColor.hex);
2225
2251
  };
@@ -2229,21 +2255,38 @@ var ColorComp = React3__default.forwardRef(
2229
2255
  onBlur?.();
2230
2256
  }
2231
2257
  };
2232
- return /* @__PURE__ */ jsxs(Popover, { open, onOpenChange: handleOpenChange, children: [
2233
- /* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
2234
- Button,
2258
+ return /* @__PURE__ */ jsxs("div", { className: "flex flex-col gap-3", children: [
2259
+ /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-2 p-2", children: PRESET_COLORS.map((presetColor) => /* @__PURE__ */ jsx(
2260
+ "button",
2235
2261
  {
2236
- ref,
2237
- variant: "outline",
2262
+ type: "button",
2238
2263
  disabled,
2239
- className: cn("w-full justify-start text-left font-normal", !value && "text-muted-foreground", className),
2240
- children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
2241
- /* @__PURE__ */ jsx("div", { className: "h-4 w-4 border border-border rounded-sm", style: { backgroundColor: color.hex, width: 20, height: 20 } }),
2242
- /* @__PURE__ */ jsx("span", { children: color.hex })
2243
- ] })
2244
- }
2245
- ) }),
2246
- /* @__PURE__ */ jsx(PopoverContent, { className: "w-auto p-3", align: "start", children: /* @__PURE__ */ jsx(ColorPicker, { color, onChange: handleColorChange, hideInput }) })
2264
+ className: cn(
2265
+ "size-6 rounded-md border-2 transition-all hover:scale-110 disabled:opacity-50 disabled:cursor-not-allowed",
2266
+ color.hex === presetColor ? "border-foreground ring-2 ring-foreground/20" : "border-border hover:border-foreground/50"
2267
+ ),
2268
+ style: { backgroundColor: presetColor },
2269
+ onClick: () => handleColorChange(presetColor),
2270
+ "aria-label": `Select color ${presetColor}`
2271
+ },
2272
+ presetColor
2273
+ )) }),
2274
+ /* @__PURE__ */ jsxs(Popover, { open, onOpenChange: handleOpenChange, children: [
2275
+ /* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsx(
2276
+ Button,
2277
+ {
2278
+ ref,
2279
+ variant: "outline",
2280
+ disabled,
2281
+ className: cn("w-full justify-start text-left font-normal", !value && "text-muted-foreground", className),
2282
+ children: /* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
2283
+ /* @__PURE__ */ jsx("div", { className: "h-4 w-4 border border-border rounded-sm", style: { backgroundColor: color.hex, width: 20, height: 20 } }),
2284
+ /* @__PURE__ */ jsx("span", { children: color.hex })
2285
+ ] })
2286
+ }
2287
+ ) }),
2288
+ /* @__PURE__ */ jsx(PopoverContent, { className: "w-auto p-3", align: "start", children: /* @__PURE__ */ jsx(ColorPicker, { color, onChange: handlePickerChange, hideInput }) })
2289
+ ] })
2247
2290
  ] });
2248
2291
  }
2249
2292
  );
@@ -5526,6 +5569,7 @@ var StringValueListInput = class extends BaseInput {
5526
5569
  };
5527
5570
  var FieldStringValueList = ({ form, input, isSubmitting }) => {
5528
5571
  const fieldName = input.name;
5572
+ const withAddBtn = input.withAddBtn ?? false;
5529
5573
  useEffect(() => {
5530
5574
  const current = form.getValues(fieldName);
5531
5575
  if (!Array.isArray(current)) {
@@ -5589,7 +5633,7 @@ var FieldStringValueList = ({ form, input, isSubmitting }) => {
5589
5633
  },
5590
5634
  index
5591
5635
  )),
5592
- /* @__PURE__ */ jsx("div", { className: "flex justify-end mt-2", children: /* @__PURE__ */ jsx(
5636
+ /* @__PURE__ */ jsx("div", { className: "flex justify-end mt-2", children: withAddBtn && /* @__PURE__ */ jsx(
5593
5637
  Button,
5594
5638
  {
5595
5639
  type: "button",