Refactor #6690 - Form ImageCompare
parent
678eb754cf
commit
a8d890cf42
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -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')};
|
||||||
|
@ -65,7 +69,7 @@ const theme = ({ dt }) => `
|
||||||
|
|
||||||
.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 {
|
||||||
|
|
Loading…
Reference in New Issue