Skip to content

Commit b148e27

Browse files
committed
feat: video preview type
1 parent 872e729 commit b148e27

File tree

7 files changed

+113
-44
lines changed

7 files changed

+113
-44
lines changed

assets/preview.less

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
}
2626
}
2727

28-
&-img {
28+
&-img,
29+
&-video {
2930
max-width: 100%;
3031
max-height: 70%;
3132
}

docs/demo/previewvideo.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: previewvideo
3+
nav:
4+
title: Demo
5+
path: /demo
6+
---
7+
8+
<code src="../examples/previewvideo.tsx"></code>

docs/examples/previewvideo.tsx

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import Image from '@rc-component/image';
2+
import * as React from 'react';
3+
import '../../assets/index.less';
4+
import { defaultIcons } from './common';
5+
6+
export default function PreviewVideo() {
7+
return (
8+
<div>
9+
<Image
10+
src="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png?x-oss-process=image/auto-orient,1/resize,p_10/quality,q_10"
11+
preview={{
12+
icons: defaultIcons,
13+
type: 'video',
14+
src: 'https://gw.alipayobjects.com/os/rmsportal/NTMlQdLIkPjOACXsdRrq.mp4',
15+
}}
16+
width={200}
17+
/>
18+
19+
<br />
20+
<h1>PreviewGroup</h1>
21+
<Image.PreviewGroup preview={{ icons: defaultIcons }}>
22+
<Image
23+
key={1}
24+
src="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png"
25+
preview={{
26+
src: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
27+
}}
28+
width={200}
29+
/>
30+
<Image
31+
key={2}
32+
src="https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png"
33+
preview={{
34+
type: 'video',
35+
src: 'https://gw.alipayobjects.com/os/rmsportal/NTMlQdLIkPjOACXsdRrq.mp4',
36+
}}
37+
width={200}
38+
/>
39+
</Image.PreviewGroup>
40+
</div>
41+
);
42+
}

src/Image.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ const ImageInternal: CompoundedComponent<ImageProps> = props => {
117117
const canPreview = !!preview;
118118

119119
const {
120+
type: previewType = 'image',
120121
src: previewSrc,
121122
open: previewOpen,
122123
onOpenChange: onPreviewOpenChange,
@@ -178,8 +179,9 @@ const ImageInternal: CompoundedComponent<ImageProps> = props => {
178179
() => ({
179180
...imgCommonProps,
180181
src,
182+
type: previewType,
181183
}),
182-
[src, imgCommonProps],
184+
[src, imgCommonProps, previewType],
183185
);
184186

185187
const imageId = useRegisterImage(canPreview, registerData);
@@ -266,6 +268,7 @@ const ImageInternal: CompoundedComponent<ImageProps> = props => {
266268
prefixCls={previewPrefixCls}
267269
onClose={onPreviewClose}
268270
mousePosition={mousePosition}
271+
type={previewType}
269272
src={src}
270273
alt={alt}
271274
imageInfo={{ width, height }}

src/Preview/index.tsx

Lines changed: 54 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ export interface InternalPreviewConfig {
7272
/** Better to use `classNames.root` instead */
7373
rootClassName?: string;
7474

75-
// Image
75+
// Media
76+
type?: 'image' | 'video';
7677
src?: string;
7778
alt?: string;
7879

@@ -121,7 +122,7 @@ export interface PreviewProps extends InternalPreviewConfig {
121122
};
122123
fallback?: string;
123124

124-
// Preview image
125+
// Preview media
125126
imgCommonProps?: React.ImgHTMLAttributes<HTMLImageElement>;
126127
width?: string | number;
127128
height?: string | number;
@@ -165,6 +166,7 @@ const Preview: React.FC<PreviewProps> = props => {
165166
const {
166167
prefixCls,
167168
rootClassName,
169+
type = 'image',
168170
src,
169171
alt,
170172
imageInfo,
@@ -425,13 +427,24 @@ const Preview: React.FC<PreviewProps> = props => {
425427
{/* Body */}
426428
<div className={classnames(`${prefixCls}-body`, classNames.body)} style={bodyStyle}>
427429
{/* Preview Image */}
428-
{imageRender
429-
? imageRender(imgNode, {
430-
transform,
431-
image,
432-
...(groupContext ? { current } : {}),
433-
})
434-
: imgNode}
430+
{type === 'image' &&
431+
(imageRender
432+
? imageRender(imgNode, {
433+
transform,
434+
image,
435+
...(groupContext ? { current } : {}),
436+
})
437+
: imgNode)}
438+
{type === 'video' && (
439+
<video
440+
className={`${prefixCls}-video`}
441+
src={src}
442+
width={props.width}
443+
height={props.height}
444+
controls
445+
autoPlay
446+
/>
447+
)}
435448
</div>
436449

437450
{/* Close Button */}
@@ -454,37 +467,38 @@ const Preview: React.FC<PreviewProps> = props => {
454467
/>
455468
)}
456469

457-
{/* Footer */}
458-
<Footer
459-
prefixCls={prefixCls}
460-
showProgress={showOperationsProgress}
461-
current={current}
462-
count={count}
463-
showSwitch={showLeftOrRightSwitches}
464-
// Style
465-
classNames={classNames}
466-
styles={styles}
467-
// Render
468-
image={image}
469-
transform={transform}
470-
icons={icons}
471-
countRender={countRender}
472-
actionsRender={actionsRender}
473-
// Scale
474-
scale={scale}
475-
minScale={minScale}
476-
maxScale={maxScale}
477-
// Actions
478-
onActive={onActive}
479-
onFlipY={onFlipY}
480-
onFlipX={onFlipX}
481-
onRotateLeft={onRotateLeft}
482-
onRotateRight={onRotateRight}
483-
onZoomOut={onZoomOut}
484-
onZoomIn={onZoomIn}
485-
onClose={onClose}
486-
onReset={onReset}
487-
/>
470+
{type === 'image' && (
471+
<Footer
472+
prefixCls={prefixCls}
473+
showProgress={showOperationsProgress}
474+
current={current}
475+
count={count}
476+
showSwitch={showLeftOrRightSwitches}
477+
// Style
478+
classNames={classNames}
479+
styles={styles}
480+
// Render
481+
image={image}
482+
transform={transform}
483+
icons={icons}
484+
countRender={countRender}
485+
actionsRender={actionsRender}
486+
// Scale
487+
scale={scale}
488+
minScale={minScale}
489+
maxScale={maxScale}
490+
// Actions
491+
onActive={onActive}
492+
onFlipY={onFlipY}
493+
onFlipX={onFlipX}
494+
onRotateLeft={onRotateLeft}
495+
onRotateRight={onRotateRight}
496+
onZoomOut={onZoomOut}
497+
onZoomIn={onZoomIn}
498+
onClose={onClose}
499+
onReset={onReset}
500+
/>
501+
)}
488502
</div>
489503
);
490504
}}

src/PreviewGroup.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ const Group: React.FC<PreviewGroupProps> = ({
6767
const [keepOpenIndex, setKeepOpenIndex] = useState(false);
6868

6969
// >>> Image
70-
const { src, ...imgCommonProps } = mergedItems[current]?.data || {};
70+
const { src, type, ...imgCommonProps } = mergedItems[current]?.data || {};
7171
// >>> Visible
7272
const [isShowPreview, setShowPreview] = useMergedState(!!previewOpen, {
7373
value: previewOpen,
@@ -136,6 +136,7 @@ const Group: React.FC<PreviewGroupProps> = ({
136136
mousePosition={mousePosition}
137137
imgCommonProps={imgCommonProps}
138138
src={src}
139+
type={type}
139140
fallback={fallback}
140141
icons={icons}
141142
current={current}

src/interface.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export type ImageElementProps = Pick<
1313
| 'srcSet'
1414
| 'useMap'
1515
| 'alt'
16-
>;
16+
> & { type?: 'image' | 'video' };
1717

1818
export type PreviewImageElementProps = {
1919
data: ImageElementProps;

0 commit comments

Comments
 (0)