Skip to content

Commit 85a7e47

Browse files
Fix broken image zoom, switch to pure CSS version
Image zoom broke with the recent Docusaurus update. This change fixes image zoom and also simplifies it by moving to a CSS only version.
1 parent 135bf39 commit 85a7e47

File tree

2 files changed

+33
-28
lines changed

2 files changed

+33
-28
lines changed

components/image.tsx

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,17 @@
1-
import useBaseUrl from '@docusaurus/useBaseUrl'
2-
import React, {useState} from 'react'
1+
import React from 'react'
32

43
export default function Image ({alt, src}) {
5-
const [isActive, setIsActive] = useState(false)
6-
74
return (
8-
<div style={{marginBottom: '20px', textAlign: 'center'}}>
5+
<div className='ZoomableImage'>
96
<img
7+
className='Thumbnail'
108
alt={alt}
11-
className='ZoomableImage'
12-
onClick={() => setIsActive(true)}
13-
src={useBaseUrl(src)}
9+
src={src}
10+
tabIndex={0}
1411
/>
15-
{isActive && (
16-
<>
17-
<div
18-
className='ImageOverlayBackdrop'
19-
onClick={() => setIsActive(false)}
20-
/>
21-
<img
22-
alt={alt}
23-
className='ImageOverlay'
24-
onClick={() => setIsActive(false)}
25-
src={useBaseUrl(src)}
26-
/>
27-
</>
28-
)}
29-
<div
30-
style={{
31-
fontStyle: 'italic',
32-
fontSize: '75%'
33-
}}
34-
>{alt}</div>
12+
<div className='ImageOverlayBackdrop' />
13+
<img alt={alt} className='ImageOverlay' src={src} />
14+
<div className='AltText'>{alt}</div>
3515
</div>
3616
)
3717
}

custom.css

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ body {
5252
}
5353

5454
.ZoomableImage {
55+
margin-bottom: 20px;
56+
text-align: center;
57+
}
58+
59+
.ZoomableImage > .Thumbnail {
5560
box-shadow: 0 0 15px rgba(24, 96, 141, 0.2);
5661
margin: 15px 0 0;
5762
object-fit: contain;
@@ -60,7 +65,13 @@ body {
6065
cursor: zoom-in;
6166
}
6267

68+
.ZoomableImage > .AltText {
69+
font-style: italic;
70+
font-size: 75%;
71+
}
72+
6373
.ImageOverlayBackdrop {
74+
display: none;
6475
cursor: zoom-out;
6576
position: fixed;
6677
top: 0;
@@ -72,6 +83,7 @@ body {
7283
}
7384

7485
.ImageOverlay {
86+
display: none;
7587
box-shadow: 0 0 15px rgba(24, 96, 141, 0.2);
7688
cursor: zoom-out;
7789
position: fixed;
@@ -83,6 +95,19 @@ body {
8395
transform: translate(-50%, -50%);
8496
}
8597

98+
.ZoomableImage:focus-within {
99+
border: 1px solid red;
100+
}
101+
102+
.ZoomableImage:focus-within > .ImageOverlayBackdrop {
103+
display: block;
104+
}
105+
106+
.ZoomableImage:focus-within > .ImageOverlay {
107+
display: block;
108+
}
109+
110+
86111
/* Github link taken from https://github.com/facebook/docusaurus/blob/master/website/src/css/custom.css */
87112
.header-github-link:hover {
88113
opacity: 0.6;

0 commit comments

Comments
 (0)