feat: json rich text editor, blocks, asides, general structure

This commit is contained in:
Simon Emanuelsson
2024-02-07 11:57:36 +01:00
parent 2bd4e25403
commit 66faa41e98
53 changed files with 966 additions and 211 deletions

View File

@@ -0,0 +1,60 @@
import { renderOptions } from "./renderOptions"
import Image from "next/image"
import JsonToHtml from "@/components/JsonToHtml"
import Link from "next/link"
import styles from "./puff.module.css"
import type { PuffProps } from "@/types/components/current/asides/puff"
export default function Puff({ imageConnection, is_internal, link, link_text, pageConnection, system, text, title }: PuffProps) {
return is_internal ? (
<Link className={styles.link} href={link.href}>
<PuffContent
imageConnection={imageConnection}
text={text}
title={title}
/>
</Link>
) : (
<a className={styles.link} href={link.href} target="_blank">
<PuffContent
imageConnection={imageConnection}
text={text}
title={title}
/>
</a>
)
}
function PuffContent({ imageConnection, text, title }: Pick<PuffProps, "imageConnection" | "text" | "title">) {
return (
<article>
{imageConnection.edges.map(image => (
<Image
alt={image.node.title}
className={styles.image}
height={image.node.dimension.height}
key={image.node.system.uid}
src={image.node.url}
unoptimized
width={image.node.dimension.width}
/>
))}
<section className={styles.content}>
<header className="content-teaser__body-wrapper">
<h3 className={styles.heading}>
{title}
</h3>
</header>
<JsonToHtml
embeds={text.embedded_itemsConnection.edges}
nodes={text.json.children}
renderOptions={renderOptions}
/>
</section>
</article>
)
}

View File

@@ -0,0 +1,47 @@
.link {
display: inline-block;
transition: 200ms ease;
}
.link:hover {
text-decoration: none;
transform: scale(1.01);
}
.image {
height: auto;
object-fit: contain;
object-position: center;
}
.content {
padding: 20px 0px;
}
.heading {
color: #00838e;
font-family: Helvetica, Arial, sans-serif;
font-weight: 400;
line-height: normal;
margin-bottom: 0;
text-decoration: none;
text-transform: none;
}
.link:hover .heading {
text-decoration: underline;
}
.p {
color: #333;
line-height: 1.3;
margin-bottom: 0;
padding-top: 7px;
text-decoration: none;
}
@media screen and (min-width: 950px) {
.heading {
font-size: 1.375rem;
}
}

View File

@@ -0,0 +1,13 @@
import styles from "./puff.module.css"
import { RTETypeEnum } from "@/types/rte/enums"
import type { EmbedByUid } from "@/types/components/jsontohtml"
import type { RTENext, RTEDefaultNode } 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 <p className={styles.p}>{next(node.children, embeds, fullRenderOptions)}</p>
},
}