-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
196 additions
and
92 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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,52 @@ | ||
'use client'; | ||
|
||
import {MutableRefObject} from 'react'; | ||
import clsx from 'clsx'; | ||
import {Gallery as PSGallery, Item, GalleryProps} from 'react-photoswipe-gallery'; | ||
import 'photoswipe/dist/photoswipe.css'; | ||
import useNetworkSpeed from '@/lib/shared/useNetworkSpeed'; | ||
import config from './config'; | ||
import GalleryItem from './GalleryItem'; | ||
|
||
const containerCn = clsx('flex', 'flex-wrap', 'gap-4', 'justify-center'); | ||
|
||
const photoSwipeOptions: GalleryProps['options'] = { | ||
zoom: false, | ||
bgOpacity: 0.9, | ||
}; | ||
|
||
/** | ||
* @returns React component. | ||
*/ | ||
export default function Gallery() { | ||
const [, isFast] = useNetworkSpeed(); | ||
|
||
return ( | ||
<div className={containerCn}> | ||
<PSGallery options={photoSwipeOptions}> | ||
{config.map(({src, lowQualitySrc, dimensions: {width, height}, blurDataURL}) => { | ||
const computedSrc = isFast ? src : lowQualitySrc; | ||
return ( | ||
<Item | ||
original={computedSrc} | ||
thumbnail={computedSrc} | ||
alt="" | ||
width={width} | ||
height={height} | ||
key={computedSrc} | ||
> | ||
{({open, ref}) => ( | ||
<GalleryItem | ||
open={open} | ||
ref={ref as MutableRefObject<HTMLImageElement>} | ||
blurDataURL={blurDataURL} | ||
src={computedSrc} | ||
/> | ||
)} | ||
</Item> | ||
); | ||
})} | ||
</PSGallery> | ||
</div> | ||
); | ||
} |
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,77 @@ | ||
import {MouseEvent} from 'react'; | ||
import clsx from 'clsx'; | ||
import Image from 'next/image'; | ||
import {forwardRef} from 'react'; | ||
import {useHotkeys} from 'react-hotkeys-hook'; | ||
import AppearInViewport from '../AppearInViewport/AppearInViewport'; | ||
|
||
/** | ||
* Props. | ||
*/ | ||
type GalleryItemProps = { | ||
src: string; | ||
blurDataURL: string; | ||
open: (e: MouseEvent) => void; | ||
}; | ||
|
||
const imgCn = clsx('rounded-md', 'overflow-hidden'); | ||
const overflowCn = clsx( | ||
'cursor-pointer', | ||
'relative', | ||
'after:absolute', | ||
'after:content-[""]', | ||
'after:w-full', | ||
'after:h-full', | ||
'after:top-0', | ||
'after:left-0', | ||
'after:bg-[radial-gradient(circle,_var(--tw-gradient-stops))] from-white to-transparent', | ||
'after:transition-opacity', | ||
'after:duration-300', | ||
'after:ease-out', | ||
'after:opacity-0', | ||
'hover:after:opacity-20', | ||
'transition-transform', | ||
'duration-500', | ||
'ease-out', | ||
'hover:translate-y-1', | ||
'rounded-md', | ||
'focus-ring', | ||
); | ||
|
||
/** | ||
* @returns React component. | ||
*/ | ||
const GalleryItem = forwardRef<HTMLImageElement, GalleryItemProps>(function GalleryItem( | ||
{open, src, blurDataURL}, | ||
ref, | ||
) { | ||
const hotkeysRef = useHotkeys<HTMLDivElement>(['enter', 'space'], open as any, { | ||
preventDefault: true, | ||
}); | ||
|
||
return ( | ||
<AppearInViewport> | ||
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events */} | ||
<div | ||
className={overflowCn} | ||
style={{height: 300, width: 400}} | ||
onClick={open} | ||
tabIndex={0} | ||
role="link" | ||
ref={hotkeysRef} | ||
> | ||
<Image | ||
className={imgCn} | ||
ref={ref} | ||
src={src} | ||
placeholder="blur" | ||
blurDataURL={blurDataURL} | ||
alt="" | ||
fill | ||
/> | ||
</div> | ||
</AppearInViewport> | ||
); | ||
}); | ||
|
||
export default GalleryItem; |
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,28 @@ | ||
/** | ||
* Gallery images configuration. | ||
*/ | ||
const config = [ | ||
{fileName: 'gallery.0.jpg', dimensions: {width: 920, height: 600}}, | ||
{fileName: 'gallery.1.jpg', dimensions: {width: 920, height: 600}}, | ||
{fileName: 'gallery.2.jpg', dimensions: {width: 920, height: 600}}, | ||
{fileName: 'gallery.3.jpg', dimensions: {width: 920, height: 600}}, | ||
{fileName: 'gallery.4.jpg', dimensions: {width: 920, height: 600}}, | ||
{fileName: 'gallery.5.jpg', dimensions: {width: 920, height: 600}}, | ||
{fileName: 'gallery.6.jpg', dimensions: {width: 920, height: 600}}, | ||
{fileName: 'gallery.7.jpg', dimensions: {width: 920, height: 600}}, | ||
{fileName: 'gallery.8.jpg', dimensions: {width: 920, height: 600}}, | ||
{fileName: 'gallery.9.jpg', dimensions: {width: 920, height: 600}}, | ||
{fileName: 'gallery.10.jpg', dimensions: {width: 920, height: 600}}, | ||
{fileName: 'gallery.11.jpg', dimensions: {width: 920, height: 600}}, | ||
{fileName: 'gallery.12.jpg', dimensions: {width: 920, height: 600}}, | ||
{fileName: 'gallery.13.jpg', dimensions: {width: 920, height: 600}}, | ||
{fileName: 'gallery.14.jpg', dimensions: {width: 920, height: 600}}, | ||
{fileName: 'gallery.15.jpg', dimensions: {width: 920, height: 600}}, | ||
] as const; | ||
|
||
export default config.map(({fileName, dimensions}) => ({ | ||
dimensions, | ||
src: `/images/${fileName}`, | ||
blurDataURL: `/images/blured/${fileName}`, | ||
lowQualitySrc: `/images/low-quality/${fileName}`, | ||
})); |
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
'use client'; | ||
|
||
import {useEffect, useState} from 'react'; | ||
import {isServer} from '@/utils/isServer'; | ||
|
||
|
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,15 @@ | ||
import {isServer} from './isServer'; | ||
|
||
const query = '(prefers-reduced-motion: reduce)'; | ||
|
||
/** | ||
* @returns True if the user has requested reduced motion. | ||
*/ | ||
export default function isPrefersReducedMotion() { | ||
if (isServer()) { | ||
return false; | ||
} | ||
|
||
const mediaQueryList = window.matchMedia(query); | ||
return mediaQueryList.matches; | ||
} |