Skip to content

Commit

Permalink
add figure description to sanityImages
Browse files Browse the repository at this point in the history
  • Loading branch information
anemne committed Dec 12, 2024
1 parent 319ca23 commit 18d1cd3
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 23 deletions.
5 changes: 4 additions & 1 deletion src/components/customerCases/customerCase/CustomerCase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ export default async function CustomerCase({
/>
</div>
<div className={styles.mainImageWrapper}>
<SanitySharedImage image={customerCase.image} />
<SanitySharedImage
image={customerCase.image}
showFigureDescription={true}
/>
</div>
<div className={styles.sectionsWrapper}>
{customerCase.sections.map((section) => (
Expand Down
58 changes: 39 additions & 19 deletions src/components/image/SanityImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Image from "next/image";
import { UseNextSanityImageProps, useNextSanityImage } from "next-sanity-image";
import { useEffect, useState } from "react";

import Text from "src/components/text/Text";
import { client } from "studio/lib/client";
import { IImage } from "studio/lib/interfaces/media";
import { sharedClient } from "studioShared/lib/client";
Expand Down Expand Up @@ -40,10 +41,12 @@ const SanityAssetImage = ({
image,
imageProps,
objectFit = "cover",
showFigureDescription,
}: {
image: IImage;
imageProps?: UseNextSanityImageProps;
objectFit?: "cover" | "none";
showFigureDescription?: boolean;
}) => {
const objectPosition = image.hotspot
? `${image.hotspot.x * 100}% ${image.hotspot.y * 100}%`
Expand All @@ -52,23 +55,28 @@ const SanityAssetImage = ({
return null;
}
return (
<Image
alt={image?.alt || ""}
{...imageProps}
width={imageProps.width}
height={imageProps.height}
blurDataURL={image.metadata?.lqip}
style={
objectFit === "none"
? {}
: {
objectFit: "cover",
objectPosition,
maxWidth: "100%",
maxHeight: "100%",
}
}
/>
<div>
<Image
alt={image?.alt || ""}
{...imageProps}
width={imageProps.width}
height={imageProps.height}
blurDataURL={image.metadata?.lqip}
style={
objectFit === "none"
? {}
: {
objectFit: "cover",
objectPosition,
maxWidth: "100%",
maxHeight: "100%",
}
}
/>
{showFigureDescription && (
<Text type="imageLabel"> {image.figureDescription}</Text>
)}
</div>
);
};

Expand All @@ -77,9 +85,21 @@ export function SanityStudioImage({ image }: { image: IImage }) {
return <SanityAssetImage image={image} imageProps={imageProps} />;
}

export function SanitySharedImage({ image }: { image: IImage }) {
export function SanitySharedImage({
image,
showFigureDescription,
}: {
image: IImage;
showFigureDescription?: boolean;
}) {
const imageProps = useNextSanityImage(sharedClient, image);
return <SanityAssetImage image={image} imageProps={imageProps} />;
return (
<SanityAssetImage
image={image}
imageProps={imageProps}
showFigureDescription={showFigureDescription}
/>
);
}

function SanityGlobalImage({
Expand Down
5 changes: 4 additions & 1 deletion src/components/text/Text.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ export type TextType =
| "bodyBig"
| "bodyXl"
| "mobileH1"
| "mobileBodyNormal";
| "mobileBodyNormal"
| "imageLabel";

const elementMap: { [key in TextType]: keyof JSX.IntrinsicElements } = {
h1: "h1",
Expand All @@ -39,6 +40,7 @@ const elementMap: { [key in TextType]: keyof JSX.IntrinsicElements } = {
bodyXl: "p",
mobileH1: "h1",
mobileBodyNormal: "p",
imageLabel: "span",
};

const classMap: { [key in TextType]?: string } = {
Expand All @@ -60,6 +62,7 @@ const classMap: { [key in TextType]?: string } = {
bodyXl: styles.bodyXl,
mobileH1: styles.mobileH1,
mobileBodyNormal: styles.mobileBodyNormal,
imageLabel: styles.imageLabel,
};

const Text = ({
Expand Down
10 changes: 10 additions & 0 deletions src/components/text/text.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
.bodySmall,
.bodyNormal,
.bodyBig,
.imageLabel,
.list {
font-family: var(--font-britti-sans);
line-height: 140%;
Expand Down Expand Up @@ -182,3 +183,12 @@
line-height: 130%;
white-space: pre-line;
}

.imageLabel {
font-size: var(--Font-size-Picture-label, 1rem);
font-style: normal;
font-weight: 400;
line-height: 150%;
letter-spacing: 0.05rem;
padding: 0rem 9.25rem 0rem 4rem;
}
1 change: 1 addition & 0 deletions studio/lib/interfaces/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ export interface IImage {
metadata?: {
lqip: string;
};
figureDescription?: string;
}

export interface ImageExtendedProps extends IImage {
Expand Down
11 changes: 10 additions & 1 deletion studio/schemas/fields/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,16 @@ export const internationalizedImage = defineField({
title: "Image",
type: "image",
options: { hotspot: true },
fields: [internationalizedImageAltField],
fields: [
internationalizedImageAltField,
{
name: "figureDescription",
type: "internationalizedArrayString",
title: "Figure Description",
description:
"Provide a figure description of the image. Leave empty if figure description is not needed.",
},
],
preview: {
select: {
alt: "alt",
Expand Down
3 changes: 2 additions & 1 deletion studioShared/lib/queries/customerCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ const INTERNATIONALIZED_IMAGE_FRAGMENT = groq`
"metadata": asset -> metadata {
lqip
},
"alt": ${translatedFieldFragment("alt")}
"alt": ${translatedFieldFragment("alt")},
"figureDescription": ${translatedFieldFragment("figureDescription")}
`;

const CUSTOMER_CASE_BASE_FRAGMENT = groq`
Expand Down

0 comments on commit 18d1cd3

Please sign in to comment.