Skip to content

Commit

Permalink
feat: set mask color of image preview to be black #000 in dark mode (w…
Browse files Browse the repository at this point in the history
  • Loading branch information
xalanq committed Mar 12, 2024
1 parent 22487ef commit 705735b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/short-wolves-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rspress/plugin-medium-zoom": patch
---

feat: set mask color of image preview to be black #000 in dark mode (#730)
13 changes: 10 additions & 3 deletions packages/plugin-medium-zoom/src/components/MediumZoom.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { useLocation } from '@rspress/runtime';
import mediumZoom, { ZoomOptions } from 'medium-zoom';
import mediumZoom, { Zoom, ZoomOptions } from 'medium-zoom';
import { useEffect } from 'react';
import './MediumZoom.css';

Expand All @@ -13,10 +13,17 @@ export default function MediumZoom(props: Props) {
const { selector = '.rspress-doc img', options = {} } = props;

useEffect(() => {
setTimeout(() => {
let zoom: Zoom | undefined;
const timeout = setTimeout(() => {
const images = document.querySelectorAll(selector);
mediumZoom(images, options);
zoom = mediumZoom(images, { ...options, background: 'var(--rp-c-bg)' });
}, 100);
return () => {
clearTimeout(timeout);
zoom?.detach();
zoom?.close();
};
}, [pathname]);

return null;
}

0 comments on commit 705735b

Please sign in to comment.