Skip to content

Commit 189da21

Browse files
Updated ShadcnAutoForm props to have only have title and submitLabel props when there are no children
1 parent 689dbdc commit 189da21

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

packages/react/src/auto/shadcn/ShadcnAutoForm.tsx

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -98,17 +98,6 @@ export const makeAutoForm = <Elements extends ShadcnElements>({
9898
<AutoFormInner
9999
key={componentKey}
100100
{...(props as AutoFormProps<GivenOptions, SchemaT, ActionFunc> & Omit<Partial<FormProps>, "action"> & { findBy: any })}
101-
elements={{
102-
Form,
103-
Input,
104-
Button,
105-
Alert,
106-
Skeleton,
107-
AlertTitle,
108-
AlertDescription,
109-
ShadcnAutoInput: AutoInput,
110-
ShadcnAutoSubmit: AutoSubmit,
111-
}}
112101
/>
113102
</AutoFormFieldsFromChildComponentsProvider>
114103
);
@@ -118,18 +107,13 @@ export const makeAutoForm = <Elements extends ShadcnElements>({
118107
GivenOptions extends OptionsType,
119108
SchemaT,
120109
ActionFunc extends ActionFunction<GivenOptions, any, any, SchemaT, any>
121-
>(
122-
props: AutoFormProps<GivenOptions, SchemaT, ActionFunc> & {
123-
elements: ShadcnElements;
124-
} & ComponentProps<any>
125-
) {
110+
>(props: AutoFormProps<GivenOptions, SchemaT, ActionFunc> & ComponentProps<typeof Form>) {
126111
const {
127112
record: _record,
128113
action,
129114
findBy,
130115
...rest
131116
} = props as AutoFormProps<GivenOptions, SchemaT, ActionFunc> & Omit<Partial<FormProps>, "action"> & { findBy: any };
132-
const { Form, Skeleton, ShadcnAutoInput, ShadcnAutoSubmit } = props.elements;
133117

134118
const {
135119
metadata,
@@ -144,7 +128,7 @@ export const makeAutoForm = <Elements extends ShadcnElements>({
144128
isLoading,
145129
} = useAutoForm(props);
146130

147-
const formTitle = props.title === undefined ? humanizeCamelCase(action.operationName) : props.title;
131+
const formTitle = "title" in props && props.title !== undefined ? props.title : humanizeCamelCase(action.operationName);
148132

149133
if (props.successContent && isSubmitSuccessful) {
150134
return props.successContent;
@@ -182,9 +166,9 @@ export const makeAutoForm = <Elements extends ShadcnElements>({
182166
{!metadataError && (
183167
<>
184168
{fields.map(({ metadata }) => (
185-
<ShadcnAutoInput field={metadata.apiIdentifier} key={metadata.apiIdentifier} />
169+
<AutoInput field={metadata.apiIdentifier} key={metadata.apiIdentifier} />
186170
))}
187-
<ShadcnAutoSubmit>{props.submitLabel ?? "Submit"}</ShadcnAutoSubmit>
171+
<AutoSubmit>{"submitLabel" in props && props.submitLabel ? props.submitLabel : "Submit"}</AutoSubmit>
188172
</>
189173
)}
190174
</>

0 commit comments

Comments
 (0)