Skip to content

Commit 01970a2

Browse files
authored
feat(Link): allow nodes to be used in link body (#1950)
- add in test demonstrating extension
1 parent 06cc194 commit 01970a2

File tree

3 files changed

+35
-3
lines changed

3 files changed

+35
-3
lines changed

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

+8
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,14 @@ export const LinkWithOpenIcon: StoryObj<Args> = {
3737
},
3838
};
3939

40+
export const LinkWithFormattedChildren: StoryObj<Args> = {
41+
args: {
42+
children: <em>emphasized link</em>,
43+
context: 'standalone',
44+
icon: 'open-in-new',
45+
},
46+
};
47+
4048
export const Emphasis: StoryObj<Args> = {
4149
args: {
4250
size: 'md',

src/components/Link/Link-v2.tsx

+2-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ export type LinkV2Props<ExtendedElement = unknown> =
1515
*/
1616
as?: string | React.ElementType;
1717
/**
18-
* The link contents or label.
18+
* The link contents or label. Using ReactNode to support customized text treatments
1919
*/
20-
children: string;
20+
children: React.ReactNode;
2121
// Design API
2222
/**
2323
* Where `Link` sits alongside other text and content:
@@ -34,7 +34,6 @@ export type LinkV2Props<ExtendedElement = unknown> =
3434
* Extra or lowered colors added to a link
3535
*/
3636
emphasis?: 'default' | 'high' | 'low';
37-
3837
/**
3938
* Link size inherits from the surrounding text.
4039
*/

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

+25
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,31 @@ exports[`<Link /> LinkWithChevron story renders snapshot 1`] = `
8787
</a>
8888
`;
8989

90+
exports[`<Link /> LinkWithFormattedChildren story renders snapshot 1`] = `
91+
<a
92+
class="link link--context-standalone link--emphasis-default link--has-right-icon link--size-lg"
93+
href="https://go.czi.team/eds"
94+
>
95+
<em>
96+
emphasized link
97+
</em>
98+
<svg
99+
aria-hidden="true"
100+
class="icon link__icon"
101+
fill="currentColor"
102+
height="1.5rem"
103+
style="--icon-size: 1.5rem;"
104+
viewBox="0 0 24 24"
105+
width="1.5rem"
106+
xmlns="http://www.w3.org/2000/svg"
107+
>
108+
<path
109+
d="M18 19H6c-.55 0-1-.45-1-1V6c0-.55.45-1 1-1h5c.55 0 1-.45 1-1s-.45-1-1-1H5c-1.11 0-2 .9-2 2v14c0 1.1.9 2 2 2h14c1.1 0 2-.9 2-2v-6c0-.55-.45-1-1-1s-1 .45-1 1v5c0 .55-.45 1-1 1zM14 4c0 .55.45 1 1 1h2.59l-9.13 9.13c-.39.39-.39 1.02 0 1.41.39.39 1.02.39 1.41 0L19 6.41V9c0 .55.45 1 1 1s1-.45 1-1V4c0-.55-.45-1-1-1h-5c-.55 0-1 .45-1 1z"
110+
/>
111+
</svg>
112+
</a>
113+
`;
114+
90115
exports[`<Link /> LinkWithOpenIcon story renders snapshot 1`] = `
91116
<a
92117
class="link link--context-standalone link--emphasis-default link--has-right-icon link--size-lg"

0 commit comments

Comments
 (0)