Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Banner mobile styles #11959

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/grumpy-cheetahs-hug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris': minor
---

Updated `Banner` styling for small screens
2 changes: 0 additions & 2 deletions polaris-react/src/components/Banner/Banner.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
}

.withinPage {
@mixin shadow-bevel var(--p-shadow-200), var(--p-border-radius-0);

@media (--p-breakpoints-sm-up) {
@mixin shadow-bevel var(--p-shadow-200), var(--p-border-radius-300);
}
Expand Down
4 changes: 2 additions & 2 deletions polaris-react/src/components/Banner/Banner.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ export const All = {
</Text>
<AllBanners
onDismiss={() => {}}
action={{content: 'Primary action'}}
secondaryAction={{content: 'Secondary action'}}
action={{content: 'Primary'}}
secondaryAction={{content: 'Secondary'}}
Comment on lines +302 to +303
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made this change so we can see some examples of buttons side by side instead of stacked on small screens

/>
<Text as="h2" variant="headingMd">
Default by status
Expand Down
56 changes: 47 additions & 9 deletions polaris-react/src/components/Banner/Banner.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export function BannerLayout({
children,
}: BannerProps) {
const i18n = useI18n();
const {smUp} = useBreakpoints();
const withinContentContainer = useContext(WithinContentContext);
const isInlineIconBanner = !title && !withinContentContainer;
const bannerTone = Object.keys(bannerAttributes).includes(tone)
Expand All @@ -118,6 +119,20 @@ export function BannerLayout({
withinContentContainer ? 'withinContentContainer' : 'withinPage'
];

let iconClassName = '';

if (smUp) {
if (isInlineIconBanner) {
iconClassName = 'icon-secondary';
} else {
iconClassName = bannerColors.icon;
}
} else if (withinContentContainer) {
iconClassName = bannerColors.icon;
} else {
iconClassName = 'icon-secondary';
}

const sharedBannerProps: BannerLayoutProps = {
backgroundColor: bannerColors.background,
textColor: bannerColors.text,
Expand All @@ -133,7 +148,7 @@ export function BannerLayout({
),
actionButtons:
action || secondaryAction ? (
<ButtonGroup>
<ButtonGroup fullWidth={!smUp} gap={smUp ? 'tight' : 'extraTight'}>
{action && (
<Button onClick={action.onAction} {...action}>
{action.content}
Expand All @@ -150,11 +165,7 @@ export function BannerLayout({
<Button
variant="tertiary"
icon={
<span
className={
styles[isInlineIconBanner ? 'icon-secondary' : bannerColors.icon]
}
>
<span className={styles[iconClassName]}>
<Icon source={XIcon} />
</span>
}
Expand Down Expand Up @@ -201,7 +212,19 @@ export function DefaultBanner({
const {smUp} = useBreakpoints();
const hasContent = children || actionButtons;

return (
const xsOnlyBannerMarkup = (
<InlineIconBanner
backgroundColor={backgroundColor}
bannerTitle={bannerTitle}
bannerIcon={bannerIcon}
actionButtons={actionButtons}
dismissButton={dismissButton}
>
{children}
</InlineIconBanner>
);

const smUpBannerMarkup = (
<Box width="100%">
<BlockStack align="space-between">
<Box
Expand Down Expand Up @@ -237,20 +260,26 @@ export function DefaultBanner({
</BlockStack>
</Box>
);

const bannerMarkup = smUp ? smUpBannerMarkup : xsOnlyBannerMarkup;

return bannerMarkup;
}

export function InlineIconBanner({
backgroundColor,
bannerTitle,
bannerIcon,
actionButtons,
dismissButton,
children,
}: PropsWithChildren<Omit<BannerLayoutProps, 'textColor' | 'bannerTitle'>>) {
}: PropsWithChildren<Omit<BannerLayoutProps, 'textColor'>>) {
const [blockAlign, setBlockAlign] =
useState<InlineStackProps['blockAlign']>('center');
const contentNode = useRef<HTMLDivElement>(null);
const iconNode = useRef<HTMLDivElement>(null);
const dismissIconNode = useRef<HTMLDivElement>(null);
const {smUp} = useBreakpoints();

const handleResize = useCallback(() => {
const contentHeight = contentNode.current?.offsetHeight;
Expand Down Expand Up @@ -285,7 +314,16 @@ export function InlineIconBanner({
) : null}
<Box ref={contentNode} width="100%">
<BlockStack gap="200">
<div>{children}</div>
{bannerTitle ? (
<BlockStack gap="100">
<Box paddingBlockStart={smUp ? '0' : '100'}>
{bannerTitle}
</Box>
{children}
</BlockStack>
) : (
<div>{children}</div>
)}
{actionButtons}
</BlockStack>
</Box>
Expand Down
4 changes: 2 additions & 2 deletions polaris-react/src/components/Banner/tests/Banner.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, {useEffect, useRef} from 'react';
import {
PlusCircleIcon,
CheckIcon,
CheckCircleIcon,
AlertTriangleIcon,
InfoIcon,
AlertDiamondIcon,
Expand Down Expand Up @@ -356,7 +356,7 @@ describe('<Banner />', () => {

describe('icon', () => {
it.each([
['success', CheckIcon],
['success', CheckCircleIcon],
['info', InfoIcon],
['warning', AlertTriangleIcon],
['critical', AlertDiamondIcon],
Expand Down
4 changes: 2 additions & 2 deletions polaris-react/src/components/Banner/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
AlertDiamondIcon,
InfoIcon,
AlertTriangleIcon,
CheckIcon,
CheckCircleIcon,
} from '@shopify/polaris-icons';
import {useImperativeHandle, useRef, useState} from 'react';

Expand Down Expand Up @@ -39,7 +39,7 @@ export const bannerAttributes: {[key in BannerTone]: BannerAttributes} = {
text: 'text-success',
icon: 'text-success',
},
icon: CheckIcon,
icon: CheckCircleIcon,
},
warning: {
withinPage: {
Expand Down
Loading