Skip to content

Commit 6759976

Browse files
authored
fix: Vertically center Banner text content when action or close button is present (#1029)
fix: Vertically center Banner text content when action or close button is present
1 parent f8c6191 commit 6759976

2 files changed

Lines changed: 54 additions & 46 deletions

File tree

src/banner/banner.module.css

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,15 @@
5959
}
6060

6161
.image img,
62-
.icon svg {
62+
.typeIcon svg {
6363
display: block;
6464
}
6565

66-
/* The close button is invisible in this resolution, so we're hiding the container to prevent flex-gap from making extra space */
67-
.icon:empty,
68-
.icon:has(.closeButton:only-child) {
66+
.typeIcon:empty {
6967
display: none;
7068
}
7169

72-
.icon .closeButton {
70+
.iconCopy .closeButton {
7371
display: none;
7472
}
7573

@@ -88,24 +86,20 @@
8886
.content {
8987
flex-direction: column;
9088
}
91-
.icon {
92-
display: flex;
93-
width: 100%;
94-
align-items: center;
95-
justify-content: space-between;
96-
}
9789
.topContent {
9890
flex-direction: column;
9991
align-items: stretch;
10092
}
101-
.icon:has(.closeButton:only-child) {
102-
display: flex;
93+
.iconCopy {
94+
flex-direction: row;
95+
align-items: center;
96+
justify-content: space-between;
10397
}
104-
.icon .closeButton {
105-
display: flex;
98+
.iconCopy:has(.typeIcon:empty) {
99+
justify-content: flex-end;
106100
}
107-
.icon .closeButton:only-child {
108-
margin-left: auto;
101+
.iconCopy .closeButton {
102+
display: flex;
109103
}
110104
.actions {
111105
align-self: flex-start;

src/banner/banner.tsx

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -156,48 +156,62 @@ const Banner = React.forwardRef<HTMLDivElement, BannerProps>(function Banner(
156156
{image ? <Box className={styles.image}>{image}</Box> : null}
157157

158158
<Box className={styles.content} display="flex" gap="small">
159-
<Box className={styles.icon}>
160-
{type === 'neutral' ? icon : <BannerIcon type={type} />}
161-
{closeButton}
162-
</Box>
163-
164159
<Box display="flex" flexDirection="column" gap="small" flexGrow={1}>
165160
<Box
166161
className={styles.topContent}
167162
display="flex"
168163
gap="small"
169-
alignItems="flexStart"
164+
alignItems="center"
170165
>
171166
<Box
172-
className={styles.copy}
167+
className={styles.iconCopy}
173168
display="flex"
174-
flexDirection="column"
169+
gap="small"
170+
alignItems="flexStart"
175171
flexGrow={1}
176172
>
177-
{title ? (
178-
<Box id={titleId} className={styles.title}>
179-
{title}
180-
</Box>
181-
) : null}
173+
<Box className={styles.typeIcon}>
174+
{type === 'neutral' ? icon : <BannerIcon type={type} />}
175+
</Box>
182176
<Box
183-
id={descriptionId}
184-
className={[styles.description, title ? styles.secondary : null]}
177+
className={styles.copy}
178+
display="flex"
179+
flexDirection="column"
180+
flexGrow={1}
185181
>
186-
{description}
187-
{inlineLinks?.map(({ label, ...props }, index) => {
188-
return (
189-
<React.Fragment key={index}>
190-
<TextLink
191-
{...props}
192-
exceptionallySetClassName={styles.inlineLink}
193-
>
194-
{label}
195-
</TextLink>
196-
{index < inlineLinks.length - 1 ? <span> · </span> : ''}
197-
</React.Fragment>
198-
)
199-
})}
182+
{title ? (
183+
<Box id={titleId} className={styles.title}>
184+
{title}
185+
</Box>
186+
) : null}
187+
<Box
188+
id={descriptionId}
189+
className={[
190+
styles.description,
191+
title ? styles.secondary : null,
192+
]}
193+
>
194+
{description}
195+
{inlineLinks?.map(({ label, ...props }, index) => {
196+
return (
197+
<React.Fragment key={index}>
198+
<TextLink
199+
{...props}
200+
exceptionallySetClassName={styles.inlineLink}
201+
>
202+
{label}
203+
</TextLink>
204+
{index < inlineLinks.length - 1 ? (
205+
<span> · </span>
206+
) : (
207+
''
208+
)}
209+
</React.Fragment>
210+
)
211+
})}
212+
</Box>
200213
</Box>
214+
{closeButton}
201215
</Box>
202216

203217
{action || closeButton ? (

0 commit comments

Comments
 (0)