Skip to content

Commit

Permalink
♻️ Simplify logo salad section
Browse files Browse the repository at this point in the history
  • Loading branch information
petterhh committed Dec 10, 2024
1 parent a752406 commit 08e6040
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 79 deletions.
35 changes: 7 additions & 28 deletions src/components/sections/logoSalad/LogoSalad.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { PortableText, PortableTextReactComponents } from "@portabletext/react";

import { SanityImage } from "src/components/image/SanityImage";
import Text from "src/components/text/Text";
import { LogoSaladSection } from "studio/lib/interfaces/pages";

import styles from "./logoSalad.module.css";
Expand All @@ -10,35 +7,17 @@ interface LogoSaladProps {
logoSalad: LogoSaladSection;
}

const myPortableTextComponents: Partial<PortableTextReactComponents> = {
block: ({ children }) => <Text type="bodyXl">{children}</Text>,
};

export const LogoSalad = ({ logoSalad }: LogoSaladProps) => {
return (
<article className={styles.wrapper} id={logoSalad._key}>
<div className={styles.logoSalad}>
{logoSalad.richText && (
<PortableText
value={logoSalad.richText}
components={myPortableTextComponents}
/>
)}
<div className={styles.logoList}>
<Text>{logoSalad.supporting}</Text>
{logoSalad.logos && (
<ul className={styles.logoWrapper}>
{logoSalad.logos.map(
(logo) =>
logo && (
<li key={logo._key}>
<SanityImage image={logo} />
</li>
),
)}
</ul>
)}
</div>
<ul className={styles.logoWrapper}>
{logoSalad.logos.map((logo) => (
<li key={logo._key}>
<SanityImage image={logo} />
</li>
))}
</ul>
</div>
</article>
);
Expand Down
11 changes: 1 addition & 10 deletions src/components/sections/logoSalad/logoSalad.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,8 @@
gap: 1.5rem;

@media (min-width: 1024px) {
gap: 7.5rem;
width: 100%;
}
}

.logoList {
composes: shared;
gap: 1.5rem;

@media (min-width: 1024px) {
text-align: center;
gap: 7.5rem;
}
}

Expand Down
47 changes: 6 additions & 41 deletions studio/schemas/objects/sections/logoSalad.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { StringInputProps, defineField } from "sanity";
import { defineField } from "sanity";

import { StringInputWithCharacterCount } from "studio/components/stringInputWithCharacterCount/StringInputWithCharacterCount";
import image from "studio/schemas/fields/media";
import { richText } from "studio/schemas/fields/text";

export const logoSaladID = "logoSalad";

Expand All @@ -11,53 +9,20 @@ export const logoSalad = defineField({
title: "Logo Salad",
type: "object",
fields: [
{
...richText,
title: "Introduction",
description:
"Optional content displayed at the top of the section in a larger body text style. Use it to introduce the section and provide key information.",
},
{
name: "supporting",
title: "Logo Description",
type: "string",
description:
"Required text displayed in a smaller body text style. Use it to provide additional context or details about the logos.",
validation: (rule) => [
rule.required().error("Logo description is required."),
rule.max(100),
],
components: {
input: (props: StringInputProps) =>
StringInputWithCharacterCount({ ...props, maxCount: 100 }),
},
},
{
name: "logos",
title: "List of Logos",
description:
"Add a list of logos to display. You must include between 6 and 12 logos.",
title: "Logos",
description: "Add the logos you want to display.",
type: "array",
of: [image],
validation: (rule) =>
rule
.min(6)
.error("At least 6 logos are required.")
.max(12)
.error("You can add up to 12 logos.")
.required()
.error("The list of logos is required."),
rule.required().error("A list of logos is required."),
},
],
preview: {
select: {
title: "supporting",
},
prepare(selection) {
const { title } = selection;
prepare() {
return {
title: title,
subtitle: "Logo Salad",
title: "Logo Salad",
};
},
},
Expand Down

0 comments on commit 08e6040

Please sign in to comment.