From b9dd395cd3c365c99709d74f1f299b103ebb26d2 Mon Sep 17 00:00:00 2001
From: MuxinFeng <434980373@qq.com>
Date: Tue, 20 Jun 2023 00:11:53 +0800
Subject: [PATCH] feat: config-provider support descriptions className and
style properties
---
.../config-provider/__tests__/style.test.tsx | 21 +++++++++++++++++++
components/config-provider/context.ts | 7 ++++---
components/config-provider/index.en-US.md | 1 +
components/config-provider/index.tsx | 7 +++++--
components/config-provider/index.zh-CN.md | 1 +
components/descriptions/index.tsx | 5 +++--
6 files changed, 35 insertions(+), 7 deletions(-)
diff --git a/components/config-provider/__tests__/style.test.tsx b/components/config-provider/__tests__/style.test.tsx
index 969e92bb4f..76fee7fad4 100644
--- a/components/config-provider/__tests__/style.test.tsx
+++ b/components/config-provider/__tests__/style.test.tsx
@@ -1,6 +1,7 @@
import React from 'react';
import ConfigProvider from '..';
import { render } from '../../../tests/utils';
+import Descriptions from '../../descriptions';
import Divider from '../../divider';
import Space from '../../space';
@@ -107,4 +108,24 @@ describe('ConfigProvider support style and className props', () => {
);
expect(container.querySelector('.ant-divider'))?.toHaveStyle({ color: 'red', height: '80px' });
});
+
+ it('Should Radio className & style works', () => {
+ const { container } = render(
+
+
+ muxin
+
+ ,
+ );
+
+ expect(container.querySelector('.ant-descriptions')).toHaveClass('config-provider-className');
+ expect(container.querySelector('.ant-descriptions')).toHaveStyle({ background: 'red' });
+ });
});
diff --git a/components/config-provider/context.ts b/components/config-provider/context.ts
index b4353ba0d8..ed76760eb2 100644
--- a/components/config-provider/context.ts
+++ b/components/config-provider/context.ts
@@ -36,12 +36,12 @@ export interface ThemeConfig {
inherit?: boolean;
}
-export interface componentStyleConfig {
+export interface ComponentStyleConfig {
className?: string;
style?: React.CSSProperties;
}
-export interface ButtonConfig extends componentStyleConfig {
+export interface ButtonConfig extends ComponentStyleConfig {
classNames?: ButtonProps['classNames'];
styles?: ButtonProps['styles'];
}
@@ -88,7 +88,8 @@ export interface ConfigConsumerProps {
showSearch?: boolean;
};
button?: ButtonConfig;
- divider?: componentStyleConfig;
+ descriptions?: ComponentStyleConfig;
+ divider?: ComponentStyleConfig;
}
const defaultGetPrefixCls = (suffixCls?: string, customizePrefixCls?: string) => {
diff --git a/components/config-provider/index.en-US.md b/components/config-provider/index.en-US.md
index e1bcd30cc2..dd79b5767b 100644
--- a/components/config-provider/index.en-US.md
+++ b/components/config-provider/index.en-US.md
@@ -102,6 +102,7 @@ const {
| Property | Description | Type | Default | Version |
| --- | --- | --- | --- | --- |
| button | Set Button common props | { className?: string, style?: React.CSSProperties, classNames?: { icon: string }, styles?: { icon: React.CSSProperties } } | - | 5.6.0 |
+| 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 |
| 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 |
| input | Set Input common props | { autoComplete?: string } | - | 4.2.0 |
diff --git a/components/config-provider/index.tsx b/components/config-provider/index.tsx
index 1dc6d52367..ffc84a0aef 100644
--- a/components/config-provider/index.tsx
+++ b/components/config-provider/index.tsx
@@ -19,7 +19,7 @@ import { DesignTokenContext } from '../theme/internal';
import defaultSeedToken from '../theme/themes/seed';
import type {
ButtonConfig,
- componentStyleConfig,
+ ComponentStyleConfig,
ConfigConsumerProps,
CSPConfig,
DirectionType,
@@ -137,7 +137,8 @@ export interface ConfigProviderProps {
popupOverflow?: PopupOverflow;
theme?: ThemeConfig;
button?: ButtonConfig;
- divider?: componentStyleConfig;
+ descriptions?: ComponentStyleConfig;
+ divider?: ComponentStyleConfig;
}
interface ProviderChildrenProps extends ConfigProviderProps {
@@ -225,6 +226,7 @@ const ProviderChildren: React.FC = (props) => {
iconPrefixCls: customIconPrefixCls,
theme,
componentDisabled,
+ descriptions,
divider,
} = props;
@@ -275,6 +277,7 @@ const ProviderChildren: React.FC = (props) => {
getPrefixCls,
iconPrefixCls,
theme: mergedTheme,
+ descriptions,
divider,
};
diff --git a/components/config-provider/index.zh-CN.md b/components/config-provider/index.zh-CN.md
index e8d70b444c..6f497a05e8 100644
--- a/components/config-provider/index.zh-CN.md
+++ b/components/config-provider/index.zh-CN.md
@@ -104,6 +104,7 @@ const {
| 参数 | 说明 | 类型 | 默认值 | 版本 |
| --- | --- | --- | --- | --- |
| button | 设置 Button 组件的通用属性 | { className?: string, style?: React.CSSProperties, classNames?: { icon: string }, styles?: { icon: React.CSSProperties } } | - | 5.6.0 |
+| descriptions | 设置 Descriptions 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| divider | 设置 Divider 组件的通用属性 | { 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 |
| input | 设置 Input 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
diff --git a/components/descriptions/index.tsx b/components/descriptions/index.tsx
index 2b5445e8db..308b919748 100644
--- a/components/descriptions/index.tsx
+++ b/components/descriptions/index.tsx
@@ -132,7 +132,7 @@ function Descriptions({
contentStyle,
...restProps
}: DescriptionsProps) {
- const { getPrefixCls, direction } = React.useContext(ConfigContext);
+ const { getPrefixCls, direction, descriptions } = React.useContext(ConfigContext);
const prefixCls = getPrefixCls('descriptions', customizePrefixCls);
const [screens, setScreens] = React.useState({});
const mergedColumn = getColumn(column, screens);
@@ -168,6 +168,7 @@ function Descriptions({
{(title || extra) && (