Skip to content

Commit

Permalink
Enable full-screen viewing of images upon click (#1587)
Browse files Browse the repository at this point in the history
Co-authored-by: Kris Stern <[email protected]>
  • Loading branch information
sridamul and krisstern authored Feb 16, 2024
1 parent 0d34471 commit acaf240
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
41 changes: 39 additions & 2 deletions plugins/plugin-site/src/components/PluginWikiContent.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,46 @@
import React from 'react';
import React, {useState} from 'react';
import PropTypes from 'prop-types';
import {lightbox} from './PluginWikiContent.module.css';

const PluginWikiContent = ({wiki}) => {
const [lightboxImage, setLightboxImage] = useState(null);

const handleClick = (event) => {
// Find the parent <a> tag with target="_blank"
let parentNode = event.target.parentNode;

while (parentNode && parentNode.tagName !== 'A') {
parentNode = parentNode.parentNode;
}

if (
parentNode &&
parentNode.tagName === 'A' &&
parentNode.getAttribute('target') === '_blank'
) {
// Prevent the default behavior of the anchor tag from redirecting to the GitHub page
event.preventDefault();
const imgSrc = parentNode.querySelector('img').getAttribute('src');
setLightboxImage(imgSrc);
}
};

const closeLightbox = () => {
setLightboxImage(null);
};

if (wiki?.childHtmlRehype) {
return <div className="content" dangerouslySetInnerHTML={{__html: wiki.childHtmlRehype.html}} />;
const html = wiki.childHtmlRehype.html;
return (
<div className="content" onClick={handleClick}>
<div dangerouslySetInnerHTML={{__html: html}} />
{lightboxImage && (
<div className={lightbox} onClick={closeLightbox}>
<img src={lightboxImage} alt="Lightbox" />
</div>
)}
</div>
);
}
if (!wiki) {
return (<div className="content">No documentation available</div>);
Expand Down
22 changes: 22 additions & 0 deletions plugins/plugin-site/src/components/PluginWikiContent.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
.lightbox {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
justify-content: center;
align-items: center;
z-index: 9999;
}

.lightbox img {
max-width: 90%;
max-height: 90%;
box-shadow: 0 0 20px rgba(0, 0, 0, 0.5);
}

.lightbox img:hover {
cursor: pointer;
}

0 comments on commit acaf240

Please sign in to comment.