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

v3 - highlighted rich text section #848

Merged
merged 1 commit into from
Oct 31, 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
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,14 @@ export interface RichTextSectionProps {
export default function RichTextSection({ section }: RichTextSectionProps) {
return (
<div className={styles.wrapper}>
<div className={styles.content}>
<RichText value={section.richText} />
<div
className={
styles.content + (section.highlighted ? ` ${styles.highlighted}` : "")
}
>
<div className={styles.innerContent}>
<RichText value={section.richText} />
</div>
</div>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,15 @@
.content {
max-width: 960px;
}

.content.highlighted {
border: 2px solid var(--primary-yellow-warning);
border-radius: 0.25rem;
background-color: var(--primary-yellow-warning);
}

.highlighted .innerContent {
background-color: var(--primary-bg);
border-radius: 1.25rem;
padding: 1rem;
}
1 change: 1 addition & 0 deletions studioShared/lib/interfaces/richTextBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ export interface RichTextBlock {
_key: string;
_type: "richTextBlock";
richText: PortableTextBlock[];
highlighted?: boolean;
}
1 change: 1 addition & 0 deletions studioShared/lib/queries/customerCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const CUSTOMER_CASES_QUERY = groq`
export const BASE_SECTIONS_FRAGMENT = groq`
_type == "richTextBlock" => {
"richText": ${translatedFieldFragment("richText")},
highlighted
},
_type == "imageBlock" => {
"images": images[] {
Expand Down
14 changes: 13 additions & 1 deletion studioShared/schemas/objects/richTextBlock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,20 @@ const richTextBlock = defineField({
title: "Rich Text",
type: "internationalizedArrayRichText",
},
{
name: "highlighted",
title: "Highlighted",
type: "boolean",
description: "Display the rich text with a highlight frame",
initialValue: false,
},
],
preview: {
select: {
richText: "richText",
highlighted: "highlighted",
},
prepare({ richText }) {
prepare({ richText, highlighted }) {
if (!isInternationalizedRichText(richText)) {
throw new TypeError(
`Expected 'richText' to be InternationalizedRichText, was ${typeof richText}`,
Expand All @@ -31,6 +39,10 @@ const richTextBlock = defineField({
translatedRichText !== null
? richTextPreview(translatedRichText)
: undefined,
subtitle:
typeof highlighted === "boolean" && highlighted
? "Highlighted"
: undefined,
};
},
},
Expand Down