-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #744 from CodeForAfrica/ft/roboshield-about-page-cms
About Page CMS
- Loading branch information
Showing
20 changed files
with
597 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Section } from "@commons-ui/core"; | ||
import { Page } from "@/root/payload-types"; | ||
import { | ||
ExtractBlockType, | ||
ExtractNestedBlockType, | ||
} from "@/roboshield/utils/blocks"; | ||
import LongFormRichText from "@/roboshield/components/LongFormRichText"; | ||
import LongFormMedia from "@/roboshield/components/LongFormMedia"; | ||
import LongFormExternalEmbed from "@/roboshield/components/LongFormExternalEmbed"; | ||
|
||
type ContentProps = ExtractBlockType< | ||
NonNullable<Page["blocks"]>[number], | ||
"content" | ||
>; | ||
|
||
export type ExternalEmbeddBlock = ExtractNestedBlockType< | ||
NonNullable<ContentProps["content"]>[number], | ||
"externalEmbedd" | ||
>; | ||
|
||
export type RichTextBlock = ExtractNestedBlockType< | ||
NonNullable<ContentProps["content"]>[number], | ||
"richtext" | ||
>; | ||
|
||
export type MediaBlock = ExtractNestedBlockType< | ||
NonNullable<ContentProps["content"]>[number], | ||
"mediaBlock" | ||
>; | ||
|
||
type ComponentMap = { | ||
richtext: (props: RichTextBlock) => JSX.Element; | ||
mediaBlock?: (props: MediaBlock) => JSX.Element; | ||
externalEmbedd?: (props: ExternalEmbeddBlock) => JSX.Element; | ||
}; | ||
export default function Content({ content }: ContentProps) { | ||
const COMPONENT_BY_CONTENT_TYPE: ComponentMap = { | ||
richtext: LongFormRichText, | ||
mediaBlock: LongFormMedia, | ||
externalEmbedd: LongFormExternalEmbed, | ||
}; | ||
|
||
return ( | ||
<Section | ||
component="section" | ||
variant="body3" | ||
sx={{ | ||
px: { xs: 2.5, sm: 0 }, | ||
my: 10, | ||
}} | ||
> | ||
{content?.map((child) => { | ||
const Component = COMPONENT_BY_CONTENT_TYPE[child.blockType]; | ||
|
||
if (Component) { | ||
return <Component key={child.id} {...child} />; | ||
} | ||
|
||
return null; | ||
})} | ||
</Section> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Content from "./Content"; | ||
|
||
export default Content; |
30 changes: 30 additions & 0 deletions
30
apps/roboshield/src/components/LongFormExternalEmbed/LongFormExternalEmbed.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { RichTypography } from "@commons-ui/core"; | ||
import { Box } from "@mui/material"; | ||
import React from "react"; | ||
import { ExternalEmbeddBlock } from "@/roboshield/components/Content/Content"; | ||
|
||
export default function LongFormExternalEmbed(props: ExternalEmbeddBlock) { | ||
const { externalEmbeddFields: { code = "", caption = "", url = "" } = {} } = | ||
props; | ||
|
||
return ( | ||
<Box | ||
sx={{ | ||
my: 5, | ||
}} | ||
> | ||
{code && <RichTypography>{code}</RichTypography>} | ||
{url && ( | ||
<iframe | ||
src={url} | ||
title={caption!} | ||
style={{ | ||
width: "100%", | ||
height: "500px", | ||
border: "none", | ||
}} | ||
/> | ||
)} | ||
</Box> | ||
); | ||
} |
3 changes: 3 additions & 0 deletions
3
apps/roboshield/src/components/LongFormExternalEmbed/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import LongFormExternalEmbed from "./LongFormExternalEmbed"; | ||
|
||
export default LongFormExternalEmbed; |
43 changes: 43 additions & 0 deletions
43
apps/roboshield/src/components/LongFormMedia/LongFormMedia.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import { Figure } from "@commons-ui/next"; | ||
import { Box } from "@mui/material"; | ||
import React from "react"; | ||
import { MediaBlock } from "@/roboshield/components/Content/Content"; | ||
import { Media } from "@/root/payload-types"; | ||
|
||
export default function LongFormMedia({ image }: MediaBlock) { | ||
const mediaImage = image as Media; | ||
return ( | ||
<Box | ||
sx={{ | ||
my: 5, | ||
}} | ||
> | ||
<Figure | ||
ImageProps={{ | ||
alt: mediaImage.alt, | ||
sx: { | ||
objectFit: "cover", | ||
position: "relative !important", | ||
}, | ||
src: mediaImage.url, | ||
}} | ||
sx={{ | ||
height: { | ||
xs: "200px", | ||
md: "500px", | ||
}, | ||
width: "100%", | ||
}} | ||
> | ||
<figcaption | ||
style={{ | ||
width: "100%", | ||
margin: "0 auto", | ||
}} | ||
> | ||
{mediaImage.alt} | ||
</figcaption> | ||
</Figure> | ||
</Box> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import LongFormMedia from "./LongFormMedia"; | ||
|
||
export default LongFormMedia; |
78 changes: 78 additions & 0 deletions
78
apps/roboshield/src/components/LongFormRichText/LongFormRichText.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import React from "react"; | ||
|
||
import RichText from "@/roboshield/components/RichText"; | ||
import { RichTextBlock } from "@/roboshield/components/Content/Content"; | ||
|
||
export default function LongFormRichText({ content }: RichTextBlock) { | ||
return ( | ||
<RichText | ||
elements={content} | ||
sx={(theme) => ({ | ||
color: "inherit", | ||
"& a, & a:visited, & a:hover": { | ||
color: "inherit", | ||
}, | ||
"& h1": { | ||
...theme.typography.h1, | ||
mb: 3.75, | ||
mt: 5, | ||
}, | ||
"& h2": { | ||
mb: 2.5, | ||
mt: 5, | ||
...theme.typography.h2, | ||
}, | ||
"& h3": { | ||
mb: 1.25, | ||
mt: 5, | ||
...theme.typography.h3, | ||
}, | ||
"& h4": { | ||
mb: 1.25, | ||
mt: 5, | ||
...theme.typography.h4, | ||
}, | ||
"& h5": { | ||
mb: 1.25, | ||
mt: 5, | ||
...theme.typography.h5Small, | ||
[theme.breakpoints.up("md")]: { | ||
...theme.typography.h5, | ||
}, | ||
}, | ||
"& h6": { | ||
mb: 1.25, | ||
mt: 5, | ||
...theme.typography.h6, | ||
}, | ||
"& p": { | ||
...theme.typography.body1, | ||
mb: 2, | ||
[theme.breakpoints.up("md")]: { | ||
...theme.typography.body3, | ||
}, | ||
}, | ||
"& a": { | ||
...theme.typography.body1, | ||
mb: 2, | ||
[theme.breakpoints.up("md")]: { | ||
...theme.typography.body3, | ||
}, | ||
}, | ||
"& ul": { | ||
mb: 2, | ||
}, | ||
"& li": { | ||
...theme.typography.body1, | ||
mt: 1, | ||
[theme.breakpoints.up("md")]: { | ||
...theme.typography.body3, | ||
}, | ||
}, | ||
"& :last-child": { | ||
mb: 0, | ||
}, | ||
})} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import LongFormRichText from "./LongFormRichText"; | ||
|
||
export default LongFormRichText; |
Oops, something went wrong.