From 4d8e6c94fccb9adb3113ee7d257aee27d2f30e79 Mon Sep 17 00:00:00 2001 From: marcoskolodny Date: Mon, 11 Nov 2024 18:41:12 +0100 Subject: [PATCH] update hero and coverHero --- src/__stories__/cover-hero-story.tsx | 17 ++++++++++ src/__stories__/hero-story.tsx | 17 ++++++++++ src/card.css.ts | 2 +- src/cover-hero.css.ts | 5 +++ src/cover-hero.tsx | 50 ++++++++++++++++++++++------ src/header.css.ts | 2 +- src/hero.css.ts | 5 +++ src/hero.tsx | 47 +++++++++++++++++++++----- 8 files changed, 124 insertions(+), 21 deletions(-) diff --git a/src/__stories__/cover-hero-story.tsx b/src/__stories__/cover-hero-story.tsx index 5a70572d78..4472f9e2c2 100644 --- a/src/__stories__/cover-hero-story.tsx +++ b/src/__stories__/cover-hero-story.tsx @@ -13,6 +13,7 @@ import usingVrImg from './images/using-vr.jpg'; import beachImg from './images/beach.jpg'; import beachVideo from './videos/beach.mp4'; +import type {HeadingType} from '../utils/types'; import type {TagType} from '..'; export default { @@ -30,7 +31,9 @@ type Args = { headlineType: TagType; headline: string; pretitle: string; + pretitleAs: HeadingType; title: string; + titleAs: HeadingType; description: string; extra: boolean; sideExtra: boolean; @@ -56,7 +59,9 @@ export const Default: StoryComponent = ({ headlineType, headline, pretitle, + pretitleAs, title, + titleAs, description, extra, sideExtra, @@ -92,7 +97,9 @@ export const Default: StoryComponent = ({ dataAttributes={{testid: 'cover-hero'}} headline={headline ? {headline} : undefined} pretitle={pretitle} + pretitleAs={pretitleAs} title={title} + titleAs={titleAs} description={description} extra={extra ? : undefined} sideExtra={sideExtra ? : undefined} @@ -118,7 +125,9 @@ Default.args = { headlineType: 'promo', headline: 'Hero', pretitle: 'Pretitle', + pretitleAs: 'span', title: 'Title', + titleAs: 'h1', description: 'This is a long description with a long text to see how this works', extra: false, sideExtra: false, @@ -197,6 +206,14 @@ Default.argTypes = { }, }, }, + pretitleAs: { + options: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'span'], + control: {type: 'select'}, + }, + titleAs: { + options: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'span'], + control: {type: 'select'}, + }, }; export const CoverHeroInSlideshow: StoryComponent = () => ( diff --git a/src/__stories__/hero-story.tsx b/src/__stories__/hero-story.tsx index 05b72ecc14..1cad9490ae 100644 --- a/src/__stories__/hero-story.tsx +++ b/src/__stories__/hero-story.tsx @@ -4,6 +4,7 @@ import usingVrImg from './images/using-vr.jpg'; import beachImg from './images/beach.jpg'; import beachVideo from './videos/beach.mp4'; +import type {HeadingType} from '../utils/types'; import type {TagType} from '..'; import type {AspectRatio} from '../video'; @@ -19,7 +20,9 @@ type HeroArgs = { headlineType: TagType; headline: string; pretitle: string; + pretitleAs: HeadingType; title: string; + titleAs: HeadingType; description: string; extra: boolean; actions: 'button' | 'link' | 'button and link'; @@ -36,7 +39,9 @@ export const Default: StoryComponent = ({ headline, headlineType, pretitle, + pretitleAs, title, + titleAs, description, actions, desktopMediaPosition, @@ -65,7 +70,9 @@ export const Default: StoryComponent = ({ media={mediaComponent} headline={headline ? {headline} : undefined} pretitle={pretitle} + pretitleAs={pretitleAs} title={title} + titleAs={titleAs} description={description} extra={extra ? : undefined} button={button} @@ -85,7 +92,9 @@ Default.args = { headlineType: 'promo', headline: 'Hero', pretitle: 'Pretitle', + pretitleAs: 'span', title: 'Title', + titleAs: 'h1', description: 'This is a long description with a long text to see how this works', extra: false, actions: 'button and link', @@ -128,4 +137,12 @@ Default.argTypes = { }, }, }, + pretitleAs: { + options: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'span'], + control: {type: 'select'}, + }, + titleAs: { + options: ['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'span'], + control: {type: 'select'}, + }, }; diff --git a/src/card.css.ts b/src/card.css.ts index 6613731128..97bf5e2ca7 100644 --- a/src/card.css.ts +++ b/src/card.css.ts @@ -415,7 +415,7 @@ export const dataCardTopActionsWithoutIcon = style({ }, }); -export const flexColumn = style({ +export const flexColumn = sprinkles({ display: 'flex', flexDirection: 'column', }); diff --git a/src/cover-hero.css.ts b/src/cover-hero.css.ts index 921f992dcc..224a816150 100644 --- a/src/cover-hero.css.ts +++ b/src/cover-hero.css.ts @@ -126,3 +126,8 @@ export const sixColumns = style({ }); export const sideExtra = sprinkles({position: 'relative'}); + +export const flexColumn = sprinkles({ + display: 'flex', + flexDirection: 'column', +}); diff --git a/src/cover-hero.tsx b/src/cover-hero.tsx index 7a03b97b63..8fb287964d 100644 --- a/src/cover-hero.tsx +++ b/src/cover-hero.tsx @@ -12,6 +12,7 @@ import * as mediaStyles from './image.css'; import GridLayout from './grid-layout'; import {CoverHeroMedia} from './cover-hero-media'; import {getPrefixedDataAttributes} from './utils/dom'; +import {isBiggerHeading} from './utils/types'; import type {DataAttributes, HeadingType} from './utils/types'; import type {ImageProps, VideoProps} from './cover-hero-media'; @@ -26,6 +27,7 @@ type BaseProps = { headline?: RendersNullableElement; pretitle?: string; pretitleLinesMax?: number; + pretitleAs?: HeadingType; title: string; titleLinesMax?: number; titleAs?: HeadingType; @@ -73,6 +75,7 @@ const CoverHero = React.forwardRef( headline, pretitle, pretitleLinesMax, + pretitleAs, title, titleLinesMax, titleAs = 'h1', @@ -108,22 +111,47 @@ const CoverHero = React.forwardRef( const textShadow = hasMedia ? '0 0 15px rgba(0, 0, 0, 0.4)' : undefined; + const pretitleContent = pretitle ? ( + + {pretitle} + + ) : undefined; + + const titleContent = ( + + {title} + + ); + const mainContent = (
{headline && {headline}} - - {pretitle && ( -
- - {pretitle} - -
+ {/** using flex instead of nested Stacks, this way we can rearrange texts so the DOM structure makes more sense for screen reader users */} +
+ {isBiggerHeading(titleAs, pretitleAs) ? ( + <> + {titleContent} + {pretitleContent && ( +
+ {pretitleContent} +
+ )} + + ) : ( + <> + {pretitleContent && ( +
+ {pretitleContent} +
+ )} + {titleContent} + )} - - {title} - - +
{description && (
{ type HeroContentProps = { headline?: RendersNullableElement; pretitle?: string; + pretitleAs?: HeadingType; title?: string; titleAs?: HeadingType; description?: string; @@ -64,6 +71,7 @@ const HeroContent = ({ title, titleAs = 'h1', pretitle, + pretitleAs, description, descriptionLinesMax, extra, @@ -71,19 +79,41 @@ const HeroContent = ({ secondaryButton, buttonLink, }: HeroContentProps) => { + const titleContent = title ? {title} : undefined; + + const pretitleContent = pretitle ? ( + + {pretitle} + + ) : undefined; + return (
{headline && headline} - - {pretitle && ( - - {pretitle} - + + {/** using flex instead of nested Stacks, this way we can rearrange texts so the DOM structure makes more sense for screen reader users */} +
+ {isBiggerHeading(titleAs, pretitleAs) ? ( + <> + {titleContent} + {pretitleContent && ( +
+ {pretitleContent} +
+ )} + + ) : ( + <> + {pretitleContent && ( +
{pretitleContent}
+ )} + {titleContent} + )} - {title && {title}} - +
+ {description && ( | RendersElement; headline?: RendersNullableElement; pretitle?: string; + pretitleAs?: HeadingType; title?: string; titleAs?: HeadingType; description?: string;