Skip to content

Trustlab: Showcase block #1181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const DonorOverviewList = React.forwardRef(
<Section
sx={(theme) => ({
px: { xs: 2.5, sm: 0 },
py: { xs: 5, md: 7, lg: 10 },
py: 4.5,
maxWidth: theme.contentWidths.values,
m: "0 auto",
...sx,
Expand Down Expand Up @@ -48,7 +48,6 @@ const DonorOverviewList = React.forwardRef(
sm={2}
justifyContent="center"
key={id}
spacing={2}
sx={{
width: {
xs: "100%",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const PartnerOverviewList = React.forwardRef(
<Box
sx={(theme) => ({
px: { xs: 2.5, sm: 0 },
py: { xs: 5, md: 7, lg: 10 },
py: 4.5,
maxWidth: theme.contentWidths.values,
m: "0 auto",
...sx,
Expand Down Expand Up @@ -54,7 +54,6 @@ const PartnerOverviewList = React.forwardRef(
sm={2}
justifyContent="center"
key={id}
spacing={2}
sx={{
width: {
xs: "100%",
Expand Down
185 changes: 185 additions & 0 deletions apps/trustlab/src/components/ShowCase/ShowCase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
import { Section } from "@commons-ui/core";
import { Figure, Link } from "@commons-ui/next";
import { LexicalRichText } from "@commons-ui/payload";
import { Box, Button } from "@mui/material";
import React from "react";

function ShowCase({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is Showcase (one word) component... The goal isn't to showcase the images and content. I think it's more of a call to action i.e. calling attention to the incubator or security course on academy.AFRICA.

direction = "rtl",
images,
title,
description,
label,
href,
}) {
if (!images || images.length < 4) {
return null;
}
const [image1, image2, image3, image4] = images;
return (
<Section
sx={{
maxWidth: { md: "100%", xs: "100%" },
bgcolor: "common.black",
color: "common.white",
py: 8,
}}
fixed={false}
>
<Box
Comment on lines +20 to +29
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment here.

sx={(theme) => ({
display: "flex",
flexDirection: {
xs: "column",
md: direction === "ltr" ? "row" : "row-reverse",
},
justifyContent: "flex-end",
width: "100%",
color: "white",
overflow: "hidden",
maxWidth: theme.contentWidths.values,
m: "0 auto",
gap: 2,
})}
>
<Box
sx={{
position: "relative",
height: { sm: "600px", xs: "360px" },
width: { xs: "390px", sm: "572px" },
maxWidth: "572px",
margin: "0 auto",
}}
>
<Figure
ImageProps={{
src: image1.image.src,
alt: image1.image.alt || "Showcase Image 1",
}}
sx={{
display: {
sm: "block",
},
height: { sm: "253px", xs: "153px" },
width: { sm: "203px", xs: 121 },
position: "absolute",
top: 0,
left: 80,
}}
/>
<Figure
ImageProps={{
src: image2.image.src,
alt: image2.image.alt || "Showcase Image 2",
}}
sx={{
display: {
sm: "block",
},
height: { sm: "253px", xs: "157px" },
width: { sm: "260px", xs: "157px" },
position: "absolute",
right: 20,
bottom: { sm: "276px", xs: "unset" },
top: { sm: "unset", xs: "16px" },
}}
/>
<Figure
ImageProps={{
src: image3.image.src,
alt: image3.image.alt || "Showcase Image 3",
}}
sx={{
display: {
sm: "block",
},
height: { sm: "260px", xs: "157px" },
width: { sm: "260px", xs: "157px" },
position: "absolute",
top: { sm: "276px", xs: "160px" },
left: { sm: 0, xs: "32px" },
}}
/>

<Figure
ImageProps={{
src: image4.image.src,
alt: image4.image.alt || "Showcase Image 4",
}}
sx={{
display: {
sm: "block",
},
height: { sm: "260px", xs: "157px" },
width: { sm: "200px", xs: "121px" },
position: "absolute",
bottom: { xs: "unset", sm: "0" },
top: { xs: "176px", sm: "unset" },
left: { sm: "276px", xs: "200px" },
}}
/>
</Box>

<Box
flex={1}
alignItems="center"
justifyContent="center"
display="flex"
sx={{
px: { xs: 2.5, sm: 0 },
}}
>
<Box
sx={{
flex: 1,
bgcolor: "white",
color: "black",
p: { xs: 3, md: 6 },
display: "flex",
flexDirection: "column",
justifyContent: "center",
ml: { xs: 0, md: direction === "ltr" ? -10 : 0 },
mr: { xs: 0, md: direction === "ltr" ? 0 : -10 },
zIndex: 1,
}}
>
<LexicalRichText
elements={title}
TypographyProps={{
variant: "display3",
gutterBottom: true,
}}
/>
<LexicalRichText
elements={description}
TypographyProps={{
sx: { mb: 3 },
}}
/>
<Button
variant="contained"
component={href ? Link : undefined}
href={href}
sx={{
bgcolor: "black",
color: "white",
fontWeight: "bold",
px: 4,
py: 1.5,
"&:hover": {
bgcolor: "#222",
},
width: "fit-content",
mt: 6,
}}
>
{label}
</Button>
</Box>
</Box>
</Box>
</Section>
);
}

export default ShowCase;
3 changes: 3 additions & 0 deletions apps/trustlab/src/components/ShowCase/ShowCase.snap.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<ShowCase /> renders unchanged 1`] = `<div />`;
17 changes: 17 additions & 0 deletions apps/trustlab/src/components/ShowCase/ShowCase.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { createRender } from "@commons-ui/testing-library";
import React from "react";

import ShowCase from "./ShowCase";

import theme from "@/trustlab/theme";

const render = createRender({ theme });

const defaultProps = {};

describe("<ShowCase />", () => {
it("renders unchanged", () => {
const { container } = render(<ShowCase {...defaultProps} />);
expect(container).toMatchSnapshot();
});
});
3 changes: 3 additions & 0 deletions apps/trustlab/src/components/ShowCase/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import ShowCase from "./ShowCase";

export default ShowCase;
4 changes: 3 additions & 1 deletion apps/trustlab/src/pages/[[...slugs]].page.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import { SWRConfig } from "swr";
import DonorOverviewList from "@/trustlab/components/DonorOverviewList";
import Hero from "@/trustlab/components/Hero";
import PartnerOverviewList from "@/trustlab/components/PartnerOverviewList";
import ShowCase from "@/trustlab/components/ShowCase";
import { getPageStaticPaths, getPageStaticProps } from "@/trustlab/lib/data";

const componentsBySlugs = {
hero: Hero,
"partner-overview-list": PartnerOverviewList,
"donor-overview-list": DonorOverviewList,
showcase: ShowCase,
};

function Page({ blocks, fallback }) {
Expand All @@ -30,7 +32,7 @@ function Page({ blocks, fallback }) {
if (!Component) {
return null;
}
return <Component {...block} key={block.slug} />;
return <Component {...block} key={block.id} />;
})}
</PageComponent>
);
Expand Down
62 changes: 62 additions & 0 deletions apps/trustlab/src/payload/blocks/ShowCase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { richText, image, link } from "@commons-ui/payload";

const ShowCase = {
slug: "showcase",
labels: {
singular: "Showcase Block",
plural: "Showcase Blocks",
},
imageURL: "/images/cms/blocks/showcase.png",
imageAltText: "Showcases images and content.",
fields: [
richText({
name: "title",
required: true,
}),
Comment on lines +12 to +15
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are titles actually rich text?

richText({
name: "description",
required: true,
admin: {
description: "A brief description of the slide content.",
},
}),
{
name: "direction",
type: "select",
options: [
{ label: "Left to Right", value: "ltr" },
{ label: "Right to Left", value: "rtl" },
],
defaultValue: "ltr",
Comment on lines +26 to +30
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rtl could mean we're writing Arabic now 😄. May be we should have order (I think Grid has something similar) i.e. images first vs content first

admin: {
description:
"Direction of images -> content card the showcase block. This is used to determine the layout of the showcase block.",
},
},
link({
name: "action",
label: "Action Link",
required: true,
}),
{
name: "images",
type: "array",
label: { en: "Images" },
minRows: 4,
maxRows: 4,
fields: [
image({
overrides: {
name: "image",
required: true,
admin: {
description: "Image to display in the showcase block.",
},
},
}),
],
},
],
};

export default ShowCase;
3 changes: 2 additions & 1 deletion apps/trustlab/src/payload/collections/Pages.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { anyone } from "@/trustlab/payload/access/anyone";
import DonorOverviewList from "@/trustlab/payload/blocks/DonorOverviewList";
import Hero from "@/trustlab/payload/blocks/Hero";
import PartnerOverviewList from "@/trustlab/payload/blocks/PartnerOverviewList";
import ShowCase from "@/trustlab/payload/blocks/ShowCase";
import { hideAPIURL } from "@/trustlab/payload/utils";

const Pages = {
Expand Down Expand Up @@ -41,7 +42,7 @@ const Pages = {
{
name: "blocks",
type: "blocks",
blocks: [Hero, DonorOverviewList, PartnerOverviewList],
blocks: [Hero, DonorOverviewList, PartnerOverviewList, ShowCase],
localized: true,
admin: {
initCollapsed: true,
Expand Down
Loading