Skip to content

Commit

Permalink
feat(imageSection): fullWidth toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiazom committed Oct 29, 2024
1 parent 54f7cff commit 6133cbf
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/components/customerCases/customerCase/CustomerCase.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { SanitySharedImage } from "src/components/image/SanityImage";
import { RichText } from "src/components/richText/RichText";
import Text from "src/components/text/Text";
import {
CustomerCase as CustomerCaseDocument,
Expand All @@ -9,6 +8,7 @@ import {

import styles from "./customerCase.module.css";
import ImageSection from "./sections/image/ImageSection";
import RichTextSection from "./sections/richText/RichTextSection";

export interface CustomerCaseProps {
customerCase: CustomerCaseDocument;
Expand All @@ -21,7 +21,7 @@ function CustomerCaseSection({
}) {
switch (section._type) {
case "richTextBlock":
return <RichText value={section.richText} />;
return <RichTextSection section={section} />;
case "quoteBlock":
return (
section.quote && (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ export interface ImageSectionProps {
export default function ImageSection({ section }: ImageSectionProps) {
return (
<div className={styles.wrapper}>
{section.images?.map((image) => (
<div
key={image._key ?? `${section._key}-${image.alt}`}
className={styles.imageWrapper}
>
<div className={styles.imageContent}>
<SanitySharedImage image={image} />
<div
className={`${styles.content}${section.fullWidth ? ` ${styles.fullWidth}` : ""}`}
>
{section.images?.map((image) => (
<div
key={image._key ?? `${section._key}-${image.alt}`}
className={styles.imageWrapper}
>
<div className={styles.imageContent}>
<SanitySharedImage image={image} />
</div>
</div>
</div>
))}
))}
</div>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
.wrapper {
display: flex;
flex-direction: column;
align-items: center;
}

.content {
max-width: 960px;
display: flex;
gap: 1rem;
justify-content: center;
Expand All @@ -8,14 +15,17 @@
}
}

.content.fullWidth {
max-width: unset;
}

.imageWrapper {
display: flex;
flex-direction: column;
align-items: center;
}

.imageContent {
max-width: 800px;
height: 100%;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { RichText } from "src/components/richText/RichText";
import { RichTextBlock } from "studioShared/lib/interfaces/richTextBlock";

import styles from "./richTextSection.module.css";

export interface RichTextSectionProps {
section: RichTextBlock;
}

export default function RichTextSection({ section }: RichTextSectionProps) {
return (
<div className={styles.wrapper}>
<div className={styles.content}>
<RichText value={section.richText} />
</div>
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.wrapper {
display: flex;
flex-direction: column;
align-items: center;
}

.content {
max-width: 960px;
}
1 change: 1 addition & 0 deletions studioShared/lib/interfaces/imageBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export interface ImageBlock {
_key: string;
_type: "imageBlock";
images: IImage[];
fullWidth?: boolean;
}
3 changes: 2 additions & 1 deletion studioShared/lib/queries/customerCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ export const CUSTOMER_CASE_QUERY = groq`
_type == "imageBlock" => {
"images": images[] {
${INTERNATIONALIZED_IMAGE_FRAGMENT}
}
},
fullWidth
},
_type == "listBlock" => {
"description": ${translatedFieldFragment("description")},
Expand Down
10 changes: 9 additions & 1 deletion studioShared/schemas/objects/imageBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,19 @@ const imageBlock = defineField({
type: "array",
of: [internationalizedImage],
},
{
name: "fullWidth",
title: "Full Width",
description: "Should these images occupy the full width of the page?",
type: "boolean",
},
],
preview: {
select: {
images: "images",
fullWidth: "fullWidth",
},
prepare: ({ images }) => {
prepare: ({ images, fullWidth }) => {
const count = Object.keys(images).length;
const firstImage = count > 0 ? images[0] : undefined;
let firstImageAlt = null;
Expand All @@ -35,6 +42,7 @@ const imageBlock = defineField({
}
return {
title: count > 1 ? `${count} images` : (firstImageAlt ?? undefined),
subtitle: fullWidth ? "Full Width" : undefined,
media: firstImage,
};
},
Expand Down

0 comments on commit 6133cbf

Please sign in to comment.