Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Header, Cards, Hero): fix spacings logic #1298

Merged
merged 1 commit into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions src/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -424,10 +424,12 @@ const CardContent = ({
</div>
)}
{headline && (
// assuming that the headline will always be followed by one of: pretitle, title, subtitle, description
Copy link
Contributor Author

@marcoskolodny marcoskolodny Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All cards were assuming this before, except of AdvancedDataCard. In #1292, I've done the same for the AdvancedDataCard, and it broke one screenshot test in webapp (they use headline and extra prop to render everything else).

I've removed all these unnecesary assumptions from everywhere

<div
ref={headlineRef}
style={{order: -2, paddingBottom: 8}}
style={{
order: -2,
paddingBottom: pretitle || title || subtitle || description ? 8 : 0,
}}
data-testid="headline"
>
{typeof headline === 'string' ? <Tag type="promo">{headline}</Tag> : headline}
Expand All @@ -452,10 +454,12 @@ const CardContent = ({
</div>
)}
{headline && (
// assuming that the headline will always be followed by one of: pretitle, title, subtitle, description
<div
ref={headlineRef}
style={{order: -1, paddingBottom: 8}}
style={{
order: -1,
paddingBottom: pretitle || title || subtitle || description ? 8 : 0,
}}
data-testid="headline"
>
{typeof headline === 'string' ? (
Expand Down Expand Up @@ -1246,8 +1250,14 @@ const DisplayCardContent = ({
</div>
)}
{headline && (
// assuming that the headline will always be followed by one of: pretitle, title, subtitle, description
<div ref={headlineRef} style={{order: -2, paddingBottom: 16}} data-testid="headline">
<div
ref={headlineRef}
style={{
order: -2,
paddingBottom: pretitle || title || subtitle || description ? 16 : 0,
}}
data-testid="headline"
>
{headline}
</div>
)}
Expand All @@ -1265,8 +1275,14 @@ const DisplayCardContent = ({
</div>
)}
{headline && (
// assuming that the headline will always be followed by one of: pretitle, title, subtitle, description
<div ref={headlineRef} style={{order: -1, paddingBottom: 16}} data-testid="headline">
<div
ref={headlineRef}
style={{
order: -1,
paddingBottom: pretitle || title || subtitle || description ? 16 : 0,
}}
data-testid="headline"
>
{headline}
</div>
)}
Expand Down
18 changes: 14 additions & 4 deletions src/community/advanced-data-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,13 @@ const CardContent = ({
</div>
)}
{headline && (
// assuming that the headline will always be followed by one of: pretitle, title, subtitle, description
<div ref={headlineRef} style={{order: -2, paddingBottom: 4}}>
<div
ref={headlineRef}
style={{
order: -2,
paddingBottom: pretitle || title || subtitle || description ? 4 : 0,
}}
>
{typeof headline === 'string' ? <Tag type="promo">{headline}</Tag> : headline}
</div>
)}
Expand All @@ -131,8 +136,13 @@ const CardContent = ({
</div>
)}
{headline && (
// assuming that the headline will always be followed by one of: pretitle, title, subtitle, description
<div ref={headlineRef} style={{order: -1, paddingBottom: 4}}>
<div
ref={headlineRef}
style={{
order: -1,
paddingBottom: pretitle || title || subtitle || description ? 4 : 0,
}}
>
{typeof headline === 'string' ? <Tag type="promo">{headline}</Tag> : headline}
</div>
)}
Expand Down
8 changes: 5 additions & 3 deletions src/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,10 @@ 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">
<div
style={{paddingBottom: pretitle || title || description ? 8 : 0, order: -1}}
data-testid="headline"
>
{headline}
</div>
) : undefined;
Expand All @@ -107,7 +109,7 @@ export const Header = ({
)}
{headlineContent}
{pretitleContent && (
<div style={{paddingBottom: pretitle || description ? 8 : 0, order: -1}}>
<div style={{paddingBottom: title || description ? 8 : 0, order: -1}}>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was a typo :(

{pretitleContent}
</div>
)}
Expand Down
6 changes: 4 additions & 2 deletions src/hero.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,10 @@ const HeroContent = ({
) : 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}}>
<div
data-testid="headline"
style={{paddingBottom: pretitle || title || description ? 16 : 0, order: -1}}
>
{headline}
</div>
) : undefined;
Expand Down
Loading