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

feat: Color Picker for Customer Cases #915

Merged
merged 2 commits into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
88 changes: 88 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"test-storybook": "test-storybook"
},
"dependencies": {
"@sanity/color-input": "^4.0.1",
"@sanity/document-internationalization": "^3.0.1",
"@sanity/image-url": "^1.0.2",
"@sanity/preview-url-secret": "^1.6.11",
Expand Down
45 changes: 41 additions & 4 deletions src/components/customerCases/customerCase/CustomerCase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ export default async function CustomerCase({
return (
<div className={styles.wrapper}>
<div className={styles.content}>
<Text type={"h1"} className={styles.mainTitle}>
{customerCase.basicTitle}
</Text>
<ColoredTitle
title={customerCase.basicTitle}
colorPart={customerCase.basicTitleColorPart}
color={customerCase.clientColors.color}
/>
<hr className={styles.divider} />
{consultantsResult.ok && (
<div className={styles.projectInfoWrapper}>
<CustomerCaseProjectInfo projectInfo={customerCase.projectInfo} />
<CustomerCaseProjectInfo
projectInfo={customerCase.projectInfo}
clientColors={customerCase.clientColors}
/>
</div>
)}
<div className={styles.mainImageWrapper}>
Expand Down Expand Up @@ -61,3 +66,35 @@ export default async function CustomerCase({
</div>
);
}

function ColoredTitle({
title,
colorPart,
color,
}: {
title: string;
colorPart?: string;
color?: string;
}) {
if (colorPart === undefined || colorPart === "")
return (
<Text type={"h1"} className={styles.mainTitle}>
{title}
</Text>
);

const startColorIndex = title.indexOf(colorPart);
const endColorIndex = startColorIndex + colorPart.length;

const preColorText = title.slice(0, startColorIndex);
const colorText = title.slice(startColorIndex, endColorIndex);
const postColorText = title.slice(endColorIndex);

return (
<Text type={"h1"} className={styles.mainTitle}>
<span>{preColorText}</span>
<span style={{ color: color }}>{colorText}</span>
<span>{postColorText}</span>
</Text>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@ import Text from "src/components/text/Text";
import { LinkType } from "studio/lib/interfaces/navigation";
import {
CustomerCaseProjectInfo as CustomerCaseCaseProjectInfoObject,
CustomerCaseClientColors,
CustomerSector,
} from "studioShared/lib/interfaces/customerCases";

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

interface CustomerCaseProjectInfoProps {
projectInfo: CustomerCaseCaseProjectInfoObject;
clientColors: CustomerCaseClientColors;
}

export default async function CustomerCaseProjectInfo({
projectInfo,
clientColors,
}: CustomerCaseProjectInfoProps) {
const t = await getTranslations("customer_case");

Expand All @@ -35,7 +38,13 @@ export default async function CustomerCaseProjectInfo({
</Text>
<div className={styles.badgeWrapper}>
{projectInfo.customerSectors.map((sector: CustomerSector) => (
<Badge key={sector._key}>{sector.customerSector}</Badge>
<Badge
key={sector._key}
badgeColor={clientColors.color}
textColor={clientColors.badgeText}
>
{sector.customerSector}
</Badge>
))}
</div>
</div>
Expand Down
7 changes: 7 additions & 0 deletions studioShared/lib/interfaces/customerCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,15 @@ export interface CustomerCaseBase {
slug: string;
domains: string[];
basicTitle: string;
basicTitleColorPart: string;
description: string;
image: IImage;
clientColors: CustomerCaseClientColors;
}

export interface CustomerCaseClientColors {
color?: string;
badgeText?: string;
}

export type CustomerCaseSection =
Expand Down
7 changes: 6 additions & 1 deletion studioShared/lib/queries/customerCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,14 @@ const CUSTOMER_CASE_BASE_FRAGMENT = groq`
${LANGUAGE_FIELD_FRAGMENT},
"slug": ${translatedFieldFragment("slug")},
"basicTitle": ${translatedFieldFragment("basicTitle")},
"basicTitleColorPart": ${translatedFieldFragment("basicTitleColorPart")},
"description": ${translatedFieldFragment("description")},
"image": image {
${INTERNATIONALIZED_IMAGE_FRAGMENT}
},
"clientColors": {
"color": clientColor.hex,
"badgeText": clientColorBadgeText.hex
}
`;

Expand Down Expand Up @@ -66,7 +71,7 @@ export const CUSTOMER_CASE_QUERY = groq`
},
collaborators,
"consultants": consultants[] {
_key,
_key,
employeeEmail,
employeeFirstName,
}
Expand Down
24 changes: 24 additions & 0 deletions studioShared/schemas/documents/customerCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,31 @@ const customerCase = defineType({
type: "internationalizedArrayString",
title: "Title",
}),
defineField({
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to the design the colors for the title and badge should be the same, is there any way to validate this or should we add that in the description?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or could we use one color picker for the "main" color, and another for the text? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If they should always be the same, then we should only have one field for it.

name: `${titleID.basic}ColorPart`,
type: "internationalizedArrayString",
title: "Title Color Part",
description: "Which part of the title should be colored",
}),
defineField({ ...domainsField, validation: (rule) => rule.required() }),
defineField({
name: "clientColor",
type: "color",
title: "Client Color (Title & Badges)",
description: "This color will be used for parts of the title and badges",
options: { disableAlpha: true },
}),
defineField({
name: "clientColorBadgeText",
type: "color",
title: "Client Color (Badge Text)",
description:
"This color will be used for the text on the badges. There are predefined colors for text in the component",
options: {
disableAlpha: true,
colorList: ["#222424", "#faf8f5"],
},
}),
defineField({
name: "description",
type: "internationalizedArrayText",
Expand Down
2 changes: 2 additions & 0 deletions studioShared/studioConfig.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { colorInput } from "@sanity/color-input";
import { visionTool } from "@sanity/vision";
import { WorkspaceOptions } from "sanity";
import { structureTool } from "sanity/structure";
Expand Down Expand Up @@ -32,6 +33,7 @@ const config: WorkspaceOptions = {
languages: supportedLanguages,
fieldTypes: ["string", "richText", "text"],
}),
colorInput(),
],
};

Expand Down