Skip to content

Commit

Permalink
Add media caption image component
Browse files Browse the repository at this point in the history
  • Loading branch information
rebeccahongsf committed Nov 5, 2024
1 parent 94dd7c2 commit 216954d
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 0 deletions.
47 changes: 47 additions & 0 deletions app/components/MediaCaptionImage/MediaCaptionImage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import Image from "next/image";
import { cnb } from "cnbuilder";
import { HTMLAttributes } from "react";
import { Text } from "../Typography";

interface MediaCaptionImageProps extends HTMLAttributes<HTMLElement> {
title?: string;
imageSrc: string;
imageAlt?: string;
link?: string;
caption: string;
}

const MediaCaptionImage = ({
title,
imageSrc,
imageAlt = "",
link,
caption,
...props
}: MediaCaptionImageProps) => {
return (
<figure
{...props}
className={cnb(
"centered lg:max-w-[920px] xl:max-w-[980px] mb-50",
props.className,
)}
>
<div className="relative aspect-[16/9] w-full">
<Image
className="object-cover"
src={imageSrc}
alt={imageAlt}
fill
sizes="(max-width: 768px) 100vw, 1000px"
/>
</div>

<figcaption className="mt-20 mx-20">
<Text className="text-15 text-black-70">{caption}</Text>
</figcaption>
</figure>
);
};

export default MediaCaptionImage;
1 change: 1 addition & 0 deletions app/components/MediaCaptionImage/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./MediaCaptionImage";
5 changes: 5 additions & 0 deletions app/example/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import TimelineOverview from "@/components/Timeline/TimelineOverview";
import { loadTimelineData } from "@/utilities/loadTimelineData";
import { GradientBanner } from "@/components/GradientBanner/GradientBanner";
import TimelineEven from "@/components/TimelineEven/TimelineOverview";
import MediaCaptionImage from "@/components/MediaCaptionImage/MediaCaptionImage";

const ExamplePage = async () => {
const timelineData = await loadTimelineData();
Expand Down Expand Up @@ -47,6 +48,10 @@ const ExamplePage = async () => {
</Text>
</FeatureHero>
<ShapeAnimation />
<MediaCaptionImage
imageSrc="https://placecats.com/neo/1500/1000"
caption="Caption/credit lorem ipsum"
/>
<PageTitle heading="100 years of" bigText="Impact" />
<GradientBanner>
<Heading
Expand Down

0 comments on commit 216954d

Please sign in to comment.