shadcn-zod-formkit 3.0.2 → 3.2.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
@@ -12763,7 +12763,8 @@ var FieldTextGroup = ({ form, input, isSubmitting }) => {
12763
12763
  isSubmitting,
12764
12764
  field,
12765
12765
  form,
12766
- isValid
12766
+ isValid,
12767
+ autoCapitalize: input.autoCapitalize
12767
12768
  }) }),
12768
12769
  input.description && /* @__PURE__ */ jsxRuntime.jsx(FormDescription, { children: input.description }),
12769
12770
  /* @__PURE__ */ jsxRuntime.jsx(FormMessage, {})
@@ -12781,7 +12782,8 @@ var CustomInputGroup = ({
12781
12782
  form,
12782
12783
  isSubmitting,
12783
12784
  onChange,
12784
- isValid
12785
+ isValid,
12786
+ autoCapitalize = "none"
12785
12787
  }) => {
12786
12788
  const groupConfig = input.inputGroupConfig;
12787
12789
  const infoTooltip = input?.infoTooltip;
@@ -12797,7 +12799,64 @@ var CustomInputGroup = ({
12797
12799
  const isPasswordField = input.keyboardType === "password" /* PASSWORD */;
12798
12800
  const isNumberField = input.keyboardType === "number" /* NUMBER */;
12799
12801
  const showInputGroupAddons = iconsRight.length > 0 || textRight || autoValidate || infoTooltip || isPasswordField;
12800
- return /* @__PURE__ */ jsxRuntime.jsxs(InputGroup, { children: [
12802
+ const applyMask = (value2, mask) => {
12803
+ if (!mask) return value2;
12804
+ if (typeof mask === "string") {
12805
+ let result = "";
12806
+ let valueIndex = 0;
12807
+ for (let i = 0; i < mask.length && valueIndex < value2.length; i++) {
12808
+ if (mask[i] === "#") {
12809
+ result += value2[valueIndex++];
12810
+ } else {
12811
+ result += mask[i];
12812
+ }
12813
+ }
12814
+ return result;
12815
+ } else if (mask instanceof RegExp) {
12816
+ const matches = value2.match(mask);
12817
+ return matches ? matches.join("") : value2;
12818
+ }
12819
+ return value2;
12820
+ };
12821
+ const formatNumber = (value2, config) => {
12822
+ if (!config || value2 === "") return value2;
12823
+ let numValue = parseFloat(value2);
12824
+ if (isNaN(numValue)) return value2;
12825
+ if (config.min !== void 0 && numValue < config.min) return config.min.toString();
12826
+ if (config.max !== void 0 && numValue > config.max) return config.max.toString();
12827
+ if (!config.allowDecimals) numValue = Math.floor(numValue);
12828
+ const options = {
12829
+ minimumFractionDigits: config.allowDecimals ? config.decimalPlaces || 2 : 0,
12830
+ maximumFractionDigits: config.allowDecimals ? config.decimalPlaces || 2 : 0
12831
+ };
12832
+ let formatted = numValue.toLocaleString("en-US", options);
12833
+ if (config.thousandsSeparator) {
12834
+ formatted = formatted.replace(/,/g, config.thousandsSeparator);
12835
+ }
12836
+ if (config.decimalSeparator && config.decimalSeparator !== ".") {
12837
+ formatted = formatted.replace(".", config.decimalSeparator);
12838
+ }
12839
+ return `${config.prefix || ""}${formatted}${config.suffix || ""}`;
12840
+ };
12841
+ const applyTransform = (value2, transform) => {
12842
+ if (!transform) return value2;
12843
+ if (typeof transform === "function") {
12844
+ return transform(value2);
12845
+ }
12846
+ switch (transform) {
12847
+ case "uppercase":
12848
+ return value2.toUpperCase();
12849
+ case "lowercase":
12850
+ return value2.toLowerCase();
12851
+ case "capitalize":
12852
+ return value2.charAt(0).toUpperCase() + value2.slice(1).toLowerCase();
12853
+ case "trim":
12854
+ return value2.trim();
12855
+ default:
12856
+ return value2;
12857
+ }
12858
+ };
12859
+ return /* @__PURE__ */ jsxRuntime.jsxs(InputGroup, { className: input.classNameGroupInput ?? "h-10", children: [
12801
12860
  (iconsLeft.length > 0 || textLeft) && /* @__PURE__ */ jsxRuntime.jsxs(InputGroupAddon, { children: [
12802
12861
  textLeft && /* @__PURE__ */ jsxRuntime.jsx(InputGroupText, { children: textLeft }),
12803
12862
  iconsLeft.map((IconComponent, index) => /* @__PURE__ */ jsxRuntime.jsx(IconComponent, { size: 20 }, index))
@@ -12805,6 +12864,7 @@ var CustomInputGroup = ({
12805
12864
  /* @__PURE__ */ jsxRuntime.jsx(
12806
12865
  InputGroupInput,
12807
12866
  {
12867
+ className: input.classNameInput ?? "h-full text-xl font-semibold",
12808
12868
  placeholder: input.placeHolder,
12809
12869
  disabled: input.disabled || isSubmitting,
12810
12870
  onBlur: field?.onBlur,
@@ -12818,7 +12878,18 @@ var CustomInputGroup = ({
12818
12878
  }
12819
12879
  let value2 = e.target.value;
12820
12880
  if (isNumberField) {
12821
- value2 = e.target.value === "" ? "" : Number(e.target.value);
12881
+ const numConfig = input.inputNumberConfig;
12882
+ const cleanValue = value2.replace(/[^\d.-]/g, "");
12883
+ const numValue = cleanValue === "" ? "" : Number(cleanValue);
12884
+ if (numConfig?.formatOnInput) {
12885
+ value2 = formatNumber(cleanValue, numConfig);
12886
+ } else {
12887
+ value2 = numValue;
12888
+ }
12889
+ } else {
12890
+ let processedValue = e.target.value;
12891
+ processedValue = applyMask(processedValue, input.mask);
12892
+ value2 = applyTransform(processedValue, input.transform);
12822
12893
  }
12823
12894
  field?.onChange(value2);
12824
12895
  isValidField(input, form);
@@ -14097,6 +14168,44 @@ var TextInput = class extends BaseInput {
14097
14168
  var FieldText = ({ input, form, isSubmitting }) => {
14098
14169
  const hidden = input.hidden ?? input.inputType === "hidden" /* HIDDEN */;
14099
14170
  const type = hidden ? "hidden" : input.keyboardType || "text";
14171
+ const applyMask = (value, mask) => {
14172
+ if (!mask) return value;
14173
+ if (typeof mask === "string") {
14174
+ let result = "";
14175
+ let valueIndex = 0;
14176
+ for (let i = 0; i < mask.length && valueIndex < value.length; i++) {
14177
+ if (mask[i] === "#") {
14178
+ result += value[valueIndex++];
14179
+ } else {
14180
+ result += mask[i];
14181
+ }
14182
+ }
14183
+ return result;
14184
+ } else if (mask instanceof RegExp) {
14185
+ const matches = value.match(mask);
14186
+ return matches ? matches.join("") : value;
14187
+ }
14188
+ return value;
14189
+ };
14190
+ const applyTransform = (value) => {
14191
+ input.inputGroupConfig?.transform || input.transform;
14192
+ if (!input.inputGroupConfig?.transform) return value;
14193
+ if (typeof input.transform === "function") {
14194
+ return input.transform(value);
14195
+ }
14196
+ switch (input.transform) {
14197
+ case "uppercase":
14198
+ return value.toUpperCase();
14199
+ case "lowercase":
14200
+ return value.toLowerCase();
14201
+ case "capitalize":
14202
+ return value.charAt(0).toUpperCase() + value.slice(1).toLowerCase();
14203
+ case "trim":
14204
+ return value.trim();
14205
+ default:
14206
+ return value;
14207
+ }
14208
+ };
14100
14209
  return /* @__PURE__ */ jsxRuntime.jsx(
14101
14210
  FormField,
14102
14211
  {
@@ -14108,10 +14217,17 @@ var FieldText = ({ input, form, isSubmitting }) => {
14108
14217
  Input,
14109
14218
  {
14110
14219
  className: "min-w-[180px]",
14220
+ autoCapitalize: input.autoCapitalize,
14111
14221
  placeholder: input.placeHolder,
14112
14222
  ...field,
14113
14223
  type,
14114
- onChange: (e) => handleOnChage(e, input, field),
14224
+ onChange: (e) => {
14225
+ let processedValue = e.target.value;
14226
+ processedValue = applyMask(processedValue, input.mask);
14227
+ const transformedValue = applyTransform(processedValue);
14228
+ field.onChange(transformedValue);
14229
+ handleOnChage(e, input, field);
14230
+ },
14115
14231
  disabled: input.disabled || isSubmitting
14116
14232
  }
14117
14233
  ) }),
@@ -15228,7 +15344,8 @@ var DynamicForm = ({
15228
15344
  debug = false,
15229
15345
  isWrapInWizard = false,
15230
15346
  totalSteps = 0,
15231
- currentStep = 1
15347
+ currentStep = 1,
15348
+ submitBtnIcon = lucideReact.Save
15232
15349
  }) => {
15233
15350
  const [isPending, startTransition] = React3.useTransition();
15234
15351
  const schema = React3.useMemo(() => {
@@ -15303,7 +15420,7 @@ var DynamicForm = ({
15303
15420
  /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "h-5 w-5 mr-2 animate-spin" })
15304
15421
  ] }) : /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
15305
15422
  submitBtnLabel,
15306
- (totalSteps == 0 || totalSteps == currentStep) && /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Save, { className: "h-5 w-5 mr-2" })
15423
+ (totalSteps == 0 || totalSteps == currentStep) && submitBtnIcon && React3__namespace.default.createElement(submitBtnIcon, { className: "h-5 w-5 mr-2" })
15307
15424
  ] })
15308
15425
  }
15309
15426
  )