Skip to content

Commit

Permalink
remove text component from sanity image and add it those places where…
Browse files Browse the repository at this point in the history
… we want figure description
  • Loading branch information
anemne committed Dec 12, 2024
1 parent 9996dcd commit 9dc4450
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 44 deletions.
10 changes: 6 additions & 4 deletions src/components/customerCases/customerCase/CustomerCase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ export default async function CustomerCase({
/>
</div>
<div className={styles.mainImageWrapper}>
<SanitySharedImage
image={customerCase.image}
showFigureDescription={true}
/>
<SanitySharedImage image={customerCase.image} />
{customerCase.image.figureDescription && (
<Text type="imageLabel">
{customerCase.image.figureDescription}
</Text>
)}
</div>
<div className={styles.sectionsWrapper}>
{customerCase.sections.map((section) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
height: 36.5rem;
overflow: hidden;
padding-top: 1.5rem;
padding-bottom: 2rem;
padding-bottom: var(--padding-xl);
}

.mainImageWrapper img {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { SanitySharedImage } from "src/components/image/SanityImage";
import Text from "src/components/text/Text";
import { ImageBlock } from "studioShared/lib/interfaces/imageBlock";

import styles from "./imageSection.module.css";
Expand All @@ -15,6 +16,9 @@ export default function ImageSection({ section }: ImageSectionProps) {
>
<div className={styles.imageContent}>
<SanitySharedImage image={section.image} />
{section.image.figureDescription && (
<Text type="imageLabel">{section.image.figureDescription}</Text>
)}
</div>
</div>
</div>
Expand Down
57 changes: 19 additions & 38 deletions src/components/image/SanityImage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ 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 @@ -41,7 +40,6 @@ const SanityAssetImage = ({
image,
imageProps,
objectFit = "cover",
showFigureDescription,
}: {
image: IImage;
imageProps?: UseNextSanityImageProps;
Expand All @@ -55,28 +53,23 @@ const SanityAssetImage = ({
return null;
}
return (
<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>
<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%",
}
}
/>
);
};

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

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

function SanityGlobalImage({
Expand Down
2 changes: 1 addition & 1 deletion src/components/text/text.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,5 @@
font-weight: 400;
line-height: 150%;
letter-spacing: 0.05rem;
padding: 0rem 9.25rem 0rem 4rem;
padding: 0rem 0.5rem;
}

0 comments on commit 9dc4450

Please sign in to comment.