Skip to content

Commit 778515c

Browse files
authored
fix!: convert Banner BEM classes to flat class names (#5114)
Renames BEM element classes to flat names scoped by CSS nesting: - eds-banner__icon → icon - eds-banner__message → message - eds-banner__actions → actions - eds-banner__dismiss → dismiss Also restructures banner.css to nest inner element selectors inside .eds-banner using CSS nesting, matching the convention established by Button, Chip, Badge, and Avatar. BREAKING CHANGE: consumers targeting these class names directly in their own CSS must update to the new flat names.
1 parent 7b3005e commit 778515c

3 files changed

Lines changed: 55 additions & 61 deletions

File tree

packages/eds-core-react/src/components/next/Banner/Banner.test.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -294,10 +294,7 @@ describe('Banner (next)', () => {
294294
<Banner.Message>Test</Banner.Message>
295295
</Banner>,
296296
)
297-
expect(screen.getByTestId('icon')).toHaveClass(
298-
'eds-banner__icon',
299-
'custom-icon',
300-
)
297+
expect(screen.getByTestId('icon')).toHaveClass('icon', 'custom-icon')
301298
})
302299

303300
it('merges className on Banner.Message', () => {
@@ -308,10 +305,7 @@ describe('Banner (next)', () => {
308305
</Banner.Message>
309306
</Banner>,
310307
)
311-
expect(screen.getByTestId('msg')).toHaveClass(
312-
'eds-banner__message',
313-
'custom-msg',
314-
)
308+
expect(screen.getByTestId('msg')).toHaveClass('message', 'custom-msg')
315309
})
316310

317311
it('merges className on Banner.Actions', () => {
@@ -324,7 +318,7 @@ describe('Banner (next)', () => {
324318
</Banner>,
325319
)
326320
expect(screen.getByTestId('actions')).toHaveClass(
327-
'eds-banner__actions',
321+
'actions',
328322
'custom-actions',
329323
)
330324
})

packages/eds-core-react/src/components/next/Banner/Banner.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ const BannerIcon = forwardRef<HTMLSpanElement, BannerIconProps>(
1414
return (
1515
<span
1616
ref={ref}
17-
className={['eds-banner__icon', className].filter(Boolean).join(' ')}
17+
className={['icon', className].filter(Boolean).join(' ')}
1818
{...rest}
1919
>
2020
{children}
@@ -28,7 +28,7 @@ const BannerMessage = forwardRef<HTMLParagraphElement, BannerMessageProps>(
2828
return (
2929
<p
3030
ref={ref}
31-
className={['eds-banner__message', className].filter(Boolean).join(' ')}
31+
className={['message', className].filter(Boolean).join(' ')}
3232
{...rest}
3333
>
3434
{children}
@@ -45,7 +45,7 @@ const BannerActions = forwardRef<HTMLDivElement, BannerActionsProps>(
4545
return (
4646
<div
4747
ref={ref}
48-
className={['eds-banner__actions', className].filter(Boolean).join(' ')}
48+
className={['actions', className].filter(Boolean).join(' ')}
4949
data-placement={placement}
5050
{...rest}
5151
>
@@ -73,7 +73,7 @@ const BannerComponent = forwardRef<HTMLDivElement, BannerProps>(function Banner(
7373
variant="ghost"
7474
icon
7575
size="small"
76-
className="eds-banner__dismiss"
76+
className="dismiss"
7777
aria-label="Dismiss"
7878
onClick={onDismiss}
7979
>

packages/eds-core-react/src/components/next/Banner/banner.css

Lines changed: 48 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -13,67 +13,67 @@
1313

1414
background: var(--eds-color-bg-surface);
1515
outline: var(--eds-sizing-stroke-thin) solid var(--eds-color-border-medium);
16-
}
1716

18-
.eds-banner__icon {
19-
display: flex;
20-
flex-shrink: 0;
21-
align-items: center;
17+
& .icon {
18+
display: flex;
19+
flex-shrink: 0;
20+
align-items: center;
2221

23-
height: var(--eds-typography-line-height, 1.5rem);
22+
height: var(--eds-typography-line-height, 1.5rem);
2423

25-
/*
26-
* Negative margin compensates for Figma's icon container padding,
27-
* pulling the icon closer to the component edge.
28-
* Figma variable: selectable/icon-container-padding (↕︎ -6px, ↔︎ -4.8px)
29-
* See #4684 for exporting this as a CSS custom property.
30-
*/
31-
margin-block: -6px;
32-
margin-inline-start: -4.8px;
24+
/*
25+
* Negative margin compensates for Figma's icon container padding,
26+
* pulling the icon closer to the component edge.
27+
* Figma variable: selectable/icon-container-padding (↕︎ -6px, ↔︎ -4.8px)
28+
* See #4684 for exporting this as a CSS custom property.
29+
*/
30+
margin-block: -6px;
31+
margin-inline-start: -4.8px;
3332

34-
color: var(--eds-color-text-subtle);
35-
}
33+
color: var(--eds-color-text-subtle);
34+
}
3635

37-
.eds-banner__message {
38-
flex: 1;
36+
& .message {
37+
flex: 1;
3938

40-
min-width: 0;
41-
margin: 0;
39+
min-width: 0;
40+
margin: 0;
4241

43-
font-family: var(--eds-typography-ui-body-font-family);
44-
font-size: var(--eds-typography-ui-body-md-font-size);
45-
line-height: var(--eds-typography-ui-body-md-line-height-default);
46-
color: var(--eds-color-text-strong);
42+
font-family: var(--eds-typography-ui-body-font-family);
43+
font-size: var(--eds-typography-ui-body-md-font-size);
44+
line-height: var(--eds-typography-ui-body-md-line-height-default);
45+
color: var(--eds-color-text-strong);
4746

48-
@supports (text-box: trim-both cap alphabetic) {
49-
text-box: trim-both cap alphabetic;
47+
@supports (text-box: trim-both cap alphabetic) {
48+
text-box: trim-both cap alphabetic;
49+
}
5050
}
51-
}
5251

53-
.eds-banner__actions {
54-
display: flex;
55-
gap: var(--eds-selectable-gap-horizontal, 8px);
56-
align-items: center;
57-
}
52+
& .actions {
53+
display: flex;
54+
gap: var(--eds-selectable-gap-horizontal, 8px);
55+
align-items: center;
5856

59-
.eds-banner__actions[data-placement='bottom'] {
60-
flex-basis: 100%;
61-
}
57+
&[data-placement='bottom'] {
58+
flex-basis: 100%;
59+
}
60+
}
6261

63-
.eds-banner:has(.eds-banner__dismiss) {
64-
padding-inline-end: calc(
65-
var(--eds-container-space-horizontal) + 24px +
66-
var(--eds-container-space-horizontal)
67-
);
68-
}
62+
&:has(.dismiss) {
63+
padding-inline-end: calc(
64+
var(--eds-container-space-horizontal) + 24px +
65+
var(--eds-container-space-horizontal)
66+
);
67+
}
6968

70-
.eds-banner__dismiss {
71-
position: absolute;
72-
top: var(--eds-container-space-vertical);
73-
right: var(--eds-container-space-horizontal);
69+
& .dismiss {
70+
position: absolute;
71+
top: var(--eds-container-space-vertical);
72+
right: var(--eds-container-space-horizontal);
7473

75-
/* Same Figma icon container padding compensation as .eds-banner__icon */
76-
margin-block: -6px;
77-
margin-inline-end: -4.8px;
74+
/* Same Figma icon container padding compensation as .icon */
75+
margin-block: -6px;
76+
margin-inline-end: -4.8px;
77+
}
7878
}
7979
}

0 commit comments

Comments
 (0)