@get-set/gs-zoom 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +46 -0
- package/dist/GSZoom.css +235 -0
- package/dist/actions/general.js +30 -0
- package/dist/actions/getAdjustTransform.js +43 -0
- package/dist/actions/getCurrentParams.js +42 -0
- package/dist/actions/getTranslateCoordToPoint.js +41 -0
- package/dist/actions/init.js +21 -0
- package/dist/actions/initActionEvents.js +93 -0
- package/dist/actions/initAdditionals.js +118 -0
- package/dist/actions/initAdjust.js +107 -0
- package/dist/actions/initAdjustAdditionalActive.js +33 -0
- package/dist/actions/initArrows.js +44 -0
- package/dist/actions/initAutoplay.js +81 -0
- package/dist/actions/initChange.js +73 -0
- package/dist/actions/initClose.js +28 -0
- package/dist/actions/initDraggle.js +303 -0
- package/dist/actions/initDraw.js +79 -0
- package/dist/actions/initDrawItem.js +83 -0
- package/dist/actions/initFullScreen.js +32 -0
- package/dist/actions/initLightBox.js +33 -0
- package/dist/actions/initMagnifier.js +54 -0
- package/dist/actions/initNavigateWithKeys.js +27 -0
- package/dist/actions/initWheel.js +51 -0
- package/dist/actions/setStyles.js +24 -0
- package/dist/components/GSZoom.js +115 -0
- package/dist/components/styles/GSZoom.css +235 -0
- package/dist/components/styles/GSZoom.css.map +1 -0
- package/dist/components/styles/GSZoom.scss +254 -0
- package/dist/constants/defaultParams.js +20 -0
- package/dist/constants/icons.js +23 -0
- package/dist/constants/magnifierDefaultProps.js +7 -0
- package/dist/constants/types.js +6 -0
- package/dist/helpers/uihelpers.js +9 -0
- package/index.js +3 -0
- package/package.json +43 -0
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import icons from "../constants/icons";
|
|
2
|
+
import initDrawItem from "./initDrawItem";
|
|
3
|
+
|
|
4
|
+
const initDraw = (ref) => {
|
|
5
|
+
const list = [...ref.list];
|
|
6
|
+
const params = ref.currentParams;
|
|
7
|
+
const $body = document.querySelector("body");
|
|
8
|
+
const $container = document.createElement("div");
|
|
9
|
+
const $header = document.createElement("div");
|
|
10
|
+
const $imgList = document.createElement("div");
|
|
11
|
+
$container.classList.add("gs-zoom-container");
|
|
12
|
+
$imgList.classList.add("gs-zoom-img-list");
|
|
13
|
+
$header.classList.add("gs-zoom-header");
|
|
14
|
+
$container.append($imgList);
|
|
15
|
+
$container.prepend($header);
|
|
16
|
+
$body.append($container);
|
|
17
|
+
ref.$container = $container;
|
|
18
|
+
ref.$imgList = $imgList;
|
|
19
|
+
|
|
20
|
+
//$imgList.style.width = `${2 * window.innerWidth}px`;
|
|
21
|
+
|
|
22
|
+
list.map((_, index) => {
|
|
23
|
+
const $mainImg = document.createElement("div");
|
|
24
|
+
$mainImg.classList.add("gs-zoom-main-img");
|
|
25
|
+
$mainImg.dataset.index = index;
|
|
26
|
+
$imgList.append($mainImg);
|
|
27
|
+
if (index <= ref.currentIndex + 1 && index >= ref.currentIndex - 1) {
|
|
28
|
+
initDrawItem(ref, index);
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
//#region Actions
|
|
33
|
+
const $actions = document.createElement("div");
|
|
34
|
+
$actions.classList.add("gs-zoom-actions");
|
|
35
|
+
$header.append($actions);
|
|
36
|
+
|
|
37
|
+
if (params.showAdditionals && ref.list.length > 1) {
|
|
38
|
+
const $btnAdditionals = document.createElement("button");
|
|
39
|
+
$btnAdditionals.classList.add("gs-zoom-btn-toggleadditionals");
|
|
40
|
+
$btnAdditionals.classList.add("gs-zoom-action");
|
|
41
|
+
$btnAdditionals.innerHTML = icons.toggleadditionals;
|
|
42
|
+
$actions.append($btnAdditionals);
|
|
43
|
+
ref.$btnAdditionals = $btnAdditionals;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const $btnZoomIn = document.createElement("button");
|
|
47
|
+
$btnZoomIn.classList.add("gs-zoom-btn-in");
|
|
48
|
+
$btnZoomIn.classList.add("gs-zoom-action");
|
|
49
|
+
$btnZoomIn.innerHTML = icons.zoomIn;
|
|
50
|
+
$actions.append($btnZoomIn);
|
|
51
|
+
ref.$btnZoomIn = $btnZoomIn;
|
|
52
|
+
|
|
53
|
+
const $btnZoomOut = document.createElement("button");
|
|
54
|
+
$btnZoomOut.classList.add("gs-zoom-btn-in");
|
|
55
|
+
$btnZoomOut.classList.add("gs-zoom-action");
|
|
56
|
+
$btnZoomOut.innerHTML = icons.zoomOut;
|
|
57
|
+
$actions.append($btnZoomOut);
|
|
58
|
+
ref.$btnZoomOut = $btnZoomOut;
|
|
59
|
+
|
|
60
|
+
if (ref.list.length > 1) {
|
|
61
|
+
const $btnAutoplay = document.createElement("button");
|
|
62
|
+
$btnAutoplay.classList.add("gs-zoom-btn-autoplay");
|
|
63
|
+
$btnAutoplay.classList.add("gs-zoom-action");
|
|
64
|
+
$btnAutoplay.innerHTML = icons.autoplay;
|
|
65
|
+
$actions.append($btnAutoplay);
|
|
66
|
+
ref.$btnAutoplay = $btnAutoplay;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const $btnClose = document.createElement("button");
|
|
70
|
+
$btnClose.classList.add("gs-zoom-btn-close");
|
|
71
|
+
$btnClose.classList.add("gs-zoom-action");
|
|
72
|
+
$btnClose.innerHTML = icons.close;
|
|
73
|
+
$actions.append($btnClose);
|
|
74
|
+
ref.$btnClose = $btnClose;
|
|
75
|
+
|
|
76
|
+
//#endregion Actions
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export default initDraw;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import initDraggle from "./initDraggle";
|
|
2
|
+
import initWheel from "./initWheel";
|
|
3
|
+
|
|
4
|
+
const initDrawItem = (ref, index) => {
|
|
5
|
+
const params = ref.currentParams;
|
|
6
|
+
const $imgList = ref.$imgList;
|
|
7
|
+
const $mainImg = $imgList.querySelector(
|
|
8
|
+
`.gs-zoom-main-img[data-index='${index}']`
|
|
9
|
+
);
|
|
10
|
+
if ($mainImg.querySelector("img") === null) {
|
|
11
|
+
const $imgTouch = document.createElement("div");
|
|
12
|
+
const $imgloading = document.createElement("div");
|
|
13
|
+
const $img = document.createElement("img");
|
|
14
|
+
const item = [...ref.list][index];
|
|
15
|
+
$imgloading.classList.add("gz-zoom-loading-container");
|
|
16
|
+
$img.src = item.src.split("?")[0] + params.mainImageQueryParameters;
|
|
17
|
+
$img.classList.add("gs-zoom-img");
|
|
18
|
+
$img.dataset.scale = 1;
|
|
19
|
+
$img.dataset.translatex = 0;
|
|
20
|
+
$img.dataset.translatey = 0;
|
|
21
|
+
$imgTouch.classList.add("gs-zoom-img-touch");
|
|
22
|
+
$img.onload = () => {
|
|
23
|
+
$mainImg.classList.remove("gz-zoom-is-loading");
|
|
24
|
+
};
|
|
25
|
+
$mainImg.classList.add("gz-zoom-is-loading");
|
|
26
|
+
$mainImg.append($img);
|
|
27
|
+
$imgloading.innerHTML = params.imgLoading;
|
|
28
|
+
$mainImg.append($imgloading);
|
|
29
|
+
$mainImg.append($imgTouch);
|
|
30
|
+
$imgList.style.transform = `translateX(-${
|
|
31
|
+
ref.currentIndex * window.innerWidth
|
|
32
|
+
}px)`;
|
|
33
|
+
if (
|
|
34
|
+
(item.dataset.gstitle != undefined &&
|
|
35
|
+
item.dataset.gstitle.trim().length > 0) ||
|
|
36
|
+
(item.dataset.gssubtitle != undefined &&
|
|
37
|
+
item.dataset.gssubtitle.trim().length > 0) ||
|
|
38
|
+
(item.dataset.gsdescription != undefined &&
|
|
39
|
+
item.dataset.gsdescription.trim().length > 0)
|
|
40
|
+
) {
|
|
41
|
+
const $txtarea = document.createElement("div");
|
|
42
|
+
$txtarea.classList.add("gs-zoom-hide-inzoomed");
|
|
43
|
+
$txtarea.classList.add("gs-zoom-info-data");
|
|
44
|
+
if (
|
|
45
|
+
item.dataset.gstitle != undefined &&
|
|
46
|
+
item.dataset.gstitle.trim().length > 0
|
|
47
|
+
) {
|
|
48
|
+
const $title = document.createElement("div");
|
|
49
|
+
$title.classList.add("gs-zoom-info-title");
|
|
50
|
+
$title.innerHTML = item.dataset.gstitle;
|
|
51
|
+
$txtarea.append($title);
|
|
52
|
+
}
|
|
53
|
+
if (
|
|
54
|
+
item.dataset.gssubtitle != undefined &&
|
|
55
|
+
item.dataset.gssubtitle.trim().length > 0
|
|
56
|
+
) {
|
|
57
|
+
const $subtitle = document.createElement("div");
|
|
58
|
+
$subtitle.classList.add("gs-zoom-info-subtitle");
|
|
59
|
+
$subtitle.innerHTML = item.dataset.gssubtitle;
|
|
60
|
+
$txtarea.append($subtitle);
|
|
61
|
+
}
|
|
62
|
+
if (
|
|
63
|
+
item.dataset.gsdescription != undefined &&
|
|
64
|
+
item.dataset.gsdescription.trim().length > 0
|
|
65
|
+
) {
|
|
66
|
+
const $description = document.createElement("div");
|
|
67
|
+
$description.classList.add("gs-zoom-info-description");
|
|
68
|
+
$description.innerHTML = item.dataset.gsdescription;
|
|
69
|
+
$txtarea.append($description);
|
|
70
|
+
}
|
|
71
|
+
$mainImg.append($txtarea);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (index == ref.currentIndex) {
|
|
75
|
+
ref.$mainImg = $mainImg;
|
|
76
|
+
ref.$imgTouch = $imgTouch;
|
|
77
|
+
ref.$img = $img;
|
|
78
|
+
}
|
|
79
|
+
initWheel(ref, index);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
export default initDrawItem;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { fullscreenchange } from "./general";
|
|
2
|
+
import initClose from "./initClose";
|
|
3
|
+
|
|
4
|
+
export const initFullScreen = (ref) => {
|
|
5
|
+
const $html = document.querySelector("html");
|
|
6
|
+
if (!ref.currentParams.disableFullScreen) {
|
|
7
|
+
if ($html.requestFullscreen) {
|
|
8
|
+
$html.requestFullscreen();
|
|
9
|
+
} else if ($html.webkitRequestFullscreen) {
|
|
10
|
+
// Safari
|
|
11
|
+
$html.webkitRequestFullscreen();
|
|
12
|
+
} else if ($html.msRequestFullscreen) {
|
|
13
|
+
// IE/Edge
|
|
14
|
+
$html.msRequestFullscreen();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
document.removeEventListener("fullscreenchange", fullscreenchange);
|
|
18
|
+
document.addEventListener("fullscreenchange", fullscreenchange);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const exitFullScreen = () => {
|
|
22
|
+
if (document.exitFullscreen) {
|
|
23
|
+
document.exitFullscreen();
|
|
24
|
+
} else if (document.webkitExitFullscreen) {
|
|
25
|
+
// Safari
|
|
26
|
+
document.webkitExitFullscreen();
|
|
27
|
+
} else if (document.msExitFullscreen) {
|
|
28
|
+
// IE/Edge
|
|
29
|
+
document.msExitFullscreen();
|
|
30
|
+
}
|
|
31
|
+
initClose();
|
|
32
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import initActionEvents from "./initActionEvents";
|
|
2
|
+
import initAdditionals from "./initAdditionals";
|
|
3
|
+
import initArrows from "./initArrows";
|
|
4
|
+
import initDraggle from "./initDraggle";
|
|
5
|
+
import initDraw from "./initDraw";
|
|
6
|
+
import { initFullScreen } from "./initFullScreen";
|
|
7
|
+
import initNavigateWithKeys from "./initNavigateWithKeys";
|
|
8
|
+
|
|
9
|
+
const initLightBox = (ref) => {
|
|
10
|
+
[...ref.list].map((item, index) => {
|
|
11
|
+
item.dataset.index = index;
|
|
12
|
+
item.addEventListener("click", function () {
|
|
13
|
+
window.GSZoomConfigue.openedZoom = ref.currentParams.reference;
|
|
14
|
+
if (typeof ref.currentParams.beforeLightBoxOpen === "function") {
|
|
15
|
+
ref.currentParams.beforeLightBoxOpen();
|
|
16
|
+
}
|
|
17
|
+
ref.currentIndex = index;
|
|
18
|
+
document.querySelector("html").classList.add("gs-zoom-opened");
|
|
19
|
+
initDraw(ref);
|
|
20
|
+
initAdditionals(ref);
|
|
21
|
+
initFullScreen(ref);
|
|
22
|
+
initNavigateWithKeys(ref);
|
|
23
|
+
initArrows(ref);
|
|
24
|
+
initActionEvents(ref);
|
|
25
|
+
if (typeof ref.currentParams.afterLightBoxOpen === "function") {
|
|
26
|
+
ref.currentParams.afterLightBoxOpen();
|
|
27
|
+
}
|
|
28
|
+
initDraggle(ref, index);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export default initLightBox;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const initMagnifier = (ref) => {
|
|
2
|
+
[...ref.list].map((item, index) => {
|
|
3
|
+
item.classList.add('gs-zoom-magnifier-instance');
|
|
4
|
+
const params = ref.currentParams.magnifier;
|
|
5
|
+
item.onmouseenter = (e) => {
|
|
6
|
+
const clientX = e.clientX;
|
|
7
|
+
const clientY = e.clientY;
|
|
8
|
+
const $magnifier = document.createElement('div');
|
|
9
|
+
$magnifier.dataset.type = params.form;
|
|
10
|
+
const $img = document.createElement('img');
|
|
11
|
+
$img.src =
|
|
12
|
+
item.dataset.gszoomsrc != undefined ? item.dataset.gszoomsrc : item.src;
|
|
13
|
+
$img.width = item.clientWidth;
|
|
14
|
+
$img.height = item.clientHeight;
|
|
15
|
+
$img.style.objectFit = window
|
|
16
|
+
.getComputedStyle(item)
|
|
17
|
+
.getPropertyValue('object-fit');
|
|
18
|
+
$img.style.transform = `scale(${params.zoom})`;
|
|
19
|
+
$magnifier.classList.add('gs-zoom-magnifier');
|
|
20
|
+
$magnifier.append($img);
|
|
21
|
+
const top = clientY - params.size / 2;
|
|
22
|
+
const left = clientX - params.size / 2;
|
|
23
|
+
$magnifier.style.width = `${params.size}px`;
|
|
24
|
+
$magnifier.style.top = `${top}px`;
|
|
25
|
+
$magnifier.style.left = `${left}px`;
|
|
26
|
+
ref.$magnifier = $magnifier;
|
|
27
|
+
ref.$img = $img;
|
|
28
|
+
document.querySelector('body').append($magnifier);
|
|
29
|
+
};
|
|
30
|
+
item.onmousemove = (e) => {
|
|
31
|
+
const $img = ref.$img;
|
|
32
|
+
const imgRect = item.getBoundingClientRect();
|
|
33
|
+
const clientX = e.clientX;
|
|
34
|
+
const clientY = e.clientY;
|
|
35
|
+
const distanceFromTop = clientY - imgRect.top;
|
|
36
|
+
const distanceFromLeft = clientX - imgRect.left;
|
|
37
|
+
const $magnifier = ref.$magnifier;
|
|
38
|
+
const top = clientY - params.size / 2;
|
|
39
|
+
const left = clientX - params.size / 2;
|
|
40
|
+
$magnifier.style.top = `${top}px`;
|
|
41
|
+
$magnifier.style.left = `${left}px`;
|
|
42
|
+
$img.style.top = `${params.size / 2 - distanceFromTop * params.zoom}px`;
|
|
43
|
+
$img.style.left = `${params.size / 2 - distanceFromLeft * params.zoom}px`;
|
|
44
|
+
$img.style.transform = `scale(${params.zoom})`;
|
|
45
|
+
};
|
|
46
|
+
item.onmouseleave = (e) => {
|
|
47
|
+
if (ref.$magnifier != null) {
|
|
48
|
+
ref.$magnifier.remove();
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export default initMagnifier;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import initChange from "./initChange";
|
|
2
|
+
|
|
3
|
+
const initNavigateWithKeys = (ref) => {
|
|
4
|
+
const params = ref.currentParams;
|
|
5
|
+
|
|
6
|
+
if (params.navigateWithKeys && ref.list.length > 1) {
|
|
7
|
+
document.onkeyup = (e) => {
|
|
8
|
+
let newIndex = 0;
|
|
9
|
+
if (e.key === "ArrowRight") {
|
|
10
|
+
if (ref.currentIndex < ref.list.length - 1) {
|
|
11
|
+
newIndex = ref.currentIndex + 1;
|
|
12
|
+
} else {
|
|
13
|
+
newIndex = 0;
|
|
14
|
+
}
|
|
15
|
+
} else if (e.key === "ArrowLeft") {
|
|
16
|
+
if (ref.currentIndex == 0) {
|
|
17
|
+
newIndex = ref.list.length - 1;
|
|
18
|
+
} else {
|
|
19
|
+
newIndex = ref.currentIndex - 1;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
initChange(ref, newIndex);
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export default initNavigateWithKeys;
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import getTranslateCoordToPoint from './getTranslateCoordToPoint';
|
|
2
|
+
import initAdjust from './initAdjust';
|
|
3
|
+
import setStyles from './setStyles';
|
|
4
|
+
|
|
5
|
+
const initWheel = (ref, index) => {
|
|
6
|
+
const params = ref.currentParams;
|
|
7
|
+
const $container = ref.$container;
|
|
8
|
+
//[...ref.$imgList.querySelectorAll(".gs-zoom-main-img")].map((item) => {
|
|
9
|
+
const item = ref.$imgList.querySelector(
|
|
10
|
+
`.gs-zoom-main-img[data-index='${index}']`
|
|
11
|
+
);
|
|
12
|
+
if (item != null) {
|
|
13
|
+
const $mainImg = item;
|
|
14
|
+
const $img = $mainImg.querySelector('.gs-zoom-img');
|
|
15
|
+
|
|
16
|
+
if (params.zoomOnWheel) {
|
|
17
|
+
$mainImg.addEventListener('wheel', (e) => {
|
|
18
|
+
const scale =
|
|
19
|
+
$img.dataset.scale != undefined ? parseFloat($img.dataset.scale) : 1;
|
|
20
|
+
|
|
21
|
+
const newScale =
|
|
22
|
+
e.deltaY < 0 && scale < params.maxZoom
|
|
23
|
+
? Math.min(scale + 0.1, params.maxZoom)
|
|
24
|
+
: e.deltaY > 0 && scale > 1
|
|
25
|
+
? Math.max(1, scale - 0.1)
|
|
26
|
+
: scale;
|
|
27
|
+
|
|
28
|
+
const [newTranslatex, newTranslatey] = getTranslateCoordToPoint(
|
|
29
|
+
$img,
|
|
30
|
+
$container,
|
|
31
|
+
scale,
|
|
32
|
+
newScale,
|
|
33
|
+
e.pageX,
|
|
34
|
+
e.pageY
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
$img.dataset.scale = newScale;
|
|
38
|
+
const transform = `scale(${newScale}) translate(${
|
|
39
|
+
newTranslatex / newScale
|
|
40
|
+
}px, ${newTranslatey / newScale}px)`;
|
|
41
|
+
setStyles(ref, $img, {
|
|
42
|
+
transform: transform,
|
|
43
|
+
});
|
|
44
|
+
initAdjust(ref, $container, $img, false);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
//});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export default initWheel;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { stopAutoplay } from "./initAutoplay";
|
|
2
|
+
|
|
3
|
+
const setStyles = (ref, $img, styles) => {
|
|
4
|
+
const $container = ref.$container;
|
|
5
|
+
for (var style in styles) {
|
|
6
|
+
$img.style[style] = styles[style];
|
|
7
|
+
}
|
|
8
|
+
const scale =
|
|
9
|
+
$img.dataset.tempscale != undefined
|
|
10
|
+
? $img.dataset.tempscale
|
|
11
|
+
: $img.dataset.scale;
|
|
12
|
+
if (scale == 1) {
|
|
13
|
+
$container.classList.remove("gs-zoom-is-zoomed");
|
|
14
|
+
ref.isZoomed = false;
|
|
15
|
+
} else {
|
|
16
|
+
$container.classList.add("gs-zoom-is-zoomed");
|
|
17
|
+
ref.isZoomed = true;
|
|
18
|
+
if (ref.autoplay != undefined) {
|
|
19
|
+
stopAutoplay(ref);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export default setStyles;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react';
|
|
2
|
+
import NewGuid from '../helpers/uihelpers';
|
|
3
|
+
import getCurrentParams from '../actions/getCurrentParams';
|
|
4
|
+
import init from '../actions/init';
|
|
5
|
+
import PropTypes from 'prop-types';
|
|
6
|
+
import '../GSZoom.css';
|
|
7
|
+
|
|
8
|
+
const zoomParams = {
|
|
9
|
+
reference: PropTypes.string,
|
|
10
|
+
arrows: PropTypes.bool,
|
|
11
|
+
navigateWithKeys: PropTypes.bool,
|
|
12
|
+
showAdditionals: PropTypes.bool,
|
|
13
|
+
zoomOnWheel: PropTypes.bool,
|
|
14
|
+
maxZoom: PropTypes.number,
|
|
15
|
+
disableFullScreen: PropTypes.bool,
|
|
16
|
+
imgLoading: PropTypes.string,
|
|
17
|
+
autoplaySpeed: PropTypes.number,
|
|
18
|
+
mainImageQueryParameters: PropTypes.string,
|
|
19
|
+
additionalImageQueryParameters: PropTypes.string,
|
|
20
|
+
type: PropTypes.oneOf(['lightbox', 'magnifier']),
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* GSZoom component to display a customizable zoom.
|
|
25
|
+
*
|
|
26
|
+
* @component
|
|
27
|
+
* @param {Object} props - The props object.
|
|
28
|
+
* @param {'lightbox' | 'magnifier'} props.type - Type of zoom effect.
|
|
29
|
+
* @param {string} props.reference - Unique key for each slideshow.
|
|
30
|
+
* @param {boolean} props.arrows - Allows to control arrows visiblity.
|
|
31
|
+
* @param {boolean} props.navigateWithKeys - Enable or disable control via keys.
|
|
32
|
+
* @param {boolean} props.showAdditionals - Control additionla images visibility.
|
|
33
|
+
* @param {boolean} props.zoomOnWheel - Control zoom via mousewheel.
|
|
34
|
+
* @param {number} props.maxZoom - Shows zoom max percent.
|
|
35
|
+
* @param {boolean} props.disableFullScreen - Control fullscreen accessibility.
|
|
36
|
+
* @param {string} props.imgLoading - Allows to set custom loading.
|
|
37
|
+
* @param {number} props.autoplaySpeed - Shows autoplay speed.
|
|
38
|
+
* @param {string} props.mainImageQueryParameters - Additional query params for main image.
|
|
39
|
+
* @param {string} props.additionalImageQueryParameters - Additional query params for additional images.
|
|
40
|
+
* @param {Array<Object>} [props.responsive] - Array of responsive configurations based on window size.
|
|
41
|
+
* @param {number} props.responsive[].windowSize - Minimum window size for this configuration.
|
|
42
|
+
* @param {Object} props.responsive[].params - The responsive configuration for the zoom.
|
|
43
|
+
* @returns {JSX.Element} The rendered zoom component.
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
const GSZoom = ({ list, ...rest }) => {
|
|
47
|
+
const params = { ...rest };
|
|
48
|
+
const [componentKey, setComponentKey] = useState(null);
|
|
49
|
+
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
if (componentKey != null) {
|
|
52
|
+
if (typeof window.GSZoomConfigue === 'undefined') {
|
|
53
|
+
window.GSZoomConfigue = {
|
|
54
|
+
references: [],
|
|
55
|
+
instance: ref => {
|
|
56
|
+
if (ref != undefined && ref != '') {
|
|
57
|
+
const instance = window.GSZoomConfigue.references.find(
|
|
58
|
+
x => x.key === ref,
|
|
59
|
+
);
|
|
60
|
+
if (instance != undefined) {
|
|
61
|
+
return instance.ref;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return `GSZoomInstance by '${ref}' reference not found`;
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
if (
|
|
69
|
+
window.GSZoomConfigue.references.find(x => x.key == componentKey) ==
|
|
70
|
+
undefined
|
|
71
|
+
) {
|
|
72
|
+
const currentParams = getCurrentParams(params);
|
|
73
|
+
|
|
74
|
+
window.GSZoomConfigue.references.push({
|
|
75
|
+
key: componentKey,
|
|
76
|
+
ref: {
|
|
77
|
+
list,
|
|
78
|
+
currentParams,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
init(
|
|
83
|
+
window.GSZoomConfigue.references.find(x => x.key === componentKey)
|
|
84
|
+
.ref,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}, [componentKey]);
|
|
89
|
+
|
|
90
|
+
useEffect(() => {
|
|
91
|
+
setComponentKey(
|
|
92
|
+
params.reference != undefined ? params.reference : NewGuid(),
|
|
93
|
+
);
|
|
94
|
+
return () => {
|
|
95
|
+
if (window.GSZoomConfigue != undefined) {
|
|
96
|
+
window.GSZoomConfigue.references =
|
|
97
|
+
window.GSZoomConfigue.references.filter(x => x.key !== componentKey);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
}, []);
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
GSZoom.propTypes = {
|
|
104
|
+
...zoomParams,
|
|
105
|
+
responsive: PropTypes.arrayOf(
|
|
106
|
+
PropTypes.shape({
|
|
107
|
+
windowSize: PropTypes.number,
|
|
108
|
+
params: PropTypes.shape({
|
|
109
|
+
...zoomParams,
|
|
110
|
+
}),
|
|
111
|
+
}),
|
|
112
|
+
),
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
export default GSZoom;
|