Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into 110-users-can-get-mor…
Browse files Browse the repository at this point in the history
…e-information-on-terms-in-the-wiki
  • Loading branch information
pascalalferink committed Nov 17, 2022
2 parents 16fd406 + bf42b66 commit b9133c3
Show file tree
Hide file tree
Showing 35 changed files with 4,090 additions and 149 deletions.
6 changes: 3 additions & 3 deletions frontend/components/Blocks/CardsBlock/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import RawHtml from "../../RawHtml/RawHtml";
import Image from "next/future/image";

type CardItem = {
title: string;
Expand Down Expand Up @@ -27,12 +26,13 @@ export default function Card({ cardItem }: Props) {
return (
<div className={` min-h-[400px] ${colorStyle} border-solid border-2 rounded-lg flex flex-col`}>
<div className="overflow-hidden relative m-4 mb-0 flex-1 border">
<Image
{/* eslint-disable @next/next/no-img-element */}
<img
src={cardItem.imageSelector.img.src}
alt={cardItem.imageSelector.img.alt}
width="725"
height="380"
className={"object-fill min-h-full"}
className="object-cover object-center h-full w-full max-w-none max-h-none"
/>
</div>

Expand Down
Empty file.
29 changes: 19 additions & 10 deletions frontend/components/Blocks/CardsBlock/CardBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React from "react";
import Card from "./Card";
import ButtonBlock from "@/components/Button/ButtonBlock";

type Props = {
data: {
type: string;
value: {
cards: Array<CardItem>;
buttonBlock: React.ComponentProps<typeof ButtonBlock["buttons"]>;
};
id: string;
};
Expand All @@ -29,19 +31,26 @@ type CardItem = {

export default function CardBlock({
data: {
value: { cards },
value: { cards, buttonBlock },
},
}: Props) {
return (
<div
className={`grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 py-12 px-10 lg:px-16 lg:pt-16 gap-8`}>
{cards.map((cardItem, index) => {
return (
<React.Fragment key={index}>
<Card cardItem={cardItem}></Card>
</React.Fragment>
);
})}
<div>
<div
className={`grid grid-cols-2 md:grid-cols-3 lg:grid-cols-4 xl:grid-cols-5 py-12 px-10 lg:px-16 lg:pt-16 gap-8`}>
{cards.map((cardItem, index) => {
return (
<React.Fragment key={index}>
<Card cardItem={cardItem}></Card>
</React.Fragment>
);
})}
</div>
{buttonBlock.length > 0 && (
<ButtonBlock
buttons={buttonBlock[0].value.buttons}
align={buttonBlock[0].value.buttonsAlign}></ButtonBlock>
)}
</div>
);
}
4 changes: 4 additions & 0 deletions frontend/components/Blocks/HeroBlock/HeroBlock.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe("<HeroBlock />", () => {
altText: "",
},
],
buttonBlock: [],
text: "Lorem ipsum",
title: "Hello world",
},
Expand Down Expand Up @@ -76,9 +77,12 @@ describe("<HeroBlock />", () => {
img: { src: "http://localhost:3000/video", width: 1, height: 1, alt: "Alt" },
id: 1,
title: "Some image",
alt: "some alt text",
},
},
],
altText: "alternative alt text",
buttonBlock: [],
text: "Lorem ipsum",
title: "Hello world",
},
Expand Down
15 changes: 9 additions & 6 deletions frontend/components/Blocks/HeroBlock/HeroBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { ArrowDownIcon } from "@heroicons/react/24/outline";
import MediaContent from "@/components/MediaContent/MediaContent";
import ButtonBlock from "@/components/Button/ButtonBlock";

import RawHtml from "../../RawHtml";

Expand All @@ -11,12 +12,8 @@ type Props = {
title: string;
text: string;
media: React.ComponentProps<typeof MediaContent>["media"];
alt_text: string;
button?: {
button_style: string;
button_text: string;
button_hyperlink: string;
};
altText: string;
buttonBlock: React.ComponentProps<typeof ButtonBlock["buttons"]>;
};
id: string;
};
Expand Down Expand Up @@ -51,6 +48,12 @@ export default function HeroBlock({ data }: Props) {
</div>

<div className="flex flex-row h-16 justify-center">
{data.value.buttonBlock.length > 0 && (
<ButtonBlock
buttons={data.value.buttonBlock[0].value.buttons}
align="btn-left"></ButtonBlock>
)}

<button
onClick={scrollDown}
className="bg-holon-purple-100 w-12 h-12 mb-4 absolute rounded-full p-2 hover:bg-holon-purple-200">
Expand Down
4 changes: 2 additions & 2 deletions frontend/components/Blocks/SectionBlock/SectionBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { useState, useEffect } from "react";
import ImageSlider from "@/components/InteractiveImage/ImageSlider";
import RawHtml from "@/components/RawHtml/RawHtml";
import Image from "next/future/image";
import { getGrid } from "services/grid";

type Props = {
Expand Down Expand Up @@ -138,7 +137,8 @@ export default function SectionBlock({ data }: Props) {
<div className={`flex flex-col ${gridValue.right}`}>
<div className="lg:sticky py-12 px-10 lg:px-16 lg:pt-24 top-0">
{Object.keys(media).length > 0 && (
<Image src={media.img?.src} alt={media.img?.alt} width="1600" height="900" />
/* eslint-disable @next/next/no-img-element */
<img src={media.img?.src} alt={media.img?.alt} width="1600" height="900" />
)}
</div>
</div>
Expand Down
51 changes: 18 additions & 33 deletions frontend/components/Blocks/TextAndMediaBlock/TextAndMediaBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,74 +1,59 @@
import RawHtml from "@/components/RawHtml";
import MediaContent from "@/components/MediaContent/MediaContent";
import ButtonBlock from "@/components/Button/ButtonBlock";
import { getGrid } from "services/grid";

type Props = {
data: {
type: string;
value: {
gridLayout: {
grid: string;
};
background: {
color: string;
size: string;
};
title: string;
text: string;
media: [
| {
id: string;
value: string;
type: string;
alt_text: string;
}
| {
type: string;
value: {
id: number;
title: string;
img: {
src: string;
width: number;
height: number;
alt: string;
};
};
}
];
media: React.ComponentProps<typeof MediaContent>["media"];
altText: string;
gridLayout: { grid: string };
button?: {
button_style: string;
button_text: string;
button_hyperlink: string;
};
buttonBlock: React.ComponentProps<typeof ButtonBlock["buttons"]>;
};
id: string;
};
};

export default function TextAndMediaBlock({ data }: Props) {
export default function TextAndMedia({ data }: Props) {
const backgroundFullcolor =
data.value.background.size == "bg__full" ? data.value.background.color : "";

// Have to create a seperate variable for this since the bg-color is semi-transparent
// Otherwise they will overlap and will the left be darker since 2 layers
const backgroundLeftColor =
data.value.background.size == "bg__full" ? "" : data.value.background.color;

const gridValue = getGrid(data.value.gridLayout.grid);

return (
<div>
<div className={`${backgroundFullcolor} storyline__row flex flex-col lg:flex-row`}>
<div className={`${backgroundFullcolor}`}>
<div className={` storyline__row flex flex-col lg:flex-row`}>
<div
className={`flex flex-col py-12 px-10 lg:px-16 lg:pt-16 ${gridValue.left} ${backgroundLeftColor}`}>
className={`flex flex-col py-8 px-10 lg:px-16 lg:pt-16 ${gridValue.left} ${backgroundLeftColor}`}>
<RawHtml html={data.value?.text} />
</div>

<div className={`flex flex-col ${gridValue.right}`}>
<div className="lg:sticky py-12 px-10 lg:px-16 lg:pt-24 top-0">
<div className="lg:sticky py-8 px-10 lg:px-16 lg:pt-24 top-0">
<MediaContent media={data.value.media} alt={data.value.altText} />
</div>
</div>
</div>

{data.value.buttonBlock.length > 0 && (
<ButtonBlock
buttons={data.value.buttonBlock[0].value.buttons}
align={data.value.buttonBlock[0].value.buttonsAlign}></ButtonBlock>
)}
</div>
);
}
1 change: 1 addition & 0 deletions frontend/components/Blocks/TitleBlock/TitleBlock.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe("<TitleBlock />", () => {
title: "Hello world",
size: "h2",
text: "Lorem ipsum",
buttonBlock: [],
},
id: "a-block",
}}
Expand Down
20 changes: 15 additions & 5 deletions frontend/components/Blocks/TitleBlock/TitleBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import RawHtml from "../../RawHtml/RawHtml";
import ButtonBlock from "@/components/Button/ButtonBlock";

type Props = {
data: {
Expand All @@ -8,6 +9,7 @@ type Props = {
title: string;
size: React.ElementType;
text: string;
buttonBlock: React.ComponentProps<typeof ButtonBlock["buttons"]>;
};
id: string;
};
Expand All @@ -18,13 +20,21 @@ export default function TitleBlock({ data }: Props) {
const Tag = data.value.size;

return (
<div className={`flex flex-row w-full h-fit py-12 px-10 lg:px-16 lg:pt-16 ${backgroundcolor}`}>
<div className={`flex flex-col justify-start lg:mr-[40%]`}>
<Tag>{data.value.title}</Tag>
<div className="mt-6" data-testid="content">
<RawHtml html={data.value?.text} />
<div>
<div
className={`flex flex-row w-full h-fit py-12 px-10 lg:px-16 lg:pt-16 ${backgroundcolor}`}>
<div className={`flex flex-col justify-start lg:mr-[40%]`}>
<Tag>{data.value.title}</Tag>
<div className="mt-6" data-testid="content">
<RawHtml html={data.value?.text} />
</div>
</div>
</div>
{data.value.buttonBlock.length > 0 && (
<ButtonBlock
buttons={data.value.buttonBlock[0].value.buttons}
align="btn-left"></ButtonBlock>
)}
</div>
);
}
69 changes: 69 additions & 0 deletions frontend/components/Button/Button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import React, { createContext, useContext } from "react";

type ButtonVariant = keyof typeof variants;

type Props<T extends React.ElementType> = {
children: React.ReactNode;
className?: string;
tag?: React.ElementType;
variant?: ButtonVariant;
} & React.ComponentPropsWithoutRef<T>;

const variants = {
dark: "border-white text-white bg-holon-blue-900 hover:bg-holon-blue-500 ",
light: "bg-holon-gold-200 border-holon-blue-900 hover:bg-holon-gold-600",
};

const ButtonContext = createContext<ButtonVariant | undefined>(undefined);

export default function Button<T extends React.ElementType>({
children,
className,
tag: Tag = "button",
variant = "dark",
details,
...rest
}: Props<T>) {
const colorClasses = variants[variant] || variants.dark;

let externLinkProps:
| boolean
| {
target: string;
rel: string;
} = {
target: "_blank",
rel: "noopener noreferrer",
};

function createLink(detail) {
if (detail.buttonLink[0].type === "intern") {
externLinkProps = false;
}
}

createLink(details);

return (
<Tag
className={`${className} ${colorClasses} relative rounded border-2 px-4 py-3 mr-4 mb-4 min-w-[8rem] text-center font-medium leading-5 transition enabled:active:translate-x-holon-bh-x enabled:active:translate-y-holon-bh-y disabled:opacity-50`.trim()}
{...rest}
href={details.buttonLink[0].value}
{...externLinkProps}>
<ButtonContext.Provider value={variant}>{children}</ButtonContext.Provider>
</Tag>
);
}

/**
* Hook which provides access to the button variant.
*/
export function useButtonContext() {
const context = useContext(ButtonContext);

if (!context) {
throw new Error("useButtonContext must be used within a Button");
}

return context;
}
39 changes: 39 additions & 0 deletions frontend/components/Button/ButtonBlock.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import Button from "@/components/Button/Button";

type Props = {
buttons: Array<Button>;
align: string;
};

type Button = {
type: string;
value: {
buttonStyle: "dark" | "light" | undefined;
buttonText: string;
buttonLink: [
{
type: "intern" | "extern";
value: number | string;
id: string;
}
];
buttonAlign: string;
};
id: string;
};

export default function ButtonBlock({ buttons, align }: Props) {
const alignValue = align === "btn-left" ? "justify-start" : "justify-center";

return (
<div className={`flex flex-row w-full ${alignValue} h-fit px-10 lg:px-16 lg:pb-4 flex-wrap `}>
{buttons.map((button, index) => {
return (
<Button tag="a" details={button.value} variant={button.value.buttonStyle} key={index}>
{button.value.buttonText}
</Button>
);
})}
</div>
);
}

0 comments on commit b9133c3

Please sign in to comment.