@nativetail/ui 0.2.2 → 0.2.3

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nativetail/ui",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "",
5
5
  "main": "src/index.ts",
6
6
  "scripts": {},
@@ -16,16 +16,8 @@ import {
16
16
  PinInputProps,
17
17
  } from "../input";
18
18
  import { MultiSelect, MultiSelectProps, Select, SelectProps } from "../select";
19
- import {
20
- Type,
21
- TSchema,
22
- Static,
23
- JavaScriptTypeBuilder,
24
- TObject,
25
- TProperties,
26
- } from "@sinclair/typebox";
27
19
 
28
- type ZodFormBuilderProps<
20
+ export type FormBuilderProps<
29
21
  T extends z.ZodObject<z.ZodRawShape>,
30
22
  IValues = z.infer<T>,
31
23
  > = {
@@ -44,46 +36,13 @@ type ZodFormBuilderProps<
44
36
  containerClassname?: string;
45
37
  submitButtonProps?: ComponentPropsWithoutRef<typeof Button>;
46
38
  onSubmit?: (values: IValues, reset?: () => void) => void;
47
- onError?: (values: Partial<Record<keyof T, any>>) => void;
48
- isSubmitting?: boolean;
49
- defaultValues?: DefaultValues<IValues>;
50
- inputContainerClassname?: string;
51
- };
52
- type TypeboxFormBuilderProps<T extends TSchema, IValues = Static<T>> = {
53
- schema: TSchema;
54
- inputs?: Partial<
55
- Record<
56
- keyof IValues,
57
- {
58
- render?: (props: {
59
- control: Control<IValues, any>;
60
- name: string;
61
- }) => React.ReactElement;
62
- } & InputType
63
- >
64
- >;
65
- containerClassname?: string;
66
- submitButtonProps?: ComponentPropsWithoutRef<typeof Button>;
67
- onSubmit?: (values: IValues, reset?: () => void) => void;
68
- onError?: (values: Partial<Record<string, any>>) => void;
39
+ onError?: (values: Partial<Record<keyof IValues, any>>) => void;
69
40
  isSubmitting?: boolean;
70
41
  defaultValues?: DefaultValues<IValues>;
71
42
  inputContainerClassname?: string;
72
43
  };
73
44
 
74
- export type FormBuilderProps<T extends z.ZodObject<z.ZodRawShape> | TSchema> =
75
- T extends z.ZodObject<z.ZodRawShape>
76
- ? ZodFormBuilderProps<T>
77
- : T extends TSchema
78
- ? TypeboxFormBuilderProps<T>
79
- : never;
80
- const isTypebox = (shape: any): shape is TObject<TProperties> => {
81
- return shape instanceof JavaScriptTypeBuilder;
82
- };
83
- const isZod = (shape: any): shape is z.ZodObject<z.ZodRawShape> => {
84
- return shape instanceof z.ZodObject;
85
- };
86
- export function FormBuilder<T extends z.ZodObject<z.ZodRawShape> | TSchema>({
45
+ export function FormBuilder<T extends z.ZodObject<z.ZodRawShape>>({
87
46
  schema,
88
47
  inputs,
89
48
  containerClassname,
@@ -97,19 +56,9 @@ export function FormBuilder<T extends z.ZodObject<z.ZodRawShape> | TSchema>({
97
56
  const shape = schema.shape;
98
57
  const keys = Object.keys(shape);
99
58
 
100
- type SchemaType = typeof schema;
101
- type FormSchemaType =
102
- SchemaType extends z.ZodObject<z.ZodRawShape>
103
- ? z.infer<SchemaType>
104
- : SchemaType extends TSchema
105
- ? Static<SchemaType>
106
- : any;
59
+ type FormSchemaType = z.infer<T>;
107
60
  const form = useForm<FormSchemaType>({
108
- resolver: isTypebox(schema)
109
- ? typeboxResolver(schema)
110
- : isZod(schema)
111
- ? zodResolver(schema)
112
- : undefined,
61
+ resolver: zodResolver(schema),
113
62
  defaultValues: defaultValues,
114
63
  });
115
64
  return (
@@ -138,9 +87,12 @@ export function FormBuilder<T extends z.ZodObject<z.ZodRawShape> | TSchema>({
138
87
  className="w-full"
139
88
  children={"Submit"}
140
89
  {...submitButtonProps}
141
- onPress={form.handleSubmit((data) => {
142
- onSubmit?.(data, form.reset);
143
- }, onError)}
90
+ onPress={form.handleSubmit(
91
+ (data) => {
92
+ onSubmit?.(data, form.reset);
93
+ },
94
+ (error) => onError?.(error)
95
+ )}
144
96
  isLoading={isSubmitting}
145
97
  />
146
98
  </View>