zoom feature displays original images at native size
This commit is contained in:
parent
f6e9b4393a
commit
6f6dea204e
@ -20,6 +20,7 @@ import {
|
|||||||
getVibrant,
|
getVibrant,
|
||||||
getHelmetSafeBodyStyle,
|
getHelmetSafeBodyStyle,
|
||||||
hasName,
|
hasName,
|
||||||
|
getCanonicalSize,
|
||||||
} from "../../utils";
|
} from "../../utils";
|
||||||
import MetadataItem from "./MetadataItem";
|
import MetadataItem from "./MetadataItem";
|
||||||
|
|
||||||
@ -35,7 +36,7 @@ const logKeyShortcut = (keyCode) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const GalleryImage = ({ data, pageContext }) => {
|
const GalleryImage = ({ data, pageContext }) => {
|
||||||
const image = data.allFile.edges[0].node;
|
const image = data.file;
|
||||||
const ar = getAspectRatio(image);
|
const ar = getAspectRatio(image);
|
||||||
|
|
||||||
const [zoom, setZoom] = useState(false);
|
const [zoom, setZoom] = useState(false);
|
||||||
@ -72,13 +73,13 @@ const GalleryImage = ({ data, pageContext }) => {
|
|||||||
|
|
||||||
const name = getName(image);
|
const name = getName(image);
|
||||||
const { meta, dateTaken: dt } = getMeta(image);
|
const { meta, dateTaken: dt } = getMeta(image);
|
||||||
// const locationString = meta.City;
|
|
||||||
let locationString;
|
let locationString;
|
||||||
if (meta.City || meta.State || meta.Location) {
|
if (meta.City || meta.State || meta.Location) {
|
||||||
const location = [meta.Location, meta.City, meta.State].filter(Boolean);
|
const location = [meta.Location, meta.City, meta.State].filter(Boolean);
|
||||||
locationString = location.join(", ");
|
locationString = location.join(", ");
|
||||||
}
|
}
|
||||||
const vibrant = getVibrant(image, true);
|
const vibrant = getVibrant(image, true);
|
||||||
|
const canonicalSize = getCanonicalSize(image);
|
||||||
|
|
||||||
const orientationClasses =
|
const orientationClasses =
|
||||||
ar > 1
|
ar > 1
|
||||||
@ -140,29 +141,33 @@ const GalleryImage = ({ data, pageContext }) => {
|
|||||||
</nav>
|
</nav>
|
||||||
<div className={classnames("flex", orientationClasses)}>
|
<div className={classnames("flex", orientationClasses)}>
|
||||||
<div
|
<div
|
||||||
className="flex-grow-0 mb-2 overflow-hidden"
|
className={classnames(
|
||||||
|
zoom ? "cursor-zoom-out" : "cursor-zoom-in",
|
||||||
|
"mb-2"
|
||||||
|
)}
|
||||||
|
onClick={() => setZoom((_zoom) => !_zoom)}
|
||||||
style={{
|
style={{
|
||||||
maxWidth: zoom
|
maxWidth: `calc(max(calc(100vh - ${verticalPad}), 500px) * ${ar})`,
|
||||||
? "unset"
|
|
||||||
: `calc(max(calc(100vh - ${verticalPad}), 500px) * ${ar})`,
|
|
||||||
width: zoom
|
|
||||||
? `max(calc(100vw - 16px), calc(100vh * ${ar}))`
|
|
||||||
: "unset",
|
|
||||||
// minHeight: zoom ? "100vh" : "unset",
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
{zoom ? (
|
||||||
|
<img
|
||||||
|
alt={name}
|
||||||
|
src={image.publicURL}
|
||||||
|
style={{
|
||||||
|
maxWidth: "unset",
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
) : (
|
||||||
<GatsbyImage
|
<GatsbyImage
|
||||||
alt={name}
|
alt={name}
|
||||||
className={classnames(
|
className="border-4 border-vibrant"
|
||||||
"border-4 border-vibrant",
|
|
||||||
zoom ? "cursor-zoom-out" : "cursor-zoom-in"
|
|
||||||
)}
|
|
||||||
image={getImage(image)}
|
image={getImage(image)}
|
||||||
key={image.base}
|
key={image.base}
|
||||||
loading="eager"
|
loading="eager"
|
||||||
objectFit="contain"
|
objectFit="contain"
|
||||||
onClick={() => setZoom((_zoom) => !_zoom)}
|
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
className={classnames(
|
className={classnames(
|
||||||
@ -259,14 +264,7 @@ const GalleryImage = ({ data, pageContext }) => {
|
|||||||
|
|
||||||
export const query = graphql`
|
export const query = graphql`
|
||||||
query GalleryImage($imageFilename: String) {
|
query GalleryImage($imageFilename: String) {
|
||||||
allFile(
|
file(base: { eq: $imageFilename }) {
|
||||||
filter: {
|
|
||||||
sourceInstanceName: { eq: "gallery" }
|
|
||||||
base: { eq: $imageFilename }
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
edges {
|
|
||||||
node {
|
|
||||||
base
|
base
|
||||||
publicURL
|
publicURL
|
||||||
childImageSharp {
|
childImageSharp {
|
||||||
@ -275,10 +273,7 @@ export const query = graphql`
|
|||||||
}
|
}
|
||||||
gatsbyImageData(
|
gatsbyImageData(
|
||||||
layout: CONSTRAINED
|
layout: CONSTRAINED
|
||||||
# placeholder: BLURRED
|
|
||||||
placeholder: DOMINANT_COLOR
|
placeholder: DOMINANT_COLOR
|
||||||
# placeholder: TRACED_SVG
|
|
||||||
height: 2160
|
|
||||||
quality: 90
|
quality: 90
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -310,8 +305,6 @@ export const query = graphql`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export default GalleryImage;
|
export default GalleryImage;
|
||||||
|
@ -13,6 +13,11 @@ export const hasName = (image) => Boolean(getMeta(image)?.meta?.ObjectName);
|
|||||||
export const getAspectRatio = (image) =>
|
export const getAspectRatio = (image) =>
|
||||||
image.childImageSharp.fluid.aspectRatio;
|
image.childImageSharp.fluid.aspectRatio;
|
||||||
|
|
||||||
|
export const getCanonicalSize = (image) => ({
|
||||||
|
height: image.childImageSharp.gatsbyImageData.height,
|
||||||
|
width: image.childImageSharp.gatsbyImageData.width,
|
||||||
|
});
|
||||||
|
|
||||||
export const getRgba = (palette, alpha) =>
|
export const getRgba = (palette, alpha) =>
|
||||||
`rgba(${palette[0]}, ${palette[1]}, ${palette[2]}, ${alpha || 1})`;
|
`rgba(${palette[0]}, ${palette[1]}, ${palette[2]}, ${alpha || 1})`;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user