Skip to content

Commit f111a0e

Browse files
authored
Fix - infobar additional div when there's no CTA (#935)
* fix - not render CTA parent div when there's no CTA * add stories
1 parent 76e70f1 commit f111a0e

File tree

2 files changed

+49
-35
lines changed

2 files changed

+49
-35
lines changed

packages/components/src/templates/next/components/complex/Infobar/Infobar.stories.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,13 @@ export const LongText: Story = {
8181
secondaryButtonUrl: "https://google.com",
8282
},
8383
}
84+
85+
export const NoCTA: Story = {
86+
args: {
87+
sectionIdx: 0,
88+
title:
89+
"Longer title here that spans multiple lines and is quite long and verbose and takes up a lot of space",
90+
description:
91+
"About a sentence worth of description here About a sentence worth of description here About a sentence worth of description here",
92+
},
93+
}

packages/components/src/templates/next/components/complex/Infobar/Infobar.tsx

Lines changed: 39 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ const Infobar = ({
5252
LinkComponent,
5353
}: InfobarProps) => {
5454
const simplifiedLayout = getTailwindVariantLayout(layout)
55+
const hasPrimaryCTA = !!buttonLabel && !!buttonUrl
56+
const hasSecondaryCTA = !!secondaryButtonLabel && !!secondaryButtonUrl
5557

5658
return (
5759
<section>
@@ -83,42 +85,44 @@ const Infobar = ({
8385
)}
8486
</div>
8587

86-
<div
87-
className={compoundStyles.buttonContainer({
88-
layout: simplifiedLayout,
89-
})}
90-
>
91-
{buttonLabel && buttonUrl && (
92-
<LinkButton
93-
href={getReferenceLinkHref(
94-
buttonUrl,
95-
site.siteMap,
96-
site.assetsBaseUrl,
97-
)}
98-
size={simplifiedLayout === "homepage" ? "lg" : "base"}
99-
LinkComponent={LinkComponent}
100-
isWithFocusVisibleHighlight
101-
>
102-
{buttonLabel}
103-
</LinkButton>
104-
)}
88+
{(hasPrimaryCTA || hasSecondaryCTA) && (
89+
<div
90+
className={compoundStyles.buttonContainer({
91+
layout: simplifiedLayout,
92+
})}
93+
>
94+
{hasPrimaryCTA && (
95+
<LinkButton
96+
href={getReferenceLinkHref(
97+
buttonUrl,
98+
site.siteMap,
99+
site.assetsBaseUrl,
100+
)}
101+
size={simplifiedLayout === "homepage" ? "lg" : "base"}
102+
LinkComponent={LinkComponent}
103+
isWithFocusVisibleHighlight
104+
>
105+
{buttonLabel}
106+
</LinkButton>
107+
)}
105108

106-
{secondaryButtonLabel && secondaryButtonUrl && (
107-
<LinkButton
108-
href={getReferenceLinkHref(
109-
secondaryButtonUrl,
110-
site.siteMap,
111-
site.assetsBaseUrl,
112-
)}
113-
size={simplifiedLayout === "homepage" ? "lg" : "base"}
114-
variant="outline"
115-
LinkComponent={LinkComponent}
116-
isWithFocusVisibleHighlight
117-
>
118-
{secondaryButtonLabel}
119-
</LinkButton>
120-
)}
121-
</div>
109+
{hasSecondaryCTA && (
110+
<LinkButton
111+
href={getReferenceLinkHref(
112+
secondaryButtonUrl,
113+
site.siteMap,
114+
site.assetsBaseUrl,
115+
)}
116+
size={simplifiedLayout === "homepage" ? "lg" : "base"}
117+
variant="outline"
118+
LinkComponent={LinkComponent}
119+
isWithFocusVisibleHighlight
120+
>
121+
{secondaryButtonLabel}
122+
</LinkButton>
123+
)}
124+
</div>
125+
)}
122126
</div>
123127
</div>
124128
</section>

0 commit comments

Comments
 (0)