From d8b12356d44f489a6fb83e2c946dca0ea54158f4 Mon Sep 17 00:00:00 2001 From: Pontus Dreij Date: Thu, 19 Sep 2024 10:11:26 +0200 Subject: [PATCH] feat(SW-213): Added renderOptions for text cols --- components/Content/Blocks/TextCols/index.tsx | 3 + .../Content/Blocks/TextCols/renderOptions.tsx | 70 +++++++++++++++++++ .../Blocks/TextCols/textcols.module.css | 7 +- 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 components/Content/Blocks/TextCols/renderOptions.tsx diff --git a/components/Content/Blocks/TextCols/index.tsx b/components/Content/Blocks/TextCols/index.tsx index 8fd79c478..e61fe754f 100644 --- a/components/Content/Blocks/TextCols/index.tsx +++ b/components/Content/Blocks/TextCols/index.tsx @@ -1,6 +1,8 @@ import JsonToHtml from "@/components/JsonToHtml" import Subtitle from "@/components/TempDesignSystem/Text/Subtitle" +import { renderOptions } from "./renderOptions" + import styles from "./textcols.module.css" import type { TextColsProps } from "@/types/components/content/blocks" @@ -16,6 +18,7 @@ export default function TextCols({ text_cols }: TextColsProps) { diff --git a/components/Content/Blocks/TextCols/renderOptions.tsx b/components/Content/Blocks/TextCols/renderOptions.tsx new file mode 100644 index 000000000..55582de95 --- /dev/null +++ b/components/Content/Blocks/TextCols/renderOptions.tsx @@ -0,0 +1,70 @@ +import Link from "@/components/TempDesignSystem/Link" + +import styles from "./textcols.module.css" + +import type { EmbedByUid } from "@/types/components/jsontohtml" +import { RTEItemTypeEnum, RTETypeEnum } from "@/types/rte/enums" +import type { + RTEDefaultNode, + RTENext, + RTENode, + RTERegularNode, +} from "@/types/rte/node" +import type { RenderOptions } from "@/types/rte/option" + +export const renderOptions: RenderOptions = { + [RTETypeEnum.p]: ( + node: RTEDefaultNode, + embeds: EmbedByUid, + next: RTENext, + fullRenderOptions: RenderOptions + ) => { + return ( +

+ {next(node.children, embeds, fullRenderOptions)} +

+ ) + }, + [RTETypeEnum.a]: ( + node: RTERegularNode, + embeds: EmbedByUid, + next: RTENext, + fullRenderOptions: RenderOptions + ) => { + if (node.attrs.url) { + return ( + + {next(node.children, embeds, fullRenderOptions)} + + ) + } + return null + }, + [RTETypeEnum.reference]: ( + node: RTENode, + embeds: EmbedByUid, + next: RTENext, + fullRenderOptions: RenderOptions + ) => { + if ("attrs" in node) { + const type = node.attrs.type + if (type !== RTEItemTypeEnum.asset) { + const href = node.attrs?.locale + ? `/${node.attrs.locale}${node.attrs.href}` + : node.attrs.href + return ( + + {next(node.children, embeds, fullRenderOptions)} + + ) + } + + return null + } + }, +} diff --git a/components/Content/Blocks/TextCols/textcols.module.css b/components/Content/Blocks/TextCols/textcols.module.css index d9fd60a1c..dfa0a3c49 100644 --- a/components/Content/Blocks/TextCols/textcols.module.css +++ b/components/Content/Blocks/TextCols/textcols.module.css @@ -14,9 +14,14 @@ flex-direction: column; } -.text p { +.p { color: var(--UI-Text-High-contrast); line-height: var(--Spacing-x3); + margin: 0; +} + +.a { + color: var(--Base-Text-High-contrast); } .text section {