@algorithm-shift/design-system 1.2.36 → 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.css +16 -0
- package/dist/index.css.map +1 -1
- package/dist/index.d.mts +15 -4
- package/dist/index.d.ts +15 -4
- package/dist/index.js +163 -6
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +162 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +5 -2
package/dist/index.mjs
CHANGED
|
@@ -30,9 +30,10 @@ import { jsx as jsx2 } from "react/jsx-runtime";
|
|
|
30
30
|
var Flex = ({
|
|
31
31
|
children,
|
|
32
32
|
className,
|
|
33
|
-
style
|
|
33
|
+
style,
|
|
34
|
+
...props
|
|
34
35
|
}) => {
|
|
35
|
-
return /* @__PURE__ */ jsx2("div", { className, style, children });
|
|
36
|
+
return /* @__PURE__ */ jsx2("div", { ...props, className, style, children });
|
|
36
37
|
};
|
|
37
38
|
var Flex_default = Flex;
|
|
38
39
|
|
|
@@ -41,9 +42,10 @@ import { jsx as jsx3 } from "react/jsx-runtime";
|
|
|
41
42
|
var Grid = ({
|
|
42
43
|
children,
|
|
43
44
|
className,
|
|
44
|
-
style
|
|
45
|
+
style,
|
|
46
|
+
...props
|
|
45
47
|
}) => {
|
|
46
|
-
return /* @__PURE__ */ jsx3("div", { className, style, children });
|
|
48
|
+
return /* @__PURE__ */ jsx3("div", { ...props, className, style, children });
|
|
47
49
|
};
|
|
48
50
|
var Grid_default = Grid;
|
|
49
51
|
|
|
@@ -52,9 +54,10 @@ import { jsx as jsx4 } from "react/jsx-runtime";
|
|
|
52
54
|
var Container = ({
|
|
53
55
|
children,
|
|
54
56
|
className,
|
|
55
|
-
style
|
|
57
|
+
style,
|
|
58
|
+
...props
|
|
56
59
|
}) => {
|
|
57
|
-
return /* @__PURE__ */ jsx4("div", { className, style, children });
|
|
60
|
+
return /* @__PURE__ */ jsx4("div", { ...props, className, style, children });
|
|
58
61
|
};
|
|
59
62
|
var Container_default = Container;
|
|
60
63
|
|
|
@@ -2798,6 +2801,158 @@ function StateProvider({ children }) {
|
|
|
2798
2801
|
function useAppState() {
|
|
2799
2802
|
return useContext(StateContext);
|
|
2800
2803
|
}
|
|
2804
|
+
|
|
2805
|
+
// src/components/Form/Wrapper.tsx
|
|
2806
|
+
import React18, { useMemo as useMemo2 } from "react";
|
|
2807
|
+
import { zodResolver } from "@hookform/resolvers/zod";
|
|
2808
|
+
import { useForm, Controller } from "react-hook-form";
|
|
2809
|
+
import { z } from "zod";
|
|
2810
|
+
import { jsx as jsx55 } from "react/jsx-runtime";
|
|
2811
|
+
function generateZodSchema(data) {
|
|
2812
|
+
const fields = data.reduce((acc, f) => {
|
|
2813
|
+
const name = f.name || "unnamed";
|
|
2814
|
+
const message = f.message || `${name} is invalid`;
|
|
2815
|
+
const passwordLen = f.passwordLength;
|
|
2816
|
+
let fieldSchema = z.string({ message });
|
|
2817
|
+
switch (f.type) {
|
|
2818
|
+
case "Text":
|
|
2819
|
+
case "Search":
|
|
2820
|
+
fieldSchema = z.string({ message });
|
|
2821
|
+
if (f?.min && f?.min !== "") fieldSchema = fieldSchema.min(f.min);
|
|
2822
|
+
else if (f.isRequired) fieldSchema = fieldSchema.min(1, { message: `${message}. Cannot be empty` });
|
|
2823
|
+
if (f?.max && f?.max !== "") fieldSchema = fieldSchema.max(f.max);
|
|
2824
|
+
if (f?.email) fieldSchema = fieldSchema.email();
|
|
2825
|
+
if (f?.url) fieldSchema = fieldSchema.url();
|
|
2826
|
+
if (f?.regex) fieldSchema = fieldSchema.regex(new RegExp(f.regex));
|
|
2827
|
+
break;
|
|
2828
|
+
case "Email":
|
|
2829
|
+
fieldSchema = z.email({ message });
|
|
2830
|
+
break;
|
|
2831
|
+
case "Password":
|
|
2832
|
+
fieldSchema = z.string({ message }).min(passwordLen, { message: `Password must be at least ${passwordLen} characters long` });
|
|
2833
|
+
break;
|
|
2834
|
+
case "Phone":
|
|
2835
|
+
fieldSchema = z.string().transform((val) => val.replace(/\D/g, "")).transform((val) => val.slice(-10)).refine((val) => {
|
|
2836
|
+
return val.length === 10;
|
|
2837
|
+
}, {
|
|
2838
|
+
message: "Phone number must be 10 digits long"
|
|
2839
|
+
});
|
|
2840
|
+
break;
|
|
2841
|
+
case "DatePicker":
|
|
2842
|
+
fieldSchema = z.iso.date({ message });
|
|
2843
|
+
break;
|
|
2844
|
+
case "FileInput":
|
|
2845
|
+
fieldSchema = z.instanceof(File, { message: "Please select a file" });
|
|
2846
|
+
if (f?.maxSize) {
|
|
2847
|
+
fieldSchema = fieldSchema.refine(
|
|
2848
|
+
(file) => file.size <= f.maxSize,
|
|
2849
|
+
{ message: `File size must be less than ${f.maxSize / 1024 / 1024}MB` }
|
|
2850
|
+
);
|
|
2851
|
+
}
|
|
2852
|
+
if (f?.acceptedTypes) {
|
|
2853
|
+
fieldSchema = fieldSchema.refine(
|
|
2854
|
+
(file) => f.acceptedTypes.includes(file.type),
|
|
2855
|
+
{ message: `File type must be one of: ${f.acceptedTypes.join(", ")}` }
|
|
2856
|
+
);
|
|
2857
|
+
}
|
|
2858
|
+
break;
|
|
2859
|
+
case "Checkbox":
|
|
2860
|
+
fieldSchema = z.boolean({ message });
|
|
2861
|
+
break;
|
|
2862
|
+
case "Dropdown":
|
|
2863
|
+
fieldSchema = z.string({ message });
|
|
2864
|
+
break;
|
|
2865
|
+
case "NumberInput":
|
|
2866
|
+
fieldSchema = z.number({ message });
|
|
2867
|
+
if (f?.min !== void 0) fieldSchema = fieldSchema.min(f.min);
|
|
2868
|
+
if (f?.max !== void 0) fieldSchema = fieldSchema.max(f.max);
|
|
2869
|
+
break;
|
|
2870
|
+
default:
|
|
2871
|
+
fieldSchema = z.any();
|
|
2872
|
+
}
|
|
2873
|
+
if (!f.isRequired) fieldSchema = fieldSchema.optional();
|
|
2874
|
+
acc[name] = fieldSchema;
|
|
2875
|
+
return acc;
|
|
2876
|
+
}, {});
|
|
2877
|
+
return z.object(fields);
|
|
2878
|
+
}
|
|
2879
|
+
var FormWrapper = ({
|
|
2880
|
+
validation,
|
|
2881
|
+
defaultValues,
|
|
2882
|
+
children,
|
|
2883
|
+
onSubmit,
|
|
2884
|
+
onReset
|
|
2885
|
+
}) => {
|
|
2886
|
+
const schema = useMemo2(() => {
|
|
2887
|
+
if (!validation || validation.length === 0) return null;
|
|
2888
|
+
return generateZodSchema(validation);
|
|
2889
|
+
}, [validation]);
|
|
2890
|
+
const {
|
|
2891
|
+
handleSubmit,
|
|
2892
|
+
control,
|
|
2893
|
+
formState: { errors },
|
|
2894
|
+
reset
|
|
2895
|
+
} = useForm({
|
|
2896
|
+
resolver: schema ? zodResolver(schema) : void 0,
|
|
2897
|
+
defaultValues
|
|
2898
|
+
});
|
|
2899
|
+
const formSubmit = (data) => {
|
|
2900
|
+
if (onSubmit) onSubmit(data);
|
|
2901
|
+
};
|
|
2902
|
+
const handleReset = () => {
|
|
2903
|
+
reset();
|
|
2904
|
+
if (onReset) onReset();
|
|
2905
|
+
};
|
|
2906
|
+
return /* @__PURE__ */ jsx55(
|
|
2907
|
+
"form",
|
|
2908
|
+
{
|
|
2909
|
+
onSubmit: handleSubmit(formSubmit),
|
|
2910
|
+
onReset: handleReset,
|
|
2911
|
+
className: cn(
|
|
2912
|
+
"space-y-4 min-h-[100px] h-auto flex justify-between flex-col"
|
|
2913
|
+
),
|
|
2914
|
+
children: /* @__PURE__ */ jsx55("div", { className: "min-h-[50px]", children: React18.Children.map(children, (child) => {
|
|
2915
|
+
const processChild = (child2) => {
|
|
2916
|
+
if (React18.isValidElement(child2)) {
|
|
2917
|
+
const node = child2.props?.node;
|
|
2918
|
+
if (node?.category === "Form Controls") {
|
|
2919
|
+
const name = node.properties?.name || "unnamed";
|
|
2920
|
+
return /* @__PURE__ */ jsx55("div", { className: "flex flex-col", children: /* @__PURE__ */ jsx55(
|
|
2921
|
+
Controller,
|
|
2922
|
+
{
|
|
2923
|
+
name,
|
|
2924
|
+
control,
|
|
2925
|
+
render: ({ field: controllerField }) => {
|
|
2926
|
+
const childElement = child2;
|
|
2927
|
+
return React18.cloneElement(childElement, {
|
|
2928
|
+
input: {
|
|
2929
|
+
...controllerField,
|
|
2930
|
+
hasFormContainer: true,
|
|
2931
|
+
validateOnMount: true,
|
|
2932
|
+
errorMessage: errors[name]?.message || null
|
|
2933
|
+
},
|
|
2934
|
+
children: void 0
|
|
2935
|
+
});
|
|
2936
|
+
}
|
|
2937
|
+
}
|
|
2938
|
+
) }, node.id);
|
|
2939
|
+
}
|
|
2940
|
+
if (child2.props?.children) {
|
|
2941
|
+
const childElement = child2;
|
|
2942
|
+
return React18.cloneElement(childElement, {
|
|
2943
|
+
children: React18.Children.map(childElement.props.children, processChild)
|
|
2944
|
+
});
|
|
2945
|
+
}
|
|
2946
|
+
return React18.cloneElement(child2);
|
|
2947
|
+
}
|
|
2948
|
+
return child2;
|
|
2949
|
+
};
|
|
2950
|
+
return processChild(child);
|
|
2951
|
+
}) })
|
|
2952
|
+
}
|
|
2953
|
+
);
|
|
2954
|
+
};
|
|
2955
|
+
var Wrapper_default = FormWrapper;
|
|
2801
2956
|
export {
|
|
2802
2957
|
BarChart_default as BarChart,
|
|
2803
2958
|
Button_default as Button,
|
|
@@ -2810,6 +2965,7 @@ export {
|
|
|
2810
2965
|
EmailComposer,
|
|
2811
2966
|
FileInput_default as FileInput,
|
|
2812
2967
|
Flex_default as FlexLayout,
|
|
2968
|
+
Wrapper_default as Form,
|
|
2813
2969
|
Grid_default as GridLayout,
|
|
2814
2970
|
Image_default as Image,
|
|
2815
2971
|
Logo_default as Logo,
|