Skip to content

Commit 61c7e18

Browse files
appf-mikeclaude
andcommitted
feat: make FeatureBanner subtitle optional
When subtitle is not provided, the subtitle element is not rendered and the title and children are vertically centered. This supports condensed banner views such as on mobile. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1ea3fdc commit 61c7e18

3 files changed

Lines changed: 42 additions & 3 deletions

File tree

src/components/FeatureBanner/FeatureBanner.spec.tsx

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,25 @@ describe('<FeatureBanner />', () => {
3939
expect(queryByText('FeatureBannerChildElement')).not.toBeNull();
4040
});
4141

42+
describe('without subtitle', () => {
43+
it('does not render subtitle', () => {
44+
const { queryByText } = render(<FeatureBanner title="FeatureBannerTitle" />);
45+
46+
expect(queryByText('FeatureBannerTitle')).not.toBeNull();
47+
});
48+
49+
it('renders title and children', () => {
50+
const { queryByText } = render(
51+
<FeatureBanner title="FeatureBannerTitle">
52+
<span>FeatureBannerChildElement</span>
53+
</FeatureBanner>
54+
);
55+
56+
expect(queryByText('FeatureBannerTitle')).not.toBeNull();
57+
expect(queryByText('FeatureBannerChildElement')).not.toBeNull();
58+
});
59+
});
60+
4261
describe('when dismissable', () => {
4362
it('can be closed', async () => {
4463
const { getByRole, queryByRole } = render(<FeatureBanner {...commonProps} dismissable />);

src/components/FeatureBanner/FeatureBanner.stories.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,19 @@ export const LiveExample: Story = {
3939
</FeatureBanner>
4040
),
4141
};
42+
43+
export const WithoutSubtitle: Story = {
44+
args: {
45+
alertText: 'New',
46+
color: 'info',
47+
title: 'Company-Wide View of Text Messages',
48+
},
49+
render: (args) => (
50+
<FeatureBanner {...args}>
51+
<Button color="primary" outline className="fw-bold text-uppercase">
52+
<Icon name="envelope" className="me-2" />
53+
Feedback
54+
</Button>
55+
</FeatureBanner>
56+
),
57+
};

src/components/FeatureBanner/FeatureBanner.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ interface FeatureBannerProps {
66
children?: ReactNode;
77
color?: string;
88
dismissable?: boolean;
9-
subtitle: ReactNode;
9+
subtitle?: ReactNode;
1010
title: string;
1111
}
1212

@@ -36,13 +36,17 @@ const FeatureBanner: FC<FeatureBannerProps> = ({
3636
isOpen={visible}
3737
>
3838
<h2 className={`${alertStyle} text-center m-0 px-3 d-none d-sm-block`}>{alertText}</h2>
39-
<div className={`d-flex flex-row flex-wrap p-3 w-100 ${dismissable ? 'pe-5' : ''}`}>
39+
<div
40+
className={`d-flex flex-row flex-wrap p-3 w-100 ${!subtitle ? 'align-items-center' : ''} ${
41+
dismissable ? 'pe-5' : ''
42+
}`}
43+
>
4044
<div className="flex-fill me-auto">
4145
<div className="d-inline-block m-0">
4246
<h2 className={`${alertStyle} d-inline d-sm-none me-2`}>{alertText}</h2>
4347
<h3 className="d-inline">{title}</h3>
4448
</div>
45-
<p className="m-0">{subtitle}</p>
49+
{subtitle && <p className="m-0">{subtitle}</p>}
4650
</div>
4751
<div className="d-inline-block my-auto">{children}</div>
4852
</div>

0 commit comments

Comments
 (0)