Skip to content

Commit

Permalink
UI: Expose more props to Image Zoom
Browse files Browse the repository at this point in the history
  • Loading branch information
fuma-nama committed Sep 12, 2024
1 parent b114e87 commit 4cb74d5
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/neat-needles-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'fumadocs-ui': patch
---

Expose more props to Image Zoom
16 changes: 10 additions & 6 deletions apps/docs/content/docs/ui/components/image-zoom.mdx
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
---
title: Zoom Image
title: Zoomable Image
description: Allow zoom-in images in your documentation
preview: zoom-image
---

## Usage

Add it to your MDX components.
Replace `img` with `ImageZoom` in your MDX components.

> A default `sizes` property will be defined if not specified
```tsx
```tsx title="page.tsx"
import { ImageZoom } from 'fumadocs-ui/components/image-zoom';
import defaultMdxComponents from 'fumadocs-ui/mdx';

const components = {
img: (props) => <ImageZoom {...props} />,
};
<MDX
components={{
...defaultMdxComponents,
img: (props) => <ImageZoom {...(props as any)} />,
}}
/>;
```
9 changes: 8 additions & 1 deletion packages/ui/src/components/image-zoom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import Image, { type ImageProps } from 'next/image';
import { type ImgHTMLAttributes } from 'react';
import Zoom from 'react-medium-image-zoom';
import Zoom, { type UncontrolledProps } from 'react-medium-image-zoom';
import { defaultImageSizes } from '@/utils/shared';
import '../../dist/image-zoom.css';

Expand All @@ -11,6 +11,11 @@ export type ImageZoomProps = ImageProps & {
* Image props when zoom in
*/
zoomInProps?: ImgHTMLAttributes<HTMLImageElement>;

/**
* Props for `react-medium-image-zoom`
*/
rmiz?: UncontrolledProps;
};

function getImageSrc(src: ImageProps['src']): string {
Expand All @@ -22,12 +27,14 @@ function getImageSrc(src: ImageProps['src']): string {
export function ImageZoom({
zoomInProps,
children,
rmiz,
...props
}: ImageZoomProps): React.ReactElement {
return (
<Zoom
zoomMargin={20}
wrapElement="span"
{...rmiz}
zoomImg={{
src: getImageSrc(props.src),
sizes: undefined,
Expand Down

0 comments on commit 4cb74d5

Please sign in to comment.