Skip to content

Commit cf749d6

Browse files
authored
feat: adapt semantic close (#455)
* feat: adapt semantic close * feat: update unit test * feat: adapt clsx
1 parent b973819 commit cf749d6

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

src/Preview/CloseBtn.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,23 @@
1+
import { clsx } from 'clsx';
12
import * as React from 'react';
23

34
export interface CloseBtnProps {
45
prefixCls: string;
56
icon?: React.ReactNode;
67
onClick: React.MouseEventHandler<HTMLButtonElement>;
8+
className?: string;
9+
style?: React.CSSProperties;
710
}
811

912
export default function CloseBtn(props: CloseBtnProps) {
10-
const { prefixCls, icon, onClick } = props;
13+
const { prefixCls, icon, onClick, className, style } = props;
1114

1215
return (
13-
<button className={`${prefixCls}-close`} onClick={onClick}>
16+
<button
17+
className={clsx(`${prefixCls}-close`, className)}
18+
style={style}
19+
onClick={onClick}
20+
>
1421
{icon}
1522
</button>
1623
);

src/Preview/index.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import PrevNext from './PrevNext';
1919

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

2424
export interface OperationIcons {
2525
rotateLeft?: React.ReactNode;
@@ -444,6 +444,8 @@ const Preview: React.FC<PreviewProps> = props => {
444444
prefixCls={prefixCls}
445445
icon={closeIcon === true ? icons.close : closeIcon || icons.close}
446446
onClick={onClose}
447+
className={classNames.close}
448+
style={styles.close}
447449
/>
448450
)}
449451

tests/preview.test.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,6 +1099,7 @@ describe('Preview', () => {
10991099
mask: 'custom-mask',
11001100
actions: 'custom-actions',
11011101
root: 'custom-root',
1102+
close: 'custom-close',
11021103
},
11031104
};
11041105
const customStyles = {
@@ -1107,6 +1108,7 @@ describe('Preview', () => {
11071108
mask: { color: 'red' },
11081109
actions: { backgroundColor: 'blue' },
11091110
root: { border: '1px solid green' },
1111+
close: { color: 'purple' },
11101112
},
11111113
};
11121114
const { baseElement } = render(
@@ -1125,12 +1127,15 @@ describe('Preview', () => {
11251127
const cover = document.querySelector('.rc-image-cover');
11261128
const mask = document.querySelector('.rc-image-preview-mask');
11271129
const actions = baseElement.querySelector('.rc-image-preview-actions');
1130+
const close = baseElement.querySelector('.rc-image-preview-close');
11281131
expect(cover).toHaveClass(customClassnames.cover);
11291132
expect(cover).toHaveStyle(customStyles.cover);
11301133
expect(mask).toHaveClass(customClassnames.popup.mask);
11311134
expect(mask).toHaveStyle(customStyles.popup.mask);
11321135
expect(actions).toHaveClass(customClassnames.popup.actions);
11331136
expect(actions).toHaveStyle(customStyles.popup.actions);
1137+
expect(close).toHaveClass(customClassnames.popup.close);
1138+
expect(close).toHaveStyle(customStyles.popup.close);
11341139
expect(baseElement.querySelector('.rc-image-preview')).toHaveClass(customClassnames.popup.root);
11351140
expect(baseElement.querySelector('.rc-image-preview')).toHaveStyle(customStyles.popup.root);
11361141
});

0 commit comments

Comments
 (0)