Browse Source

feat: config-provider support Form className and style properties (#43230)

* feat: config-provider support Input className and style properties

* Revert "feat: config-provider support Input className and style properties"

This reverts commit 46cd51e2b7.

* feat: config-provider support Form className and style properties
pull/43270/head
muxin 1 year ago
committed by GitHub
parent
commit
67e32373fb
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      components/config-provider/__tests__/style.test.tsx
  2. 2
      components/config-provider/context.ts
  3. 2
      components/config-provider/index.en-US.md
  4. 2
      components/config-provider/index.tsx
  5. 2
      components/config-provider/index.zh-CN.md
  6. 3
      components/form/Form.tsx

17
components/config-provider/__tests__/style.test.tsx

@ -8,6 +8,7 @@ import Checkbox from '../../checkbox';
import Descriptions from '../../descriptions';
import Divider from '../../divider';
import Empty from '../../empty';
import Form from '../../form';
import Image from '../../image';
import Input from '../../input';
import Layout from '../../layout';
@ -243,6 +244,22 @@ describe('ConfigProvider support style and className props', () => {
expect(element).toHaveStyle({ backgroundColor: 'red' });
});
it('Should Form className & style works', () => {
const { container } = render(
<ConfigProvider form={{ className: 'cp-form', style: { backgroundColor: 'red' } }}>
<Form name="basic">
<Form.Item label="Username" name="username">
<Input />
</Form.Item>
</Form>
</ConfigProvider>,
);
const element = container.querySelector<HTMLDivElement>('.ant-form');
expect(element).toHaveClass('cp-form');
expect(element).toHaveStyle({ backgroundColor: 'red' });
});
it('Should Image className & style works', () => {
const { container } = render(
<ConfigProvider

2
components/config-provider/context.ts

@ -79,7 +79,7 @@ export interface ConfigConsumerProps {
virtual?: boolean;
popupMatchSelectWidth?: boolean;
popupOverflow?: PopupOverflow;
form?: {
form?: ComponentStyleConfig & {
requiredMark?: RequiredMark;
colon?: boolean;
scrollToFirstError?: Options | boolean;

2
components/config-provider/index.en-US.md

@ -109,7 +109,7 @@ const {
| descriptions | Set Descriptions common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| divider | Set Divider common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| empty | Set Empty common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| form | Set Form common props | { validateMessages?: [ValidateMessages](/components/form/#validatemessages), requiredMark?: boolean \| `optional`, scrollToFirstError?: boolean \| [Options](https://github.com/stipsan/scroll-into-view-if-needed/tree/ece40bd9143f48caf4b99503425ecb16b0ad8249#options) } | - | requiredMark: 4.8.0; colon: 4.18.0; scrollToFirstError: 5.2.0 |
| form | Set Form common props | { className?: string, style?: React.CSSProperties, validateMessages?: [ValidateMessages](/components/form/#validatemessages), requiredMark?: boolean \| `optional`, scrollToFirstError?: boolean \| [Options](https://github.com/stipsan/scroll-into-view-if-needed/tree/ece40bd9143f48caf4b99503425ecb16b0ad8249#options) } | - | requiredMark: 4.8.0; colon: 4.18.0; scrollToFirstError: 5.2.0; className: 5.7.0; style: 5.7.0 |
| image | Set Image common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| input | Set Input common props | { autoComplete?: string, className?: string, style?: React.CSSProperties } | - | 4.2.0 |
| layout | Set Layout common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |

2
components/config-provider/index.tsx

@ -102,7 +102,7 @@ export interface ConfigProviderProps {
renderEmpty?: RenderEmptyHandler;
csp?: CSPConfig;
autoInsertSpaceInButton?: boolean;
form?: {
form?: ComponentStyleConfig & {
validateMessages?: ValidateMessages;
requiredMark?: RequiredMark;
colon?: boolean;

2
components/config-provider/index.zh-CN.md

@ -111,7 +111,7 @@ const {
| descriptions | 设置 Descriptions 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| divider | 设置 Divider 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| empty | 设置 Empty 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| form | 设置 Form 组件的通用属性 | { validateMessages?: [ValidateMessages](/components/form-cn#validatemessages), requiredMark?: boolean \| `optional`, colon?: boolean, scrollToFirstError?: boolean \| [Options](https://github.com/stipsan/scroll-into-view-if-needed/tree/ece40bd9143f48caf4b99503425ecb16b0ad8249#options)} | - | requiredMark: 4.8.0; colon: 4.18.0; scrollToFirstError: 5.2.0 |
| form | 设置 Form 组件的通用属性 | { className?: string, style?: React.CSSProperties, validateMessages?: [ValidateMessages](/components/form-cn#validatemessages), requiredMark?: boolean \| `optional`, colon?: boolean, scrollToFirstError?: boolean \| [Options](https://github.com/stipsan/scroll-into-view-if-needed/tree/ece40bd9143f48caf4b99503425ecb16b0ad8249#options)} | - | requiredMark: 4.8.0; colon: 4.18.0; scrollToFirstError: 5.2.0; className: 5.7.0; style: 5.7.0 |
| image | 设置 Image 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| input | 设置 Input 组件的通用属性 | { autoComplete?: string, className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| layout | 设置 Layout 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |

3
components/form/Form.tsx

@ -63,6 +63,7 @@ const InternalForm: React.ForwardRefRenderFunction<FormInstance, FormProps> = (p
requiredMark,
onFinishFailed,
name,
style,
...restFormProps
} = props;
@ -107,6 +108,7 @@ const InternalForm: React.ForwardRefRenderFunction<FormInstance, FormProps> = (p
[`${prefixCls}-${mergedSize}`]: mergedSize,
},
hashId,
contextForm?.className,
className,
rootClassName,
);
@ -174,6 +176,7 @@ const InternalForm: React.ForwardRefRenderFunction<FormInstance, FormProps> = (p
name={name}
onFinishFailed={onInternalFinishFailed}
form={wrapForm}
style={{ ...contextForm?.style, ...style }}
className={formClassName}
/>
</FormContext.Provider>

Loading…
Cancel
Save