Skip to content

Commit

Permalink
add heroHTML
Browse files Browse the repository at this point in the history
  • Loading branch information
twentytitus committed Jul 10, 2024
1 parent 8359fd3 commit e65a53e
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 16 deletions.
37 changes: 23 additions & 14 deletions components/Hero/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,37 @@ import Image from 'next/image';
import { getAssetURL } from '../Util/getAssetURL';

type HeroProps = {
heroHTML: string | null;
heroTitle: string | null;
heroSubTitle: string | null;
heroImage: string;
heroImage: string | null;
};

export const Hero = ({ heroTitle, heroSubTitle, heroImage }: HeroProps) => {
export const Hero = ({
heroHTML,
heroTitle,
heroSubTitle,
heroImage,
}: HeroProps) => {
const [imageLoaded, setImageLoaded] = useState(false);

return (
<section className={s.heroContainer}>
<div className={s.imageContainer}>
<Image
onLoad={() => {
setImageLoaded(true);
}}
className={cN(s.heroImage, { [s.imageZoom]: imageLoaded })}
src={getAssetURL(heroImage)}
alt={'Bild der Expedition Grundeinkommen'}
layout={'fill'}
priority={true}
/>
</div>
{heroImage && (
<div className={s.imageContainer}>
<Image
onLoad={() => {
setImageLoaded(true);
}}
className={cN(s.heroImage, { [s.imageZoom]: imageLoaded })}
src={getAssetURL(heroImage)}
alt={'Bild der Expedition Grundeinkommen'}
layout={'fill'}
priority={true}
/>
</div>
)}
{heroHTML && <div className={s.heroHTMLContainer}>{heroHTML}</div>}
{heroTitle && <h1 className={cN(s.title, s.titles)}>{heroTitle}</h1>}
{heroSubTitle && (
<h3 className={cN(s.subTitle, s.titles)}>{heroSubTitle}</h3>
Expand Down
2 changes: 2 additions & 0 deletions components/Section/SectionWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type SectionWrapperProps = {
title?: string;
status?: Status;
hasHero?: boolean;
heroHTML?: string;
heroTitle?: string;
heroImage?: string;
anchor?: string;
Expand All @@ -26,6 +27,7 @@ export const SectionWrapper = ({
title,
status,
hasHero,
heroHTML,
heroTitle,
heroImage,
anchor,
Expand Down
2 changes: 2 additions & 0 deletions components/Section/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type Section = {
includeAgs: string[];
excludeAgs: string[];
hasHero: boolean;
heroHTML?: string;
heroTitle?: string;
heroImage?: string;
render: SectionElement[];
Expand Down Expand Up @@ -184,6 +185,7 @@ export const Section = ({
status={modifiedSection.status}
hasHero={modifiedSection.hasHero}
heroImage={modifiedSection.heroImage}
heroHTML={modifiedSection.heroHTML}
heroTitle={modifiedSection.heroTitle}
anchor={modifiedSection.anchor}
isFirstSection={isFirstSection}
Expand Down
5 changes: 3 additions & 2 deletions pages/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ const PageWithSections = ({ page }: PageProps): ReactElement => {
}
return (
<section>
{page.hasHero && page.heroImage && (
{page.hasHero && (page.heroImage || page.heroHTML) && (
<Hero
heroHTML={page.heroHTML ?? ''}
heroTitle={page.heroTitle}
heroSubTitle={page.heroSubTitle}
heroImage={page.heroImage}
heroImage={page.heroImage ?? ''}
/>
)}
<div className="pageWidth">
Expand Down
1 change: 1 addition & 0 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const Start = ({ page }: PageProps): ReactElement => {
<>
{page.hasHero && page.heroImage && (
<Hero
heroHTML={page.heroHTML}
heroTitle={page.heroTitle}
heroSubTitle={page.heroSubTitle}
heroImage={page.heroImage}
Expand Down
6 changes: 6 additions & 0 deletions utils/getPageProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export type Page = {
title: string;
status: Status;
hasHero: boolean;
heroHTML: string | null;
heroTitle: string | null;
heroSubTitle: string | null;
heroImage: string | null;
Expand All @@ -34,6 +35,7 @@ type FetchedPage = {
title: string;
status: Status;
hasHero: boolean;
heroHTML: string | null;
heroTitle: string | null;
heroSubTitle: string | null;
heroImage: string | null;
Expand All @@ -48,6 +50,7 @@ const pageFields = [
'title',
'status',
'hasHero',
'heroHTML',
'heroTitle',
'heroSubTitle',
'heroImage',
Expand All @@ -69,6 +72,7 @@ type FetchedSectionData = {
includeAgs?: string[];
excludeAgs?: string[];
hasHero: boolean;
heroHTML?: string;
heroTitle?: string;
heroImage?: string;
elements: FetchedElement[];
Expand Down Expand Up @@ -232,6 +236,7 @@ const updatePageStructure = (
title: fetchedPage.title,
status: fetchedPage.status,
hasHero: fetchedPage.hasHero,
heroHTML: fetchedPage.heroHTML,
heroTitle: fetchedPage.heroTitle,
heroSubTitle: fetchedPage.heroSubTitle,
heroImage: fetchedPage.heroImage,
Expand All @@ -257,6 +262,7 @@ const updatePageStructure = (
includeAgs: section.item.includeAgs || [],
excludeAgs: section.item.excludeAgs || [],
hasHero: section.item.hasHero,
heroHTML: section.item.heroHTML,
heroTitle: section.item.heroTitle,
heroImage: section.item.heroImage,
render: section.item.elements
Expand Down

0 comments on commit e65a53e

Please sign in to comment.