Browse Source

feat: config-provider support descriptions className and style properties

pull/43106/head
MuxinFeng 1 year ago
parent
commit
b9dd395cd3
  1. 21
      components/config-provider/__tests__/style.test.tsx
  2. 7
      components/config-provider/context.ts
  3. 1
      components/config-provider/index.en-US.md
  4. 7
      components/config-provider/index.tsx
  5. 1
      components/config-provider/index.zh-CN.md
  6. 5
      components/descriptions/index.tsx

21
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(
<ConfigProvider
descriptions={{
className: 'config-provider-className',
style: {
background: 'red',
},
}}
>
<Descriptions title="User Info">
<Descriptions.Item label="UserName">muxin</Descriptions.Item>
</Descriptions>
</ConfigProvider>,
);
expect(container.querySelector('.ant-descriptions')).toHaveClass('config-provider-className');
expect(container.querySelector('.ant-descriptions')).toHaveStyle({ background: 'red' });
});
});

7
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) => {

1
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 |

7
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<ProviderChildrenProps> = (props) => {
iconPrefixCls: customIconPrefixCls,
theme,
componentDisabled,
descriptions,
divider,
} = props;
@ -275,6 +277,7 @@ const ProviderChildren: React.FC<ProviderChildrenProps> = (props) => {
getPrefixCls,
iconPrefixCls,
theme: mergedTheme,
descriptions,
divider,
};

1
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 |

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

Loading…
Cancel
Save