From f27dee0c56afd6a6720f2ddf352befd3082f9a5c Mon Sep 17 00:00:00 2001 From: Pontus Dreij Date: Wed, 18 Sep 2024 15:12:11 +0200 Subject: [PATCH] feat(SW-213): Created Text Cols component and added to Blocks in Contentstack --- components/Content/Blocks/TextCols/index.tsx | 26 ++++++++++++++ .../Blocks/TextCols/textcols.module.css | 36 +++++++++++++++++++ components/Content/Blocks/index.tsx | 3 ++ lib/graphql/Query/ContentPage.graphql | 22 ++++++++++++ .../contentstack/contentPage/output.ts | 22 +++++++++--- types/components/content/blocks.ts | 3 ++ types/components/content/enums.ts | 1 + .../trpc/routers/contentstack/contentPage.ts | 21 ++++++++++- 8 files changed, 129 insertions(+), 5 deletions(-) create mode 100644 components/Content/Blocks/TextCols/index.tsx create mode 100644 components/Content/Blocks/TextCols/textcols.module.css diff --git a/components/Content/Blocks/TextCols/index.tsx b/components/Content/Blocks/TextCols/index.tsx new file mode 100644 index 000000000..4777c496a --- /dev/null +++ b/components/Content/Blocks/TextCols/index.tsx @@ -0,0 +1,26 @@ +import JsonToHtml from "@/components/JsonToHtml" +import Subtitle from "@/components/TempDesignSystem/Text/Subtitle" + +import styles from "./textcols.module.css" + +import { TextColsProps } from "@/types/components/content/blocks" + +export default function TextCols({ text_cols }: TextColsProps) { + return ( +
+ {text_cols.columns.map((col) => { + return ( +
+ {col.title} +
+ +
+
+ ) + })} +
+ ) +} diff --git a/components/Content/Blocks/TextCols/textcols.module.css b/components/Content/Blocks/TextCols/textcols.module.css new file mode 100644 index 000000000..d9fd60a1c --- /dev/null +++ b/components/Content/Blocks/TextCols/textcols.module.css @@ -0,0 +1,36 @@ +.columns { + display: flex; + flex-direction: column; + gap: var(--Spacing-x3); + padding: var(--Spacing-x3) var(--Spacing-x4); + background-color: var(--UI-Opacity-White-100); +} + +.column { + padding-bottom: var(--Spacing-x2); + border-bottom: 1px solid var(--Base-Border-Subtle); + gap: var(--Spacing-x1); + display: flex; + flex-direction: column; +} + +.text p { + color: var(--UI-Text-High-contrast); + line-height: var(--Spacing-x3); +} + +.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)); + } +} diff --git a/components/Content/Blocks/index.tsx b/components/Content/Blocks/index.tsx index 9c396ed11..fc162f590 100644 --- a/components/Content/Blocks/index.tsx +++ b/components/Content/Blocks/index.tsx @@ -3,6 +3,7 @@ import JsonToHtml from "@/components/JsonToHtml" import Shortcuts from "@/components/MyPages/Blocks/Shortcuts" import CardsGrid from "./CardsGrid" +import TextCols from "./TextCols" import type { BlocksProps } from "@/types/components/content/blocks" import { ContentBlocksTypenameEnum } from "@/types/components/content/enums" @@ -38,6 +39,8 @@ export function Blocks({ blocks }: BlocksProps) { firstItem={firstItem} /> ) + case ContentBlocksTypenameEnum.ContentPageBlocksTextCols: + return default: return null } diff --git a/lib/graphql/Query/ContentPage.graphql b/lib/graphql/Query/ContentPage.graphql index dec4b0d6f..e84612c0c 100644 --- a/lib/graphql/Query/ContentPage.graphql +++ b/lib/graphql/Query/ContentPage.graphql @@ -98,6 +98,28 @@ query GetContentPage($locale: String!, $uid: String!) { } } } + ... on ContentPageBlocksTextCols { + __typename + text_cols { + columns { + title + text { + json + embedded_itemsConnection { + edges { + node { + __typename + ...LoyaltyPageLink + ...ContentPageLink + ...HotelPageLink + } + } + totalCount + } + } + } + } + } } title header { diff --git a/server/routers/contentstack/contentPage/output.ts b/server/routers/contentstack/contentPage/output.ts index 1aa324041..21d7b1708 100644 --- a/server/routers/contentstack/contentPage/output.ts +++ b/server/routers/contentstack/contentPage/output.ts @@ -12,12 +12,8 @@ import { SidebarDynamicComponentEnum, SidebarTypenameEnum, } from "@/types/components/content/enums" -import { ImageVaultAsset } from "@/types/components/imageVault" -import { Embeds } from "@/types/requests/embeds" import { PageLinkEnum } from "@/types/requests/pageLinks" import { RTEEmbedsEnum } from "@/types/requests/rte" -import { EdgesWithTotalCount } from "@/types/requests/utils/edges" -import { RTEDocument } from "@/types/rte/node" // Block schemas export const contentPageBlockTextContent = z.object({ @@ -135,11 +131,29 @@ export const contentPageCards = z.object({ }), }) +export const contentPageTextCols = z.object({ + __typename: z.literal(ContentBlocksTypenameEnum.ContentPageBlocksTextCols), + text_cols: z.object({ + columns: z.array( + z.object({ + title: z.string(), + text: z.object({ + json: z.any(), + embedded_itemsConnection: z.object({ + edges: z.array(z.any()), + totalCount: z.number(), + }), + }), + }) + ), + }), +}) const contentPageBlockItem = z.discriminatedUnion("__typename", [ contentPageBlockTextContent, contentPageCards, contentPageDynamicContent, contentPageShortcuts, + contentPageTextCols, ]) export const contentPageSidebarTextContent = z.object({ diff --git a/types/components/content/blocks.ts b/types/components/content/blocks.ts index a97ac9780..a9f27bafb 100644 --- a/types/components/content/blocks.ts +++ b/types/components/content/blocks.ts @@ -7,6 +7,7 @@ import { Block, CardsGrid, DynamicContent, + TextCols, } from "@/types/trpc/routers/contentstack/contentPage" export type BlocksProps = { @@ -17,6 +18,8 @@ export type CardsGridProps = Pick & { firstItem?: boolean } +export type TextColsProps = Pick + export type DynamicContentProps = { dynamicContent: DynamicContent["dynamic_content"] firstItem: boolean diff --git a/types/components/content/enums.ts b/types/components/content/enums.ts index 3bc20ac48..cafb608fa 100644 --- a/types/components/content/enums.ts +++ b/types/components/content/enums.ts @@ -6,6 +6,7 @@ export enum ContentBlocksTypenameEnum { ContentPageBlocksShortcuts = "ContentPageBlocksShortcuts", ContentPageBlocksCardsGrid = "ContentPageBlocksCardsGrid", ContentPageBlocksDynamicContent = "ContentPageBlocksDynamicContent", + ContentPageBlocksTextCols = "ContentPageBlocksTextCols", } export enum CardsGridEnum { diff --git a/types/trpc/routers/contentstack/contentPage.ts b/types/trpc/routers/contentstack/contentPage.ts index 4c3f27ce6..35bb9118f 100644 --- a/types/trpc/routers/contentstack/contentPage.ts +++ b/types/trpc/routers/contentstack/contentPage.ts @@ -9,6 +9,7 @@ import { contentPageShortcuts, contentPageSidebarDynamicContent, contentPageSidebarTextContent, + contentPageTextCols, loyaltyCardBlock, validateContentPageRefsSchema, validateContentPageSchema, @@ -81,4 +82,22 @@ export type CardsGrid = Omit & { } export type CardsRaw = CardsGrid["cards_grid"]["cards"][number] -export type Block = RteBlockContent | Shortcuts | CardsGrid | DynamicContent +type TextColsRaw = z.infer +export interface TextCols extends TextColsRaw { + text_cols: { + columns: { + title: string + text: { + json: RTEDocument + embedded_itemsConnection: EdgesWithTotalCount + } + }[] + } +} + +export type Block = + | RteBlockContent + | Shortcuts + | CardsGrid + | DynamicContent + | TextCols