diff --git a/packages/react-core/src/components/Banner/Banner.tsx b/packages/react-core/src/components/Banner/Banner.tsx index f04edb943e7..1e2db401c5c 100644 --- a/packages/react-core/src/components/Banner/Banner.tsx +++ b/packages/react-core/src/components/Banner/Banner.tsx @@ -3,16 +3,18 @@ import styles from '@patternfly/react-styles/css/components/Banner/banner'; import { css } from '@patternfly/react-styles'; export interface BannerProps extends React.HTMLProps { - /** Content rendered inside the banner */ + /** Content rendered inside the banner. */ children?: React.ReactNode; - /** Additional classes added to the banner */ + /** Additional classes added to the banner. */ className?: string; - /** Variant styles for the banner */ - variant?: 'default' | 'info' | 'danger' | 'success' | 'warning'; /** 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. Defaults to "${variant} banner" if this prop is not passed in */ + /** Text announced by screen readers to indicate the type of banner. This prop should only + * be passed in when the banner conveys status/severity. + */ screenReaderText?: string; + /** Variant styles for the banner. */ + variant?: 'default' | 'info' | 'danger' | 'success' | 'warning'; } export const Banner: React.FunctionComponent = ({ @@ -32,8 +34,8 @@ export const Banner: React.FunctionComponent = ({ )} {...props} > + {screenReaderText && {screenReaderText}} {children} - {screenReaderText || `${variant} banner`} ); 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 1dc8d86b33e..894f6ec2ae0 100644 --- a/packages/react-core/src/components/Banner/__tests__/Banner.test.tsx +++ b/packages/react-core/src/components/Banner/__tests__/Banner.test.tsx @@ -51,22 +51,12 @@ test('Renders with class name pf-m-info when "info" is passed to variant prop', expect(screen.getByText('Test')).toHaveClass('pf-m-info'); }); -test('Renders pf-u-screen-reader class by default for screenReaderText', () => { +test('Does not render pf-u-screen-reader class by default', () => { render(Test); - expect(screen.getByText('default banner')).toHaveClass('pf-u-screen-reader', { exact: true }); + expect(screen.getByText('Test')).not.toContainHTML(''); }); -test('Renders screenReaderText as "default banner" by default', () => { - render(Test); - expect(screen.getByText('default banner')).toBeInTheDocument(); -}); - -test('Renders screenReaderText as "success banner" when variant="success"', () => { - render(Test); - expect(screen.getByText('success banner')).toBeInTheDocument(); -}); - -test('Renders custom screenReaderText passed via prop', () => { +test('Renders screenReaderText passed via prop', () => { render(Test); 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 1d6551bd157..d595c3708d2 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,11 +6,6 @@ exports[`Matches the snapshot 1`] = ` class="pf-c-banner" > Test - - default banner - `; diff --git a/packages/react-core/src/components/Banner/examples/Banner.md b/packages/react-core/src/components/Banner/examples/Banner.md index 8669d5220ea..49876b514a6 100644 --- a/packages/react-core/src/components/Banner/examples/Banner.md +++ b/packages/react-core/src/components/Banner/examples/Banner.md @@ -5,9 +5,28 @@ 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. + ```ts file="./BannerBasic.tsx" + +``` + +### Status + +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. The `screenReaderText` prop should also be passed in to convey the status/severity of the banner to users of certain assistive technologies such as screen readers. + +In the following example, a flex layout is used inside the banner content to show one possible way to create spacing between the icons and banner text. + +```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 71a895c37de..31ad5034525 100644 --- a/packages/react-core/src/components/Banner/examples/BannerBasic.tsx +++ b/packages/react-core/src/components/Banner/examples/BannerBasic.tsx @@ -2,17 +2,15 @@ import React from 'react'; import { Banner } from '@patternfly/react-core'; export const BannerBasic: React.FunctionComponent = () => ( - - Default banner + <> + Default banner
- - Info banner - + Blue banner
- Danger banner + Red banner
- Success banner + Green banner
- Warning 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 new file mode 100644 index 00000000000..016c067a5b0 --- /dev/null +++ b/packages/react-core/src/components/Banner/examples/BannerStatus.tsx @@ -0,0 +1,56 @@ +import React from 'react'; +import { Banner, Flex, FlexItem } 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 + + +
+ + + + + + Info banner + + +
+ + + + + + Danger banner + + +
+ + + + + + Success banner + + +
+ + + + + + Warning banner + + + +);