diff --git a/.changeset/rude-dolphins-reply.md b/.changeset/rude-dolphins-reply.md
new file mode 100644
index 0000000000..89545cde1f
--- /dev/null
+++ b/.changeset/rude-dolphins-reply.md
@@ -0,0 +1,5 @@
+---
+'@backstage/plugin-techdocs-module-addons-contrib': minor
+---
+
+Enable zoom icon for techdocs images inside lightbox
diff --git a/docs/features/techdocs/addons.md b/docs/features/techdocs/addons.md
index bd709ee15f..a41995c260 100644
--- a/docs/features/techdocs/addons.md
+++ b/docs/features/techdocs/addons.md
@@ -122,12 +122,12 @@ page header, TechDocs Addons whose location is `Header` will not be rendered.
Addons can, in principle, be provided by any plugin! To make it easier to
discover available Addons, we've compiled a list of them here:
-| Addon | Package/Plugin | Description |
-| ---------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
-| [``](https://backstage.io/docs/reference/plugin-techdocs-module-addons-contrib.expandablenavigation) | `@backstage/plugin-techdocs-module-addons-contrib` | Allows TechDocs users to expand or collapse the entire TechDocs main navigation, and keeps the user's preferred state between documentation sites. |
-| [``](https://backstage.io/docs/reference/plugin-techdocs-module-addons-contrib.reportissue) | `@backstage/plugin-techdocs-module-addons-contrib` | Allows TechDocs users to select a portion of text on a TechDocs page and open an issue against the repository that contains the documentation, populating the issue description with the selected text according to a configurable template. |
-| [``](https://backstage.io/docs/reference/plugin-techdocs-module-addons-contrib.textsize) | `@backstage/plugin-techdocs-module-addons-contrib` | This TechDocs addon allows users to customize text size on documentation pages, they can select how much they want to increase or decrease the font size via slider or buttons. The default value for font size is 100% and this setting is kept in the browser's local storage whenever it is changed. |
-| [``](https://backstage.io/docs/reference/plugin-techdocs-module-addons-contrib.lightbox) | `@backstage/plugin-techdocs-module-addons-contrib` | This TechDocs addon allows users to open images in a light-box on documentation pages, they can navigate between images if there are several on one page. The image size of the light-box image is the same as the image size on the document page. |
+| Addon | Package/Plugin | Description |
+| ---------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| [``](https://backstage.io/docs/reference/plugin-techdocs-module-addons-contrib.expandablenavigation) | `@backstage/plugin-techdocs-module-addons-contrib` | Allows TechDocs users to expand or collapse the entire TechDocs main navigation, and keeps the user's preferred state between documentation sites. |
+| [``](https://backstage.io/docs/reference/plugin-techdocs-module-addons-contrib.reportissue) | `@backstage/plugin-techdocs-module-addons-contrib` | Allows TechDocs users to select a portion of text on a TechDocs page and open an issue against the repository that contains the documentation, populating the issue description with the selected text according to a configurable template. |
+| [``](https://backstage.io/docs/reference/plugin-techdocs-module-addons-contrib.textsize) | `@backstage/plugin-techdocs-module-addons-contrib` | This TechDocs addon allows users to customize text size on documentation pages, they can select how much they want to increase or decrease the font size via slider or buttons. The default value for font size is 100% and this setting is kept in the browser's local storage whenever it is changed. |
+| [``](https://backstage.io/docs/reference/plugin-techdocs-module-addons-contrib.lightbox) | `@backstage/plugin-techdocs-module-addons-contrib` | This TechDocs addon allows users to open images in a light-box on documentation pages, they can navigate between images if there are several on one page. The image size of the light-box image is the same as the image size on the document page. When clicking on the zoom icon it zooms the image to fit in the screen (similar to `background-size: contain`). |
Got an Addon to contribute? Feel free to add a row above!
diff --git a/plugins/techdocs-module-addons-contrib/src/LigthBox/LightBox.tsx b/plugins/techdocs-module-addons-contrib/src/LigthBox/LightBox.tsx
index b74c2f9659..38269e6245 100644
--- a/plugins/techdocs-module-addons-contrib/src/LigthBox/LightBox.tsx
+++ b/plugins/techdocs-module-addons-contrib/src/LigthBox/LightBox.tsx
@@ -17,7 +17,7 @@
import { useEffect } from 'react';
import { useShadowRootElements } from '@backstage/plugin-techdocs-react';
// @ts-ignore
-import PhotoSwipeLightbox, { DataSource } from 'photoswipe/lightbox';
+import PhotoSwipeLightbox, { DataSource, ZoomLevel } from 'photoswipe/lightbox';
import PhotoSwipe from 'photoswipe';
import 'photoswipe/style.css';
import './lightbox.css';
@@ -30,6 +30,21 @@ export const LightBoxAddon = () => {
let lightbox = new PhotoSwipeLightbox({
pswpModule: PhotoSwipe,
+ initialZoomLevel: 1,
+ secondaryZoomLevel: (zoomLevelObject: ZoomLevel) => {
+ // photoswipe/lightbox won't zoom the image further then the given width and height.
+ // therefore we need to calculate the zoom factor needed to fit the complete image in the viewport manually.
+ const imageWidth = zoomLevelObject.elementSize.x;
+ const imageHeight = zoomLevelObject.elementSize.y;
+ const viewportWidth = zoomLevelObject.panAreaSize.x;
+ const viewportHeight = zoomLevelObject.panAreaSize.y;
+
+ const widthScale = viewportWidth / imageWidth;
+ const heightScale = viewportHeight / imageHeight;
+
+ const scaleFactor = Math.min(widthScale, heightScale);
+ return scaleFactor;
+ },
wheelToZoom: true,
arrowPrevSVG:
'',
@@ -37,8 +52,9 @@ export const LightBoxAddon = () => {
'',
closeSVG:
'',
- zoomSVG:
- '',
+ zoomSVG: ``,
});
images.forEach((image, index) => {
diff --git a/plugins/techdocs-module-addons-contrib/src/LigthBox/lightbox.css b/plugins/techdocs-module-addons-contrib/src/LigthBox/lightbox.css
index 3371d0fa53..c864699bed 100644
--- a/plugins/techdocs-module-addons-contrib/src/LigthBox/lightbox.css
+++ b/plugins/techdocs-module-addons-contrib/src/LigthBox/lightbox.css
@@ -9,3 +9,13 @@
.pswp__img {
cursor: pointer !important;
}
+
+/* hide "-" icon path */
+.pswp--zoomed-allowed #photoswipe-zoom-icon-zoomout-path {
+ display: none;
+}
+
+/* hide "+" path and show "-" */
+.pswp--zoomed-in #photoswipe-zoom-icon-zoomin-path {
+ display: none;
+}