Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add figure description to sanityImages #1008

Merged
merged 5 commits into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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}
anemne marked this conversation as resolved.
Show resolved Hide resolved
/>
</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
Loading