Skip to content

Commit

Permalink
🐛 add titlestyles to the paddingtop check (#2359)
Browse files Browse the repository at this point in the history
  • Loading branch information
BorghildSelle authored Jun 10, 2024
1 parent 3745e7c commit 45b17a8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
2 changes: 1 addition & 1 deletion web/pageComponents/pageTemplates/TopicPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const TopicPage = ({ data }: TopicPageProps) => {
{data.hero.type !== HeroTypes.DEFAULT && !data?.isCampaign && (
<SharedTitle sharedTitle={data.title} background={titleStyles.background} />
)}
<PageContent data={data} />
<PageContent data={data} titleBackground={titleStyles} />
</main>
</>
)
Expand Down
48 changes: 35 additions & 13 deletions web/pageComponents/pageTemplates/shared/SharedPageContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,18 @@ import {
CardsListData,
GridData,
CampaignBannerData,
DesignOptions,
} from '../../../types/types'
import { getColorForTheme } from '../../shared/textTeaser/theme'
import Grid from '@sections/Grid/Grid'
import { CampaignBanner } from '@sections/CampaignBanner'
import { BackgroundContainerProps } from '@components/Backgrounds'

type DefaultComponent = {
id?: string
type?: string
designOptions?: DesignOptions
}
// How could we do this for several different component types?
export type ComponentProps =
| TeaserData
Expand All @@ -81,8 +88,12 @@ export type ComponentProps =
| CookieDeclarationData
| TextTeaserData
| KeyNumbersData
| DefaultComponent

type PageContentProps = { data: TopicPageSchema | MagazinePageSchema }
type PageContentProps = {
data: TopicPageSchema | MagazinePageSchema
titleBackground?: BackgroundContainerProps
}

/* eslint-disable @typescript-eslint/ban-ts-comment */
/**
Expand Down Expand Up @@ -120,12 +131,15 @@ const isColoredBackgroundAndNotWhite = (componentsDO: any, isWhiteColor: boolean
}

const isSameColorBackground = (currentComponentsDO: any, previousComponentsDO: any) => {
return (
(currentComponentsDO?.backgroundUtility &&
previousComponentsDO?.backgroundUtility &&
currentComponentsDO?.backgroundUtility === previousComponentsDO?.backgroundUtility) ??
currentComponentsDO?.backgroundColor === previousComponentsDO?.backgroundColor
)
if (
currentComponentsDO?.backgroundUtility &&
currentComponentsDO?.backgroundUtility !== '' &&
previousComponentsDO?.backgroundUtility &&
previousComponentsDO?.backgroundUtility !== ''
) {
return currentComponentsDO?.backgroundUtility === previousComponentsDO?.backgroundUtility
}
return currentComponentsDO?.backgroundColor === previousComponentsDO?.backgroundColor
}

const applyPaddingTopIfApplicable = (currentComponent: ComponentProps, prevComponent: ComponentProps): string => {
Expand Down Expand Up @@ -162,20 +176,28 @@ const applyPaddingTopIfApplicable = (currentComponent: ComponentProps, prevCompo

/*eslint-enable @typescript-eslint/ban-ts-comment */

export const PageContent = ({ data }: PageContentProps) => {
export const PageContent = ({ data, titleBackground }: PageContentProps) => {
const content = (data?.content || []).map((c: ComponentProps, index) => {
const prevComponent = data?.content?.[index - 1]
const anchorReference =
(prevComponent as unknown as ComponentProps)?.type === 'anchorLink'
? (prevComponent as unknown as AnchorLinkData)?.anchorReference
: undefined

//Returns pt-12 when applicable or empty string
//Returns pt-20 when applicable or empty string
const previousComponentIndex = prevComponent?.type === 'anchorLink' ? index - 2 : index - 1
const topSpacingClassName = applyPaddingTopIfApplicable(
c,
data?.content?.[previousComponentIndex] as unknown as ComponentProps,
)

const previousComponentToCompare =
index === 0
? ({
type: 'pageTitle',
designOptions: {
background: titleBackground?.background,
},
} as DefaultComponent)
: (data?.content?.[previousComponentIndex] as unknown as ComponentProps)

const topSpacingClassName = applyPaddingTopIfApplicable(c, previousComponentToCompare)

switch (c.type) {
case 'teaser':
Expand Down

0 comments on commit 45b17a8

Please sign in to comment.