Skip to content

Commit fc6bb78

Browse files
authored
feat: allow react nodes on subtitle (#1954)
1 parent 6198b9e commit fc6bb78

12 files changed

+136
-17
lines changed

src/components/Accordion/Accordion-v2.stories.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export const TitleAndSubtitle: Story = {
5353
<Accordion.Row>
5454
<Accordion.Button
5555
data-testid="accordion-button"
56-
subtitle="Quam lacus maecenas nibh malesuada."
56+
subtitle={<span>"Quam lacus maecenas nibh malesuada."</span>}
5757
title="Massa quam egestas massa."
5858
></Accordion.Button>
5959
<Accordion.Panel data-testid="accordion-panel">

src/components/Accordion/Accordion-v2.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@ type AccordionButtonProps = {
6161
*/
6262
headingAs?: HeadingElement;
6363
/**
64-
*
64+
* Icon to preceed the text in an accordion header
6565
*/
6666
leadingIcon?: ReactNode;
6767
/**
68-
*
68+
* Secondary text used to describe the content in more detail
6969
*/
70-
subtitle?: string;
70+
subtitle?: ReactNode;
7171
/**
72-
*
72+
* The title/heading of the component
7373
*/
7474
title?: string;
7575
/**

src/components/Accordion/__snapshots__/Accordion-v2.test.tsx.snap

+3-1
Original file line numberDiff line numberDiff line change
@@ -1167,7 +1167,9 @@ exports[`<Accordion /> TitleAndSubtitle story renders snapshot 1`] = `
11671167
<span
11681168
class="text text--body-md accordion-button__subtitle"
11691169
>
1170-
Quam lacus maecenas nibh malesuada.
1170+
<span>
1171+
"Quam lacus maecenas nibh malesuada."
1172+
</span>
11711173
</span>
11721174
</h2>
11731175
<svg

src/components/Card/Card-v2.stories.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ export const WithFullHeaderAndIcon: StoryObj<Args> = {
9292
<Card.Header
9393
eyebrow="Recommended for you"
9494
icon="person-encircled"
95-
subTitle="Get to know your colleagues"
95+
subTitle={<span>Get to know your colleagues</span>}
9696
title="Question of the day"
9797
/>
9898
<Card.Body>

src/components/Card/Card-v2.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@ export interface CardHeaderProps {
9090
*/
9191
size?: Extract<Size, 'sm' | 'md'>;
9292
/**
93-
* Text below the main title of the card, to add supplementary information about the title
93+
* Secondary text used to describe the content in more detail
9494
*/
95-
subTitle?: string;
95+
subTitle?: ReactNode;
9696
/**
97-
* Main title of the card
97+
* The title/heading of the component
9898
*/
9999
title?: string;
100100
}

src/components/Card/__snapshots__/Card-v2.test.ts.snap

+3-1
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,9 @@ exports[`<Card /> (v2) WithFullHeaderAndIcon story renders snapshot 1`] = `
675675
<div
676676
class="text text--body-lg header__sub-title header--size-md"
677677
>
678-
Get to know your colleagues
678+
<span>
679+
Get to know your colleagues
680+
</span>
679681
</div>
680682
</div>
681683
</header>

src/components/InlineNotification/InlineNotification-v2.stories.ts renamed to src/components/InlineNotification/InlineNotification-v2.stories.tsx

+13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import type { StoryObj, Meta } from '@storybook/react';
2+
import React from 'react';
3+
24
import { InlineNotification } from './InlineNotification-v2';
35

46
export default {
@@ -23,6 +25,17 @@ export const WithSubTitle: StoryObj<Args> = {
2325
},
2426
};
2527

28+
export const WithFormattedSubTitle: StoryObj<Args> = {
29+
args: {
30+
...Default.args,
31+
subTitle: (
32+
<span>
33+
<em>Additional text</em> which provides additional detail
34+
</span>
35+
),
36+
},
37+
};
38+
2639
export const Favorable: StoryObj<Args> = {
2740
args: {
2841
...WithSubTitle.args,

src/components/InlineNotification/InlineNotification-v2.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ type InlineNotificationProps = {
2121
*/
2222
status?: Status;
2323
/**
24-
* Secondary text used to describe the notification in more detail
24+
* Secondary text used to describe the content in more detail
2525
*/
26-
subTitle?: string;
26+
subTitle?: React.ReactNode;
2727
/**
28-
* The text contents of the tag, nested inside the component, in addition to the icon.
28+
* The title/heading of the component
2929
*/
3030
title: string;
3131
};

src/components/InlineNotification/__snapshots__/InlineNotification-v2.test.ts.snap

+40
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,46 @@ exports[`<InlineNotification /> (v2) Warning story renders snapshot 1`] = `
165165
</div>
166166
`;
167167

168+
exports[`<InlineNotification /> (v2) WithFormattedSubTitle story renders snapshot 1`] = `
169+
<div
170+
class="inline-notification inline-notification--status-informational"
171+
>
172+
<svg
173+
aria-hidden="true"
174+
class="icon inline-notification__icon"
175+
fill="currentColor"
176+
height="1rem"
177+
style="--icon-size: 1rem;"
178+
viewBox="0 0 24 24"
179+
width="1rem"
180+
xmlns="http://www.w3.org/2000/svg"
181+
>
182+
<path
183+
d="M12 17C12.2833 17 12.5208 16.9042 12.7125 16.7125C12.9042 16.5208 13 16.2833 13 16V12C13 11.7167 12.9042 11.4792 12.7125 11.2875C12.5208 11.0958 12.2833 11 12 11C11.7167 11 11.4792 11.0958 11.2875 11.2875C11.0958 11.4792 11 11.7167 11 12V16C11 16.2833 11.0958 16.5208 11.2875 16.7125C11.4792 16.9042 11.7167 17 12 17ZM12 9C12.2833 9 12.5208 8.90417 12.7125 8.7125C12.9042 8.52083 13 8.28333 13 8C13 7.71667 12.9042 7.47917 12.7125 7.2875C12.5208 7.09583 12.2833 7 12 7C11.7167 7 11.4792 7.09583 11.2875 7.2875C11.0958 7.47917 11 7.71667 11 8C11 8.28333 11.0958 8.52083 11.2875 8.7125C11.4792 8.90417 11.7167 9 12 9ZM12 22C10.6167 22 9.31667 21.7375 8.1 21.2125C6.88333 20.6875 5.825 19.975 4.925 19.075C4.025 18.175 3.3125 17.1167 2.7875 15.9C2.2625 14.6833 2 13.3833 2 12C2 10.6167 2.2625 9.31667 2.7875 8.1C3.3125 6.88333 4.025 5.825 4.925 4.925C5.825 4.025 6.88333 3.3125 8.1 2.7875C9.31667 2.2625 10.6167 2 12 2C13.3833 2 14.6833 2.2625 15.9 2.7875C17.1167 3.3125 18.175 4.025 19.075 4.925C19.975 5.825 20.6875 6.88333 21.2125 8.1C21.7375 9.31667 22 10.6167 22 12C22 13.3833 21.7375 14.6833 21.2125 15.9C20.6875 17.1167 19.975 18.175 19.075 19.075C18.175 19.975 17.1167 20.6875 15.9 21.2125C14.6833 21.7375 13.3833 22 12 22Z"
184+
/>
185+
</svg>
186+
<div
187+
class="inline-notication__body"
188+
>
189+
<div
190+
class="text text--title-xs inline-notification__title"
191+
>
192+
Inline notifications lorem ipsum text
193+
</div>
194+
<div
195+
class="text text--body-xs"
196+
>
197+
<span>
198+
<em>
199+
Additional text
200+
</em>
201+
which provides additional detail
202+
</span>
203+
</div>
204+
</div>
205+
</div>
206+
`;
207+
168208
exports[`<InlineNotification /> (v2) WithSubTitle story renders snapshot 1`] = `
169209
<div
170210
class="inline-notification inline-notification--status-informational"

src/components/PageNotification/PageNotification.stories.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ export const Warning: StoryObj<Args> = {
4747
},
4848
};
4949

50+
export const WarningWithSubtitle: StoryObj<Args> = {
51+
args: {
52+
status: 'warning',
53+
subTitle: <span>Subtitle text</span>,
54+
},
55+
};
56+
5057
/**
5158
* When using critical, make sure `Button` has a matching variant specified.
5259
*/

src/components/PageNotification/PageNotification.tsx

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ export type PageNotificationProps = {
3535
*/
3636
status?: Status;
3737
/**
38-
* Secondary text used to describe the notification in more detail
38+
* Secondary text used to describe the content in more detail
3939
*/
40-
subTitle?: string;
40+
subTitle?: ReactNode;
4141
/**
42-
* The title/heading of the notification
42+
* The title/heading of the component
4343
*/
4444
title?: string;
4545
};

src/components/PageNotification/__snapshots__/PageNotification.test.ts.snap

+55
Original file line numberDiff line numberDiff line change
@@ -418,3 +418,58 @@ exports[`<PageNotification /> (v2) Warning story renders snapshot 1`] = `
418418
</div>
419419
</aside>
420420
`;
421+
422+
exports[`<PageNotification /> (v2) WarningWithSubtitle story renders snapshot 1`] = `
423+
<aside
424+
class="page-notification page-notification--status-warning"
425+
>
426+
<svg
427+
aria-hidden="true"
428+
class="icon page-notification__icon"
429+
fill="currentColor"
430+
height="1.5rem"
431+
style="--icon-size: 1.5rem;"
432+
viewBox="0 0 24 24"
433+
width="1.5rem"
434+
xmlns="http://www.w3.org/2000/svg"
435+
>
436+
<path
437+
d="M2.72503 20C2.5417 20 2.37503 19.9542 2.22503 19.8625C2.07503 19.7708 1.95837 19.65 1.87503 19.5C1.7917 19.35 1.74587 19.1875 1.73753 19.0125C1.7292 18.8375 1.77503 18.6667 1.87503 18.5L11.125 2.5C11.225 2.33333 11.3542 2.20833 11.5125 2.125C11.6709 2.04167 11.8334 2 12 2C12.1667 2 12.3292 2.04167 12.4875 2.125C12.6459 2.20833 12.775 2.33333 12.875 2.5L22.125 18.5C22.225 18.6667 22.2709 18.8375 22.2625 19.0125C22.2542 19.1875 22.2084 19.35 22.125 19.5C22.0417 19.65 21.925 19.7708 21.775 19.8625C21.625 19.9542 21.4584 20 21.275 20H2.72503ZM12 17C12.2834 17 12.5209 16.9042 12.7125 16.7125C12.9042 16.5208 13 16.2833 13 16C13 15.7167 12.9042 15.4792 12.7125 15.2875C12.5209 15.0958 12.2834 15 12 15C11.7167 15 11.4792 15.0958 11.2875 15.2875C11.0959 15.4792 11 15.7167 11 16C11 16.2833 11.0959 16.5208 11.2875 16.7125C11.4792 16.9042 11.7167 17 12 17ZM12 14C12.2834 14 12.5209 13.9042 12.7125 13.7125C12.9042 13.5208 13 13.2833 13 13V10C13 9.71667 12.9042 9.47917 12.7125 9.2875C12.5209 9.09583 12.2834 9 12 9C11.7167 9 11.4792 9.09583 11.2875 9.2875C11.0959 9.47917 11 9.71667 11 10V13C11 13.2833 11.0959 13.5208 11.2875 13.7125C11.4792 13.9042 11.7167 14 12 14Z"
438+
/>
439+
</svg>
440+
<div
441+
class="page-notification__body page-notification--has-vertical-cta"
442+
>
443+
<div
444+
class="page-notification__text"
445+
>
446+
<h3
447+
class="heading heading--title-md"
448+
>
449+
Alert title which communicates info to the user
450+
</h3>
451+
<p
452+
class="text text--body-sm page-notification__sub-title"
453+
>
454+
<span>
455+
Subtitle text
456+
</span>
457+
</p>
458+
</div>
459+
<div
460+
class="page-notification__call-to-action"
461+
>
462+
<button
463+
class="button button--layout-none button--secondary button--sm button--variant-neutral"
464+
type="button"
465+
>
466+
<span
467+
class="button__text"
468+
>
469+
Call to Action
470+
</span>
471+
</button>
472+
</div>
473+
</div>
474+
</aside>
475+
`;

0 commit comments

Comments
 (0)