mirror of
https://github.com/ant-design/ant-design.git
synced 2024-11-24 02:59:58 +08:00
feat: CP support Modal closeIcon (#47226)
* feat: CP support Modal closeIcon * fix: fix
This commit is contained in:
parent
5031ca9032
commit
a11d3b4b63
@ -642,27 +642,23 @@ describe('ConfigProvider support style and className props', () => {
|
|||||||
expect(container.querySelector('.ant-mentions')).toHaveStyle({ background: 'red' });
|
expect(container.querySelector('.ant-mentions')).toHaveStyle({ background: 'red' });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should Modal className & style works', () => {
|
it('Should Modal className & style & closeIcon works', () => {
|
||||||
const { baseElement } = render(
|
const { baseElement } = render(
|
||||||
<ConfigProvider
|
<ConfigProvider
|
||||||
modal={{
|
modal={{
|
||||||
className: 'cp-modal',
|
className: 'cp-modal',
|
||||||
style: {
|
style: { background: 'red' },
|
||||||
background: 'red',
|
closeIcon: <span className="cp-test-closeIcon">cp-test-closeIcon</span>,
|
||||||
},
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<Modal title="Basic Modal" open>
|
<Modal open>test</Modal>
|
||||||
<p>Some contents...</p>
|
|
||||||
<p>Some contents...</p>
|
|
||||||
<p>Some contents...</p>
|
|
||||||
</Modal>
|
|
||||||
</ConfigProvider>,
|
</ConfigProvider>,
|
||||||
);
|
);
|
||||||
|
const selectors = '.ant-modal-content .ant-modal-close .cp-test-closeIcon';
|
||||||
const element = baseElement.querySelector<HTMLDivElement>('.ant-modal');
|
const element = baseElement.querySelector<HTMLDivElement>('.ant-modal');
|
||||||
expect(element).toHaveClass('cp-modal');
|
expect(element).toHaveClass('cp-modal');
|
||||||
expect(element).toHaveStyle({ background: 'red' });
|
expect(element).toHaveStyle({ background: 'red' });
|
||||||
|
expect(element?.querySelector<HTMLSpanElement>(selectors)).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Should Result className & style works', () => {
|
it('Should Result className & style works', () => {
|
||||||
|
@ -75,7 +75,8 @@ export interface TableConfig extends ComponentStyleConfig {
|
|||||||
|
|
||||||
export type TourConfig = Pick<TourProps, 'closeIcon'>;
|
export type TourConfig = Pick<TourProps, 'closeIcon'>;
|
||||||
|
|
||||||
export type ModalConfig = ComponentStyleConfig & Pick<ModalProps, 'classNames' | 'styles'>;
|
export type ModalConfig = ComponentStyleConfig &
|
||||||
|
Pick<ModalProps, 'classNames' | 'styles' | 'closeIcon'>;
|
||||||
|
|
||||||
export type BadgeConfig = ComponentStyleConfig & Pick<BadgeProps, 'classNames' | 'styles'>;
|
export type BadgeConfig = ComponentStyleConfig & Pick<BadgeProps, 'classNames' | 'styles'>;
|
||||||
|
|
||||||
|
@ -130,7 +130,7 @@ const {
|
|||||||
| menu | Set Menu common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| menu | Set Menu common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
| mentions | Set Mentions common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| mentions | Set Mentions common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
| message | Set Message common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| message | Set Message common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
| modal | Set Modal common props | { className?: string, style?: React.CSSProperties, classNames?: [ModalProps\["classNames"\]](/components/modal-cn#api), styles?: [ModalProps\["styles"\]](/components/modal-cn#api) } | - | 5.7.0, `classNames` and `styles`: 5.10.0 |
|
| modal | Set Modal common props | { className?: string, style?: React.CSSProperties, classNames?: [ModalProps\["classNames"\]](/components/modal-cn#api), styles?: [ModalProps\["styles"\]](/components/modal-cn#api), closeIcon?: React.ReactNode } | - | 5.7.0, `classNames` and `styles`: 5.10.0, `closeIcon`: 5.14.0 |
|
||||||
| notification | Set Notification common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| notification | Set Notification common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
| pagination | Set Pagination common props | { showSizeChanger?: boolean, className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| pagination | Set Pagination common props | { showSizeChanger?: boolean, className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
| progress | Set Progress common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| progress | Set Progress common props | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
|
@ -132,7 +132,7 @@ const {
|
|||||||
| menu | 设置 Menu 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| menu | 设置 Menu 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
| mentions | 设置 Mentions 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| mentions | 设置 Mentions 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
| message | 设置 Message 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| message | 设置 Message 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
| modal | 设置 Modal 组件的通用属性 | { className?: string, style?: React.CSSProperties, classNames?: [ModalProps\["classNames"\]](/components/modal-cn#api), styles?: [ModalProps\["styles"\]](/components/modal-cn#api) } | - | 5.7.0, `classNames` 和 `styles`: 5.10.0 |
|
| modal | 设置 Modal 组件的通用属性 | { className?: string, style?: React.CSSProperties, classNames?: [ModalProps\["classNames"\]](/components/modal-cn#api), styles?: [ModalProps\["styles"\]](/components/modal-cn#api), closeIcon?: React.ReactNode } | - | 5.7.0, `classNames` 和 `styles`: 5.10.0, `closeIcon`: 5.14.0 |
|
||||||
| notification | 设置 Notification 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| notification | 设置 Notification 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
| pagination | 设置 Pagination 组件的通用属性 | { showSizeChanger?: boolean, className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| pagination | 设置 Pagination 组件的通用属性 | { showSizeChanger?: boolean, className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
| progress | 设置 Progress 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
| progress | 设置 Progress 组件的通用属性 | { className?: string, style?: React.CSSProperties } | - | 5.7.0 |
|
||||||
|
@ -252,11 +252,7 @@ const ConfirmDialog: React.FC<ConfirmDialogProps> = (props) => {
|
|||||||
mask={mask}
|
mask={mask}
|
||||||
maskClosable={maskClosable}
|
maskClosable={maskClosable}
|
||||||
style={style}
|
style={style}
|
||||||
styles={{
|
styles={{ body: bodyStyle, mask: maskStyle, ...styles }}
|
||||||
body: bodyStyle,
|
|
||||||
mask: maskStyle,
|
|
||||||
...styles,
|
|
||||||
}}
|
|
||||||
width={width}
|
width={width}
|
||||||
zIndex={mergedZIndex}
|
zIndex={mergedZIndex}
|
||||||
afterClose={afterClose}
|
afterClose={afterClose}
|
||||||
|
@ -4,19 +4,19 @@ import classNames from 'classnames';
|
|||||||
import Dialog from 'rc-dialog';
|
import Dialog from 'rc-dialog';
|
||||||
|
|
||||||
import useClosable from '../_util/hooks/useClosable';
|
import useClosable from '../_util/hooks/useClosable';
|
||||||
|
import { useZIndex } from '../_util/hooks/useZIndex';
|
||||||
import { getTransitionName } from '../_util/motion';
|
import { getTransitionName } from '../_util/motion';
|
||||||
import { canUseDocElement } from '../_util/styleChecker';
|
import { canUseDocElement } from '../_util/styleChecker';
|
||||||
import { devUseWarning } from '../_util/warning';
|
import { devUseWarning } from '../_util/warning';
|
||||||
import zIndexContext from '../_util/zindexContext';
|
import zIndexContext from '../_util/zindexContext';
|
||||||
import { ConfigContext } from '../config-provider';
|
import { ConfigContext } from '../config-provider';
|
||||||
|
import useCSSVarCls from '../config-provider/hooks/useCSSVarCls';
|
||||||
import { NoFormStyle } from '../form/context';
|
import { NoFormStyle } from '../form/context';
|
||||||
import { NoCompactStyle } from '../space/Compact';
|
import { NoCompactStyle } from '../space/Compact';
|
||||||
import { usePanelRef } from '../watermark/context';
|
import { usePanelRef } from '../watermark/context';
|
||||||
import type { ModalProps, MousePosition } from './interface';
|
import type { ModalProps, MousePosition } from './interface';
|
||||||
import { Footer, renderCloseIcon } from './shared';
|
import { Footer, renderCloseIcon } from './shared';
|
||||||
import useStyle from './style';
|
import useStyle from './style';
|
||||||
import { useZIndex } from '../_util/hooks/useZIndex';
|
|
||||||
import useCSSVarCls from '../config-provider/hooks/useCSSVarCls';
|
|
||||||
|
|
||||||
let mousePosition: MousePosition;
|
let mousePosition: MousePosition;
|
||||||
|
|
||||||
@ -105,9 +105,10 @@ const Modal: React.FC<ModalProps> = (props) => {
|
|||||||
const dialogFooter = footer !== null && (
|
const dialogFooter = footer !== null && (
|
||||||
<Footer {...props} onOk={handleOk} onCancel={handleCancel} />
|
<Footer {...props} onOk={handleOk} onCancel={handleCancel} />
|
||||||
);
|
);
|
||||||
|
|
||||||
const [mergedClosable, mergedCloseIcon] = useClosable(
|
const [mergedClosable, mergedCloseIcon] = useClosable(
|
||||||
closable,
|
closable,
|
||||||
closeIcon,
|
typeof closeIcon !== 'undefined' ? closeIcon : modal?.closeIcon,
|
||||||
(icon) => renderCloseIcon(prefixCls, icon),
|
(icon) => renderCloseIcon(prefixCls, icon),
|
||||||
<CloseOutlined className={`${prefixCls}-close-icon`} />,
|
<CloseOutlined className={`${prefixCls}-close-icon`} />,
|
||||||
true,
|
true,
|
||||||
|
Loading…
Reference in New Issue
Block a user