Skip to content

Commit

Permalink
feat(antd/next): support 16427form scope with Form
Browse files Browse the repository at this point in the history
  • Loading branch information
janryWang committed Feb 13, 2022
1 parent cad37da commit 09a597f
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 30 deletions.
37 changes: 22 additions & 15 deletions packages/antd/src/form/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import React from 'react'
import { Form as FormType, IFormFeedback } from '@formily/core'
import { useForm, FormProvider, JSXComponent } from '@formily/react'
import {
useForm,
FormProvider,
ExpressionScope,
JSXComponent,
} from '@formily/react'
import { FormLayout, IFormLayoutProps } from '../form-layout'
import { PreviewText } from '../preview-text'
export interface FormProps extends IFormLayoutProps {
Expand All @@ -21,21 +26,23 @@ export const Form: React.FC<FormProps> = ({
}) => {
const top = useForm()
const renderContent = (form: FormType) => (
<PreviewText.Placeholder value={previewTextPlaceholder}>
<FormLayout {...props}>
{React.createElement(
component,
{
onSubmit(e: React.FormEvent) {
e?.stopPropagation?.()
e?.preventDefault?.()
form.submit(onAutoSubmit).catch(onAutoSubmitFailed)
<ExpressionScope value={{ $$form: form }}>
<PreviewText.Placeholder value={previewTextPlaceholder}>
<FormLayout {...props}>
{React.createElement(
component,
{
onSubmit(e: React.FormEvent) {
e?.stopPropagation?.()
e?.preventDefault?.()
form.submit(onAutoSubmit).catch(onAutoSubmitFailed)
},
},
},
props.children
)}
</FormLayout>
</PreviewText.Placeholder>
props.children
)}
</FormLayout>
</PreviewText.Placeholder>
</ExpressionScope>
)
if (form)
return <FormProvider form={form}>{renderContent(form)}</FormProvider>
Expand Down
37 changes: 22 additions & 15 deletions packages/next/src/form/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import React, { useMemo } from 'react'
import { FormProvider, JSXComponent, useForm } from '@formily/react'
import {
FormProvider,
ExpressionScope,
JSXComponent,
useForm,
} from '@formily/react'
import { FormLayout, IFormLayoutProps } from '../form-layout'
import { ConfigProvider } from '@alifd/next'
import {
Expand Down Expand Up @@ -34,21 +39,23 @@ export const Form: React.FC<FormProps> = ({
}, [lang])

const renderContent = (form: FormType) => (
<PreviewText.Placeholder value={previewTextPlaceholder}>
<FormLayout {...props}>
{React.createElement(
component,
{
onSubmit(e: React.FormEvent) {
e?.stopPropagation?.()
e?.preventDefault?.()
form.submit(onAutoSubmit).catch(onAutoSubmitFailed)
<ExpressionScope value={{ $$form: form }}>
<PreviewText.Placeholder value={previewTextPlaceholder}>
<FormLayout {...props}>
{React.createElement(
component,
{
onSubmit(e: React.FormEvent) {
e?.stopPropagation?.()
e?.preventDefault?.()
form.submit(onAutoSubmit).catch(onAutoSubmitFailed)
},
},
},
props.children
)}
</FormLayout>
</PreviewText.Placeholder>
props.children
)}
</FormLayout>
</PreviewText.Placeholder>
</ExpressionScope>
)

if (form)
Expand Down

0 comments on commit 09a597f

Please sign in to comment.