memorium/components/RecipeHero.tsx

109 lines
2.9 KiB
TypeScript
Raw Normal View History

2023-07-30 19:40:39 +02:00
import { Star } from "@components/Stars.tsx";
2023-08-02 13:11:17 +02:00
import {
IconArrowNarrowLeft,
IconEdit,
IconExternalLink,
} from "@components/icons.tsx";
2023-08-06 17:47:26 +02:00
import { isLocalImage } from "@lib/string.ts";
2023-08-08 21:55:10 +02:00
import Image from "@components/Image.tsx";
2023-08-02 01:58:03 +02:00
2023-07-30 23:55:51 +02:00
export function RecipeHero(
2023-08-02 01:58:03 +02:00
{ data, subline, backlink, editLink }: {
2023-07-30 23:55:51 +02:00
backlink: string;
2023-07-31 17:21:17 +02:00
subline?: string[];
2023-08-02 01:58:03 +02:00
editLink?: string;
data: {
meta?: { thumbnail?: string; image?: string; link?: string };
name: string;
};
2023-07-30 23:55:51 +02:00
},
) {
const { meta: { image } = {} } = data;
2023-08-06 17:47:26 +02:00
const imageUrl = (image && isLocalImage(image))
? `/api/images?image=${image}&width=800`
: image;
2023-07-26 13:47:01 +02:00
return (
2023-07-30 21:43:09 +02:00
<div
2023-08-02 00:23:51 +02:00
class={`flex justify-between flex-col relative w-full min-h-[${
2023-07-30 21:43:09 +02:00
imageUrl ? 400 : 200
}px] rounded-3xl overflow-hidden`}
>
{imageUrl &&
(
2023-08-08 21:55:10 +02:00
<Image
2023-07-30 21:43:09 +02:00
src={imageUrl}
thumbnail={data.meta?.thumbnail}
2023-07-30 21:43:09 +02:00
alt="Recipe Banner"
style={{ objectPosition: "0% 25%" }}
2023-08-02 00:23:51 +02:00
class="absolute object-cover w-full h-full -z-10"
2023-07-30 21:43:09 +02:00
/>
)}
2023-07-26 13:47:01 +02:00
2023-08-02 00:23:51 +02:00
<div class="flex justify-between mx-8 mt-8">
2023-07-26 13:47:01 +02:00
<a
2023-08-02 01:58:03 +02:00
class="px-4 py-2 bg-gray-300 text-gray-800 rounded-lg flex gap-1 items-center"
2023-07-30 23:55:51 +02:00
href={backlink}
2023-07-26 13:47:01 +02:00
>
2023-08-02 01:58:03 +02:00
<IconArrowNarrowLeft class="w-5 h-5" /> Back
2023-07-26 13:47:01 +02:00
</a>
2023-08-02 01:58:03 +02:00
{editLink &&
(
<a
class={`px-4 py-2 ${
imageUrl ? "bg-gray-300 text-gray-800" : "text-gray-200"
} rounded-lg flex gap-1 items-center`}
href={editLink}
>
<IconEdit class="w-5 h-5" />
</a>
)}
2023-07-26 13:47:01 +02:00
</div>
2023-08-01 21:35:21 +02:00
<div
2023-08-02 01:58:03 +02:00
class={`relative inset-x-0 py-4 px-8 ${imageUrl ? "py-8" : ""} `}
2023-08-01 21:35:21 +02:00
>
2023-07-31 17:21:17 +02:00
<div
2023-08-02 13:11:17 +02:00
class={`${
imageUrl ? "noisy-gradient" : ""
} after:opacity-90 flex gap-4 items-center ${
2023-08-01 21:35:21 +02:00
imageUrl ? "pt-12" : ""
}`}
>
2023-07-31 17:21:17 +02:00
<h2
class="relative text-4xl font-bold z-10"
style={{ color: imageUrl ? "#1F1F1F" : "white" }}
>
{data.name}
2023-08-02 00:23:51 +02:00
{data.meta?.link &&
(
<a
href={data.meta.link}
target="__blank"
class="p-2 inline-flex"
name="Link to Original recipe"
>
<IconExternalLink />
</a>
)}
2023-07-31 17:21:17 +02:00
</h2>
2023-07-30 19:40:39 +02:00
2023-07-31 17:21:17 +02:00
{data.meta?.rating && <Star rating={data.meta.rating} />}
</div>
{subline?.length &&
(
<div
2023-08-02 01:58:03 +02:00
class={`relative z-50 flex gap-5 font-sm text-light mt-3`}
2023-07-31 17:21:17 +02:00
style={{ color: imageUrl ? "#1F1F1F" : "white" }}
>
2023-08-01 21:35:21 +02:00
{subline.filter((s) => s && s?.length > 1).map((s) => {
2023-07-31 17:21:17 +02:00
return <span>{s}</span>;
})}
</div>
)}
2023-07-26 13:47:01 +02:00
</div>
</div>
);
}