Skip to content

Commit a8bef5a

Browse files
avelinechazdean
authored andcommitted
[Banner] Rebuild with layout components (#7365)
Fixes #7358 Refactors `Banner` component to use new layout primitive components
1 parent e1f27f4 commit a8bef5a

File tree

4 files changed

+34
-68
lines changed

4 files changed

+34
-68
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 & 25 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 {Text} from '../Text';
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,16 +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-
<Text as="p" variant="headingMd">
89-
{title}
90-
</Text>
91-
</div>
85+
<Text as="h2" variant="headingMd">
86+
{title}
87+
</Text>
9288
);
9389
}
9490

@@ -111,13 +107,13 @@ export const Banner = forwardRef<BannerHandles, BannerProps>(function Banner(
111107
) : null;
112108

113109
const primaryActionMarkup = action ? (
114-
<div className={styles.PrimaryAction}>
110+
<Box paddingRight="2">
115111
{action.loading
116112
? spinnerMarkup
117113
: unstyledButtonFrom(action, {
118-
className: styles.Button,
114+
className: `${styles.Button} ${styles.PrimaryAction}`,
119115
})}
120-
</div>
116+
</Box>
121117
) : null;
122118

123119
const secondaryActionMarkup = secondaryAction ? (
@@ -126,24 +122,25 @@ export const Banner = forwardRef<BannerHandles, BannerProps>(function Banner(
126122

127123
const actionMarkup =
128124
action || secondaryAction ? (
129-
<div className={styles.Actions}>
125+
<Box
126+
paddingTop={withinContentContainer ? '3' : '4'}
127+
paddingBottom={withinContentContainer ? '1' : undefined}
128+
>
130129
<ButtonGroup>
131130
{primaryActionMarkup}
132131
{secondaryActionMarkup}
133132
</ButtonGroup>
134-
</div>
133+
</Box>
135134
) : null;
136135

137136
let contentMarkup: React.ReactNode = null;
138-
let contentID: string | undefined;
139137

140138
if (children || actionMarkup) {
141-
contentID = `${id}Content`;
142139
contentMarkup = (
143-
<div className={styles.Content} id={contentID}>
140+
<Box paddingTop="05" paddingBottom="05">
144141
{children}
145142
{actionMarkup}
146-
</div>
143+
</Box>
147144
);
148145
}
149146

@@ -170,19 +167,17 @@ export const Banner = forwardRef<BannerHandles, BannerProps>(function Banner(
170167
onMouseUp={handleMouseUp}
171168
onKeyUp={handleKeyUp}
172169
onBlur={handleBlur}
173-
aria-labelledby={headingID}
174-
aria-describedby={contentID}
175170
>
176171
{dismissButton}
177172

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

182-
<div className={styles.ContentWrapper}>
177+
<Bleed top="05">
183178
{headingMarkup}
184179
{contentMarkup}
185-
</div>
180+
</Bleed>
186181
</div>
187182
</BannerContext.Provider>
188183
);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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(Text, {as: 'p'})).toContainReactText('Banner title');
24+
expect(banner.find(Text)).toContainReactText('Banner title');
2525
});
2626

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

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

0 commit comments

Comments
 (0)