Skip to content

Commit

Permalink
feat(richTextBlock): highlight option
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiazom committed Oct 31, 2024
1 parent d0d2971 commit d03d308
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
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

0 comments on commit d03d308

Please sign in to comment.