Files
web/apps/scandic-web/components/Blocks/TextCols/renderOptions.tsx
Anton Gunnarsson 8518d018f8 Merged in feat/sw-3230-move-link-to-design-system (pull request #2618)
feat(SW-3230): Move Link to design-system

* Move Link to design-system

* Remove comments


Approved-by: Linus Flood
2025-08-12 12:35:20 +00:00

58 lines
1.4 KiB
TypeScript

import Link from "@scandic-hotels/design-system/Link"
import styles from "./textcols.module.css"
import type { EmbedByUid } from "@/types/transitionTypes/jsontohtml"
import { RTEItemTypeEnum, RTETypeEnum } from "@/types/transitionTypes/rte/enums"
import type {
RTENext,
RTENode,
RTERegularNode,
} from "@/types/transitionTypes/rte/node"
import type { RenderOptions } from "@/types/transitionTypes/rte/option"
export const renderOptions: RenderOptions = {
[RTETypeEnum.a]: (
node: RTERegularNode,
embeds: EmbedByUid,
next: RTENext,
fullRenderOptions: RenderOptions
) => {
if (node.attrs.url) {
return (
<a
href={node.attrs.url}
target={node.attrs.target ?? "_blank"}
key={node.uid}
className={styles.a}
>
{next(node.children, embeds, fullRenderOptions)}
</a>
)
}
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 (
<Link href={href} key={node.uid} className={styles.a}>
{next(node.children, embeds, fullRenderOptions)}
</Link>
)
}
return null
}
},
}