@@ -25,7 +25,7 @@ npm install --save @uform/antd
25
25
- [ ` table ` ] ( #table )
26
26
- [ 布局组件] ( #Layout-Components )
27
27
- [ ` <FormCard/> ` ] ( #FormCard )
28
- - [ ` <FormBlock/> ` ] ( #FormBlock )
28
+ - [ ` <FormBlock/> ` ] ( #FormBlock )
29
29
- [ ` <FormStep/> ` ] ( #FormStep )
30
30
- [ ` <FormLayout/> ` ] ( #FormLayout )
31
31
- [ ` <FormItemGrid/> ` ] ( #FormItemGrid )
@@ -53,15 +53,15 @@ npm install --save @uform/antd
53
53
- [ ` useFieldState ` ] ( #useFieldState )
54
54
- [ ` useForm ` ] ( #useForm )
55
55
- [ ` useField ` ] ( #useField )
56
- - [ ` useVirtualField ` ] ( #useVirtualField )
57
- - [ ` useFormSpy ` ] ( #useFormSpy )
56
+ - [ ` useVirtualField ` ] ( #useVirtualField )
57
+ - [ ` useFormSpy ` ] ( #useFormSpy )
58
58
- [ API] ( #API )
59
59
- [ ` createFormActions ` ] ( #createFormActions )
60
60
- [ ` createAsyncFormActions ` ] ( #createAsyncFormActions )
61
61
- [ ` FormEffectHooks ` ] ( #FormEffectHooks )
62
62
- [ ` createEffectHook ` ] ( #createEffectHook )
63
63
- [ ` connect ` ] ( #connect )
64
- - [ ` registerFormField ` ] ( #registerFormField )
64
+ - [ ` registerFormField ` ] ( #registerFormField )
65
65
- [ Interfaces] ( #Interfaces )
66
66
- [ ` ISchema ` ] ( #ischema )
67
67
- [ ` IFormActions ` ] ( #IFormActions )
@@ -82,10 +82,64 @@ npm install --save @uform/antd
82
82
- [ ` IFieldProps ` ] ( #IFieldProps )
83
83
- [ ` IConnectOptions ` ] ( #IConnectOptions )
84
84
- [ ` ISpyHook ` ] ( #ISpyHook )
85
-
86
85
87
86
### 使用方式
88
87
88
+ #### 安装
89
+
90
+ ``` bash
91
+ $ yarn add antd @uform/antd
92
+
93
+ # or
94
+
95
+ $ npm install --save antd @uform/antd
96
+ ```
97
+
98
+ ### 按需加载
99
+
100
+ #### 在 umijs 中使用
101
+ 在开始之前,你可能需要安装 [ umijs] ( https://umijs.org/zh/guide/getting-started.html ) , 并开启 [ antd 配置] ( https://umijs.org/zh/plugin/umi-plugin-react.html#antd ) 。
102
+
103
+ 然后在 umijs 的 ` .umirc.js ` 或 ` config/config.js ` (二选一)中增加 ` extraBabelIncludes ` 配置项
104
+
105
+ > 在使用 uform 组件的时候,请使用 ES Modules import 导入模块
106
+
107
+ ``` js
108
+ extraBabelIncludes: [
109
+ / node_modules[\\ /][\\ @] uform[\\ /] antd[\\ /] esm/
110
+ ],
111
+ ```
112
+
113
+ ---
114
+
115
+ #### 在 create-react-app 中使用
116
+
117
+ 在开始之前,请先按照 antd 的[ 教程] ( https://ant-design.gitee.io/docs/react/use-with-create-react-app-cn ) ,完成对 ` babel-plugin-import ` 的配置, 然后只需要在 ` config-overrides.js ` 中加入 ` babelInclude `
118
+
119
+ > 在使用 uform 组件的时候,请使用 ES Modules import 导入模块
120
+
121
+ ``` js
122
+ // config-overrides.js
123
+
124
+ const { override , fixBabelImports , babelInclude } = require (' customize-cra' );
125
+ const path = require (' path' );
126
+
127
+ module .exports = override (
128
+ fixBabelImports (' import' , {
129
+ libraryName: ' antd' ,
130
+ libraryDirectory: ' es' ,
131
+ style: ' css' ,
132
+ }),
133
+ babelInclude ([
134
+ path .resolve (' src' ),
135
+ / node_modules[\\ /][\\ @] uform[\\ /] antd[\\ /] esm/ ,
136
+ ]),
137
+ )
138
+ ```
139
+
140
+ #### 更多脚手架
141
+ ` @uform/antd ` 底层依赖 ` antd ` ,在对 ` @uform/antd ` 进行按需加载实际也是对 ` antd ` 进行按需加载,从上面的例子可以看出,脚手架只需要配置好了 ` babel-plugin-import ` ,然后再把 ` @uform/antd/esm ` 加入 ` babel ` 的 ` include ` 中即可完成功能配置
142
+
89
143
---
90
144
91
145
#### 快速开始
@@ -405,7 +459,7 @@ interface IAntdSchemaFormProps {
405
459
// 内联表单
406
460
inline? : boolean
407
461
// 扩展class
408
- className? : string
462
+ className? : string
409
463
style? : React .CSSProperties
410
464
// label 布局控制
411
465
labelCol? : number | { span: number ; offset? : number }
@@ -451,7 +505,7 @@ interface IAntdSchemaFormProps {
451
505
import React , { Component } from ' react'
452
506
import ReactDOM from ' react-dom'
453
507
import SchemaForm, {
454
- Field ,
508
+ Field ,
455
509
connect ,
456
510
createFormActions
457
511
} from ' @uform/antd'
@@ -481,7 +535,7 @@ ReactDOM.render(
481
535
import React , { Component } from ' react'
482
536
import ReactDOM from ' react-dom'
483
537
import SchemaForm, {
484
- Field ,
538
+ Field ,
485
539
createFormActions ,
486
540
FormLayout ,
487
541
FormButtonGroup ,
@@ -597,7 +651,7 @@ import React, { Component } from 'react'
597
651
import ReactDOM from ' react-dom'
598
652
import SchemaForm, {
599
653
FormSlot ,
600
- Field ,
654
+ Field ,
601
655
createFormActions ,
602
656
FormLayout ,
603
657
FormButtonGroup ,
@@ -611,10 +665,10 @@ ReactDOM.render(
611
665
< SchemaForm>
612
666
< FormSlot>< div> required< / div>< / FormSlot>
613
667
< Field name= " a" required type= " string" title= " field1" / >
614
-
668
+
615
669
< FormSlot>< div> description< / div>< / FormSlot>
616
670
< Field name= " b" description= " description" type= " string" title= " field1" / >
617
-
671
+
618
672
< FormSlot>< div> default value< / div>< / FormSlot>
619
673
< Field name= " c" default= {10 } type= " string" title= " field1" / >
620
674
@@ -2416,7 +2470,7 @@ const FormFragment = () => {
2416
2470
2417
2471
return (
2418
2472
< React .Fragment >
2419
- < CheckedField name = " trigger" label = " show/hide" / >
2473
+ < CheckedField name = " trigger" label = " show/hide" / >
2420
2474
<div >
2421
2475
< InputField label = " a" name = " a" / >
2422
2476
< / div >
@@ -2457,7 +2511,7 @@ import React, { useRef } from 'react'
2457
2511
import ReactDOM from ' react-dom'
2458
2512
import { Form , Field , VirtualField ,
2459
2513
createFormActions , createEffectHook ,
2460
- useForm ,
2514
+ useForm ,
2461
2515
useFormState ,
2462
2516
useFormEffects ,
2463
2517
useFieldState ,
@@ -2485,7 +2539,7 @@ const InputField = props => (
2485
2539
)
2486
2540
2487
2541
const actions = createFormActions ()
2488
- const FormFragment = (props ) => {
2542
+ const FormFragment = (props ) => {
2489
2543
const [formState, setFormState ] = useFormState ({ extendVar: 0 })
2490
2544
const { extendVar } = formState
2491
2545
@@ -2523,7 +2577,7 @@ import React, { useRef } from 'react'
2523
2577
import ReactDOM from ' react-dom'
2524
2578
import { Form , Field , VirtualField ,
2525
2579
createFormActions , createEffectHook ,
2526
- useForm ,
2580
+ useForm ,
2527
2581
useFormEffects ,
2528
2582
useFieldState ,
2529
2583
LifeCycleTypes
@@ -2551,12 +2605,12 @@ const InputField = props => (
2551
2605
2552
2606
const changeTab$ = createEffectHook (' changeTab' )
2553
2607
const actions = createFormActions ()
2554
- const TabFragment = (props ) => {
2608
+ const TabFragment = (props ) => {
2555
2609
const [fieldState, setLocalFieldState ] = useFieldState ({ current: 0 })
2556
2610
const { current } = fieldState
2557
2611
const { children, dataSource, form } = props
2558
2612
2559
- const update = (cur ) => {
2613
+ const update = (cur ) => {
2560
2614
form .notify (' changeTab' , cur )
2561
2615
setLocalFieldState ({
2562
2616
current: cur
@@ -2665,7 +2719,7 @@ const FormFragment = (props) => {
2665
2719
props : fieldProps,
2666
2720
mutators
2667
2721
} = useField ({ name: ' username' })
2668
-
2722
+
2669
2723
return <input {... fieldProps } {... props } value = {state .value} onChange = {mutators .change} />
2670
2724
}
2671
2725
```
@@ -2691,7 +2745,7 @@ const FormFragment = (props) => {
2691
2745
state,
2692
2746
props: fieldProps,
2693
2747
} = UseVirtualField({ name: 'username' })
2694
-
2748
+
2695
2749
return <div style={{ width: fieldProps.width, height: fieldProps.height }}>
2696
2750
{props.children}
2697
2751
</div>
@@ -2723,7 +2777,7 @@ const FormFragment = (props) => {
2723
2777
count: state.count ? state.count + 1 : 1
2724
2778
})
2725
2779
})
2726
-
2780
+
2727
2781
return <div>
2728
2782
<div>count: {state.count || 0}</div>
2729
2783
</div>
@@ -2886,7 +2940,7 @@ ReactDOM.render(<App />, document.getElementById('root'))
2886
2940
> 包装字段组件,让字段组件只需要支持value / defaultValue / onChange 属性即可快速接入表单
2887
2941
2888
2942
` ` ` typescript
2889
- type Connect = <T extends React.ComponentType<IFieldProps>>(options?: IConnectOptions<T>) =>
2943
+ type Connect = <T extends React.ComponentType<IFieldProps>>(options?: IConnectOptions<T>) =>
2890
2944
(Target: T) => React.PureComponent<IFieldProps>
2891
2945
` ` `
2892
2946
** 用法**
@@ -3606,12 +3660,12 @@ interface IConnectOptions<T> {
3606
3660
//默认props
3607
3661
defaultProps?: Partial<IConnectProps>
3608
3662
//取值函数,有些场景我们的事件函数取值并不是事件回调的第一个参数,需要做进一步的定制
3609
- getValueFromEvent?: (props: IFieldProps['x-props'], event: Event, ...args: any[]) => any
3663
+ getValueFromEvent?: (props: IFieldProps['x-props'], event: Event, ...args: any[]) => any
3610
3664
//字段组件props transformer
3611
- getProps?: (connectProps: IConnectProps, fieldProps: IFieldProps) => IConnectProps
3665
+ getProps?: (connectProps: IConnectProps, fieldProps: IFieldProps) => IConnectProps
3612
3666
//字段组件component transformer
3613
- getComponent?: (
3614
- target: T,
3667
+ getComponent?: (
3668
+ target: T,
3615
3669
connectProps: IConnectProps,
3616
3670
fieldProps: IFieldProps
3617
3671
) => T
@@ -3627,4 +3681,4 @@ interface ISpyHook {
3627
3681
state: any
3628
3682
type: string
3629
3683
}
3630
- ` ` `
3684
+ ` ` `
0 commit comments