@algorithm-shift/design-system 1.2.41 → 1.2.42

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
@@ -1,6 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React$1 from 'react';
3
3
  import { z } from 'zod';
4
+ import { UseFormReturn } from 'react-hook-form';
4
5
  import { ClassValue } from 'clsx';
5
6
 
6
7
  interface ElementProps {
@@ -296,7 +297,7 @@ type CanvasAction = {
296
297
  };
297
298
  declare function stateReducer(state: CanvasState, action: CanvasAction): CanvasState;
298
299
 
299
- interface FormWrapperProps<T extends z.ZodObject<any>> {
300
+ interface FormProps<T extends z.ZodObject<any>> {
300
301
  validation?: any[];
301
302
  formName?: string;
302
303
  defaultValues?: Partial<z.infer<T>> | any;
@@ -304,9 +305,19 @@ interface FormWrapperProps<T extends z.ZodObject<any>> {
304
305
  onSubmit?: (data: z.infer<T>) => void;
305
306
  onReset?: () => void;
306
307
  }
308
+ declare const Form: <T extends z.ZodObject<any>>({ validation, defaultValues, children, onSubmit, onReset, }: FormProps<T>) => react_jsx_runtime.JSX.Element;
309
+
310
+ interface FormWrapperProps<T extends z.ZodObject<any>> {
311
+ validation?: any[];
312
+ formName?: string;
313
+ defaultValues?: Partial<z.infer<T>> | any;
314
+ children?: React$1.ReactNode | ((form: UseFormReturn<z.infer<T>>) => React$1.ReactNode);
315
+ onSubmit?: (data: z.infer<T>) => void;
316
+ onReset?: () => void;
317
+ }
307
318
  declare const FormWrapper: <T extends z.ZodObject<any>>({ validation, defaultValues, children, onSubmit, onReset, }: FormWrapperProps<T>) => react_jsx_runtime.JSX.Element;
308
319
 
309
320
  declare function cn(...inputs: ClassValue[]): string;
310
321
  declare function getInitials(name: string): string;
311
322
 
312
- export { ChartComponent as BarChart, Breadcrumb, ButtonWrapper as Button, SplitButton as ButtonGroup, CheckboxInput as Checkbox, Container, DatePicker, DateRange, Dropdown, EmailInput as Email, EmailComposer, FileInput, Flex as FlexLayout, FormWrapper as Form, Grid as GridLayout, ImageControl as Image, Modal, MultiCheckbox, Navbar, NumberInput, CustomPagination as Pagination, PasswordInput as Password, PhoneInput as Phone, DonutChart as PieChart, RadioInput as RadioGroup, RichText, SearchInput as Search, Shape, Spacer, StagesComponent as Stages, StateProvider, SwitchToggle, Table, Tabs, TextInput as Text, TextInputGroup, Textarea, Typography, UrlInput as URL, cn, getInitials, showSonnerToast, stateReducer, useAppState };
323
+ export { ChartComponent as BarChart, Breadcrumb, ButtonWrapper as Button, SplitButton as ButtonGroup, CheckboxInput as Checkbox, Container, DatePicker, DateRange, Dropdown, EmailInput as Email, EmailComposer, FileInput, Flex as FlexLayout, Form, FormWrapper, Grid as GridLayout, ImageControl as Image, Modal, MultiCheckbox, Navbar, NumberInput, CustomPagination as Pagination, PasswordInput as Password, PhoneInput as Phone, DonutChart as PieChart, RadioInput as RadioGroup, RichText, SearchInput as Search, Shape, Spacer, StagesComponent as Stages, StateProvider, SwitchToggle, Table, Tabs, TextInput as Text, TextInputGroup, Textarea, Typography, UrlInput as URL, cn, getInitials, showSonnerToast, stateReducer, useAppState };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import React$1 from 'react';
3
3
  import { z } from 'zod';
4
+ import { UseFormReturn } from 'react-hook-form';
4
5
  import { ClassValue } from 'clsx';
5
6
 
6
7
  interface ElementProps {
@@ -296,7 +297,7 @@ type CanvasAction = {
296
297
  };
297
298
  declare function stateReducer(state: CanvasState, action: CanvasAction): CanvasState;
298
299
 
299
- interface FormWrapperProps<T extends z.ZodObject<any>> {
300
+ interface FormProps<T extends z.ZodObject<any>> {
300
301
  validation?: any[];
301
302
  formName?: string;
302
303
  defaultValues?: Partial<z.infer<T>> | any;
@@ -304,9 +305,19 @@ interface FormWrapperProps<T extends z.ZodObject<any>> {
304
305
  onSubmit?: (data: z.infer<T>) => void;
305
306
  onReset?: () => void;
306
307
  }
308
+ declare const Form: <T extends z.ZodObject<any>>({ validation, defaultValues, children, onSubmit, onReset, }: FormProps<T>) => react_jsx_runtime.JSX.Element;
309
+
310
+ interface FormWrapperProps<T extends z.ZodObject<any>> {
311
+ validation?: any[];
312
+ formName?: string;
313
+ defaultValues?: Partial<z.infer<T>> | any;
314
+ children?: React$1.ReactNode | ((form: UseFormReturn<z.infer<T>>) => React$1.ReactNode);
315
+ onSubmit?: (data: z.infer<T>) => void;
316
+ onReset?: () => void;
317
+ }
307
318
  declare const FormWrapper: <T extends z.ZodObject<any>>({ validation, defaultValues, children, onSubmit, onReset, }: FormWrapperProps<T>) => react_jsx_runtime.JSX.Element;
308
319
 
309
320
  declare function cn(...inputs: ClassValue[]): string;
310
321
  declare function getInitials(name: string): string;
311
322
 
312
- export { ChartComponent as BarChart, Breadcrumb, ButtonWrapper as Button, SplitButton as ButtonGroup, CheckboxInput as Checkbox, Container, DatePicker, DateRange, Dropdown, EmailInput as Email, EmailComposer, FileInput, Flex as FlexLayout, FormWrapper as Form, Grid as GridLayout, ImageControl as Image, Modal, MultiCheckbox, Navbar, NumberInput, CustomPagination as Pagination, PasswordInput as Password, PhoneInput as Phone, DonutChart as PieChart, RadioInput as RadioGroup, RichText, SearchInput as Search, Shape, Spacer, StagesComponent as Stages, StateProvider, SwitchToggle, Table, Tabs, TextInput as Text, TextInputGroup, Textarea, Typography, UrlInput as URL, cn, getInitials, showSonnerToast, stateReducer, useAppState };
323
+ export { ChartComponent as BarChart, Breadcrumb, ButtonWrapper as Button, SplitButton as ButtonGroup, CheckboxInput as Checkbox, Container, DatePicker, DateRange, Dropdown, EmailInput as Email, EmailComposer, FileInput, Flex as FlexLayout, Form, FormWrapper, Grid as GridLayout, ImageControl as Image, Modal, MultiCheckbox, Navbar, NumberInput, CustomPagination as Pagination, PasswordInput as Password, PhoneInput as Phone, DonutChart as PieChart, RadioInput as RadioGroup, RichText, SearchInput as Search, Shape, Spacer, StagesComponent as Stages, StateProvider, SwitchToggle, Table, Tabs, TextInput as Text, TextInputGroup, Textarea, Typography, UrlInput as URL, cn, getInitials, showSonnerToast, stateReducer, useAppState };
package/dist/index.js CHANGED
@@ -43,7 +43,8 @@ __export(index_exports, {
43
43
  EmailComposer: () => EmailComposer,
44
44
  FileInput: () => FileInput_default,
45
45
  FlexLayout: () => Flex_default,
46
- Form: () => Wrapper_default,
46
+ Form: () => Form_default,
47
+ FormWrapper: () => Wrapper_default,
47
48
  GridLayout: () => Grid_default,
48
49
  Image: () => Image_default,
49
50
  Modal: () => Modal_default,
@@ -2984,7 +2985,7 @@ function useAppState() {
2984
2985
  return (0, import_react15.useContext)(StateContext);
2985
2986
  }
2986
2987
 
2987
- // src/components/Form/Wrapper.tsx
2988
+ // src/components/Form/Form.tsx
2988
2989
  var import_react16 = __toESM(require("react"));
2989
2990
  var import_zod = require("@hookform/resolvers/zod");
2990
2991
  var import_react_hook_form = require("react-hook-form");
@@ -3058,7 +3059,7 @@ function generateZodSchema(data) {
3058
3059
  }, {});
3059
3060
  return import_zod2.z.object(fields);
3060
3061
  }
3061
- var FormWrapper = ({
3062
+ var Form = ({
3062
3063
  validation,
3063
3064
  defaultValues,
3064
3065
  children,
@@ -3135,6 +3136,116 @@ var FormWrapper = ({
3135
3136
  }
3136
3137
  );
3137
3138
  };
3139
+ var Form_default = Form;
3140
+
3141
+ // src/components/Form/Wrapper.tsx
3142
+ var import_react17 = require("react");
3143
+ var import_zod3 = require("@hookform/resolvers/zod");
3144
+ var import_react_hook_form2 = require("react-hook-form");
3145
+ var import_zod4 = require("zod");
3146
+ var import_jsx_runtime58 = require("react/jsx-runtime");
3147
+ function generateZodSchema2(data) {
3148
+ const fields = data.reduce((acc, f) => {
3149
+ const name = f.name || "unnamed";
3150
+ const message = f.message || `${name} is invalid`;
3151
+ const passwordLen = f.passwordLength;
3152
+ let fieldSchema = import_zod4.z.string({ message });
3153
+ switch (f.type) {
3154
+ case "Text":
3155
+ case "Search":
3156
+ fieldSchema = import_zod4.z.string({ message });
3157
+ if (f?.min && f?.min !== "") fieldSchema = fieldSchema.min(f.min);
3158
+ else if (f.isRequired) fieldSchema = fieldSchema.min(1, { message: `${message}. Cannot be empty` });
3159
+ if (f?.max && f?.max !== "") fieldSchema = fieldSchema.max(f.max);
3160
+ if (f?.email) fieldSchema = fieldSchema.email();
3161
+ if (f?.url) fieldSchema = fieldSchema.url();
3162
+ if (f?.regex) fieldSchema = fieldSchema.regex(new RegExp(f.regex));
3163
+ break;
3164
+ case "Email":
3165
+ fieldSchema = import_zod4.z.email({ message });
3166
+ break;
3167
+ case "Password":
3168
+ fieldSchema = import_zod4.z.string({ message }).min(passwordLen, { message: `Password must be at least ${passwordLen} characters long` });
3169
+ break;
3170
+ case "Phone":
3171
+ fieldSchema = import_zod4.z.string().transform((val) => val.replace(/\D/g, "")).transform((val) => val.slice(-10)).refine((val) => {
3172
+ return val.length === 10;
3173
+ }, {
3174
+ message: "Phone number must be 10 digits long"
3175
+ });
3176
+ break;
3177
+ case "DatePicker":
3178
+ fieldSchema = import_zod4.z.iso.date({ message });
3179
+ break;
3180
+ case "FileInput":
3181
+ fieldSchema = import_zod4.z.instanceof(File, { message: "Please select a file" });
3182
+ if (f?.maxSize) {
3183
+ fieldSchema = fieldSchema.refine(
3184
+ (file) => file.size <= f.maxSize,
3185
+ { message: `File size must be less than ${f.maxSize / 1024 / 1024}MB` }
3186
+ );
3187
+ }
3188
+ if (f?.acceptedTypes) {
3189
+ fieldSchema = fieldSchema.refine(
3190
+ (file) => f.acceptedTypes.includes(file.type),
3191
+ { message: `File type must be one of: ${f.acceptedTypes.join(", ")}` }
3192
+ );
3193
+ }
3194
+ break;
3195
+ case "Checkbox":
3196
+ fieldSchema = import_zod4.z.boolean({ message });
3197
+ break;
3198
+ case "Dropdown":
3199
+ fieldSchema = import_zod4.z.string({ message });
3200
+ break;
3201
+ case "NumberInput":
3202
+ fieldSchema = import_zod4.z.number({ message });
3203
+ if (f?.min !== void 0) fieldSchema = fieldSchema.min(f.min);
3204
+ if (f?.max !== void 0) fieldSchema = fieldSchema.max(f.max);
3205
+ break;
3206
+ default:
3207
+ fieldSchema = import_zod4.z.any();
3208
+ }
3209
+ if (!f.isRequired) fieldSchema = fieldSchema.optional();
3210
+ acc[name] = fieldSchema;
3211
+ return acc;
3212
+ }, {});
3213
+ return import_zod4.z.object(fields);
3214
+ }
3215
+ var FormWrapper = ({
3216
+ validation,
3217
+ defaultValues,
3218
+ children,
3219
+ onSubmit,
3220
+ onReset
3221
+ }) => {
3222
+ const schema = (0, import_react17.useMemo)(() => {
3223
+ if (!validation || validation.length === 0) return null;
3224
+ return generateZodSchema2(validation);
3225
+ }, [validation]);
3226
+ const form = (0, import_react_hook_form2.useForm)({
3227
+ resolver: schema ? (0, import_zod3.zodResolver)(schema) : void 0,
3228
+ defaultValues
3229
+ });
3230
+ const formSubmit = (data) => {
3231
+ if (onSubmit) onSubmit(data);
3232
+ };
3233
+ const handleReset = () => {
3234
+ form.reset();
3235
+ if (onReset) onReset();
3236
+ };
3237
+ return /* @__PURE__ */ (0, import_jsx_runtime58.jsx)(
3238
+ "form",
3239
+ {
3240
+ onSubmit: form.handleSubmit(formSubmit),
3241
+ onReset: handleReset,
3242
+ className: cn(
3243
+ "space-y-4 min-h-[100px] h-auto flex justify-between flex-col"
3244
+ ),
3245
+ children: /* @__PURE__ */ (0, import_jsx_runtime58.jsx)("div", { className: "min-h-[50px]", children: typeof children === "function" ? children(form) : children })
3246
+ }
3247
+ );
3248
+ };
3138
3249
  var Wrapper_default = FormWrapper;
3139
3250
  // Annotate the CommonJS export names for ESM import in node:
3140
3251
  0 && (module.exports = {
@@ -3152,6 +3263,7 @@ var Wrapper_default = FormWrapper;
3152
3263
  FileInput,
3153
3264
  FlexLayout,
3154
3265
  Form,
3266
+ FormWrapper,
3155
3267
  GridLayout,
3156
3268
  Image,
3157
3269
  Modal,