Skip to content

Commit c91c911

Browse files
authored
feat(Banner): add pill variant (#12440)
1 parent 8b528bb commit c91c911

4 files changed

Lines changed: 54 additions & 1 deletion

File tree

packages/react-core/src/components/Banner/Banner.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export interface BannerProps extends React.HTMLProps<HTMLDivElement> {
1212
className?: string;
1313
/** If set to true, the banner sticks to the top of its container */
1414
isSticky?: boolean;
15+
/** If set to true, the banner will have a pill shape */
16+
isPill?: boolean;
1517
/** Text announced by screen readers to indicate the type of banner. This prop should only
1618
* be passed in when the banner conveys status/severity.
1719
*/
@@ -36,6 +38,7 @@ export const Banner: React.FunctionComponent<StatusBanner | NonStatusBanner> = (
3638
className,
3739
screenReaderText,
3840
isSticky = false,
41+
isPill = false,
3942
color,
4043
status,
4144
...props
@@ -52,7 +55,13 @@ export const Banner: React.FunctionComponent<StatusBanner | NonStatusBanner> = (
5255

5356
return (
5457
<div
55-
className={css(styles.banner, getStatusOrColorModifier(), isSticky && styles.modifiers.sticky, className)}
58+
className={css(
59+
styles.banner,
60+
getStatusOrColorModifier(),
61+
isSticky && styles.modifiers.sticky,
62+
isPill && styles.modifiers.pill,
63+
className
64+
)}
5665
{...props}
5766
>
5867
{screenReaderText && <span className="pf-v6-screen-reader">{screenReaderText}</span>}

packages/react-core/src/components/Banner/__tests__/Banner.test.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,21 @@ test('Renders with inherited element props spread to the component', () => {
121121
expect(screen.getByText('Test')).toHaveAccessibleName('Test label');
122122
});
123123

124+
test(`Renders with class name ${styles.modifiers.pill} when isPill prop is true`, () => {
125+
render(<Banner isPill>Test</Banner>);
126+
expect(screen.getByText('Test')).toHaveClass(styles.modifiers.pill);
127+
});
128+
129+
test(`Does not render with class name ${styles.modifiers.pill} when isPill is false`, () => {
130+
render(<Banner isPill={false}>Test</Banner>);
131+
expect(screen.getByText('Test')).not.toHaveClass(styles.modifiers.pill);
132+
});
133+
134+
test(`Does not render with class name ${styles.modifiers.pill} when isPill is undefined`, () => {
135+
render(<Banner>Test</Banner>);
136+
expect(screen.getByText('Test')).not.toHaveClass(styles.modifiers.pill);
137+
});
138+
124139
test('Matches the snapshot', () => {
125140
const { asFragment } = render(<Banner>Test</Banner>);
126141
expect(asFragment()).toMatchSnapshot();

packages/react-core/src/components/Banner/examples/Banner.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,11 @@ In the following example, a flex layout is used inside the banner content to sho
3232
```ts file="./BannerStatus.tsx"
3333

3434
```
35+
36+
### Pill
37+
38+
Banners may also have a rounded pill style by passing the `isPill` prop.
39+
40+
```ts file="./BannerPill.tsx"
41+
42+
```
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { Banner, Flex, FlexItem } from '@patternfly/react-core';
2+
import RhUiCheckCircleFillIcon from '@patternfly/react-icons/dist/esm/icons/rh-ui-check-circle-fill-icon';
3+
4+
export const BannerPill: React.FunctionComponent = () => (
5+
<>
6+
<Banner isPill>Default pill banner</Banner>
7+
<br />
8+
<Banner color="red" isPill>
9+
Red pill banner
10+
</Banner>
11+
<br />
12+
<Banner isPill screenReaderText="Success pill banner" status="success">
13+
<Flex spaceItems={{ default: 'spaceItemsSm' }}>
14+
<FlexItem>
15+
<RhUiCheckCircleFillIcon />
16+
</FlexItem>
17+
<FlexItem>Success pill banner</FlexItem>
18+
</Flex>
19+
</Banner>
20+
</>
21+
);

0 commit comments

Comments
 (0)