diff --git a/packages/react-core/src/components/Banner/Banner.tsx b/packages/react-core/src/components/Banner/Banner.tsx index bf96e5a60e2..ef0e3a648a9 100644 --- a/packages/react-core/src/components/Banner/Banner.tsx +++ b/packages/react-core/src/components/Banner/Banner.tsx @@ -1,28 +1,20 @@ import * as React from 'react'; import styles from '@patternfly/react-styles/css/components/Banner/banner'; import { css } from '@patternfly/react-styles'; -import { variantIcons } from '../Alert/AlertIcon'; -import { Flex, FlexItem } from '../../layouts'; export interface BannerProps extends React.HTMLProps { /** Content rendered inside the banner. */ children?: React.ReactNode; /** Additional classes added to the banner. */ className?: string; - /** A custom icon for the banner. This property will override the icon that is set based on - * the variant property. - */ - customIcon?: React.ReactNode; - /** Flag for indicating whether the banner has a status icon. When set to "true", the icon - * will be set based on the variant property. - */ - hasStatusIcon?: boolean; /** If set to true, the banner sticks to the top of its container */ isSticky?: boolean; - /** Text announced by screen readers to indicate the type of banner when the hasStatusIcon property - * is passed in. Defaults to "${variant} banner" if this property is not passed in. + /** Text announced by screen readers to indicate the type of banner. Defaults to "${variant} banner" + * if this property is not passed in. + * + * Pass in null to omit this text from the banner when the banner does not convey status/severity. */ - screenReaderText?: string; + screenReaderText?: string | null; /** Variant styles for the banner. */ variant?: 'default' | 'info' | 'danger' | 'success' | 'warning'; } @@ -30,39 +22,22 @@ export interface BannerProps extends React.HTMLProps { export const Banner: React.FunctionComponent = ({ children, className, - customIcon, - hasStatusIcon = false, variant = 'default', screenReaderText, isSticky = false, ...props -}: BannerProps) => { - const StatusIcon = variantIcons[variant]; - - return ( -
- {hasStatusIcon ? ( - - - {screenReaderText || `${variant} banner`} - {customIcon || } - - -
{children}
-
-
- ) : ( - children - )} -
- ); -}; +}: BannerProps) => ( +
+ {screenReaderText !== null && {screenReaderText || `${variant} banner`}} + {children} +
+); Banner.displayName = 'Banner'; diff --git a/packages/react-core/src/components/Banner/__tests__/Banner.test.tsx b/packages/react-core/src/components/Banner/__tests__/Banner.test.tsx index 1e3d0a48780..b478039f060 100644 --- a/packages/react-core/src/components/Banner/__tests__/Banner.test.tsx +++ b/packages/react-core/src/components/Banner/__tests__/Banner.test.tsx @@ -2,14 +2,6 @@ import { Banner } from '../Banner'; import React from 'react'; import { render, screen } from '@testing-library/react'; -jest.mock('@patternfly/react-icons/dist/esm/icons/check-circle-icon', () => () => 'Check circle icon mock'); -jest.mock('@patternfly/react-icons/dist/esm/icons/exclamation-circle-icon', () => () => 'Exclamation circle icon mock'); -jest.mock('@patternfly/react-icons/dist/esm/icons/exclamation-triangle-icon', () => () => - 'Exclamation triangle icon mock' -); -jest.mock('@patternfly/react-icons/dist/esm/icons/info-circle-icon', () => () => 'Info circle icon mock'); -jest.mock('@patternfly/react-icons/dist/esm/icons/bell-icon', () => () => 'Bell icon mock'); - ['default', 'info', 'success', 'warning', 'danger'].forEach((variant: string) => { test(`${variant} banner`, () => { const { asFragment } = render( @@ -34,58 +26,20 @@ test(`sticky banner`, () => { expect(asFragment()).toMatchSnapshot(); }); -test('Renders with the bell icon when variant is not passed and hasStatusIcon is passed', () => { - render(Default banner); - - expect(screen.getByText('Bell icon mock')).toBeVisible(); -}); - -test('Renders with the bell icon when variant = "default" and hasStatusIcon is passed', () => { - render( - - Default banner - - ); - - expect(screen.getByText('Bell icon mock')).toBeVisible(); -}); - -test('Renders with the info circle icon when variant = "info" and hasStatusIcon is passed', () => { - render( - - Info banner - - ); - - expect(screen.getByText('Info circle icon mock')).toBeVisible(); -}); - -test('Renders with the exclamation circle icon when variant = "danger" and hasStatusIcon is passed', () => { - render( - - Danger banner - - ); +test('Renders with screen reader text by default', () => { + render(Banner text); - expect(screen.getByText('Exclamation circle icon mock')).toBeVisible(); + expect(screen.getByText('default banner')).toBeInTheDocument(); }); -test('Renders with the check circle icon when variant = "success" and hasStatusIcon is passed', () => { - render( - - Success banner - - ); +test('Does not render with screen reader text when screenReaderText = null', () => { + render(Banner text); - expect(screen.getByText('Check circle icon mock')).toBeVisible(); + expect(screen.queryByText('default banner')).not.toBeInTheDocument(); }); -test('Renders with the exclamation triangle icon when variant = "warning" and hasStatusIcon is passed', () => { - render( - - Warning banner - - ); +test('Renders with custom screen reader text when screenReaderText is passed', () => { + render(Banner text); - expect(screen.getByText('Exclamation triangle icon mock')).toBeVisible(); + expect(screen.getByText('Custom screen reader text')).toBeInTheDocument(); }); diff --git a/packages/react-core/src/components/Banner/__tests__/__snapshots__/Banner.test.tsx.snap b/packages/react-core/src/components/Banner/__tests__/__snapshots__/Banner.test.tsx.snap index 902f1fca6ad..c82e467ffcb 100644 --- a/packages/react-core/src/components/Banner/__tests__/__snapshots__/Banner.test.tsx.snap +++ b/packages/react-core/src/components/Banner/__tests__/__snapshots__/Banner.test.tsx.snap @@ -6,6 +6,11 @@ exports[`danger banner 1`] = ` aria-label="danger" class="pf-c-banner pf-m-danger" > + + danger banner + danger Banner @@ -17,6 +22,11 @@ exports[`default banner 1`] = ` aria-label="default" class="pf-c-banner" > + + default banner + default Banner @@ -28,6 +38,11 @@ exports[`info banner 1`] = ` aria-label="info" class="pf-c-banner pf-m-info" > + + info banner + info Banner @@ -39,6 +54,11 @@ exports[`sticky banner 1`] = ` aria-label="sticky" class="pf-c-banner pf-m-sticky" > + + default banner + Sticky Banner @@ -50,6 +70,11 @@ exports[`success banner 1`] = ` aria-label="success" class="pf-c-banner pf-m-success" > + + success banner + success Banner @@ -61,6 +86,11 @@ exports[`warning banner 1`] = ` aria-label="warning" class="pf-c-banner pf-m-warning" > + + warning banner + warning Banner diff --git a/packages/react-core/src/components/Banner/examples/Banner.md b/packages/react-core/src/components/Banner/examples/Banner.md index 0d320d9cce3..22b67fc6ee2 100644 --- a/packages/react-core/src/components/Banner/examples/Banner.md +++ b/packages/react-core/src/components/Banner/examples/Banner.md @@ -5,18 +5,26 @@ cssPrefix: pf-c-banner propComponents: ['Banner'] --- +import CheckCircleIcon from '@patternfly/react-icons/dist/esm/icons/check-circle-icon'; +import ExclamationCircleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-circle-icon'; +import ExclamationTriangleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-triangle-icon'; +import InfoCircleIcon from '@patternfly/react-icons/dist/esm/icons/info-circle-icon'; +import BellIcon from '@patternfly/react-icons/dist/esm/icons/bell-icon'; + ## Examples ### Basic Banners can be styled with one of 5 different colors. A basic banner should only be used when the banner color does not represent status or severity. +The following example also passes in the `screenReaderText` property with a value of `null` to prevent visually hidden text meant for screen readers from rendering. When using a basic banner, a value of `null` or text that does not convey status/severity should be passed into `screenReaderText`. + ```ts file="./BannerBasic.tsx" ``` ### Status -When a banner is used to convey status, it is advised to pass in either the `hasStatusIcon` or `customIcon` property to render an icon inside the banner. This icon should convey the banner variant beyond just the banner color. +When a banner is used to convey status, it is advised to pass in an icon inside the banner to convey the status in a way besides just color. ```ts file="./BannerStatus.tsx" ``` diff --git a/packages/react-core/src/components/Banner/examples/BannerBasic.tsx b/packages/react-core/src/components/Banner/examples/BannerBasic.tsx index 31ad5034525..c783287e59b 100644 --- a/packages/react-core/src/components/Banner/examples/BannerBasic.tsx +++ b/packages/react-core/src/components/Banner/examples/BannerBasic.tsx @@ -3,14 +3,22 @@ import { Banner } from '@patternfly/react-core'; export const BannerBasic: React.FunctionComponent = () => ( <> - Default banner + Default banner
- Blue banner + + Blue banner +
- Red banner + + Red banner +
- Green banner + + Green banner +
- Gold banner + + Gold banner + ); diff --git a/packages/react-core/src/components/Banner/examples/BannerStatus.tsx b/packages/react-core/src/components/Banner/examples/BannerStatus.tsx index 926bad49b74..7251469df58 100644 --- a/packages/react-core/src/components/Banner/examples/BannerStatus.tsx +++ b/packages/react-core/src/components/Banner/examples/BannerStatus.tsx @@ -1,24 +1,31 @@ import React from 'react'; import { Banner } from '@patternfly/react-core'; +import CheckCircleIcon from '@patternfly/react-icons/dist/esm/icons/check-circle-icon'; +import ExclamationCircleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-circle-icon'; +import ExclamationTriangleIcon from '@patternfly/react-icons/dist/esm/icons/exclamation-triangle-icon'; +import InfoCircleIcon from '@patternfly/react-icons/dist/esm/icons/info-circle-icon'; +import BellIcon from '@patternfly/react-icons/dist/esm/icons/bell-icon'; export const BannerStatus: React.FunctionComponent = () => ( <> - Default banner + + Default banner +
- - Info banner + + Info banner
- - Danger banner + + Danger banner
- - Success banner + + Success banner
- - Warning banner + + Warning banner );