Skip to content

Commit

Permalink
update headline order in hero/coverHero/header and fix spacing bug in…
Browse files Browse the repository at this point in the history
… header
  • Loading branch information
marcoskolodny committed Nov 25, 2024
1 parent 6b410b0 commit 369bf37
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/__tests__/cover-hero-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {makeTheme} from './test-utils';
import {render, screen} from '@testing-library/react';
import ThemeContextProvider from '../theme-context-provider';

const pretitleFirst = 'HeadlinePretitleTitleDescription';
const titleFirst = 'HeadlineTitlePretitleDescription';
const pretitleFirst = 'PretitleHeadlineTitleDescription';
const titleFirst = 'TitleHeadlinePretitleDescription';

test.each`
pretitleAs | titleAs | expectedOrder
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/header-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import {makeTheme} from './test-utils';
import {render, screen} from '@testing-library/react';
import ThemeContextProvider from '../theme-context-provider';

const pretitleFirst = 'HeadlinePretitleTitleDescription';
const titleFirst = 'HeadlineTitlePretitleDescription';
const pretitleFirst = 'PretitleHeadlineTitleDescription';
const titleFirst = 'TitleHeadlinePretitleDescription';

test.each`
pretitleAs | titleAs | expectedOrder
Expand Down
4 changes: 2 additions & 2 deletions src/__tests__/hero-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {makeTheme} from './test-utils';
import {render, screen} from '@testing-library/react';
import ThemeContextProvider from '../theme-context-provider';

const pretitleFirst = 'HeadlinePretitleTitleDescription';
const titleFirst = 'HeadlineTitlePretitleDescription';
const pretitleFirst = 'PretitleHeadlineTitleDescription';
const titleFirst = 'TitleHeadlinePretitleDescription';

test.each`
pretitleAs | titleAs | expectedOrder
Expand Down
25 changes: 15 additions & 10 deletions src/cover-hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const CoverHero = React.forwardRef<HTMLDivElement, CoverHeroProps>(
</Text3>
) : undefined;

const titleContent = (
const titleContent = title ? (
<Text8
as={titleAs}
truncate={titleLinesMax}
Expand All @@ -132,24 +132,28 @@ const CoverHero = React.forwardRef<HTMLDivElement, CoverHeroProps>(
>
{title}
</Text8>
);
) : undefined;

const headlineContent = headline ? (
<div style={{order: -1}}>
<Box
dataAttributes={{testid: 'headline'}}
paddingBottom={{desktop: 8, tablet: 8, mobile: 16}}
>
{headline}
</Box>
</div>
) : undefined;

const mainContent = (
<div className={styles.mainContent}>
{headline && (
<Box
dataAttributes={{testid: 'headline'}}
paddingBottom={{desktop: 8, tablet: 8, mobile: 16}}
>
{headline}
</Box>
)}
<Stack space={16}>
{/** using flex instead of nested Stacks, this way we can rearrange texts so the DOM structure makes more sense for screen reader users */}
<div className={styles.flexColumn}>
{isBiggerHeading(titleAs, pretitleAs) ? (
<>
{titleContent}
{headlineContent}
{pretitleContent && (
<div
className={styles.sixColumns}
Expand All @@ -166,6 +170,7 @@ const CoverHero = React.forwardRef<HTMLDivElement, CoverHeroProps>(
{pretitleContent}
</div>
)}
{headlineContent}
{titleContent}
</>
)}
Expand Down
26 changes: 13 additions & 13 deletions src/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,30 +87,29 @@ export const Header = ({
)
) : undefined;

const headlineContent = headline ? (
// assuming that the headline will always be followed by one of: pretitle, title, description
<div style={{paddingBottom: 8, order: -1}} data-testid="headline">
{headline}
</div>
) : undefined;

return (
<Stack space={{mobile: 24, desktop: 32}} dataAttributes={{testid: 'Header', ...dataAttributes}}>
{(title || pretitle || description) && (
<Box paddingRight={16}>
{/** using flex instead of nested Stacks, this way we can rearrange texts so the DOM structure makes more sense for screen reader users */}
<div className={styles.flexColumn}>
{headline && (
<div
style={{paddingBottom: pretitle || title || description ? 8 : 0}}
data-testid="headline"
>
{headline}
</div>
)}

{isBiggerHeading(titleAs, pretitleAs) ? (
<>
{titleContent && (
<div style={{paddingBottom: pretitle || description ? 8 : 0, order: 1}}>
{titleContent}
</div>
<div style={{paddingBottom: description ? 8 : 0}}>{titleContent}</div>
)}
{headlineContent}
{pretitleContent && (
<div style={{paddingBottom: description ? 8 : 0}}>{pretitleContent}</div>
<div style={{paddingBottom: pretitle || description ? 8 : 0, order: -1}}>
{pretitleContent}
</div>
)}
</>
) : (
Expand All @@ -120,6 +119,7 @@ export const Header = ({
{pretitleContent}
</div>
)}
{headlineContent}
{titleContent && (
<div style={{paddingBottom: description ? 8 : 0}}>{titleContent}</div>
)}
Expand Down
11 changes: 9 additions & 2 deletions src/hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,23 @@ const HeroContent = ({
</Text3>
) : undefined;

const headlineContent = headline ? (
// assuming that the headline will always be followed by one of: pretitle, title, subtitle, description
<div data-testid="headline" style={{paddingBottom: 16, order: -1}}>
{headline}
</div>
) : undefined;

return (
<section className={styles.contentContainer}>
<div>
<Stack space={16}>
{headline && <div data-testid="headline">{headline}</div>}

{/** using flex instead of nested Stacks, this way we can rearrange texts so the DOM structure makes more sense for screen reader users */}
<div className={styles.flexColumn}>
{isBiggerHeading(titleAs, pretitleAs) ? (
<>
{titleContent}
{headlineContent}
{pretitleContent && (
<div style={{paddingBottom: title ? 8 : 0, order: -1}}>
{pretitleContent}
Expand All @@ -113,6 +119,7 @@ const HeroContent = ({
{pretitleContent && (
<div style={{paddingBottom: title ? 8 : 0}}>{pretitleContent}</div>
)}
{headlineContent}
{titleContent}
</>
)}
Expand Down

0 comments on commit 369bf37

Please sign in to comment.