Skip to content

Commit 160d9c1

Browse files
[Banner] Add hideIcon prop and update mobile web styling (#8349)
### WHY are these changes introduced? Fixes #6152 <!-- link to issue if one exists --> [Figma exploration](https://www.figma.com/file/GmN4pZi5fdSOUfWhE9LYB8/Banner?node-id=0%3A1&t=Cv8L57p4HY0sqZlj-1) [Storybook](https://5d559397bae39100201eedc1-eipbfirzou.chromatic.com/?path=/story/all-components-banner--default) ### WHAT is this pull request doing? 1. Updates styles for widths less than `490px` and are in page (aren't in card or in modal) 2. Adds a `hideIcon` prop > Note: We intentionally did not add a new example to the styleguide/storybook for the `hideIcon` prop since we want it used as a last resort for better spacing and we don't want to encourage incorrect patterns. Using the banner with an icon is still preferred and when there isn't enough space, there are probably better design solutions (i.e. tooltips) to use before resorting to a `hideIcon` Banner In the Admin mobile width: <img width="481" alt="Screenshot 2023-02-14 at 5 37 28 PM" src="https://user-images.githubusercontent.com/20652326/218879086-6fe8ff57-407c-4e4c-8dc7-a91ae5341eb0.png"> Banners within content containers (i.e. modals and cards) are not affected: <img width="337" alt="Screenshot 2023-02-14 at 5 12 44 PM" src="https://user-images.githubusercontent.com/20652326/218875124-ef0b2b14-0f5b-4247-aaff-9981f5008998.png"> Hide Icon: <img width="319" alt="Screenshot 2023-02-14 at 5 34 58 PM" src="https://user-images.githubusercontent.com/20652326/218878694-c1198a13-acdd-4cd5-8f2e-cfac6e8cac0d.png"> ### How to 🎩 Try to create discount without adding collection to get error banner: https://admin.web.web-9fv7.sophie-schneider.us.spin.dev/store/shop1/discounts/new?type=moneyOffProduct You can also look at the banner states in [Storybook](https://5d559397bae39100201eedc1-cuwxzjwkzy.chromatic.com/?path=/story/all-components-banner--with-no-icon) ### 🎩 checklist - [x] Tested on [mobile](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting.md#cross-browser-testing) - [x] Tested on [multiple browsers](https://help.shopify.com/en/manual/shopify-admin/supported-browsers) - [x] Tested for [accessibility](https://github.com/Shopify/polaris/blob/main/documentation/Accessibility%20testing.md) - [x] Updated the component's `README.md` with documentation changes - [x] [Tophatted documentation](https://github.com/Shopify/polaris/blob/main/documentation/Tophatting%20documentation.md) changes in the style guide
1 parent 5d4c2c1 commit 160d9c1

File tree

4 files changed

+31
-36
lines changed

4 files changed

+31
-36
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+
Add hideIcon prop to Banner and update Banner styles for mobile web

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

Lines changed: 15 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,51 @@
11
@import '../../styles/common';
22

33
@mixin banner-variants($in-page) {
4-
// stylelint-disable -- Polaris component custom properties
5-
--pc-banner-background: var(--p-background);
6-
--pc-banner-border: var(--p-banner-border-default);
7-
// stylelint-enable
8-
transition: box-shadow var(--p-duration-200) var(--p-ease);
9-
transition-delay: var(--p-duration-100);
10-
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
11-
box-shadow: var(--pc-banner-border);
12-
outline: var(--p-border-width-1) solid transparent;
4+
border: var(--p-border-width-1) solid var(--p-border-neutral-subdued);
5+
background-color: var(--p-background);
136

147
@if $in-page {
158
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
169
@include focus-ring('wide');
1710
border-radius: var(--p-border-radius-2);
18-
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
19-
background-color: var(--pc-banner-background);
11+
12+
@media #{$p-breakpoints-sm-down} {
13+
border-radius: 0;
14+
border-width: var(--p-border-width-1) 0;
15+
}
2016
} @else {
2117
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
2218
@include focus-ring('base');
2319
border-radius: var(--p-border-radius-1);
24-
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
25-
background-color: var(--pc-banner-background);
2620
}
2721

2822
&:focus {
2923
outline: none;
3024
}
3125

3226
&.keyFocused {
33-
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
34-
box-shadow: var(--pc-banner-border);
3527
// stylelint-disable-next-line -- generated by polaris-migrator DO NOT COPY
3628
@include focus-ring('wide', $style: 'focused');
3729
}
3830

3931
&.statusSuccess {
40-
// stylelint-disable -- Polaris component custom properties
41-
--pc-banner-background: var(--p-surface-success-subdued);
42-
--pc-banner-border: var(--p-banner-border-success);
43-
// stylelint-enable
32+
border-color: var(--p-border-success-subdued);
33+
background-color: var(--p-surface-success-subdued);
4434
}
4535

4636
&.statusInfo {
47-
// stylelint-disable -- Polaris component custom properties
48-
--pc-banner-background: var(--p-surface-highlight-subdued);
49-
--pc-banner-border: var(--p-banner-border-highlight);
50-
// stylelint-enable
37+
border-color: var(--p-border-highlight-subdued);
38+
background-color: var(--p-surface-highlight-subdued);
5139
}
5240

5341
&.statusWarning {
54-
// stylelint-disable -- Polaris component custom properties
55-
--pc-banner-background: var(--p-surface-warning-subdued);
56-
--pc-banner-border: var(--p-banner-border-warning);
57-
// stylelint-enable
42+
border-color: var(--p-border-warning-subdued);
43+
background-color: var(--p-surface-warning-subdued);
5844
}
5945

6046
&.statusCritical {
61-
// stylelint-disable -- Polaris component custom properties
62-
--pc-banner-background: var(--p-surface-critical-subdued);
63-
--pc-banner-border: var(--p-banner-border-critical);
64-
// stylelint-enable
47+
border-color: var(--p-border-critical-subdued);
48+
background-color: var(--p-surface-critical-subdued);
6549
}
6650
}
6751

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,10 @@ export type BannerStatus = 'success' | 'info' | 'warning' | 'critical';
3434
export interface BannerProps {
3535
/** Title content for the banner. */
3636
title?: string;
37-
/** Icon to display in the banner. Use only major, duotone icons */
37+
/** Status icon to display in the banner. Use only major icons */
3838
icon?: IconProps['source'];
39+
/** Renders the banner without a status icon. */
40+
hideIcon?: boolean;
3941
/** Sets the status of the banner. */
4042
status?: BannerStatus;
4143
/** The child elements to render in the banner. */
@@ -60,6 +62,7 @@ export const Banner = forwardRef<BannerHandles, BannerProps>(function Banner(
6062
status,
6163
onDismiss,
6264
stopAnnouncements,
65+
hideIcon,
6366
}: BannerProps,
6467
bannerRef,
6568
) {
@@ -169,9 +172,11 @@ export const Banner = forwardRef<BannerHandles, BannerProps>(function Banner(
169172
>
170173
{dismissButton}
171174

172-
<Box paddingInlineEnd="4">
173-
<Icon source={iconName} color={iconColor} />
174-
</Box>
175+
{hideIcon ? null : (
176+
<Box paddingInlineEnd="4">
177+
<Icon source={iconName} color={iconColor} />
178+
</Box>
179+
)}
175180

176181
<div className={styles.ContentWrapper}>
177182
{headingMarkup}

polaris.shopify.com/content/components/feedback-indicators/banner.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ Banners should:
6565
- Not be used to call attention to what a merchant needs to do in the UI instead of making the action clear in the UI itself.
6666
- Not be the primary entry point to information or actions merchants need on a regular basis.
6767
- Be dismissible unless they contain critical information or an important step merchants need to take.
68-
- Use the default icon for `success`, `info`, `warning` and `critical` statuses. If the icon is changed, use only [major, duotone icons](https://polaris.shopify.com/design/icons#using-icons-in-your-designs).
68+
- Use the default icon for `success`, `info`, `warning` and `critical` statuses. If the status icon is changed, use only [major icons](https://polaris.shopify.com/design/icons#major-icons-20-20).
69+
- Remove the status icon only in scenarios where it takes up too much space, such as very small breakpoints or in side navigation cards.
6970

7071
### Placement
7172

0 commit comments

Comments
 (0)