feat: config-provider support descriptions className and style proper… (#43106)

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

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

This reverts commit b9dd395cd3.

* feat: config-provider support descriptions className and style properties
This commit is contained in:
muxin 2023-06-26 14:38:02 +08:00 committed by GitHub
parent 58e88d23a9
commit 35bc35e4d9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 2 deletions

View File

@ -3,6 +3,7 @@ import ConfigProvider from '..';
import { render } from '../../../tests/utils';
import Breadcrumb from '../../breadcrumb';
import Checkbox from '../../checkbox';
import Descriptions from '../../descriptions';
import Divider from '../../divider';
import Image from '../../image';
import Result from '../../result';
@ -236,4 +237,24 @@ describe('ConfigProvider support style and className props', () => {
expect(container.querySelector('.ant-checkbox-wrapper')).toHaveClass('cp-breadcrumb');
expect(container.querySelector('.ant-checkbox-wrapper')).toHaveStyle({ background: 'red' });
});
it('Should Descriptions className & style works', () => {
const { container } = render(
<ConfigProvider
descriptions={{
className: 'cp-className',
style: {
background: 'red',
},
}}
>
<Descriptions title="User Info">
<Descriptions.Item label="UserName">muxin</Descriptions.Item>
</Descriptions>
</ConfigProvider>,
);
expect(container.querySelector('.ant-descriptions')).toHaveClass('cp-className');
expect(container.querySelector('.ant-descriptions')).toHaveStyle({ background: 'red' });
});
});

View File

@ -98,6 +98,7 @@ export interface ConfigConsumerProps {
slider?: ComponentStyleConfig;
breadcrumb?: ComponentStyleConfig;
checkbox?: ComponentStyleConfig;
descriptions?: ComponentStyleConfig;
}
const defaultGetPrefixCls = (suffixCls?: string, customizePrefixCls?: string) => {

View File

@ -104,6 +104,7 @@ const {
| breadcrumb | Set Breadcrumb common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| button | Set Button common props | { className?: string, style?: React.CSSProperties, classNames?: { icon: string }, styles?: { icon: React.CSSProperties } } | - | 5.6.0 |
| checkbox | Set Checkbox common props | { className?: string, style?: React.CSSProperties } | - | 5.7.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 |
| image | Set Image common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |

View File

@ -147,6 +147,7 @@ export interface ConfigProviderProps {
slider?: ComponentStyleConfig;
breadcrumb?: ComponentStyleConfig;
checkbox?: ComponentStyleConfig;
descriptions?: ComponentStyleConfig;
}
interface ProviderChildrenProps extends ConfigProviderProps {
@ -238,6 +239,7 @@ const ProviderChildren: React.FC<ProviderChildrenProps> = (props) => {
spin,
typography,
checkbox,
descriptions,
divider,
steps,
image,
@ -299,6 +301,7 @@ const ProviderChildren: React.FC<ProviderChildrenProps> = (props) => {
spin,
typography,
checkbox,
descriptions,
divider,
steps,
image,

View File

@ -106,6 +106,7 @@ const {
| breadcrumb | 设置 Breadcrumb 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| button | 设置 Button 组件的通用属性 | { className?: string, style?: React.CSSProperties, classNames?: { icon: string }, styles?: { icon: React.CSSProperties } } | - | 5.6.0 |
| checkbox | 设置 Checkbox 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.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 |
| image | 设置 Image 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |

View File

@ -126,7 +126,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<ScreenMap>({});
const mergedColumn = getColumn(column, screens);
@ -162,6 +162,7 @@ function Descriptions({
<div
className={classNames(
prefixCls,
descriptions?.className,
{
[`${prefixCls}-${mergedSize}`]: mergedSize && mergedSize !== 'default',
[`${prefixCls}-bordered`]: !!bordered,
@ -171,7 +172,7 @@ function Descriptions({
rootClassName,
hashId,
)}
style={style}
style={{ ...descriptions?.style, ...style }}
{...restProps}
>
{(title || extra) && (