Skip to content

Commit

Permalink
Add medium type zoom to images (#8)
Browse files Browse the repository at this point in the history
* Add medium-zoom package

* Add ImageZoom and ThemedImageZoom components

* Use the new components

* Reformat
  • Loading branch information
bjsowa authored Apr 2, 2024
1 parent e5c8e32 commit 0e72870
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 23 deletions.
43 changes: 22 additions & 21 deletions docs/leo-rover/00-specification.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ sidebar_label: Specification
sidebar_position: 1
---

import ThemedImage from '@theme/ThemedImage';
import useBaseUrl from '@docusaurus/useBaseUrl';
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import Admonition from '@theme/Admonition';
import FlexTable from '@site/src/components/FlexTable';
import FlexTableItem from '@site/src/components/FlexTableItem';
import ImageZoom from '@site/src/components/ImageZoom';
import ThemedImageZoom from '@site/src/components/ThemedImageZoom';

# Leo Rover specification

<center>
<img
<ImageZoom
loading="eager"
src="/img/website_images/leo-rover.webp"
alt="Leo Rover 1.8"
Expand Down Expand Up @@ -44,7 +45,7 @@ import FlexTableItem from '@site/src/components/FlexTableItem';
### Dimensions

<center>
<ThemedImage
<ThemedImageZoom
alt="Leo Rover Dimensions"
sources={{
light: useBaseUrl('/img/docs_images/leo-rover_dimensions-black.webp'),
Expand Down Expand Up @@ -164,18 +165,18 @@ WiFi 2.4 or 5 GHz on internal RPi antennas for connectivity
<Tabs groupId="leo-rover-version">
<TabItem value='leo-1.8' label='Leo Rover v1.8'>
<center>
<ThemedImage
<ThemedImageZoom
alt="Leo Rover 1.8 hardware diagram"
sources={{
light: useBaseUrl('/img/docs_images/leo-rover-v1.8_hardware-diagram_black.webp'),
dark: useBaseUrl('/img/docs_images/leo-rover-v1.8_hardware-diagram_white.webp'),
}}
width='800px'
height='auto'
style={{
aspectRatio:'800/484',
objectFit: 'contain',
}}
light: useBaseUrl('/img/docs_images/leo-rover-v1.8_hardware-diagram_black.webp'),
dark: useBaseUrl('/img/docs_images/leo-rover-v1.8_hardware-diagram_white.webp'),
}}
width='800px'
height='auto'
style={{
aspectRatio:'800/484',
objectFit: 'contain',
}}
/>
</center>

Expand All @@ -185,7 +186,7 @@ WiFi 2.4 or 5 GHz on internal RPi antennas for connectivity
together with the Raspberry Pi computer, controls all the Rover's functionalities.

<center>
<img
<ImageZoom
src='/img/docs_images/LeoCore.webp'
alt="LeoCore controller"
width='600'
Expand Down Expand Up @@ -222,12 +223,12 @@ WiFi 2.4 or 5 GHz on internal RPi antennas for connectivity
</TabItem>
<TabItem value='leo-pre1.8' label='Leo Rover < v1.8'>
<center>
<ThemedImage
<ThemedImageZoom
alt="Leo Rover pre1.8 hardware diagram"
sources={{
light: useBaseUrl('/img/docs_images/leo-rover-pre1.8_hardware-diagram_black.webp'),
dark: useBaseUrl('/img/docs_images/leo-rover-pre1.8_hardware-diagram_white.webp'),
}}
light: useBaseUrl('/img/docs_images/leo-rover-pre1.8_hardware-diagram_black.webp'),
dark: useBaseUrl('/img/docs_images/leo-rover-pre1.8_hardware-diagram_white.webp'),
}}
width='800px'
height='auto'
style={{
Expand All @@ -245,7 +246,7 @@ By default Leo Rover uses standard [WEIPU](https://www.weipuconnector.com/) SP13
for connecting battery, Main Electronics Box and other possible addons.

<center>
<ThemedImage
<ThemedImageZoom
alt="Weipu SP13-3 pinout"
sources={{
light: useBaseUrl('/img/docs_images/weipu_SP13-3_pinout_black.webp'),
Expand All @@ -271,7 +272,7 @@ for connecting battery, Main Electronics Box and other possible addons.
<Tabs groupId="leo-rover-version">
<TabItem value="leo-1.8" label="Leo Rover v1.8">
<center>
<ThemedImage
<ThemedImageZoom
alt="Leo Rover 1.8 software diagram"
sources={{
light: useBaseUrl(
Expand All @@ -292,7 +293,7 @@ for connecting battery, Main Electronics Box and other possible addons.
</TabItem>
<TabItem value="leo-pre1.8" label="Leo Rover < v1.8">
<center>
<ThemedImage
<ThemedImageZoom
alt="Leo Rover pre1.8 software diagram"
sources={{
light: useBaseUrl(
Expand Down
24 changes: 22 additions & 2 deletions docs/leo-rover/01-documentation/01-getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ sidebar_label: Getting started
sidebar_position: 1
---

import useBaseUrl from '@docusaurus/useBaseUrl';
import ImageZoom from '@site/src/components/ImageZoom';
import ThemedImageZoom from '@site/src/components/ThemedImageZoom';

# Getting started

## Before you power on the Rover
Expand All @@ -12,7 +16,15 @@ sidebar_position: 1

Connect the mating pair of the 3-pin connectors: the battery and the converter located on the opposite side of the Rover. Then, fit the battery cables inside the Rover's back-rib and slide the battery on back-left quarter of the Rover's body. Tighten the 3x M5 screws using the provided screwdriver.

![leo-rover-allen](/img/leo-battery-allen.jpg)
<center>
<ImageZoom
loading="eager"
src="/img/leo-battery-allen.jpg"
alt="Leo Battery allen"
width="400"
height="auto"
/>
</center>

## Operation & maintenance

Expand Down Expand Up @@ -42,7 +54,15 @@ To access the Web User Interface, open your web browser and type in the address
http://10.0.0.1/
```

![leo-ui](/img/leo-ui.jpg)
<center>
<ImageZoom
loading="eager"
src="/img/leo-ui.jpg"
alt="Leo UI"
width="400"
height="auto"
/>
</center>

## Turn off the Rover properly

Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"@docusaurus/preset-classic": "3.1.1",
"@mdx-js/react": "^3.0.1",
"clsx": "^2.1.0",
"medium-zoom": "^1.1.0",
"prism-react-renderer": "^2.3.1",
"react": "^18.0.0",
"react-dom": "^18.0.0"
Expand Down
31 changes: 31 additions & 0 deletions src/components/ImageZoom.tsx
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} />;
}
19 changes: 19 additions & 0 deletions src/components/ThemedImageZoom.tsx
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>
);
}
7 changes: 7 additions & 0 deletions src/css/custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
--ifm-color-primary-lightest: #f59b3b;
--ifm-code-font-size: 95%;
--docusaurus-highlighted-code-line-bg: rgba(0, 0, 0, 0.1);
--plugin-image-zoom-background-color: #fff;
}

/* For readability concerns, you should choose a lighter palette in dark mode. */
Expand All @@ -27,6 +28,7 @@
--ifm-color-primary-lighter: #e3b27f;
--ifm-color-primary-lightest: #e8c197;
--docusaurus-highlighted-code-line-bg: rgba(0, 0, 0, 0.3);
--plugin-image-zoom-background-color: var(--ifm-background-color);
}

.header-github-link::before {
Expand All @@ -42,4 +44,9 @@

.header-github-link:hover::before {
background-color: var(--ifm-navbar-link-hover-color);
}

.medium-zoom-overlay,
.medium-zoom-image--opened {
z-index: 999;
}
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 0e72870

Please sign in to comment.