-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add medium-zoom package * Add ImageZoom and ThemedImageZoom components * Use the new components * Reformat
- Loading branch information
Showing
7 changed files
with
107 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { useRef, ComponentProps, RefCallback } from 'react'; | ||
import mediumZoom, { Zoom } from 'medium-zoom'; | ||
|
||
export interface ImageZoomProps extends ComponentProps<'img'> {} | ||
|
||
export default function ImageZoom(props: ImageZoomProps): JSX.Element { | ||
const { ...propsRest } = props; | ||
const zoomRef = useRef<Zoom | null>(null); | ||
|
||
function getZoom() { | ||
if (zoomRef.current === null) { | ||
zoomRef.current = mediumZoom({ | ||
background: 'var(--plugin-image-zoom-background-color)', | ||
}); | ||
} | ||
|
||
return zoomRef.current; | ||
} | ||
|
||
const attachZoom: RefCallback<HTMLImageElement> = (node) => { | ||
const zoom = getZoom(); | ||
|
||
if (node) { | ||
zoom.attach(node); | ||
} else { | ||
zoom.detach(); | ||
} | ||
}; | ||
|
||
return <img {...propsRest} ref={attachZoom} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Props as ThemedImageProps } from '@theme/ThemedImage'; | ||
import { ThemedComponent } from '@docusaurus/theme-common'; | ||
import ImageZoom, { ImageZoomProps } from './ImageZoom'; | ||
|
||
export interface ThemedImageZoomProps | ||
extends ThemedImageProps, | ||
ImageZoomProps {} | ||
|
||
export default function ThemedImageZoom(props: ThemedImageZoomProps) { | ||
const { sources, className: parentClassName, ...propsRest } = props; | ||
|
||
return ( | ||
<ThemedComponent className={parentClassName}> | ||
{({ theme, className }) => ( | ||
<ImageZoom src={sources[theme]} className={className} {...propsRest} /> | ||
)} | ||
</ThemedComponent> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6026,6 +6026,11 @@ [email protected]: | |
resolved "https://registry.yarnpkg.com/media-typer/-/media-typer-0.3.0.tgz#8710d7af0aa626f8fffa1ce00168545263255748" | ||
integrity sha512-dq+qelQ9akHpcOl/gUVRTxVIOkAJ1wR3QAvb4RsVjS8oVoFjDGTc679wJYmUmknUF5HwMLOgb5O+a3KxfWapPQ== | ||
|
||
medium-zoom@^1.1.0: | ||
version "1.1.0" | ||
resolved "https://registry.yarnpkg.com/medium-zoom/-/medium-zoom-1.1.0.tgz#6efb6bbda861a02064ee71a2617a8dc4381ecc71" | ||
integrity sha512-ewyDsp7k4InCUp3jRmwHBRFGyjBimKps/AJLjRSox+2q/2H4p/PNpQf+pwONWlJiOudkBXtbdmVbFjqyybfTmQ== | ||
|
||
memfs@^3.1.2, memfs@^3.4.3: | ||
version "3.6.0" | ||
resolved "https://registry.yarnpkg.com/memfs/-/memfs-3.6.0.tgz#d7a2110f86f79dd950a8b6df6d57bc984aa185f6" | ||
|