@algorithm-shift/design-system 1.2.37 → 1.2.38
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 +12 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +154 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +153 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import React$1 from 'react';
|
|
3
|
+
import { z } from 'zod';
|
|
3
4
|
import { ClassValue } from 'clsx';
|
|
4
5
|
|
|
5
6
|
interface ElementProps {
|
|
@@ -299,6 +300,16 @@ type CanvasAction = {
|
|
|
299
300
|
};
|
|
300
301
|
declare function stateReducer(state: CanvasState, action: CanvasAction): CanvasState;
|
|
301
302
|
|
|
303
|
+
interface FormWrapperProps<T extends z.ZodObject<any>> {
|
|
304
|
+
validation?: any[];
|
|
305
|
+
formName?: string;
|
|
306
|
+
defaultValues?: Partial<z.infer<T>> | any;
|
|
307
|
+
children?: React$1.ReactNode;
|
|
308
|
+
onSubmit?: (data: z.infer<T>) => void;
|
|
309
|
+
onReset?: () => void;
|
|
310
|
+
}
|
|
311
|
+
declare const FormWrapper: <T extends z.ZodObject<any>>({ validation, defaultValues, children, onSubmit, onReset, }: FormWrapperProps<T>) => react_jsx_runtime.JSX.Element;
|
|
312
|
+
|
|
302
313
|
declare function cn(...inputs: ClassValue[]): string;
|
|
303
314
|
|
|
304
|
-
export { ChartComponent as BarChart, ButtonWrapper as Button, CheckboxInput as Checkbox, Container, DatePicker, DateRange, Dropdown, EmailInput as Email, EmailComposer, FileInput, Flex as FlexLayout, Grid as GridLayout, ImageControl as Image, Logo, Modal, MultiCheckbox, Navbar, Notification, NumberInput, CustomPagination as Pagination, PasswordInput as Password, PhoneInput as Phone, DonutChart as PieChart, Profile, 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, showSonnerToast, stateReducer, useAppState };
|
|
315
|
+
export { ChartComponent as BarChart, ButtonWrapper as Button, CheckboxInput as Checkbox, Container, DatePicker, DateRange, Dropdown, EmailInput as Email, EmailComposer, FileInput, Flex as FlexLayout, FormWrapper as Form, Grid as GridLayout, ImageControl as Image, Logo, Modal, MultiCheckbox, Navbar, Notification, NumberInput, CustomPagination as Pagination, PasswordInput as Password, PhoneInput as Phone, DonutChart as PieChart, Profile, 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, showSonnerToast, stateReducer, useAppState };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import React$1 from 'react';
|
|
3
|
+
import { z } from 'zod';
|
|
3
4
|
import { ClassValue } from 'clsx';
|
|
4
5
|
|
|
5
6
|
interface ElementProps {
|
|
@@ -299,6 +300,16 @@ type CanvasAction = {
|
|
|
299
300
|
};
|
|
300
301
|
declare function stateReducer(state: CanvasState, action: CanvasAction): CanvasState;
|
|
301
302
|
|
|
303
|
+
interface FormWrapperProps<T extends z.ZodObject<any>> {
|
|
304
|
+
validation?: any[];
|
|
305
|
+
formName?: string;
|
|
306
|
+
defaultValues?: Partial<z.infer<T>> | any;
|
|
307
|
+
children?: React$1.ReactNode;
|
|
308
|
+
onSubmit?: (data: z.infer<T>) => void;
|
|
309
|
+
onReset?: () => void;
|
|
310
|
+
}
|
|
311
|
+
declare const FormWrapper: <T extends z.ZodObject<any>>({ validation, defaultValues, children, onSubmit, onReset, }: FormWrapperProps<T>) => react_jsx_runtime.JSX.Element;
|
|
312
|
+
|
|
302
313
|
declare function cn(...inputs: ClassValue[]): string;
|
|
303
314
|
|
|
304
|
-
export { ChartComponent as BarChart, ButtonWrapper as Button, CheckboxInput as Checkbox, Container, DatePicker, DateRange, Dropdown, EmailInput as Email, EmailComposer, FileInput, Flex as FlexLayout, Grid as GridLayout, ImageControl as Image, Logo, Modal, MultiCheckbox, Navbar, Notification, NumberInput, CustomPagination as Pagination, PasswordInput as Password, PhoneInput as Phone, DonutChart as PieChart, Profile, 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, showSonnerToast, stateReducer, useAppState };
|
|
315
|
+
export { ChartComponent as BarChart, ButtonWrapper as Button, CheckboxInput as Checkbox, Container, DatePicker, DateRange, Dropdown, EmailInput as Email, EmailComposer, FileInput, Flex as FlexLayout, FormWrapper as Form, Grid as GridLayout, ImageControl as Image, Logo, Modal, MultiCheckbox, Navbar, Notification, NumberInput, CustomPagination as Pagination, PasswordInput as Password, PhoneInput as Phone, DonutChart as PieChart, Profile, 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, showSonnerToast, stateReducer, useAppState };
|
package/dist/index.js
CHANGED
|
@@ -41,6 +41,7 @@ __export(index_exports, {
|
|
|
41
41
|
EmailComposer: () => EmailComposer,
|
|
42
42
|
FileInput: () => FileInput_default,
|
|
43
43
|
FlexLayout: () => Flex_default,
|
|
44
|
+
Form: () => Wrapper_default,
|
|
44
45
|
GridLayout: () => Grid_default,
|
|
45
46
|
Image: () => Image_default,
|
|
46
47
|
Logo: () => Logo_default,
|
|
@@ -2875,6 +2876,158 @@ function StateProvider({ children }) {
|
|
|
2875
2876
|
function useAppState() {
|
|
2876
2877
|
return (0, import_react15.useContext)(StateContext);
|
|
2877
2878
|
}
|
|
2879
|
+
|
|
2880
|
+
// src/components/Form/Wrapper.tsx
|
|
2881
|
+
var import_react16 = __toESM(require("react"));
|
|
2882
|
+
var import_zod = require("@hookform/resolvers/zod");
|
|
2883
|
+
var import_react_hook_form = require("react-hook-form");
|
|
2884
|
+
var import_zod2 = require("zod");
|
|
2885
|
+
var import_jsx_runtime55 = require("react/jsx-runtime");
|
|
2886
|
+
function generateZodSchema(data) {
|
|
2887
|
+
const fields = data.reduce((acc, f) => {
|
|
2888
|
+
const name = f.name || "unnamed";
|
|
2889
|
+
const message = f.message || `${name} is invalid`;
|
|
2890
|
+
const passwordLen = f.passwordLength;
|
|
2891
|
+
let fieldSchema = import_zod2.z.string({ message });
|
|
2892
|
+
switch (f.type) {
|
|
2893
|
+
case "Text":
|
|
2894
|
+
case "Search":
|
|
2895
|
+
fieldSchema = import_zod2.z.string({ message });
|
|
2896
|
+
if (f?.min && f?.min !== "") fieldSchema = fieldSchema.min(f.min);
|
|
2897
|
+
else if (f.isRequired) fieldSchema = fieldSchema.min(1, { message: `${message}. Cannot be empty` });
|
|
2898
|
+
if (f?.max && f?.max !== "") fieldSchema = fieldSchema.max(f.max);
|
|
2899
|
+
if (f?.email) fieldSchema = fieldSchema.email();
|
|
2900
|
+
if (f?.url) fieldSchema = fieldSchema.url();
|
|
2901
|
+
if (f?.regex) fieldSchema = fieldSchema.regex(new RegExp(f.regex));
|
|
2902
|
+
break;
|
|
2903
|
+
case "Email":
|
|
2904
|
+
fieldSchema = import_zod2.z.email({ message });
|
|
2905
|
+
break;
|
|
2906
|
+
case "Password":
|
|
2907
|
+
fieldSchema = import_zod2.z.string({ message }).min(passwordLen, { message: `Password must be at least ${passwordLen} characters long` });
|
|
2908
|
+
break;
|
|
2909
|
+
case "Phone":
|
|
2910
|
+
fieldSchema = import_zod2.z.string().transform((val) => val.replace(/\D/g, "")).transform((val) => val.slice(-10)).refine((val) => {
|
|
2911
|
+
return val.length === 10;
|
|
2912
|
+
}, {
|
|
2913
|
+
message: "Phone number must be 10 digits long"
|
|
2914
|
+
});
|
|
2915
|
+
break;
|
|
2916
|
+
case "DatePicker":
|
|
2917
|
+
fieldSchema = import_zod2.z.iso.date({ message });
|
|
2918
|
+
break;
|
|
2919
|
+
case "FileInput":
|
|
2920
|
+
fieldSchema = import_zod2.z.instanceof(File, { message: "Please select a file" });
|
|
2921
|
+
if (f?.maxSize) {
|
|
2922
|
+
fieldSchema = fieldSchema.refine(
|
|
2923
|
+
(file) => file.size <= f.maxSize,
|
|
2924
|
+
{ message: `File size must be less than ${f.maxSize / 1024 / 1024}MB` }
|
|
2925
|
+
);
|
|
2926
|
+
}
|
|
2927
|
+
if (f?.acceptedTypes) {
|
|
2928
|
+
fieldSchema = fieldSchema.refine(
|
|
2929
|
+
(file) => f.acceptedTypes.includes(file.type),
|
|
2930
|
+
{ message: `File type must be one of: ${f.acceptedTypes.join(", ")}` }
|
|
2931
|
+
);
|
|
2932
|
+
}
|
|
2933
|
+
break;
|
|
2934
|
+
case "Checkbox":
|
|
2935
|
+
fieldSchema = import_zod2.z.boolean({ message });
|
|
2936
|
+
break;
|
|
2937
|
+
case "Dropdown":
|
|
2938
|
+
fieldSchema = import_zod2.z.string({ message });
|
|
2939
|
+
break;
|
|
2940
|
+
case "NumberInput":
|
|
2941
|
+
fieldSchema = import_zod2.z.number({ message });
|
|
2942
|
+
if (f?.min !== void 0) fieldSchema = fieldSchema.min(f.min);
|
|
2943
|
+
if (f?.max !== void 0) fieldSchema = fieldSchema.max(f.max);
|
|
2944
|
+
break;
|
|
2945
|
+
default:
|
|
2946
|
+
fieldSchema = import_zod2.z.any();
|
|
2947
|
+
}
|
|
2948
|
+
if (!f.isRequired) fieldSchema = fieldSchema.optional();
|
|
2949
|
+
acc[name] = fieldSchema;
|
|
2950
|
+
return acc;
|
|
2951
|
+
}, {});
|
|
2952
|
+
return import_zod2.z.object(fields);
|
|
2953
|
+
}
|
|
2954
|
+
var FormWrapper = ({
|
|
2955
|
+
validation,
|
|
2956
|
+
defaultValues,
|
|
2957
|
+
children,
|
|
2958
|
+
onSubmit,
|
|
2959
|
+
onReset
|
|
2960
|
+
}) => {
|
|
2961
|
+
const schema = (0, import_react16.useMemo)(() => {
|
|
2962
|
+
if (!validation || validation.length === 0) return null;
|
|
2963
|
+
return generateZodSchema(validation);
|
|
2964
|
+
}, [validation]);
|
|
2965
|
+
const {
|
|
2966
|
+
handleSubmit,
|
|
2967
|
+
control,
|
|
2968
|
+
formState: { errors },
|
|
2969
|
+
reset
|
|
2970
|
+
} = (0, import_react_hook_form.useForm)({
|
|
2971
|
+
resolver: schema ? (0, import_zod.zodResolver)(schema) : void 0,
|
|
2972
|
+
defaultValues
|
|
2973
|
+
});
|
|
2974
|
+
const formSubmit = (data) => {
|
|
2975
|
+
if (onSubmit) onSubmit(data);
|
|
2976
|
+
};
|
|
2977
|
+
const handleReset = () => {
|
|
2978
|
+
reset();
|
|
2979
|
+
if (onReset) onReset();
|
|
2980
|
+
};
|
|
2981
|
+
return /* @__PURE__ */ (0, import_jsx_runtime55.jsx)(
|
|
2982
|
+
"form",
|
|
2983
|
+
{
|
|
2984
|
+
onSubmit: handleSubmit(formSubmit),
|
|
2985
|
+
onReset: handleReset,
|
|
2986
|
+
className: cn(
|
|
2987
|
+
"space-y-4 min-h-[100px] h-auto flex justify-between flex-col"
|
|
2988
|
+
),
|
|
2989
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime55.jsx)("div", { className: "min-h-[50px]", children: import_react16.default.Children.map(children, (child) => {
|
|
2990
|
+
const processChild = (child2) => {
|
|
2991
|
+
if (import_react16.default.isValidElement(child2)) {
|
|
2992
|
+
const node = child2.props?.node;
|
|
2993
|
+
if (node?.category === "Form Controls") {
|
|
2994
|
+
const name = node.properties?.name || "unnamed";
|
|
2995
|
+
return /* @__PURE__ */ (0, import_jsx_runtime55.jsx)("div", { className: "flex flex-col", children: /* @__PURE__ */ (0, import_jsx_runtime55.jsx)(
|
|
2996
|
+
import_react_hook_form.Controller,
|
|
2997
|
+
{
|
|
2998
|
+
name,
|
|
2999
|
+
control,
|
|
3000
|
+
render: ({ field: controllerField }) => {
|
|
3001
|
+
const childElement = child2;
|
|
3002
|
+
return import_react16.default.cloneElement(childElement, {
|
|
3003
|
+
input: {
|
|
3004
|
+
...controllerField,
|
|
3005
|
+
hasFormContainer: true,
|
|
3006
|
+
validateOnMount: true,
|
|
3007
|
+
errorMessage: errors[name]?.message || null
|
|
3008
|
+
},
|
|
3009
|
+
children: void 0
|
|
3010
|
+
});
|
|
3011
|
+
}
|
|
3012
|
+
}
|
|
3013
|
+
) }, node.id);
|
|
3014
|
+
}
|
|
3015
|
+
if (child2.props?.children) {
|
|
3016
|
+
const childElement = child2;
|
|
3017
|
+
return import_react16.default.cloneElement(childElement, {
|
|
3018
|
+
children: import_react16.default.Children.map(childElement.props.children, processChild)
|
|
3019
|
+
});
|
|
3020
|
+
}
|
|
3021
|
+
return import_react16.default.cloneElement(child2);
|
|
3022
|
+
}
|
|
3023
|
+
return child2;
|
|
3024
|
+
};
|
|
3025
|
+
return processChild(child);
|
|
3026
|
+
}) })
|
|
3027
|
+
}
|
|
3028
|
+
);
|
|
3029
|
+
};
|
|
3030
|
+
var Wrapper_default = FormWrapper;
|
|
2878
3031
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2879
3032
|
0 && (module.exports = {
|
|
2880
3033
|
BarChart,
|
|
@@ -2888,6 +3041,7 @@ function useAppState() {
|
|
|
2888
3041
|
EmailComposer,
|
|
2889
3042
|
FileInput,
|
|
2890
3043
|
FlexLayout,
|
|
3044
|
+
Form,
|
|
2891
3045
|
GridLayout,
|
|
2892
3046
|
Image,
|
|
2893
3047
|
Logo,
|