Skip to content

Commit 28b353f

Browse files
committed
optional dismissable prop for feature banner
1 parent 751f809 commit 28b353f

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

src/components/FeatureBanner/FeatureBanner.spec.tsx

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,17 @@ describe('<FeatureBanner />', () => {
3838

3939
expect(queryByText('FeatureBannerChildElement')).not.toBeNull();
4040
});
41-
});
41+
42+
describe('when dismissable', () => {
43+
it('can be closed', () => {
44+
const { getByRole, queryByText } = render(
45+
<FeatureBanner {...commonProps} dismissable />
46+
);
47+
const closeButton = getByRole('button');
48+
49+
expect(queryByText('FeatureBannerTitle')).not.toBeNull();
50+
closeButton.click();
51+
expect(queryByText('FeatureBannerTitle')).toBeNull();
52+
});
53+
});
54+
});

src/components/FeatureBanner/FeatureBanner.stories.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export const LiveExample: Story = {
2626
args: {
2727
alertText: 'New',
2828
color: 'info',
29+
dismissable: false,
2930
title: 'Company-Wide View of Text Messages',
3031
subtitle: 'View all text messages sent by your company from this page.',
3132
},

src/components/FeatureBanner/FeatureBanner.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { FC, ReactNode } from 'react';
1+
import React, { FC, ReactNode, useState } from 'react';
22
import { Alert } from 'reactstrap';
33

44
interface FeatureBannerProps {
@@ -7,23 +7,28 @@ interface FeatureBannerProps {
77
color?: string;
88
subtitle: ReactNode;
99
title: string;
10+
toggle?: boolean;
1011
}
1112

1213
const defaultProps = {
1314
alertText: 'new',
1415
color: 'info',
16+
dismissable: false,
1517
};
1618

1719
const FeatureBanner: FC<FeatureBannerProps> = ({
1820
alertText = defaultProps.alertText,
1921
color = defaultProps.color,
22+
dismissable = defaultProps.dismissable,
2023
title,
2124
subtitle,
2225
children,
2326
}) => {
2427
const alertStyle = 'fw-bold text-uppercase';
28+
const [visible, setVisible] = useState(true);
29+
const toggle = dismissable ? setVisible(!visible) : undefined;
2530
return (
26-
<Alert color={color} className="align-items-center d-flex p-0" fade={false}>
31+
<Alert color={color} className="align-items-center d-flex p-0" fade={false} toggle={toggle} isOpen={visible}>
2732
<h2 className={`${alertStyle} text-center m-0 px-3 d-none d-sm-block`}>{alertText}</h2>
2833
<div className="d-flex flex-row flex-wrap p-3 w-100">
2934
<div className="flex-fill me-auto">

0 commit comments

Comments
 (0)