Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: reset preview prop to Dialog #76

Merged
merged 3 commits into from
Feb 20, 2021
Merged
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
9 changes: 8 additions & 1 deletion src/Image.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ import useMergedState from 'rc-util/lib/hooks/useMergedState';
import { GetContainer } from 'rc-util/lib/PortalWrapper';
import Preview, { PreviewProps } from './Preview';
import PreviewGroup, { context } from './PreviewGroup';
import { IDialogPropTypes } from 'rc-dialog/lib/IDialogPropTypes';

export interface ImagePreviewType {
export interface ImagePreviewType
extends Omit<
IDialogPropTypes,
'mask' | 'visible' | 'closable' | 'prefixCls' | 'onClose' | 'afterClose' | 'wrapClassName'
> {
src?: string;
visible?: boolean;
onVisibleChange?: (value: boolean, prevValue: boolean) => void;
Expand Down Expand Up @@ -81,6 +86,7 @@ const ImageInternal: CompoundedComponent<ImageProps> = ({
mask: previewMask,
maskClassName,
icons,
...dialogProps
}: ImagePreviewType = typeof preview === 'object' ? preview : {};
const src = previewSrc ?? imgSrc;
const isControlled = previewVisible !== undefined;
Expand Down Expand Up @@ -255,6 +261,7 @@ const ImageInternal: CompoundedComponent<ImageProps> = ({
alt={alt}
getContainer={getPreviewContainer}
icons={icons}
{...dialogProps}
/>
)}
</>
Expand Down
2 changes: 1 addition & 1 deletion src/Preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ const Preview: React.FC<PreviewProps> = props => {

return (
<Dialog
{...restProps}
transitionName="zoom"
maskTransitionName="fade"
closable={false}
Expand All @@ -244,6 +243,7 @@ const Preview: React.FC<PreviewProps> = props => {
afterClose={onAfterClose}
visible={visible}
wrapClassName={wrapClassName}
{...restProps}
>
<ul className={`${prefixCls}-operations`}>
{tools.map(({ icon, onClick, type, disabled }) => (
Expand Down
4 changes: 3 additions & 1 deletion src/PreviewGroup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ImagePreviewType } from './Image';
import Preview, { PreviewProps } from './Preview';

export interface PreviewGroupPreview
extends Pick<ImagePreviewType, 'visible' | 'onVisibleChange' | 'getContainer'> {
extends Omit<ImagePreviewType, 'icons' | 'mask' | 'maskClassName'> {
/**
* If Preview the show img index
* @default 0
Expand Down Expand Up @@ -54,6 +54,7 @@ const Group: React.FC<GroupConsumerProps> = ({
onVisibleChange: onPreviewVisibleChange = undefined,
getContainer = undefined,
current: currentIndex = 0,
...dialogProps
} = typeof preview === 'object' ? preview : {};
const [previewUrls, setPreviewUrls] = useState<Map<number, string>>(new Map());
const [current, setCurrent] = useState<number>();
Expand Down Expand Up @@ -127,6 +128,7 @@ const Group: React.FC<GroupConsumerProps> = ({
src={previewUrls.get(current)}
icons={icons}
getContainer={getContainer}
{...dialogProps}
/>
</Provider>
);
Expand Down
31 changes: 31 additions & 0 deletions tests/preview.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -479,4 +479,35 @@ describe('Preview', () => {
expect(wrapper.find('.rc-image-preview').get(0)).toBeTruthy();
expect(wrapper.find('.rc-image-preview-img').prop('src')).toBe(previewSrc);
});

it('Customize preview props', () => {
const src = 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png';
const wrapper = mount(
<Image
src={src}
preview={{
visible: true,
transitionName: 'abc',
maskTransitionName: 'def',
}}
/>,
);

expect(wrapper.find('Preview').prop('transitionName')).toBe('abc');
expect(wrapper.find('Preview').prop('maskTransitionName')).toBe('def');
});

it('Customize Group preview props', () => {
const src = 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png';
const wrapper = mount(
<Image.PreviewGroup
preview={{ visible: true, transitionName: 'abc', maskTransitionName: 'def' }}
>
<Image src={src} />
</Image.PreviewGroup>,
);

expect(wrapper.find('Preview').prop('transitionName')).toBe('abc');
expect(wrapper.find('Preview').prop('maskTransitionName')).toBe('def');
});
});