Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/Preview/CloseBtn.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
import { clsx } from 'clsx';
import * as React from 'react';

export interface CloseBtnProps {
prefixCls: string;
icon?: React.ReactNode;
onClick: React.MouseEventHandler<HTMLButtonElement>;
className?: string;
style?: React.CSSProperties;
}

export default function CloseBtn(props: CloseBtnProps) {
const { prefixCls, icon, onClick } = props;
const { prefixCls, icon, onClick, className, style } = props;

return (
<button className={`${prefixCls}-close`} onClick={onClick}>
<button
className={clsx(`${prefixCls}-close`, className)}
style={style}
onClick={onClick}
>
{icon}
</button>
);
Expand Down
4 changes: 3 additions & 1 deletion src/Preview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import PrevNext from './PrevNext';

// Note: if you want to add `action`,
// pls contact @zombieJ or @thinkasany first.
export type PreviewSemanticName = 'root' | 'mask' | 'body' | FooterSemanticName;
export type PreviewSemanticName = 'root' | 'mask' | 'body' | 'close' | FooterSemanticName;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

补一下测试用例


export interface OperationIcons {
rotateLeft?: React.ReactNode;
Expand Down Expand Up @@ -436,6 +436,8 @@ const Preview: React.FC<PreviewProps> = props => {
prefixCls={prefixCls}
icon={closeIcon === true ? icons.close : closeIcon || icons.close}
onClick={onClose}
className={classNames.close}
style={styles.close}
/>
)}

Expand Down
5 changes: 5 additions & 0 deletions tests/preview.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,7 @@ describe('Preview', () => {
mask: 'custom-mask',
actions: 'custom-actions',
root: 'custom-root',
close: 'custom-close',
},
};
const customStyles = {
Expand All @@ -1087,6 +1088,7 @@ describe('Preview', () => {
mask: { color: 'red' },
actions: { backgroundColor: 'blue' },
root: { border: '1px solid green' },
close: { color: 'purple' },
},
};
const { baseElement } = render(
Expand All @@ -1105,12 +1107,15 @@ describe('Preview', () => {
const cover = document.querySelector('.rc-image-cover');
const mask = document.querySelector('.rc-image-preview-mask');
const actions = baseElement.querySelector('.rc-image-preview-actions');
const close = baseElement.querySelector('.rc-image-preview-close');
expect(cover).toHaveClass(customClassnames.cover);
expect(cover).toHaveStyle(customStyles.cover);
expect(mask).toHaveClass(customClassnames.popup.mask);
expect(mask).toHaveStyle(customStyles.popup.mask);
expect(actions).toHaveClass(customClassnames.popup.actions);
expect(actions).toHaveStyle(customStyles.popup.actions);
expect(close).toHaveClass(customClassnames.popup.close);
expect(close).toHaveStyle(customStyles.popup.close);
expect(baseElement.querySelector('.rc-image-preview')).toHaveClass(customClassnames.popup.root);
expect(baseElement.querySelector('.rc-image-preview')).toHaveStyle(customStyles.popup.root);
});
Expand Down