update photo gallery layout strategy and add a few ultrawide pics
This commit is contained in:
parent
50e84332bd
commit
9cc0da8543
BIN
data/gallery/DSC08495.jpg
(Stored with Git LFS)
Normal file
BIN
data/gallery/DSC08495.jpg
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
data/gallery/DSC08573.jpg
(Stored with Git LFS)
Normal file
BIN
data/gallery/DSC08573.jpg
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
data/gallery/DSC08588.jpg
(Stored with Git LFS)
Normal file
BIN
data/gallery/DSC08588.jpg
(Stored with Git LFS)
Normal file
Binary file not shown.
@ -7,10 +7,13 @@ import useBreakpoint from "use-breakpoint";
|
|||||||
|
|
||||||
import themeBreakpoints from "../breakpoints";
|
import themeBreakpoints from "../breakpoints";
|
||||||
|
|
||||||
const MasonryGallery = ({ images, itemsPerRow: itemsPerRowByBreakpoint }) => {
|
const MasonryGallery = ({
|
||||||
|
images,
|
||||||
|
aspectsByBreakpoint: aspectTargetsByBreakpoint,
|
||||||
|
}) => {
|
||||||
const breakpoints = React.useMemo(
|
const breakpoints = React.useMemo(
|
||||||
() => R.pick(R.keys(itemsPerRowByBreakpoint), themeBreakpoints),
|
() => R.pick(R.keys(aspectTargetsByBreakpoint), themeBreakpoints),
|
||||||
[itemsPerRowByBreakpoint]
|
[aspectTargetsByBreakpoint]
|
||||||
);
|
);
|
||||||
|
|
||||||
const { breakpoint } = useBreakpoint(breakpoints, "sm");
|
const { breakpoint } = useBreakpoint(breakpoints, "sm");
|
||||||
@ -19,54 +22,78 @@ const MasonryGallery = ({ images, itemsPerRow: itemsPerRowByBreakpoint }) => {
|
|||||||
() => R.map(getAspectRatio, images),
|
() => R.map(getAspectRatio, images),
|
||||||
[images]
|
[images]
|
||||||
);
|
);
|
||||||
const rowAspectRatioSumsByBreakpoint = React.useMemo(
|
|
||||||
|
const rowsByBreakpoint = React.useMemo(
|
||||||
() =>
|
() =>
|
||||||
R.map(R.pipe(R.splitEvery(R.__, aspectRatios), R.map(R.sum)))(
|
R.map(
|
||||||
itemsPerRowByBreakpoint
|
R.pipe(
|
||||||
),
|
(targetAspect) =>
|
||||||
[aspectRatios, itemsPerRowByBreakpoint]
|
R.reduce(
|
||||||
|
(acc, currentAspect) => {
|
||||||
|
const currentRow = acc.pop();
|
||||||
|
if (currentRow.aspect + currentAspect > targetAspect) {
|
||||||
|
return [
|
||||||
|
...acc,
|
||||||
|
currentRow,
|
||||||
|
{
|
||||||
|
aspect: currentAspect,
|
||||||
|
images: 1,
|
||||||
|
startIndex: currentRow.startIndex + currentRow.images,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
return [
|
||||||
|
...acc,
|
||||||
|
{
|
||||||
|
aspect: currentRow.aspect + currentAspect,
|
||||||
|
images: currentRow.images + 1,
|
||||||
|
startIndex: currentRow.startIndex,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
},
|
||||||
|
[{ aspect: 0, startIndex: 0, images: 0 }],
|
||||||
|
aspectRatios
|
||||||
|
),
|
||||||
|
R.indexBy(R.prop("startIndex"))
|
||||||
|
)
|
||||||
|
)(aspectTargetsByBreakpoint),
|
||||||
|
[aspectRatios, aspectTargetsByBreakpoint]
|
||||||
);
|
);
|
||||||
|
|
||||||
const itemsPerRow = itemsPerRowByBreakpoint[breakpoint];
|
const rows = rowsByBreakpoint[breakpoint];
|
||||||
const rowAspectRatioSumsForCurrentBP =
|
|
||||||
rowAspectRatioSumsByBreakpoint[breakpoint];
|
|
||||||
|
|
||||||
|
let cursor = 0;
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="w-full"
|
className="w-full"
|
||||||
style={{
|
style={{
|
||||||
position: "relative",
|
position: "relative",
|
||||||
}}
|
}}
|
||||||
// style={{ maxWidth: minWidth }}
|
|
||||||
>
|
>
|
||||||
{images.map((image, i) => {
|
{images.map((image, i) => {
|
||||||
const rowIndex = Math.floor(i / itemsPerRow);
|
let currentRow = rows[cursor];
|
||||||
const rowAspectRatioSum = rowAspectRatioSumsForCurrentBP[rowIndex];
|
if (rows[i]) {
|
||||||
// const width = ((getAspectRatio(image) / rowAspectRatioSum) * 100).toFixed(10);
|
cursor = i;
|
||||||
|
currentRow = rows[i];
|
||||||
|
}
|
||||||
|
const rowAspectRatioSum = currentRow.aspect;
|
||||||
const ar = getAspectRatio(image);
|
const ar = getAspectRatio(image);
|
||||||
const widthNumber =
|
const widthNumber = ((ar / rowAspectRatioSum) * 100).toFixed(7);
|
||||||
rowAspectRatioSum === ar
|
|
||||||
? // image is only one in row
|
|
||||||
100 / itemsPerRow
|
|
||||||
: // image is one of several in row
|
|
||||||
((ar / rowAspectRatioSum) * 100).toFixed(7);
|
|
||||||
|
|
||||||
const width = `${widthNumber}%`;
|
const width = `${widthNumber}%`;
|
||||||
return (
|
return (
|
||||||
<Link
|
<Link
|
||||||
className="inline-block"
|
className="border border-black inline-block"
|
||||||
key={`${image.base}`}
|
key={`${image.base}`}
|
||||||
state={{ modal: true }}
|
state={{ modal: true }}
|
||||||
style={{
|
style={{
|
||||||
width,
|
width,
|
||||||
// marginLeft: '8px',
|
|
||||||
}}
|
}}
|
||||||
to={`/photogallery/${image.base}`}
|
to={`/photogallery/${image.base}`}
|
||||||
>
|
>
|
||||||
<GatsbyImage
|
<GatsbyImage
|
||||||
alt={getName(image)}
|
alt={getName(image)}
|
||||||
className="w-full"
|
className="w-full"
|
||||||
// style={{ width }}
|
|
||||||
image={getImage(image)}
|
image={getImage(image)}
|
||||||
objectFit="cover"
|
objectFit="cover"
|
||||||
/>
|
/>
|
||||||
|
@ -5,9 +5,6 @@ import { Helmet } from "react-helmet";
|
|||||||
|
|
||||||
import MasonryGallery from "../components/MasonryGallery";
|
import MasonryGallery from "../components/MasonryGallery";
|
||||||
|
|
||||||
// TODO: caption and title more images
|
|
||||||
// TODO: more images
|
|
||||||
|
|
||||||
const GalleryPage = ({ data }) => {
|
const GalleryPage = ({ data }) => {
|
||||||
const images = React.useMemo(
|
const images = React.useMemo(
|
||||||
() => data.allFile.edges.map((edge) => edge.node, [data]),
|
() => data.allFile.edges.map((edge) => edge.node, [data]),
|
||||||
@ -41,18 +38,18 @@ const GalleryPage = ({ data }) => {
|
|||||||
gallery
|
gallery
|
||||||
</Link>
|
</Link>
|
||||||
</nav>
|
</nav>
|
||||||
<div className="bg-black min-h-screen mx-auto 2xl:container">
|
<div className="bg-black min-h-screen mx-auto">
|
||||||
<h1 className="text-5xl mt-0 ml-5 font-serif font-black z-10 relative">
|
<h1 className="text-5xl mt-0 ml-5 font-serif font-black z-10 relative">
|
||||||
Photo Gallery
|
Photo Gallery
|
||||||
</h1>
|
</h1>
|
||||||
<div className="mx-auto">
|
<div className="mx-auto">
|
||||||
<MasonryGallery
|
<MasonryGallery
|
||||||
images={images}
|
images={images}
|
||||||
itemsPerRow={{
|
aspectsByBreakpoint={{
|
||||||
sm: 2,
|
sm: 3.6,
|
||||||
md: 2,
|
md: 4,
|
||||||
lg: 3,
|
lg: 5,
|
||||||
xl: 3,
|
xl: 6.1,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user