feat: config-provider support rangePicker className and style (#45479)

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

* test: add rangepicker className & style test

* chore: change props  verison

* feat:RangePicker className and style properties

---------

Co-authored-by: lijianan <574980606@qq.com>
This commit is contained in:
Chen_Z 2023-10-24 00:57:38 +08:00 committed by GitHub
parent 2940f626d4
commit d04e9efe16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 3 deletions

View File

@ -1045,6 +1045,34 @@ describe('ConfigProvider support style and className props', () => {
expect(container.querySelector('.ant-picker')).toHaveStyle('color: red; font-size: 16px;'); expect(container.querySelector('.ant-picker')).toHaveStyle('color: red; font-size: 16px;');
}); });
it('Should RangePicker className works', () => {
const { RangePicker } = TimePicker;
const { container } = render(
<ConfigProvider
rangePicker={{
className: 'test-class',
}}
>
<RangePicker />
</ConfigProvider>,
);
expect(container.querySelector('.ant-picker')).toHaveClass('test-class');
});
it('Should RangePicker style works', () => {
const { RangePicker } = TimePicker;
const { container } = render(
<ConfigProvider
rangePicker={{
style: { color: 'red' },
}}
>
<RangePicker style={{ fontSize: '16px' }} />
</ConfigProvider>,
);
expect(container.querySelector('.ant-picker')).toHaveStyle('color: red; font-size: 16px;');
});
it('Should message className & style works', () => { it('Should message className & style works', () => {
const Demo: React.FC = () => { const Demo: React.FC = () => {
const [messageApi, contextHolder] = message.useMessage(); const [messageApi, contextHolder] = message.useMessage();

View File

@ -5,18 +5,18 @@ import type { Options } from 'scroll-into-view-if-needed';
import type { WarningContextProps } from '../_util/warning'; import type { WarningContextProps } from '../_util/warning';
import type { ShowWaveEffect } from '../_util/wave/interface'; import type { ShowWaveEffect } from '../_util/wave/interface';
import type { BadgeProps } from '../badge'; import type { BadgeProps } from '../badge';
import type { ModalProps } from '../modal';
import type { ButtonProps } from '../button'; import type { ButtonProps } from '../button';
import type { DrawerProps } from '../drawer';
import type { FlexProps } from '../flex/interface'; import type { FlexProps } from '../flex/interface';
import type { RequiredMark } from '../form/Form'; import type { RequiredMark } from '../form/Form';
import type { InputProps } from '../input'; import type { InputProps } from '../input';
import type { Locale } from '../locale'; import type { Locale } from '../locale';
import type { ModalProps } from '../modal';
import type { SpaceProps } from '../space'; import type { SpaceProps } from '../space';
import type { TabsProps } from '../tabs'; import type { TabsProps } from '../tabs';
import type { AliasToken, MappingAlgorithm, OverrideToken } from '../theme/interface'; import type { AliasToken, MappingAlgorithm, OverrideToken } from '../theme/interface';
import type { RenderEmptyHandler } from './defaultRenderEmpty'; import type { RenderEmptyHandler } from './defaultRenderEmpty';
import type { SizeType } from './SizeContext'; import type { SizeType } from './SizeContext';
import type { DrawerProps } from '../drawer';
export const defaultIconPrefixCls = 'anticon'; export const defaultIconPrefixCls = 'anticon';
@ -171,6 +171,7 @@ export interface ConfigConsumerProps {
tree?: ComponentStyleConfig; tree?: ComponentStyleConfig;
colorPicker?: ComponentStyleConfig; colorPicker?: ComponentStyleConfig;
datePicker?: ComponentStyleConfig; datePicker?: ComponentStyleConfig;
rangePicker?: ComponentStyleConfig;
flex?: FlexConfig; flex?: FlexConfig;
wave?: WaveConfig; wave?: WaveConfig;
warning?: WarningContextProps; warning?: WarningContextProps;

View File

@ -118,6 +118,7 @@ const {
| collapse | Set Collapse common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | | collapse | Set Collapse common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| colorPicker | Set ColorPicker common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | | colorPicker | Set ColorPicker common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| datePicker | Set datePicker common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | | datePicker | Set datePicker common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| rangePicker | Set rangePicker common props | { className?: string, style?: React.CSSProperties } | - | 5.11.0 |
| descriptions | Set Descriptions 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 | | divider | Set Divider common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| drawer | Set Drawer common props | { className?: string, style?: React.CSSProperties, classNames?: [DrawerProps\["classNames"\]](/components/drawer-cn#api), styles?: [DrawerProps\["styles"\]](/components/drawer-cn#api) } | - | 5.7.0, `classNames` and `styles`: 5.10.0 | | drawer | Set Drawer common props | { className?: string, style?: React.CSSProperties, classNames?: [DrawerProps\["classNames"\]](/components/drawer-cn#api), styles?: [DrawerProps\["styles"\]](/components/drawer-cn#api) } | - | 5.7.0, `classNames` and `styles`: 5.10.0 |

View File

@ -198,6 +198,7 @@ export interface ConfigProviderProps {
tree?: ComponentStyleConfig; tree?: ComponentStyleConfig;
colorPicker?: ComponentStyleConfig; colorPicker?: ComponentStyleConfig;
datePicker?: ComponentStyleConfig; datePicker?: ComponentStyleConfig;
rangePicker?: ComponentStyleConfig;
flex?: FlexConfig; flex?: FlexConfig;
/** /**
* Wave is special component which only patch on the effect of component interaction. * Wave is special component which only patch on the effect of component interaction.
@ -339,6 +340,7 @@ const ProviderChildren: React.FC<ProviderChildrenProps> = (props) => {
tree, tree,
colorPicker, colorPicker,
datePicker, datePicker,
rangePicker,
flex, flex,
wave, wave,
warning: warningConfig, warning: warningConfig,
@ -430,6 +432,7 @@ const ProviderChildren: React.FC<ProviderChildrenProps> = (props) => {
tree, tree,
colorPicker, colorPicker,
datePicker, datePicker,
rangePicker,
flex, flex,
wave, wave,
warning: warningConfig, warning: warningConfig,

View File

@ -120,6 +120,7 @@ const {
| collapse | 设置 Collapse 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | | collapse | 设置 Collapse 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| colorPicker | 设置 ColorPicker 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | | colorPicker | 设置 ColorPicker 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| datePicker | 设置 DatePicker 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 | | datePicker | 设置 DatePicker 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| rangePicker | 设置 RangePicker 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.11.0 |
| descriptions | 设置 Descriptions 组件的通用属性 | { 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 | | divider | 设置 Divider 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
| drawer | 设置 Drawer 组件的通用属性 | { className?: string, style?: React.CSSProperties, classNames?: [DrawerProps\["classNames"\]](/components/drawer-cn#api), styles?: [DrawerProps\["styles"\]](/components/drawer-cn#api) } | - | 5.7.0, `classNames``styles`: 5.10.0 | | drawer | 设置 Drawer 组件的通用属性 | { className?: string, style?: React.CSSProperties, classNames?: [DrawerProps\["classNames"\]](/components/drawer-cn#api), styles?: [DrawerProps\["styles"\]](/components/drawer-cn#api) } | - | 5.7.0, `classNames``styles`: 5.10.0 |

View File

@ -48,6 +48,7 @@ export default function generateRangePicker<DateType>(generateConfig: GenerateCo
prefixCls: customizePrefixCls, prefixCls: customizePrefixCls,
getPopupContainer: customGetPopupContainer, getPopupContainer: customGetPopupContainer,
className, className,
style,
placement, placement,
size: customizeSize, size: customizeSize,
disabled: customDisabled, disabled: customDisabled,
@ -63,7 +64,7 @@ export default function generateRangePicker<DateType>(generateConfig: GenerateCo
} = props; } = props;
const innerRef = React.useRef<RCRangePicker<DateType>>(null); const innerRef = React.useRef<RCRangePicker<DateType>>(null);
const { getPrefixCls, direction, getPopupContainer } = useContext(ConfigContext); const { getPrefixCls, direction, getPopupContainer, rangePicker } = useContext(ConfigContext);
const prefixCls = getPrefixCls('picker', customizePrefixCls); const prefixCls = getPrefixCls('picker', customizePrefixCls);
const { compactSize, compactItemClassnames } = useCompactItemContext(prefixCls, direction); const { compactSize, compactItemClassnames } = useCompactItemContext(prefixCls, direction);
const { format, showTime, picker } = props as any; const { format, showTime, picker } = props as any;
@ -138,8 +139,10 @@ export default function generateRangePicker<DateType>(generateConfig: GenerateCo
hashId, hashId,
compactItemClassnames, compactItemClassnames,
className, className,
rangePicker?.className,
rootClassName, rootClassName,
)} )}
style={{ ...rangePicker?.style, ...style }}
locale={locale.lang} locale={locale.lang}
prefixCls={prefixCls} prefixCls={prefixCls}
getPopupContainer={customGetPopupContainer || getPopupContainer} getPopupContainer={customGetPopupContainer || getPopupContainer}