Skip to content

Commit

Permalink
Refactor #5682, #5683 - For Image
Browse files Browse the repository at this point in the history
  • Loading branch information
tugcekucukoglu committed May 6, 2024
1 parent 262fcf0 commit 2eec11b
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 10 deletions.
4 changes: 4 additions & 0 deletions components/lib/image/BaseImage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ export default {
type: String,
default: undefined
},
previewIcon: {
type: String,
default: undefined
},
zoomInDisabled: {
type: Boolean,
default: false
Expand Down
37 changes: 35 additions & 2 deletions components/lib/image/Image.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,13 @@ export interface ImageProps {
imageClass?: any;
/**
* Custom indicator icon.
* @deprecated since v3.27.0. Use 'indicatoricon' slot.
* @deprecated since v4.0. Use 'previewIcon' prop instead.
*/
indicatorIcon?: string;
indicatorIcon?: string | undefined;
/**
* Custom indicator icon.
*/
previewIcon?: string | undefined;
/**
* Disable the zoom-in button
* @defaultValue false
Expand Down Expand Up @@ -227,6 +231,11 @@ export interface ImageSlots {
/**
* Custom indicator template.
*/
previewicon(): VNode[];
/**
* @deprecated since v4.0. Use 'previewicon' slot instead.
* Custom indicator template.
*/
indicatoricon(): VNode[];
/**
* Custom refresh template.
Expand Down Expand Up @@ -272,6 +281,7 @@ export interface ImageSlots {
errorCallback: () => void;
}): VNode[];
/**
* @deprecated since v4.0. use 'original' slot instead.
* Custom preview template.
* @param {Object} scope - preview slot's params.
*/
Expand All @@ -294,6 +304,29 @@ export interface ImageSlots {
*/
previewCallback: () => void;
}): VNode[];
/**
* Custom original template.
* @param {Object} scope - original slot's params.
*/
original(scope: {
/**
* Style class of the original image element.
*/
class: any;
/**
* Style of the original image element.
*/
style: any;
/**
* Original click function.
* @deprecated since v3.39.0. Use 'previewCallback' property instead.
*/
onClick: () => void;
/**
* Preview click function.
*/
previewCallback: () => void;
}): VNode[];
}

export interface ImageEmits {}
Expand Down
8 changes: 5 additions & 3 deletions components/lib/image/Image.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
<img :style="imageStyle" :class="imageClass" @error="onError" v-bind="{ ...$attrs, ...ptm('image') }" />
</slot>
<button v-if="preview" ref="previewButton" :aria-label="zoomImageAriaLabel" type="button" :class="cx('previewMask')" @click="onImageClick" v-bind="{ ...previewButtonProps, ...ptm('previewMask') }">
<slot name="indicatoricon">
<component :is="indicatorIcon ? 'i' : 'EyeIcon'" :class="cx('previewIcon')" v-bind="ptm('previewIcon')" />
<!-- TODO: indicator* deprecated since v4.0-->
<slot :name="$slots.previewicon ? 'previewicon' : 'indicatoricon'">
<component :is="previewIcon || indicatorIcon ? 'i' : 'EyeIcon'" :class="cx('previewIcon')" v-bind="ptm('previewIcon')" />
</slot>
</button>
<Portal>
Expand Down Expand Up @@ -43,7 +44,8 @@
</div>
<transition name="p-image-original" @before-enter="onBeforeEnter" @enter="onEnter" @leave="onLeave" @before-leave="onBeforeLeave" @after-leave="onAfterLeave" v-bind="ptm('transition')">
<div v-if="previewVisible" v-bind="ptm('originalContainer')">
<slot name="preview" :class="cx('original')" :style="imagePreviewStyle" :onClick="onPreviewImageClick" :previewCallback="onPreviewImageClick">
<!-- TODO: preview deprecated since v4.0-->
<slot :name="$slots.original ? 'original' : 'preview'" :class="cx('original')" :style="imagePreviewStyle" :onClick="onPreviewImageClick" :previewCallback="onPreviewImageClick">
<img :src="$attrs.src" :class="cx('original')" :style="imagePreviewStyle" @click="onPreviewImageClick" v-bind="ptm('original')" />
</slot>
</div>
Expand Down
10 changes: 5 additions & 5 deletions doc/image/TemplateDoc.vue
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<template>
<DocSectionText v-bind="$attrs">
<p>
An eye icon is displayed by default when the image is hovered in preview mode, use the <i>indicatoricon</i> slot for custom content. In addition, the <i>image</i> and <i>preview</i> slots are available to define the thumbnail and detailed
An eye icon is displayed by default when the image is hovered in preview mode, use the <i>previewicon</i> slot for custom content. In addition, the <i>image</i> and <i>preview</i> slots are available to define the thumbnail and detailed
image respectively.
</p>
</DocSectionText>
<div class="card flex justify-content-center">
<Image alt="Image" preview>
<template #indicatoricon>
<template #previewicon>
<i class="pi pi-search"></i>
</template>
<template #image>
Expand All @@ -28,7 +28,7 @@ export default {
code: {
basic: `
<Image alt="Image" preview>
<template #indicatoricon>
<template #previewicon>
<i class="pi pi-search"></i>
</template>
<template #image>
Expand All @@ -43,7 +43,7 @@ export default {
<template>
<div class="card flex justify-content-center">
<Image alt="Image" preview>
<template #indicatoricon>
<template #previewicon>
<i class="pi pi-search"></i>
</template>
<template #image>
Expand All @@ -60,7 +60,7 @@ export default {
<template>
<div class="card flex justify-content-center">
<Image alt="Image" preview>
<template #indicatoricon>
<template #previewicon>
<i class="pi pi-search"></i>
</template>
<template #image>
Expand Down

0 comments on commit 2eec11b

Please sign in to comment.