feat(SW-66, SW-348): search functionality and ui
This commit is contained in:
29
components/Blocks/TextCols/index.tsx
Normal file
29
components/Blocks/TextCols/index.tsx
Normal file
@@ -0,0 +1,29 @@
|
||||
import JsonToHtml from "@/components/JsonToHtml"
|
||||
import Subtitle from "@/components/TempDesignSystem/Text/Subtitle"
|
||||
|
||||
import { renderOptions } from "./renderOptions"
|
||||
|
||||
import styles from "./textcols.module.css"
|
||||
|
||||
import type { TextColProps } from "@/types/components/blocks/textCols"
|
||||
|
||||
export default function TextCols({ text_cols }: TextColProps) {
|
||||
return (
|
||||
<div className={styles.columns}>
|
||||
{text_cols.columns.map((col) => {
|
||||
return (
|
||||
<section key={col.title} className={styles.column}>
|
||||
<Subtitle>{col.title}</Subtitle>
|
||||
<div className={styles.text}>
|
||||
<JsonToHtml
|
||||
nodes={col.text.json.children}
|
||||
embeds={col.text.embedded_itemsConnection.edges}
|
||||
renderOptions={renderOptions}
|
||||
/>
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
})}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
70
components/Blocks/TextCols/renderOptions.tsx
Normal file
70
components/Blocks/TextCols/renderOptions.tsx
Normal file
@@ -0,0 +1,70 @@
|
||||
import Link from "@/components/TempDesignSystem/Link"
|
||||
|
||||
import styles from "./textcols.module.css"
|
||||
|
||||
import type { EmbedByUid } from "@/types/transitionTypes/jsontohtml"
|
||||
import { RTEItemTypeEnum, RTETypeEnum } from "@/types/transitionTypes/rte/enums"
|
||||
import type {
|
||||
RTEDefaultNode,
|
||||
RTENext,
|
||||
RTENode,
|
||||
RTERegularNode,
|
||||
} from "@/types/transitionTypes/rte/node"
|
||||
import type { RenderOptions } from "@/types/transitionTypes/rte/option"
|
||||
|
||||
export const renderOptions: RenderOptions = {
|
||||
[RTETypeEnum.p]: (
|
||||
node: RTEDefaultNode,
|
||||
embeds: EmbedByUid,
|
||||
next: RTENext,
|
||||
fullRenderOptions: RenderOptions
|
||||
) => {
|
||||
return (
|
||||
<p key={node.uid} className={styles.p}>
|
||||
{next(node.children, embeds, fullRenderOptions)}
|
||||
</p>
|
||||
)
|
||||
},
|
||||
[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
|
||||
}
|
||||
},
|
||||
}
|
||||
40
components/Blocks/TextCols/textcols.module.css
Normal file
40
components/Blocks/TextCols/textcols.module.css
Normal file
@@ -0,0 +1,40 @@
|
||||
.columns {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: var(--Spacing-x3);
|
||||
padding: var(--Spacing-x3) var(--Spacing-x4);
|
||||
}
|
||||
|
||||
.column {
|
||||
padding-bottom: var(--Spacing-x2);
|
||||
border-bottom: 1px solid var(--Base-Border-Subtle);
|
||||
gap: var(--Spacing-x1);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.p {
|
||||
color: var(--UI-Text-High-contrast);
|
||||
line-height: var(--Spacing-x3);
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.a {
|
||||
color: var(--Base-Text-High-contrast);
|
||||
}
|
||||
|
||||
.text > section {
|
||||
gap: 0;
|
||||
}
|
||||
|
||||
@media (min-width: 768px) {
|
||||
.columns {
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
|
||||
.column {
|
||||
flex: 0 0 calc(50% - var(--Spacing-x3));
|
||||
max-width: calc(50% - var(--Spacing-x3));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user