Skip to content

Commit 48a7f4d

Browse files
kyledurandsophschneider
authored andcommitted
[Banner] Change status prop to tone (#10206)
<!-- ☝️How to write a good PR title: - Prefix it with [ComponentName] (if applicable), for example: [Button] - Start with a verb, for example: Add, Delete, Improve, Fix… - Give as much context as necessary and as little as possible - Prefix it with [WIP] while it’s a work in progress --> ### WHY are these changes introduced? Fixes #10050 <!-- Context about the problem that’s being addressed. --> ### WHAT is this pull request doing? Changes the status prop on banner to tone
1 parent b8cdb78 commit 48a7f4d

16 files changed

+52
-58
lines changed

.changeset/olive-clouds-pretend.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@shopify/polaris': major
3+
---
4+
5+
Changed `status` prop on `Banner` to `tone`

documentation/guides/migrating-from-v11-to-v12.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ Polaris v12.0.0 ([full release notes](https://github.com/Shopify/polaris/release
5858

5959
// TODO - Boolean prop to tone, variant migration
6060

61+
**Banner**
62+
63+
`npx @shopify/polaris-migrator react-rename-component-prop <path> --componentName="Banner" --from="status" --to="tone"`
64+
6165
**Icon**
6266

6367
- Backdrop is not a pattern in the new Polaris design language. If you must use a backdrop on your icon, use Box.

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export function WithFooterCallToAction() {
4343
return (
4444
<Banner
4545
title="Some of your product variants are missing weights"
46-
status="warning"
46+
tone="warning"
4747
action={{content: 'Edit variant weights', url: ''}}
4848
secondaryAction={{content: 'Learn more', url: ''}}
4949
onDismiss={() => {}}
@@ -62,7 +62,7 @@ export function Informational() {
6262
title="USPS has updated their rates"
6363
action={{content: 'Update rates', url: ''}}
6464
secondaryAction={{content: 'Learn more'}}
65-
status="info"
65+
tone="info"
6666
onDismiss={() => {}}
6767
>
6868
<p>Make sure you know how these changes affect your store.</p>
@@ -74,7 +74,7 @@ export function Success() {
7474
return (
7575
<Banner
7676
title="Your shipping label is ready to print."
77-
status="success"
77+
tone="success"
7878
action={{content: 'Print label'}}
7979
onDismiss={() => {}}
8080
/>
@@ -86,7 +86,7 @@ export function Warning() {
8686
<Banner
8787
title="Before you can purchase a shipping label, this change needs to be made:"
8888
action={{content: 'Edit address'}}
89-
status="warning"
89+
tone="warning"
9090
>
9191
<List>
9292
<List.Item>
@@ -103,7 +103,7 @@ export function Critical() {
103103
<Banner
104104
title="High risk of fraud detected"
105105
action={{content: 'Review risk analysis'}}
106-
status="critical"
106+
tone="critical"
107107
>
108108
<p>
109109
Before fulfilling this order or capturing payment, please{' '}
@@ -139,7 +139,7 @@ export function InAModal() {
139139
>
140140
<Modal.Section>
141141
<TextContainer>
142-
<Banner action={{content: 'Connect account'}} status="warning">
142+
<Banner action={{content: 'Connect account'}} tone="warning">
143143
<p>
144144
Connect your instagram account to your shop before proceeding.
145145
</p>
@@ -165,7 +165,7 @@ export function WithFocus() {
165165
<Banner
166166
title="High risk of fraud detected"
167167
onDismiss={() => {}}
168-
status="critical"
168+
tone="critical"
169169
ref={banner}
170170
>
171171
<p>
@@ -214,7 +214,7 @@ export function InALegacyCard() {
214214

215215
export function WithEndJustifiedContent() {
216216
return (
217-
<Banner status="critical">
217+
<Banner tone="critical">
218218
<BlockStack gap="1">
219219
<InlineStack gap="4" align="space-between">
220220
<Text variant="headingMd" fontWeight="semibold" as="h3">
@@ -233,7 +233,7 @@ export function WithEndJustifiedContent() {
233233
export function HideIcon() {
234234
return (
235235
<LegacyCard title="Edit customer" sectioned>
236-
<Banner status="warning" hideIcon>
236+
<Banner tone="warning" hideIcon>
237237
<Text as="p" fontWeight="semibold">
238238
Changing the phone number for this customer will unsubscribe them from
239239
SMS marketing text messages until they provide consent.
@@ -246,7 +246,7 @@ export function HideIcon() {
246246
export function CustomIcon() {
247247
return (
248248
<Banner
249-
status="info"
249+
tone="info"
250250
icon={DiscountsMajor}
251251
title="Choose a plan and your discount will be applied at checkout."
252252
/>
@@ -408,25 +408,25 @@ function AllBanners(props) {
408408
/>
409409
<Banner
410410
title="Info"
411-
status="info"
411+
tone="info"
412412
children={<Text as="p">Info status</Text>}
413413
{...props}
414414
/>
415415
<Banner
416416
title="Success"
417-
status="success"
417+
tone="success"
418418
children={<Text as="p">Success status</Text>}
419419
{...props}
420420
/>
421421
<Banner
422422
title="Warning"
423-
status="warning"
423+
tone="warning"
424424
children={<Text as="p">Warning status</Text>}
425425
{...props}
426426
/>
427427
<Banner
428428
title="Critical"
429-
status="critical"
429+
tone="critical"
430430
children={<Text as="p">Critical status</Text>}
431431
{...props}
432432
/>

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import styles from './Banner.scss';
3232
import type {BannerHandles} from './utilities';
3333
import {bannerAttributes, useBannerFocus} from './utilities';
3434

35-
export type BannerStatus = 'success' | 'info' | 'warning' | 'critical';
35+
export type BannerTone = 'success' | 'info' | 'warning' | 'critical';
3636

3737
export interface BannerProps {
3838
/** Title content for the banner. */
@@ -42,7 +42,7 @@ export interface BannerProps {
4242
/** Renders the banner without a status icon. */
4343
hideIcon?: boolean;
4444
/** Sets the status of the banner. */
45-
status?: BannerStatus;
45+
tone?: BannerTone;
4646
/** The child elements to render in the banner. */
4747
children?: React.ReactNode;
4848
/** Action for banner */
@@ -59,7 +59,7 @@ export const Banner = forwardRef<BannerHandles, BannerProps>(function Banner(
5959
props: BannerProps,
6060
bannerRef,
6161
) {
62-
const {status, stopAnnouncements} = props;
62+
const {tone, stopAnnouncements} = props;
6363
const withinContentContainer = useContext(WithinContentContext);
6464
const {wrapperRef, handleKeyUp, handleBlur, handleMouseUp, shouldShowFocus} =
6565
useBannerFocus(bannerRef);
@@ -76,9 +76,7 @@ export const Banner = forwardRef<BannerHandles, BannerProps>(function Banner(
7676
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
7777
tabIndex={0}
7878
ref={wrapperRef}
79-
role={
80-
status === 'warning' || status === 'critical' ? 'alert' : 'status'
81-
}
79+
role={tone === 'warning' || tone === 'critical' ? 'alert' : 'status'}
8280
aria-live={stopAnnouncements ? 'off' : 'polite'}
8381
onMouseUp={handleMouseUp}
8482
onKeyUp={handleKeyUp}
@@ -100,7 +98,7 @@ interface BannerLayoutProps {
10098
}
10199

102100
export function BannerLayout({
103-
status = 'info',
101+
tone = 'info',
104102
icon,
105103
hideIcon,
106104
onDismiss,
@@ -112,11 +110,11 @@ export function BannerLayout({
112110
const i18n = useI18n();
113111
const withinContentContainer = useContext(WithinContentContext);
114112
const isInlineIconBanner = !title && !withinContentContainer;
115-
const bannerStatus = Object.keys(bannerAttributes).includes(status)
116-
? status
113+
const bannerTone = Object.keys(bannerAttributes).includes(tone)
114+
? tone
117115
: 'info';
118116
const bannerColors =
119-
bannerAttributes[bannerStatus][
117+
bannerAttributes[bannerTone][
120118
withinContentContainer ? 'withinContentContainer' : 'withinPage'
121119
];
122120

@@ -130,7 +128,7 @@ export function BannerLayout({
130128
) : null,
131129
bannerIcon: hideIcon ? null : (
132130
<span className={styles[bannerColors.icon]}>
133-
<Icon source={icon ?? bannerAttributes[bannerStatus].icon} />
131+
<Icon source={icon ?? bannerAttributes[bannerTone].icon} />
134132
</span>
135133
),
136134
actionButtons:

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import {
2424
InlineIconBanner,
2525
WithinContentContainerBanner,
2626
} from '../Banner';
27-
import type {BannerStatus} from '../Banner';
27+
import type {BannerTone} from '../Banner';
2828
import type {BannerHandles} from '../utilities';
2929

3030
window.matchMedia =
@@ -244,7 +244,7 @@ describe('<Banner />', () => {
244244
banner.current && banner.current.focus();
245245
}, []);
246246

247-
return <Banner ref={banner} status="critical" />;
247+
return <Banner ref={banner} tone="critical" />;
248248
}
249249

250250
const testComponent = mountWithApp(<Test />);
@@ -357,14 +357,11 @@ describe('<Banner />', () => {
357357
['info', 'status'],
358358
['warning', 'alert'],
359359
['critical', 'alert'],
360-
])(
361-
'aria role when status is %s',
362-
(status: BannerStatus, role: 'string') => {
363-
const banner = mountWithApp(<Banner status={status} />);
360+
])('aria role when status is %s', (tone: BannerTone, role: 'string') => {
361+
const banner = mountWithApp(<Banner tone={tone} />);
364362

365-
expect(banner).toContainReactComponent('div', {role});
366-
},
367-
);
363+
expect(banner).toContainReactComponent('div', {role});
364+
});
368365
});
369366

370367
describe('icon', () => {
@@ -373,8 +370,8 @@ describe('<Banner />', () => {
373370
['info', InfoMinor],
374371
['warning', RiskMinor],
375372
['critical', DiamondAlertMinor],
376-
])('icon when status is %s', (status: BannerStatus, icon: any) => {
377-
const banner = mountWithApp(<Banner status={status} />);
373+
])('icon when status is %s', (tone: BannerTone, icon: any) => {
374+
const banner = mountWithApp(<Banner tone={tone} />);
378375

379376
expect(banner).toContainReactComponent(Icon, {
380377
source: icon,

polaris-react/src/components/Banner/utilities.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {useImperativeHandle, useRef, useState} from 'react';
1313

1414
import type {IconSource} from '../../types';
1515

16-
import type {BannerStatus} from './Banner';
16+
import type {BannerTone} from './Banner';
1717

1818
interface BannerColorAliases {
1919
background: ColorBackgroundAlias;
@@ -27,7 +27,7 @@ interface BannerAttributes {
2727
icon: IconSource;
2828
}
2929

30-
export const bannerAttributes: {[key in BannerStatus]: BannerAttributes} = {
30+
export const bannerAttributes: {[key in BannerTone]: BannerAttributes} = {
3131
success: {
3232
withinPage: {
3333
background: 'bg-success-strong',

polaris-react/src/index.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,7 @@ export {
6666
export type {BadgeProps} from './components/Badge';
6767

6868
export {Banner} from './components/Banner';
69-
export type {
70-
BannerProps,
71-
BannerStatus,
72-
BannerHandles,
73-
} from './components/Banner';
69+
export type {BannerProps, BannerTone, BannerHandles} from './components/Banner';
7470

7571
export {Bleed} from './components/Bleed';
7672
export type {BleedProps} from './components/Bleed';

polaris.shopify.com/pages/examples/banner-critical.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function BannerExample() {
77
<Banner
88
title="High risk of fraud detected"
99
action={{content: 'Review risk analysis'}}
10-
status="critical"
10+
tone="critical"
1111
>
1212
<p>
1313
Before fulfilling this order or capturing payment, please{' '}

polaris.shopify.com/pages/examples/banner-in-a-modal.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function BannerInModalExample() {
2727
>
2828
<Modal.Section>
2929
<TextContainer>
30-
<Banner action={{content: 'Connect account'}} status="warning">
30+
<Banner action={{content: 'Connect account'}} tone="warning">
3131
<p>
3232
Connect your instagram account to your shop before proceeding.
3333
</p>

polaris.shopify.com/pages/examples/banner-informational.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function BannerExample() {
88
title="USPS has updated their rates"
99
action={{content: 'Update rates', url: ''}}
1010
secondaryAction={{content: 'Learn more'}}
11-
status="info"
11+
tone="info"
1212
onDismiss={() => {}}
1313
>
1414
<p>Make sure you know how these changes affect your store.</p>

0 commit comments

Comments
 (0)