diff --git a/api-generator/components/image.js b/api-generator/components/image.js
index 7d67f8685e..30e16eec64 100644
--- a/api-generator/components/image.js
+++ b/api-generator/components/image.js
@@ -5,6 +5,18 @@ const ImageProps = [
default: 'false',
description: 'Controls the preview functionality.'
},
+ {
+ name: 'src',
+ type: 'string',
+ default: 'null',
+ description: 'Specifies the path to the image.'
+ },
+ {
+ name: 'previewSrc',
+ type: 'string',
+ default: 'null',
+ description: 'Preview image that may be different than "src" image.'
+ },
{
name: 'downloadable',
type: 'boolean',
diff --git a/components/doc/image/index.js b/components/doc/image/index.js
index f7febba69b..e378942600 100644
--- a/components/doc/image/index.js
+++ b/components/doc/image/index.js
@@ -1,9 +1,9 @@
-import React, { memo } from 'react';
import Link from 'next/link';
-import { TabView, TabPanel } from '../../lib/tabview/TabView';
-import { useLiveEditorTabs } from '../common/liveeditor';
+import React, { memo } from 'react';
+import { TabPanel, TabView } from '../../lib/tabview/TabView';
import { CodeHighlight } from '../common/codehighlight';
import { DevelopmentSection } from '../common/developmentsection';
+import { useLiveEditorTabs } from '../common/liveeditor';
const ImageDoc = memo(() => {
const sources = {
@@ -22,9 +22,12 @@ export class ImageDemo extends Component {
Basic
- Preview
+
+ Preview and Zoom
-
+
+ Thumbnail
+
)
}
@@ -45,8 +48,11 @@ const ImageDemo = () => {
Basic
- Preview
+ Preview and Zoom
+
+ Thumbnail
+
)
@@ -67,8 +73,11 @@ const ImageDemo = () => {
Basic
- Preview
+ Preview and Zoom
+
+ Thumbnail
+
)
@@ -92,8 +101,11 @@ const ImageDemo = () => {
Basic
- Preview
+ Preview and Zoom
+
+ Thumbnail
+
)
@@ -135,6 +147,11 @@ import { Image } from 'primereact/image';
Preview
Preview mode displays a modal layer when the image is clicked that provides transformation options such as rotating and zooming.
+ Thumbnail
+
+ Allow different images or sizes for source and preview images using previewSrc property.
+
+
Templating
An eye icon is displayed by default when the image is hovered in preview mode. Use thetemplate prop for custom content.
@@ -159,12 +176,24 @@ import { Image } from 'primereact/image';
+
+ src
+ string
+ null
+ Specifies the path to the image.
+
preview
boolean
false
Controls the preview functionality.
+
+ previewSrc
+ string
+ null
+ Preview image that may be different than "src" image.
+
downloadable
boolean
diff --git a/components/lib/image/Image.js b/components/lib/image/Image.js
index 05e541d954..a9902de6f2 100644
--- a/components/lib/image/Image.js
+++ b/components/lib/image/Image.js
@@ -17,7 +17,7 @@ export const Image = React.memo(
const previewRef = React.useRef(null);
const previewClick = React.useRef(false);
- const onImageClick = () => {
+ const show = () => {
if (props.preview) {
setMaskVisibleState(true);
setTimeout(() => {
@@ -26,11 +26,7 @@ export const Image = React.memo(
}
};
- const onPreviewImageClick = () => {
- previewClick.current = true;
- };
-
- const onMaskClick = () => {
+ const hide = () => {
if (!previewClick.current) {
setPreviewVisibleState(false);
setRotateState(0);
@@ -40,6 +36,10 @@ export const Image = React.memo(
previewClick.current = false;
};
+ const onPreviewImageClick = () => {
+ previewClick.current = true;
+ };
+
const onDownload = () => {
const { alt: name, src } = props;
@@ -96,7 +96,7 @@ export const Image = React.memo(
const createPreview = () => {
if (props.preview) {
return (
-
+
{content}
);
@@ -112,7 +112,7 @@ export const Image = React.memo(
// const rotateClassName = 'p-image-preview-rotate-' + rotateScale;
return (
-
+
{downloadable && (
@@ -148,7 +148,7 @@ export const Image = React.memo(
onExited={onExited}
>
-
+
@@ -157,6 +157,8 @@ export const Image = React.memo(
React.useImperativeHandle(ref, () => ({
props,
+ show,
+ hide,
getElement: () => elementRef.current,
getImage: () => imageRef.current
}));
@@ -169,7 +171,7 @@ export const Image = React.memo(
const element = createElement();
const content = props.template ? ObjectUtils.getJSXElement(props.template, props) :
;
const preview = createPreview();
- const image =
;
+ const image = props.src &&
;
return (
@@ -184,15 +186,16 @@ export const Image = React.memo(
Image.displayName = 'Image';
Image.defaultProps = {
__TYPE: 'Image',
- preview: false,
+ alt: null,
className: null,
downloadable: false,
- imageStyle: null,
+ height: null,
imageClassName: null,
- template: null,
+ imageStyle: null,
+ onError: null,
+ preview: false,
+ previewSrc: null,
src: null,
- alt: null,
- width: null,
- height: null,
- onError: null
+ template: null,
+ width: null
};
diff --git a/components/lib/image/image.d.ts b/components/lib/image/image.d.ts
index df082833e4..fa2167938a 100644
--- a/components/lib/image/image.d.ts
+++ b/components/lib/image/image.d.ts
@@ -1,21 +1,24 @@
import * as React from 'react';
export interface ImageProps extends Omit, HTMLSpanElement>, 'ref'> {
- preview?: boolean;
+ alt?: string;
+ children?: React.ReactNode;
downloadable?: boolean;
- imageStyle?: string;
+ height?: string;
imageClassName?: string;
- template?: any;
+ imageStyle?: string;
+ preview?: boolean;
+ previewSrc?: string;
src?: string;
- alt?: string;
+ template?: any;
width?: string;
- height?: string;
onShow?(): void;
onHide?(): void;
- children?: React.ReactNode;
}
export declare class Image extends React.Component {
+ public show(): void;
+ public hide(): void;
public getElement(): HTMLSpanElement;
public getImage(): HTMLImageElement;
}
diff --git a/pages/image/index.js b/pages/image/index.js
index 37d3ad1b0d..3e749e72d6 100644
--- a/pages/image/index.js
+++ b/pages/image/index.js
@@ -1,10 +1,10 @@
-import React from 'react';
-import { Image } from '../../components/lib/image/Image';
+import getConfig from 'next/config';
+import Head from 'next/head';
import Link from 'next/link';
-import ImageDoc from '../../components/doc/image';
+import React from 'react';
import { DocActions } from '../../components/doc/common/docactions';
-import Head from 'next/head';
-import getConfig from 'next/config';
+import ImageDoc from '../../components/doc/image';
+import { Image } from '../../components/lib/image/Image';
const ImageDemo = () => {
const contextPath = getConfig().publicRuntimeConfig.contextPath;
@@ -32,8 +32,11 @@ const ImageDemo = () => {
Basic
- Preview
-
+ Preview and Zoom
+
+
+ Thumbnail
+