ZoomIn and zoomOut props added

pull/3847/head
Olgu Örs Başak 2023-04-10 13:35:15 +03:00
parent fd29176b48
commit 5f57291418
3 changed files with 53 additions and 5 deletions

View File

@ -10,6 +10,18 @@ const ImageProps = [
type: 'string', type: 'string',
default: 'pi pi-eye', default: 'pi pi-eye',
description: 'Custom indicator icon.' description: 'Custom indicator icon.'
},
{
name: 'zoomInDisabled',
type: 'boolean',
default: 'false',
description: 'Disable the zoom-in button'
},
{
name: 'zoomOutDisabled',
type: 'boolean',
default: 'false',
description: 'Disable the zoom-out button'
} }
]; ];

View File

@ -32,6 +32,16 @@ export interface ImageProps {
* @defaultValue pi pi-eye * @defaultValue pi pi-eye
*/ */
indicatorIcon?: string; indicatorIcon?: string;
/**
* Disable the zoom-in button
* @defaultValue false
*/
zoomInDisabled?: boolean | undefined;
/**
* Disable the zoom-out button
* @defaultValue false
*/
zoomOutDisabled?: boolean | undefined;
} }
/** /**

View File

@ -21,13 +21,13 @@
</slot> </slot>
</button> </button>
<button class="p-image-action p-link" @click="zoomOut" type="button" :disabled="zoomDisabled" :aria-label="zoomOutAriaLabel"> <button class="p-image-action p-link" @click="zoomOut" type="button" :disabled="isZoomOutDisabled" :aria-label="zoomOutAriaLabel">
<slot name="zoomout"> <slot name="zoomout">
<SearchMinusIcon /> <SearchMinusIcon />
</slot> </slot>
</button> </button>
<button class="p-image-action p-link" @click="zoomIn" type="button" :disabled="zoomDisabled" :aria-label="zoomInAriaLabel"> <button class="p-image-action p-link" @click="zoomIn" type="button" :disabled="isZoomInDisabled" :aria-label="zoomInAriaLabel">
<slot name="zoomin"> <slot name="zoomin">
<SearchPlusIcon /> <SearchPlusIcon />
</slot> </slot>
@ -92,6 +92,14 @@ export default {
indicatorIcon: { indicatorIcon: {
type: String, type: String,
default: undefined default: undefined
},
zoomInDisabled: {
type: Boolean,
default: false
},
zoomOutDisabled: {
type: Boolean,
default: false
} }
}, },
mask: null, mask: null,
@ -126,7 +134,13 @@ export default {
onPreviewImageClick() { onPreviewImageClick() {
this.previewClick = true; this.previewClick = true;
}, },
onMaskClick() { onMaskClick(event) {
const isActionbarTarget = [event.target.classList].includes('p-image-action') || event.target.closest('.p-image-action');
if (isActionbarTarget) {
return;
}
if (!this.previewClick) { if (!this.previewClick) {
this.previewVisible = false; this.previewVisible = false;
this.rotate = 0; this.rotate = 0;
@ -192,6 +206,11 @@ export default {
if (focusTarget) { if (focusTarget) {
focusTarget.focus(); focusTarget.focus();
} }
},
hidePreview() {
this.previewVisible = false;
this.rotate = 0;
this.scale = 1;
} }
}, },
computed: { computed: {
@ -213,8 +232,11 @@ export default {
imagePreviewStyle() { imagePreviewStyle() {
return { transform: 'rotate(' + this.rotate + 'deg) scale(' + this.scale + ')' }; return { transform: 'rotate(' + this.rotate + 'deg) scale(' + this.scale + ')' };
}, },
zoomDisabled() { isZoomInDisabled() {
return this.scale <= 0.5 || this.scale >= 1.5; return this.zoomInDisabled || this.scale >= 1.5;
},
isZoomOutDisabled() {
return this.zoomOutDisabled || this.scale <= 0.5;
}, },
rightAriaLabel() { rightAriaLabel() {
return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.rotateRight : undefined; return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.rotateRight : undefined;
@ -298,6 +320,10 @@ export default {
align-items: center; align-items: center;
} }
.p-image-action.p-link[disabled] {
opacity: 0.5;
}
.p-image-preview { .p-image-preview {
transition: transform 0.15s; transition: transform 0.15s;
max-width: 100vw; max-width: 100vw;