Refactor #6690 - Form ImageCompare

pull/6697/head
tugcekucukoglu 2024-10-31 10:29:52 +03:00
parent 678eb754cf
commit a8d890cf42
2 changed files with 40 additions and 4 deletions

View File

@ -12,12 +12,44 @@ import BaseImageCompare from './BaseImageCompare.vue';
export default { export default {
name: 'ImageCompare', name: 'ImageCompare',
extends: BaseImageCompare, extends: BaseImageCompare,
mutationObserver: null,
data() {
return {
isRTL: false
};
},
beforeUnmount() {
if (this.mutationObserver) {
this.mutationObserver.disconnect();
}
},
mounted() {
this.updateDirection();
this.observeDirectionChanges();
},
methods: { methods: {
onSlide(event) { onSlide(event) {
const value = event.target.value; const value = event.target.value;
const image = event.target.previousElementSibling; const image = event.target.previousElementSibling;
image.style.clipPath = 'polygon(0 0,' + value + '% 0,' + value + '% 100%, 0 100%)'; if (this.isRTL) {
image.style.clipPath = `polygon(${100 - value}% 0, 100% 0, 100% 100%, ${100 - value}% 100%)`;
} else {
image.style.clipPath = `polygon(0 0, ${value}% 0, ${value}% 100%, 0 100%)`;
}
},
updateDirection() {
this.isRTL = !!this.$el.closest('[dir="rtl"]');
},
observeDirectionChanges() {
const targetNode = document.documentElement;
const config = { attributes: true, attributeFilter: ['dir'] };
this.mutationObserver = new MutationObserver(() => {
this.updateDirection();
});
this.mutationObserver.observe(targetNode, config);
} }
} }
}; };

View File

@ -18,12 +18,16 @@ const theme = ({ dt }) => `
clip-path: polygon(0 0, 50% 0, 50% 100%, 0 100%); clip-path: polygon(0 0, 50% 0, 50% 100%, 0 100%);
} }
.p-imagecompare:dir(rtl) img + img {
clip-path: polygon(50% 0, 100% 0, 100% 100%, 50% 100%);
}
.p-imagecompare-slider { .p-imagecompare-slider {
position: relative; position: relative;
-webkit-appearance: none; -webkit-appearance: none;
width: calc(100% + ${dt('imagecompare.handle.size')}); width: calc(100% + ${dt('imagecompare.handle.size')});
height: 100%; height: 100%;
margin-left: calc(-1 * calc(${dt('imagecompare.handle.size')} / 2)); margin-inline-start: calc(-1 * calc(${dt('imagecompare.handle.size')} / 2));
background-color: transparent; background-color: transparent;
outline: none; outline: none;
transition: all ${dt('imagecompare.handle.transition.duration')}; transition: all ${dt('imagecompare.handle.transition.duration')};
@ -62,10 +66,10 @@ const theme = ({ dt }) => `
outline: ${dt('imagecompare.handle.focus.ring.width')} ${dt('imagecompare.handle.focus.ring.style')} ${dt('imagecompare.handle.focus.ring.color')}; outline: ${dt('imagecompare.handle.focus.ring.width')} ${dt('imagecompare.handle.focus.ring.style')} ${dt('imagecompare.handle.focus.ring.color')};
outline-offset: ${dt('imagecompare.handle.focus.ring.offset')}; outline-offset: ${dt('imagecompare.handle.focus.ring.offset')};
} }
.p-imagecompare-slider:hover { .p-imagecompare-slider:hover {
width: calc(100% + ${dt('imagecompare.handle.hover.size')}); width: calc(100% + ${dt('imagecompare.handle.hover.size')});
margin-left: calc(-1 * calc(${dt('imagecompare.handle.hover.size')} / 2)); margin-inline-start: calc(-1 * calc(${dt('imagecompare.handle.hover.size')} / 2));
} }
.p-imagecompare-slider:hover::-webkit-slider-thumb { .p-imagecompare-slider:hover::-webkit-slider-thumb {