diff --git a/.changeset/neat-bobcats-clean.md b/.changeset/neat-bobcats-clean.md new file mode 100644 index 00000000000..3409993fd0b --- /dev/null +++ b/.changeset/neat-bobcats-clean.md @@ -0,0 +1,5 @@ +--- +'@shopify/polaris': patch +--- + +Add border to Banner on breakpoint-xs and change success icon to CheckCircleIcon diff --git a/polaris-react/src/components/Banner/Banner.module.css b/polaris-react/src/components/Banner/Banner.module.css index e30f8efbc62..89bf3a0c917 100644 --- a/polaris-react/src/components/Banner/Banner.module.css +++ b/polaris-react/src/components/Banner/Banner.module.css @@ -21,12 +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); - } - + .Banner { margin-top: var(--p-space-400); } diff --git a/polaris-react/src/components/Banner/Banner.tsx b/polaris-react/src/components/Banner/Banner.tsx index a46ab9e2b9c..b261fac43dc 100644 --- a/polaris-react/src/components/Banner/Banner.tsx +++ b/polaris-react/src/components/Banner/Banner.tsx @@ -1,18 +1,10 @@ -import React, { - forwardRef, - useContext, - useRef, - useState, - useEffect, - useCallback, -} from 'react'; +import React, {forwardRef, useContext, useRef} from 'react'; import type {PropsWithChildren} from 'react'; import type {ColorTextAlias} from '@shopify/polaris-tokens'; import {XIcon} from '@shopify/polaris-icons'; import type {Action, DisableableAction, LoadableAction} from '../../types'; import {Text} from '../Text'; -import type {InlineStackProps} from '../InlineStack'; import {InlineStack} from '../InlineStack'; import type {BoxProps} from '../Box'; import {Box} from '../Box'; @@ -23,9 +15,7 @@ import type {IconProps} from '../Icon'; import {BannerContext} from '../../utilities/banner-context'; import {WithinContentContext} from '../../utilities/within-content-context'; import {classNames} from '../../utilities/css'; -import {useBreakpoints} from '../../utilities/breakpoints'; import {useI18n} from '../../utilities/i18n'; -import {useEventListener} from '../../utilities/use-event-listener'; import {BlockStack} from '../BlockStack'; import styles from './Banner.module.css'; @@ -81,6 +71,7 @@ export const Banner = forwardRef(function Banner( onMouseUp={handleMouseUp} onKeyUp={handleKeyUp} onBlur={handleBlur} + style={{overflow: 'hidden'}} > @@ -109,7 +100,7 @@ export function BannerLayout({ }: BannerProps) { const i18n = useI18n(); const withinContentContainer = useContext(WithinContentContext); - const isInlineIconBanner = !title && !withinContentContainer; + const isInlineIconBanner = !withinContentContainer; const bannerTone = Object.keys(bannerAttributes).includes(tone) ? tone : 'info'; @@ -122,7 +113,7 @@ export function BannerLayout({ backgroundColor: bannerColors.background, textColor: bannerColors.text, bannerTitle: title ? ( - + {title} ) : null, @@ -178,100 +169,33 @@ export function BannerLayout({ ); } - if (isInlineIconBanner) { - return ( - - {childrenMarkup} - - ); - } - - return {childrenMarkup}; -} - -export function DefaultBanner({ - backgroundColor, - textColor, - bannerTitle, - bannerIcon, - actionButtons, - dismissButton, - children, -}: PropsWithChildren) { - const {smUp} = useBreakpoints(); - const hasContent = children || actionButtons; - return ( - - - - - - {bannerIcon} - {bannerTitle} - - {dismissButton} - - - {hasContent && ( - - -
{children}
- {actionButtons} -
-
- )} -
-
+ {childrenMarkup} ); } export function InlineIconBanner({ backgroundColor, + bannerTitle, bannerIcon, actionButtons, dismissButton, children, -}: PropsWithChildren>) { - const [blockAlign, setBlockAlign] = - useState('center'); +}: PropsWithChildren>) { const contentNode = useRef(null); const iconNode = useRef(null); const dismissIconNode = useRef(null); - const handleResize = useCallback(() => { - const contentHeight = contentNode.current?.offsetHeight; - const iconBoxHeight = - iconNode.current?.offsetHeight || dismissIconNode.current?.offsetHeight; - - if (!contentHeight || !iconBoxHeight) return; - - contentHeight > iconBoxHeight - ? setBlockAlign('start') - : setBlockAlign('center'); - }, []); - - useEffect(() => handleResize(), [handleResize]); - useEventListener('resize', handleResize); - return ( - + - + {bannerIcon ? (
) : null} - + -
{children}
+ + {bannerTitle} +
{children}
+
{actionButtons}
diff --git a/polaris-react/src/components/Banner/tests/Banner.test.tsx b/polaris-react/src/components/Banner/tests/Banner.test.tsx index 0ffa122fac5..9f80e36160b 100644 --- a/polaris-react/src/components/Banner/tests/Banner.test.tsx +++ b/polaris-react/src/components/Banner/tests/Banner.test.tsx @@ -1,10 +1,10 @@ import React, {useEffect, useRef} from 'react'; import { PlusCircleIcon, - CheckIcon, AlertTriangleIcon, InfoIcon, AlertDiamondIcon, + CheckCircleIcon, } from '@shopify/polaris-icons'; import {mountWithApp} from 'tests/utilities'; @@ -20,7 +20,6 @@ import {BannerContext} from '../../../utilities/banner-context'; import {WithinContentContext} from '../../../utilities/within-content-context'; import { Banner, - DefaultBanner, InlineIconBanner, WithinContentContainerBanner, } from '../Banner'; @@ -320,11 +319,6 @@ describe('', () => { expect(modal).toContainReactComponent(WithinContentContainerBanner); }); - it('shows the DefaultBanner variant by default', () => { - const banner = mountWithApp(); - expect(banner).toContainReactComponent(DefaultBanner); - }); - it('shows the InlineIconBanner variant by default when there is no title and it is not in a content container', () => { const banner = mountWithApp(); expect(banner).toContainReactComponent(InlineIconBanner); @@ -356,7 +350,7 @@ describe('', () => { describe('icon', () => { it.each([ - ['success', CheckIcon], + ['success', CheckCircleIcon], ['info', InfoIcon], ['warning', AlertTriangleIcon], ['critical', AlertDiamondIcon], diff --git a/polaris-react/src/components/Banner/utilities.ts b/polaris-react/src/components/Banner/utilities.ts index 84d9936e1b0..9d30ecd1ae5 100644 --- a/polaris-react/src/components/Banner/utilities.ts +++ b/polaris-react/src/components/Banner/utilities.ts @@ -7,7 +7,7 @@ import { AlertDiamondIcon, InfoIcon, AlertTriangleIcon, - CheckIcon, + CheckCircleIcon, } from '@shopify/polaris-icons'; import {useImperativeHandle, useRef, useState} from 'react'; @@ -39,7 +39,7 @@ export const bannerAttributes: {[key in BannerTone]: BannerAttributes} = { text: 'text-success', icon: 'text-success', }, - icon: CheckIcon, + icon: CheckCircleIcon, }, warning: { withinPage: {