Skip to content

Commit e82527c

Browse files
janhasseltw15egankodiakhq[bot]joshblack
authored
feat(link): add support for icon with standalone links (#8361)
* feat(link): add support for icon with standalone links * fix(link): correct alignment when disabled Co-authored-by: TJ Egan <tw15egan@gmail.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: Josh Black <josh@josh.black>
1 parent e5bd439 commit e82527c

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

packages/components/src/components/link/_link.scss

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
@include reset;
2626
@include type-style('body-short-01');
2727

28+
display: inline-flex;
2829
color: $link-primary;
2930
text-decoration: none;
3031
outline: none;
@@ -60,7 +61,6 @@
6061
@include reset;
6162
@include type-style('body-short-01');
6263

63-
display: inline;
6464
color: $text-disabled;
6565
font-weight: 400;
6666
text-decoration: none;
@@ -95,6 +95,12 @@
9595
.#{$prefix}--link--lg {
9696
@include type-style('body-short-02');
9797
}
98+
99+
.#{$prefix}--link__icon {
100+
display: inline-flex;
101+
align-self: center;
102+
margin-left: $spacing-03;
103+
}
98104
}
99105

100106
@include exports('link') {

packages/react/__tests__/__snapshots__/PublicAPI-test.js.snap

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3227,6 +3227,19 @@ Map {
32273227
"inline": Object {
32283228
"type": "bool",
32293229
},
3230+
"renderIcon": Object {
3231+
"args": Array [
3232+
Array [
3233+
Object {
3234+
"type": "func",
3235+
},
3236+
Object {
3237+
"type": "object",
3238+
},
3239+
],
3240+
],
3241+
"type": "oneOfType",
3242+
},
32303243
"size": Object {
32313244
"args": Array [
32323245
Array [

packages/react/src/components/Link/Link-story.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import React from 'react';
1111
import { action } from '@storybook/addon-actions';
1212
import { withKnobs, text, boolean, select } from '@storybook/addon-knobs';
13+
import { Download16 } from '@carbon/icons-react';
1314
import Link from '../Link';
1415
import mdx from './Link.mdx';
1516

@@ -52,4 +53,10 @@ _Default.story = {
5253
name: 'Link',
5354
};
5455

56+
export const PairedWithIcon = () => (
57+
<Link href="http://www.carbondesignsystem.com" renderIcon={Download16}>
58+
Download
59+
</Link>
60+
);
61+
5562
export const Playground = () => <Link {...props()}>Link</Link>;

packages/react/src/components/Link/Link.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ const Link = ({
1919
disabled,
2020
inline,
2121
visited,
22+
renderIcon: Icon,
2223
size,
2324
...other
2425
}) => {
@@ -38,6 +39,11 @@ const Link = ({
3839
rel={rel}
3940
{...other}>
4041
{children}
42+
{!inline && Icon && (
43+
<div className={`${prefix}--link__icon`}>
44+
<Icon />
45+
</div>
46+
)}
4147
</Tag>
4248
);
4349
};
@@ -68,6 +74,12 @@ Link.propTypes = {
6874
*/
6975
inline: PropTypes.bool,
7076

77+
/**
78+
* Optional prop to render an icon next to the link.
79+
* Can be a React component class
80+
*/
81+
renderIcon: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
82+
7183
/**
7284
* Specify the size of the Link. Currently supports either `sm`, 'md' (default) or 'lg` as an option.
7385
*/

0 commit comments

Comments
 (0)