From 7af7971d9b2d02d29d3bb3e813265b5342aaa7f5 Mon Sep 17 00:00:00 2001 From: marcoskolodny Date: Mon, 11 Nov 2024 16:49:45 +0100 Subject: [PATCH] update header --- src/header.css.ts | 5 +++ src/header.tsx | 89 +++++++++++++++++++++++++++++++++------------ src/utils/types.tsx | 7 ++++ 3 files changed, 77 insertions(+), 24 deletions(-) diff --git a/src/header.css.ts b/src/header.css.ts index cae9bbbaeb..f2e5dfe137 100644 --- a/src/header.css.ts +++ b/src/header.css.ts @@ -23,3 +23,8 @@ export const hideOnDesktop = style({ }, }, }); + +export const flexColumn = style({ + display: 'flex', + flexDirection: 'column', +}); diff --git a/src/header.tsx b/src/header.tsx index 3c2b3743ac..ba57177ff5 100644 --- a/src/header.tsx +++ b/src/header.tsx @@ -10,10 +10,16 @@ import {vars} from './skins/skin-contract.css'; import * as styles from './header.css'; import {getPrefixedDataAttributes} from './utils/dom'; import {Title3, Title4} from './title'; +import { + isBiggerHeading, + type DataAttributes, + type HeadingType, + type RendersElement, + type RendersNullableElement, +} from './utils/types'; import type NavigationBreadcrumbs from './navigation-breadcrumbs'; import type {ButtonPrimary, ButtonSecondary} from './button'; -import type {DataAttributes, HeadingType, RendersElement, RendersNullableElement} from './utils/types'; import type {TextPresetProps} from './text'; type OverridableTextProps = { @@ -61,31 +67,66 @@ export const Header = ({ ); }; + const pretitleContent = pretitle + ? renderRichText(pretitle, {color: vars.colors.textPrimary, as: pretitleAs}) + : undefined; + + const titleContent = title ? ( + small ? ( + {title} + ) : ( + {title} + ) + ) : undefined; + return ( {(title || pretitle || description) && ( - - {headline} - {pretitle && - renderRichText(pretitle, {color: vars.colors.textPrimary, as: pretitleAs})} - {title && - (small ? ( - {title} - ) : ( - {title} - ))} - {description && - (small ? ( - - {description} - - ) : ( - - {description} - - ))} - + {/** using flex instead of nested Stacks, this way we can rearrange texts so the DOM structure makes more sense for screen reader users */} +
+
+ {headline} +
+ + {isBiggerHeading(titleAs, pretitleAs) ? ( + <> + {titleContent && ( +
+ {titleContent} +
+ )} + {pretitleContent && ( +
{pretitleContent}
+ )} + + ) : ( + <> + {pretitleContent && ( +
+ {pretitleContent} +
+ )} + {titleContent && ( +
{titleContent}
+ )} + + )} + + {description && ( +
+ {small ? ( + + {description} + + ) : ( + + {description} + + )} +
+ )} +
)}
@@ -155,7 +196,7 @@ export const HeaderLayout = ({ return (
- + = T | {mobile: T; tablet?: T; desktop: T}; export type HeadingType = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6' | 'span'; + +export const isBiggerHeading = (heading: HeadingType, otherHeading?: HeadingType): boolean => { + if (!otherHeading) { + return true; + } + return heading !== 'span' && (otherHeading === 'span' || heading < otherHeading); +};