Skip to content

Commit

Permalink
Merge pull request #949 from CodeForAfrica/ft/climatemapped-visualisa…
Browse files Browse the repository at this point in the history
…tion-guide

ClimateMapped Data Visualisation Guide
  • Loading branch information
kelvinkipruto authored Oct 23, 2024
2 parents 736d0f3 + c60ddaf commit 23e6c9c
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 11 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 24 additions & 2 deletions apps/climatemappedafrica/src/components/Card/Card.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Link } from "@commons-ui/next";
import { Card as MuiCard } from "@mui/material";
import clsx from "clsx";
import PropTypes from "prop-types";
import React from "react";

Expand Down Expand Up @@ -28,6 +27,7 @@ function Card({
title,
titleProps,
variant,
sx,
...props
}) {
const squareMedia = mediaProps?.square;
Expand All @@ -43,7 +43,29 @@ function Card({
};

return (
<MuiCard elevation={0} square className={clsx(classes.root, className)}>
<MuiCard
elevation={0}
square
sx={(theme) => ({
backgroundColor: "inherit",
boxShadow: "none",
borderRadius: 0,
padding: {
xs: squareMedia ? `0 ${theme.typography.pxToRem(36)}` : 0,
md: 0,
},
minWidth: {
xs: theme.typography.pxToRem(350),
md: "unset",
},
width: {
xs: "100%",
md: theme.typography.pxToRem(squareMedia ? 278 : 296),
lg: theme.typography.pxToRem(squareMedia ? 278 : 376),
},
...sx,
})}
>
<CardActionArea
{...actionAreaProps}
classes={{
Expand Down
2 changes: 1 addition & 1 deletion apps/climatemappedafrica/src/components/Card/Card.snap.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
exports[`<Card /> renders unchanged 1`] = `
<div>
<div
class="MuiPaper-root MuiPaper-elevation MuiPaper-elevation0 MuiCard-root makeStyles-root-1 makeStyles-root-11 css-1rw30ef-MuiPaper-root-MuiCard-root"
class="MuiPaper-root MuiPaper-elevation MuiPaper-elevation0 MuiCard-root css-s2nibj-MuiPaper-root-MuiCard-root"
/>
</div>
`;
24 changes: 17 additions & 7 deletions apps/climatemappedafrica/src/components/Card/Content.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { RichTypography } from "@commons-ui/core";
import { RichText } from "@commons-ui/payload";
import { CardContent } from "@mui/material";
import makeStyles from "@mui/styles/makeStyles";
import clsx from "clsx";
Expand Down Expand Up @@ -44,13 +45,22 @@ function Content({
<RichTypography variant="h5" {...titleProps} className={classes.title}>
{title}
</RichTypography>
<RichTypography
variant="subtitle2"
{...descriptionProps}
className={classes.description}
>
{description}
</RichTypography>
{/* Support for rich text while keeping backwards compatibility */}
{Array.isArray(description) ? (
<RichText
{...descriptionProps}
className={classes.description}
elements={description}
/>
) : (
<RichTypography
variant="subtitle2"
{...descriptionProps}
className={classes.description}
>
{description}
</RichTypography>
)}
</CardContent>
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { RichTypography } from "@commons-ui/core";
import { useMediaQuery, Box, Grid } from "@mui/material";
import PropTypes from "prop-types";
import React from "react";

import Card from "@/climatemappedafrica/components/Card";
import Carousel from "@/climatemappedafrica/components/Carousel";
import Section from "@/climatemappedafrica/components/Section";

function DataVisualisationGuide({ title, items }) {
const isDesktop = useMediaQuery((theme) => theme.breakpoints.up("lg"));

if (!items?.length) {
return null;
}
return (
<Box
sx={(theme) => ({
padding: `${theme.typography.pxToRem(40)} 0`,
})}
>
<Section>
<RichTypography component="h4" variant="h4">
{title}
</RichTypography>
<Box
sx={{
display: {
xs: "none",
md: "block",
},
}}
>
<Carousel showDots={!isDesktop}>
{items.map((item) => (
<Card
key={item.id}
{...item}
sx={{
marginTop: "40px",
"& .bold": {
fontWeight: "bold",
},
}}
/>
))}
</Carousel>
</Box>
<Box
sx={{
display: {
xs: "block",
md: "none",
},
}}
>
<Grid
container
direction={{ xs: "column", md: "row" }}
justifyContent={{ md: "space-between" }}
>
{items.map((item) => (
<Grid item xs={12} key={item.id}>
<Card
{...item}
sx={(theme) => ({
marginTop: theme.typography.pxToRem(40),
"& .bold": {
fontWeight: "bold",
},
})}
/>
</Grid>
))}
</Grid>
</Box>
</Section>
</Box>
);
}

DataVisualisationGuide.propTypes = {
title: PropTypes.string,
items: PropTypes.arrayOf(
PropTypes.shape({
description: PropTypes.string || PropTypes.array,
image: PropTypes.string,
}),
),
};

export default DataVisualisationGuide;
2 changes: 2 additions & 0 deletions apps/climatemappedafrica/src/pages/[[...slugs]].js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import React from "react";
import { SWRConfig } from "swr";

import AboutTeam from "@/climatemappedafrica/components/AboutTeam";
import DataVisualisationGuide from "@/climatemappedafrica/components/DataVisualisationGuide";
import Footer from "@/climatemappedafrica/components/Footer";
import Hero from "@/climatemappedafrica/components/Hero";
import HowItWorks from "@/climatemappedafrica/components/HowItWorks";
Expand All @@ -12,6 +13,7 @@ import Summary from "@/climatemappedafrica/components/Summary";
import { getPageServerSideProps } from "@/climatemappedafrica/lib/data";

const componentsBySlugs = {
"data-visualisation-guide": DataVisualisationGuide,
hero: Hero,
"how-it-works": HowItWorks,
"page-hero": PageHero,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { slateEditor } from "@payloadcms/richtext-slate";

import image from "../fields/image";

const DataVisualisationGuide = {
slug: "data-visualisation-guide",
imageURL: "/images/cms/blocks/data-visualisation-guide.png",
fields: [
{
name: "title",
type: "text",
required: true,
localized: true,
},
{
name: "items",
type: "array",
minRows: 1,
fields: [
image({
overrides: {
required: true,
},
}),
{
name: "description",
type: "richText",
required: true,
editor: slateEditor({
admin: {
elements: ["link"],
leaves: ["bold", "code", "italic", "underline"],
},
}),
},
],
},
],
};

export default DataVisualisationGuide;
10 changes: 9 additions & 1 deletion apps/climatemappedafrica/src/payload/collections/Pages.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import DataVisualisationGuide from "../blocks/DataVisualisationGuide";
import Hero from "../blocks/Hero";
import HowItWorks from "../blocks/HowItWorks";
import PageHero from "../blocks/PageHero";
Expand Down Expand Up @@ -32,7 +33,14 @@ const Pages = {
{
name: "blocks",
type: "blocks",
blocks: [Hero, HowItWorks, PageHero, Summary, Team],
blocks: [
DataVisualisationGuide,
Hero,
HowItWorks,
PageHero,
Summary,
Team,
],
localized: true,
admin: {
initCollapsed: true,
Expand Down

0 comments on commit 23e6c9c

Please sign in to comment.