Skip to content

Commit d04d727

Browse files
avelinelaurkim
authored andcommitted
[Banner] Rebuild with layout components (#7365)
### WHY are these changes introduced? Fixes #7358 ### WHAT is this pull request doing? Refactors `Banner` component to use new layout primitive components
1 parent b463c50 commit d04d727

File tree

4 files changed

+35
-67
lines changed

4 files changed

+35
-67
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/polaris': minor
3+
---
4+
5+
Updated `Banner` component to use new layout primitives

polaris-react/src/components/Banner/Banner.scss

Lines changed: 6 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
position: relative;
5555
display: flex;
5656

57-
// stylelint-disable selector-max-class, selector-max-combinators, selector-max-specificity
58-
&.statusCritical .PrimaryAction .Button {
57+
// stylelint-disable selector-max-class, selector-max-specificity
58+
&.statusCritical .PrimaryAction.Button {
5959
border-color: var(--p-border-critical-subdued);
6060
background: var(--p-surface-critical-subdued);
6161

@@ -75,7 +75,7 @@
7575
}
7676
}
7777

78-
&.statusWarning .PrimaryAction .Button {
78+
&.statusWarning .PrimaryAction.Button {
7979
border-color: var(--p-border-warning-subdued);
8080
background: var(--p-surface-warning-subdued);
8181

@@ -95,7 +95,7 @@
9595
}
9696
}
9797

98-
&.statusInfo .PrimaryAction .Button {
98+
&.statusInfo .PrimaryAction.Button {
9999
border-color: var(--p-border-highlight-subdued);
100100
background: var(--p-surface-highlight-subdued);
101101

@@ -115,7 +115,7 @@
115115
}
116116
}
117117

118-
&.statusSuccess .PrimaryAction .Button {
118+
&.statusSuccess .PrimaryAction.Button {
119119
border-color: var(--p-border-success-subdued);
120120
background: var(--p-surface-success-subdued);
121121

@@ -134,12 +134,7 @@
134134
background: var(--p-surface-success-subdued);
135135
}
136136
}
137-
// stylelint-enable selector-max-class, selector-max-combinators, selector-max-specificity
138-
}
139-
140-
.ContentWrapper {
141-
margin-top: calc(-1 * var(--p-space-05));
142-
flex: 1 1 auto;
137+
// stylelint-enable selector-max-class, selector-max-specificity
143138
}
144139

145140
.withinContentContainer {
@@ -151,19 +146,11 @@
151146
position: absolute;
152147
}
153148

154-
.Ribbon {
155-
padding-right: var(--p-space-4);
156-
}
157-
158149
@include banner-variants($in-page: false);
159150

160151
+ .Banner {
161152
margin-top: var(--p-space-2);
162153
}
163-
164-
.Actions {
165-
padding: var(--p-space-3) 0 var(--p-space-1) 0;
166-
}
167154
}
168155

169156
.withinPage {
@@ -180,10 +167,6 @@
180167
padding-right: var(--p-space-4);
181168
}
182169

183-
.Actions {
184-
padding-top: var(--p-space-4);
185-
}
186-
187170
.Dismiss {
188171
right: var(--p-space-4);
189172
top: var(--p-space-5);
@@ -195,23 +178,6 @@
195178
padding-right: calc(var(--p-space-8) + var(--p-icon-size-small));
196179
}
197180

198-
.Heading {
199-
word-break: break-word;
200-
}
201-
202-
.Content {
203-
@include text-breakword;
204-
padding: var(--p-space-05) 0;
205-
}
206-
207-
.Ribbon {
208-
flex: 0 0 var(--p-space-8);
209-
}
210-
211-
.PrimaryAction {
212-
margin-right: var(--p-space-2);
213-
}
214-
215181
// We need pretty high specificity to do the descendant selectors
216182
// onto the text, which needs to be the relative positioned wrapper
217183
// so that the borders/ backgrounds do not extend outside of it.

polaris-react/src/components/Banner/Banner.tsx

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@ import {
1515

1616
import {classNames, variationName} from '../../utilities/css';
1717
import {BannerContext} from '../../utilities/banner-context';
18-
import {useUniqueId} from '../../utilities/unique-id';
1918
import {useI18n} from '../../utilities/i18n';
2019
import type {Action, DisableableAction, LoadableAction} from '../../types';
2120
import {Button} from '../Button';
22-
import {Heading} from '../Heading';
2321
import {ButtonGroup} from '../ButtonGroup';
2422
import {UnstyledButton, unstyledButtonFrom} from '../UnstyledButton';
2523
import {UnstyledLink} from '../UnstyledLink';
2624
import {Spinner} from '../Spinner';
2725
import {Icon, IconProps} from '../Icon';
2826
import {WithinContentContext} from '../../utilities/within-content-context';
27+
import {Text} from '../Text';
28+
import {Box} from '../Box';
29+
import {Bleed} from '../Bleed';
2930

3031
import styles from './Banner.scss';
3132

@@ -64,7 +65,6 @@ export const Banner = forwardRef<BannerHandles, BannerProps>(function Banner(
6465
bannerRef,
6566
) {
6667
const withinContentContainer = useContext(WithinContentContext);
67-
const id = useUniqueId('Banner');
6868
const i18n = useI18n();
6969
const {wrapperRef, handleKeyUp, handleBlur, handleMouseUp, shouldShowFocus} =
7070
useBannerFocus(bannerRef);
@@ -79,14 +79,12 @@ export const Banner = forwardRef<BannerHandles, BannerProps>(function Banner(
7979
);
8080

8181
let headingMarkup: React.ReactNode = null;
82-
let headingID: string | undefined;
8382

8483
if (title) {
85-
headingID = `${id}Heading`;
8684
headingMarkup = (
87-
<div className={styles.Heading} id={headingID}>
88-
<Heading element="p">{title}</Heading>
89-
</div>
85+
<Text as="h2" variant="headingMd">
86+
{title}
87+
</Text>
9088
);
9189
}
9290

@@ -109,13 +107,13 @@ export const Banner = forwardRef<BannerHandles, BannerProps>(function Banner(
109107
) : null;
110108

111109
const primaryActionMarkup = action ? (
112-
<div className={styles.PrimaryAction}>
110+
<Box paddingRight="2">
113111
{action.loading
114112
? spinnerMarkup
115113
: unstyledButtonFrom(action, {
116-
className: styles.Button,
114+
className: `${styles.Button} ${styles.PrimaryAction}`,
117115
})}
118-
</div>
116+
</Box>
119117
) : null;
120118

121119
const secondaryActionMarkup = secondaryAction ? (
@@ -124,24 +122,25 @@ export const Banner = forwardRef<BannerHandles, BannerProps>(function Banner(
124122

125123
const actionMarkup =
126124
action || secondaryAction ? (
127-
<div className={styles.Actions}>
125+
<Box
126+
paddingTop={withinContentContainer ? '3' : '4'}
127+
paddingBottom={withinContentContainer ? '1' : undefined}
128+
>
128129
<ButtonGroup>
129130
{primaryActionMarkup}
130131
{secondaryActionMarkup}
131132
</ButtonGroup>
132-
</div>
133+
</Box>
133134
) : null;
134135

135136
let contentMarkup: React.ReactNode = null;
136-
let contentID: string | undefined;
137137

138138
if (children || actionMarkup) {
139-
contentID = `${id}Content`;
140139
contentMarkup = (
141-
<div className={styles.Content} id={contentID}>
140+
<Box paddingTop="05" paddingBottom="05">
142141
{children}
143142
{actionMarkup}
144-
</div>
143+
</Box>
145144
);
146145
}
147146

@@ -168,19 +167,17 @@ export const Banner = forwardRef<BannerHandles, BannerProps>(function Banner(
168167
onMouseUp={handleMouseUp}
169168
onKeyUp={handleKeyUp}
170169
onBlur={handleBlur}
171-
aria-labelledby={headingID}
172-
aria-describedby={contentID}
173170
>
174171
{dismissButton}
175172

176-
<div className={styles.Ribbon}>
173+
<Box paddingRight="4">
177174
<Icon source={iconName} color={iconColor} />
178-
</div>
175+
</Box>
179176

180-
<div className={styles.ContentWrapper}>
177+
<Bleed top="05">
181178
{headingMarkup}
182179
{contentMarkup}
183-
</div>
180+
</Bleed>
184181
</div>
185182
</BannerContext.Provider>
186183
);

polaris-react/src/components/Banner/tests/Banner.test.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
import {mountWithApp} from 'tests/utilities';
1010

1111
import {Button} from '../../Button';
12-
import {Heading} from '../../Heading';
12+
import {Text} from '../../Text';
1313
import {Icon} from '../../Icon';
1414
import {Spinner} from '../../Spinner';
1515
import {UnstyledButton} from '../../UnstyledButton';
@@ -21,12 +21,12 @@ import {Banner, BannerHandles} from '../Banner';
2121
describe('<Banner />', () => {
2222
it('renders a title', () => {
2323
const banner = mountWithApp(<Banner title="Banner title" />);
24-
expect(banner.find(Heading)).toContainReactText('Banner title');
24+
expect(banner.find(Text)).toContainReactText('Banner title');
2525
});
2626

27-
it('passes a p element to Heading', () => {
27+
it('passes an h2 element to Heading', () => {
2828
const banner = mountWithApp(<Banner title="Banner title" />);
29-
expect(banner).toContainReactComponent(Heading, {element: 'p'});
29+
expect(banner).toContainReactComponent(Text, {as: 'h2'});
3030
});
3131

3232
it('passes the provided icon source to Icon', () => {

0 commit comments

Comments
 (0)