Skip to content

Commit

Permalink
chore: added zoom in images and other changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Franqsanz committed Nov 29, 2023
1 parent ba63fe8 commit 27d727e
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 16 deletions.
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"chakra-react-select": "4.7.6",
"firebase": "10.5.2",
"framer-motion": "10.16.4",
"medium-zoom": "1.1.0",
"million": "2.6.4",
"nanoid": "5.0.3",
"pako": "2.1.0",
Expand Down
34 changes: 34 additions & 0 deletions src/components/ImageZoom.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import React, { useRef } from 'react';
import { Image, ImageProps } from '@chakra-ui/react';
import mediumZoom, { Zoom, ZoomOptions, ZoomSelector } from 'medium-zoom';

type ImageZoomProps = ImageProps & {
options?: ZoomOptions;
};

export function ImageZoom({ options, ...props }: ImageZoomProps) {
const zoomRef = useRef<Zoom | null>(null);

function getZoom() {
if (zoomRef.current === null) {
zoomRef.current = mediumZoom({
background: '#000000d6',
margin: 70,
});
}

return zoomRef.current;
}

function attachZoom(node: ZoomSelector) {
const zoom = getZoom();

if (node) {
zoom.attach(node);
} else {
zoom.detach();
}
}

return <Image {...props} ref={attachZoom} />;
}
2 changes: 1 addition & 1 deletion src/components/cards/RelatedCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function RelatedCard({
<>
<Box
w='full'
h={{ base: 'auto', md: '245px' }}
h={{ base: 'auto', md: '270px' }}
mx={{ base: 0, md: 2 }}
rounded='xl'
border='1px'
Expand Down
32 changes: 17 additions & 15 deletions src/pages/Book.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { MyTag } from '../components/MyTag';
import { ModalShare } from '../components/ModalShare';
import { MyLink } from '../components/MyLink';
import { BooksSection } from '../components/BooksSection';
import { ImageZoom } from '../components/ImageZoom';

const Categories = lazy(() => import('../components/Categories'));
const MoreBooksAuthors = lazy(
Expand Down Expand Up @@ -130,7 +131,7 @@ export default function Book() {
pb='4'
>
<LazyLoad width={230} height={340} offset={0} threshold={0.99}>
<Image
<ImageZoom
w='230px'
h='340px'
src={data.image.url}
Expand Down Expand Up @@ -334,7 +335,7 @@ export default function Book() {
position='relative'
>
<LazyLoad width={290} height={420} offset={0} threshold={0.99}>
<Image
<ImageZoom
w='290px'
h='420px'
src={data.image.url}
Expand All @@ -346,6 +347,7 @@ export default function Book() {
filter='blur(10px)'
transition='filter 0.5s ease-in-out'
onLoad={handleImageLoad}
zIndex='9999'
/>
</LazyLoad>
</Flex>
Expand Down Expand Up @@ -382,6 +384,7 @@ export default function Book() {
}}
>
<Box
w='270px'
p='1.25rem 2px 2px 2px'
h='24'
fontSize='2xl'
Expand All @@ -392,20 +395,19 @@ export default function Book() {
Categorías
<Box mt='2' borderBottom='1px'></Box>
</Box>
<Center h='80%'>
<Suspense
fallback={
<Center>
<Spinner size='lg' />
</Center>
}
>
<Flex direction='column' flexWrap='wrap'>
<Categories />
</Flex>
</Suspense>
</Center>
<Suspense
fallback={
<Center h='500px'>
<Spinner size='lg' />
</Center>
}
>
<Flex direction='column' flexWrap='wrap'>
<Categories />
</Flex>
</Suspense>
<Box
w='270px'
position='sticky'
h='7'
bottom='0'
Expand Down

1 comment on commit 27d727e

@vercel
Copy link

@vercel vercel bot commented on 27d727e Nov 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

xbu – ./

xbu-franqsanz.vercel.app
xbu-git-main-franqsanz.vercel.app
xbu.vercel.app

Please sign in to comment.