|
9 | 9 | StrictRJSFSchema, |
10 | 10 | } from '@rjsf/utils'; |
11 | 11 | import classNames from 'classnames'; |
12 | | -import Col from 'antd/lib/col'; |
13 | | -import Row from 'antd/lib/row'; |
14 | | -import { ConfigConsumer, ConfigConsumerProps } from 'antd/lib/config-provider/context'; |
| 12 | +import { Col, Row, ConfigProvider } from 'antd'; |
| 13 | +import { useContext } from 'react'; |
15 | 14 |
|
16 | 15 | const DESCRIPTION_COL_STYLE = { |
17 | 16 | paddingBottom: '8px', |
@@ -63,70 +62,64 @@ export default function ArrayFieldTemplate< |
63 | 62 | } = registry.templates; |
64 | 63 | const { labelAlign = 'right', rowGutter = 24 } = formContext as GenericObjectType; |
65 | 64 |
|
| 65 | + const { getPrefixCls } = useContext(ConfigProvider.ConfigContext); |
| 66 | + const prefixCls = getPrefixCls('form'); |
| 67 | + const labelClsBasic = `${prefixCls}-item-label`; |
| 68 | + const labelColClassName = classNames( |
| 69 | + labelClsBasic, |
| 70 | + labelAlign === 'left' && `${labelClsBasic}-left` |
| 71 | + // labelCol.className, |
| 72 | + ); |
| 73 | + |
66 | 74 | return ( |
67 | | - <ConfigConsumer> |
68 | | - {(configProps: ConfigConsumerProps) => { |
69 | | - const { getPrefixCls } = configProps; |
70 | | - const prefixCls = getPrefixCls('form'); |
71 | | - const labelClsBasic = `${prefixCls}-item-label`; |
72 | | - const labelColClassName = classNames( |
73 | | - labelClsBasic, |
74 | | - labelAlign === 'left' && `${labelClsBasic}-left` |
75 | | - // labelCol.className, |
76 | | - ); |
| 75 | + <fieldset className={className} id={idSchema.$id}> |
| 76 | + <Row gutter={rowGutter}> |
| 77 | + {(uiOptions.title || title) && ( |
| 78 | + <Col className={labelColClassName} span={24}> |
| 79 | + <ArrayFieldTitleTemplate |
| 80 | + idSchema={idSchema} |
| 81 | + required={required} |
| 82 | + title={uiOptions.title || title} |
| 83 | + schema={schema} |
| 84 | + uiSchema={uiSchema} |
| 85 | + registry={registry} |
| 86 | + /> |
| 87 | + </Col> |
| 88 | + )} |
| 89 | + {(uiOptions.description || schema.description) && ( |
| 90 | + <Col span={24} style={DESCRIPTION_COL_STYLE}> |
| 91 | + <ArrayFieldDescriptionTemplate |
| 92 | + description={uiOptions.description || schema.description} |
| 93 | + idSchema={idSchema} |
| 94 | + schema={schema} |
| 95 | + uiSchema={uiSchema} |
| 96 | + registry={registry} |
| 97 | + /> |
| 98 | + </Col> |
| 99 | + )} |
| 100 | + <Col className='row array-item-list' span={24}> |
| 101 | + {items && |
| 102 | + items.map(({ key, ...itemProps }: ArrayFieldTemplateItemType<T, S, F>) => ( |
| 103 | + <ArrayFieldItemTemplate key={key} {...itemProps} /> |
| 104 | + ))} |
| 105 | + </Col> |
77 | 106 |
|
78 | | - return ( |
79 | | - <fieldset className={className} id={idSchema.$id}> |
80 | | - <Row gutter={rowGutter}> |
81 | | - {(uiOptions.title || title) && ( |
82 | | - <Col className={labelColClassName} span={24}> |
83 | | - <ArrayFieldTitleTemplate |
84 | | - idSchema={idSchema} |
85 | | - required={required} |
86 | | - title={uiOptions.title || title} |
87 | | - schema={schema} |
88 | | - uiSchema={uiSchema} |
89 | | - registry={registry} |
90 | | - /> |
91 | | - </Col> |
92 | | - )} |
93 | | - {(uiOptions.description || schema.description) && ( |
94 | | - <Col span={24} style={DESCRIPTION_COL_STYLE}> |
95 | | - <ArrayFieldDescriptionTemplate |
96 | | - description={uiOptions.description || schema.description} |
97 | | - idSchema={idSchema} |
98 | | - schema={schema} |
99 | | - uiSchema={uiSchema} |
100 | | - registry={registry} |
101 | | - /> |
102 | | - </Col> |
103 | | - )} |
104 | | - <Col className='row array-item-list' span={24}> |
105 | | - {items && |
106 | | - items.map(({ key, ...itemProps }: ArrayFieldTemplateItemType<T, S, F>) => ( |
107 | | - <ArrayFieldItemTemplate key={key} {...itemProps} /> |
108 | | - ))} |
| 107 | + {canAdd && ( |
| 108 | + <Col span={24}> |
| 109 | + <Row gutter={rowGutter} justify='end'> |
| 110 | + <Col flex='192px'> |
| 111 | + <AddButton |
| 112 | + className='array-item-add' |
| 113 | + disabled={disabled || readonly} |
| 114 | + onClick={onAddClick} |
| 115 | + uiSchema={uiSchema} |
| 116 | + registry={registry} |
| 117 | + /> |
109 | 118 | </Col> |
110 | | - |
111 | | - {canAdd && ( |
112 | | - <Col span={24}> |
113 | | - <Row gutter={rowGutter} justify='end'> |
114 | | - <Col flex='192px'> |
115 | | - <AddButton |
116 | | - className='array-item-add' |
117 | | - disabled={disabled || readonly} |
118 | | - onClick={onAddClick} |
119 | | - uiSchema={uiSchema} |
120 | | - registry={registry} |
121 | | - /> |
122 | | - </Col> |
123 | | - </Row> |
124 | | - </Col> |
125 | | - )} |
126 | 119 | </Row> |
127 | | - </fieldset> |
128 | | - ); |
129 | | - }} |
130 | | - </ConfigConsumer> |
| 120 | + </Col> |
| 121 | + )} |
| 122 | + </Row> |
| 123 | + </fieldset> |
131 | 124 | ); |
132 | 125 | } |
0 commit comments