-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add dialog for mainImage. Re-use code from other image dialog.
- Loading branch information
Showing
8 changed files
with
131 additions
and
64 deletions.
There are no files selected for viewing
File renamed without changes.
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,40 @@ | ||
import { RecipeQueryResult } from "../../../sanity.types"; | ||
import { ImageDialogContent } from "./ImageDialogContent"; | ||
import { Image } from "../Image/Image"; | ||
import { urlForImage } from "@/sanity/lib/utils"; | ||
|
||
export type ImageType = NonNullable< | ||
NonNullable<RecipeQueryResult>["mainImage"] | ||
>; | ||
|
||
const width = 1200; | ||
const height = 800; | ||
|
||
type ImageDialogSingleProps = { | ||
title: string; | ||
description: string; | ||
image: ImageType; | ||
}; | ||
|
||
export const ImageDialogSingle = (props: ImageDialogSingleProps) => { | ||
const { title, description, image } = props; | ||
|
||
const url = | ||
urlForImage(image)?.width(width).height(height).fit("max").dpr(2).url() ?? | ||
""; | ||
|
||
return ( | ||
<ImageDialogContent title={title} description={description}> | ||
<Image | ||
className="pointer-events-none aspect-[3/2] h-full max-h-[90vh] w-full rounded-lg object-cover" | ||
src={url} | ||
width={width} | ||
height={height} | ||
alt={image.alt ?? "Recipe"} | ||
priority={true} | ||
blurDataURL={image?.asset?.metadata?.lqip ?? undefined} | ||
sizes="(max-width: 768px) 100vw, 70vw" | ||
/> | ||
</ImageDialogContent> | ||
); | ||
}; |
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,59 @@ | ||
import { urlForImage } from "@/sanity/lib/utils"; | ||
import { title } from "process"; | ||
import { Image } from "../../Image/Image"; | ||
import { Dialog, DialogTrigger } from "@/components/ui/dialog"; | ||
import { ComponentProps } from "react"; | ||
import { RecipeHeader } from "./RecipeHeader"; | ||
import dynamic from "next/dynamic"; | ||
|
||
const ImageDialogSingle = dynamic(() => | ||
import("@/components/ImageDialog/ImageDialogSingle").then( | ||
(mod) => mod.ImageDialogSingle, | ||
), | ||
); | ||
|
||
export type MainImageProps = { | ||
mainImage: ComponentProps<typeof RecipeHeader>["mainImage"]; | ||
}; | ||
|
||
const mainImageWidth = 1024; | ||
const mainImageHeight = 400; | ||
|
||
export const MainImage = ({ mainImage }: MainImageProps) => { | ||
if (!mainImage) { | ||
return ( | ||
<div className="flex aspect-[16/3] w-full items-center justify-center rounded-lg bg-secondary text-2xl sm:text-7xl"> | ||
🍞🍰🧑🍳 | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<Dialog> | ||
<DialogTrigger> | ||
<Image | ||
className="w-full cursor-zoom-in rounded-lg" | ||
src={ | ||
urlForImage(mainImage) | ||
?.width(mainImageWidth) | ||
.height(mainImageHeight) | ||
.fit("max") | ||
.dpr(2) | ||
.url() ?? "" | ||
} | ||
width={mainImageWidth} | ||
height={mainImageHeight} | ||
alt={mainImage.alt ?? title ?? "Recipe"} | ||
priority={true} | ||
blurDataURL={mainImage?.asset?.metadata?.lqip ?? undefined} | ||
sizes="(max-width: 768px) 100vw, 70vw" | ||
/> | ||
</DialogTrigger> | ||
<ImageDialogSingle | ||
image={mainImage} | ||
title="Main image" | ||
description={mainImage.alt ?? ""} | ||
/> | ||
</Dialog> | ||
); | ||
}; |
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,21 @@ | ||
import { RecipeQueryResult } from "../../../../sanity.types"; | ||
import { TypographyH1 } from "../../Typography/TypographyH1"; | ||
import { MainImage } from "./MainImage"; | ||
|
||
type RQR = NonNullable<RecipeQueryResult>; | ||
|
||
export type RecipeHeaderProps = { | ||
title: RQR["title"]; | ||
mainImage: RQR["mainImage"]; | ||
}; | ||
|
||
export const RecipeHeader = ({ title, mainImage }: RecipeHeaderProps) => { | ||
return ( | ||
<> | ||
{title ? ( | ||
<TypographyH1 className="text-center sm:mb-8">{title}</TypographyH1> | ||
) : null} | ||
<MainImage mainImage={mainImage} /> | ||
</> | ||
); | ||
}; |
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 was deleted.
Oops, something went wrong.