Skip to content

Commit f167fd6

Browse files
authored
feat(link): introduce inline variant (#3859)
Fixes #3228.
1 parent 99ef10b commit f167fd6

File tree

7 files changed

+78
-13
lines changed

7 files changed

+78
-13
lines changed

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@
5252
}
5353

5454
&:visited {
55-
color: $link-01;
55+
color: $visited-link;
5656
}
57-
}
5857

59-
.#{$prefix}--link--visited {
60-
color: $visited-link;
58+
&:visited:hover {
59+
color: $hover-primary-text;
60+
}
6161
}
6262

6363
.#{$prefix}--link--disabled {
@@ -68,6 +68,26 @@
6868
font-weight: 400;
6969
cursor: not-allowed;
7070
}
71+
72+
.#{$prefix}--link.#{$prefix}--link--inline {
73+
text-decoration: underline;
74+
75+
&:hover {
76+
color: $hover-primary-text;
77+
}
78+
79+
&:focus {
80+
text-decoration: none;
81+
}
82+
83+
&:visited {
84+
text-decoration: none;
85+
}
86+
}
87+
88+
.#{$prefix}--link--disabled.#{$prefix}--link--inline {
89+
text-decoration: underline;
90+
}
7191
}
7292

7393
@include exports('link') {

packages/components/src/components/link/link.config.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,23 @@ module.exports = {
1313
context: {
1414
prefix,
1515
},
16+
variants: [
17+
{
18+
name: 'default',
19+
label: 'Default',
20+
},
21+
{
22+
name: 'inline',
23+
label: 'Inline',
24+
notes: `
25+
Inline by default has underline.
26+
Its intended use is in paragraphs and sentences,
27+
where underline makes it more accessible,
28+
so that color blue is not the only visual differentiator.
29+
`,
30+
context: {
31+
inline: true,
32+
},
33+
},
34+
],
1635
};

packages/components/src/components/link/link.hbs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
LICENSE file in the root directory of this source tree.
66
-->
77

8-
<a href="#" class="{{@root.prefix}}--link">Link</a>
9-
<a class="{{@root.prefix}}--link" aria-disabled="true">Placeholder link</a>
10-
<p class="{{@root.prefix}}--link--disabled">Disabled Link</p>
8+
<a href="#" class="{{@root.prefix}}--link{{#if inline}} {{@root.prefix}}--link--inline{{/if}}">Link</a>
9+
<a class="{{@root.prefix}}--link{{#if inline}} {{@root.prefix}}--link--inline{{/if}}" aria-disabled="true">Placeholder link</a>
10+
<p class="{{@root.prefix}}--link--disabled{{#if inline}} {{@root.prefix}}--link--inline{{/if}}">Disabled Link</p>
1111
<div style="width:200px">
12-
<a href="#" class="{{@root.prefix}}--link">Text wrap example for hover, focus, and active state testing.</a>
12+
<a href="#" class="{{@root.prefix}}--link{{#if inline}} {{@root.prefix}}--link--inline{{/if}}">Text wrap example for hover, focus, and active state testing.</a>
1313
</div>

packages/components/src/globals/scss/_theme-tokens.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ $inverse-focus-ui: $ibm-color__white-0 !default;
4747
/// @type Color
4848
/// @access public
4949
/// @group link
50-
$link-visited: $ibm-color__purple-60 !default;
50+
/// @deprecated
51+
$link-visited: $visited-link !default;
5152

5253
/// @type Color
5354
/// @access public

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import Link from '../Link';
1616
const props = () => ({
1717
className: 'some-class',
1818
href: text('The link href (href)', '#'),
19+
inline: boolean('Use the in-line variant (inline)', false),
1920
onClick: (handler => evt => {
2021
evt.preventDefault(); // Prevent link from being followed for demo purpose
2122
handler(evt);

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ describe('Link', () => {
2020
</Link>
2121
);
2222
it('should use the appropriate link class', () => {
23+
expect(link.name()).toEqual('a');
2324
expect(link.hasClass(`${prefix}--link`)).toEqual(true);
2425
});
2526
it('should inherit the href property', () => {
@@ -31,5 +32,14 @@ describe('Link', () => {
3132
it('should all for custom classes to be applied', () => {
3233
expect(link.hasClass('some-class')).toEqual(true);
3334
});
35+
it('should support disabled link', () => {
36+
link.setProps({ disabled: true });
37+
expect(link.name()).toEqual('p');
38+
expect(link.hasClass(`${prefix}--link--disabled`)).toEqual(true);
39+
});
40+
it('should support inline link', () => {
41+
link.setProps({ inline: true });
42+
expect(link.hasClass(`${prefix}--link--inline`)).toEqual(true);
43+
});
3444
});
3545
});

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@ import { settings } from 'carbon-components';
1212

1313
const { prefix } = settings;
1414

15-
const Link = ({ children, className, href, ...other }) => {
16-
const classNames = classnames(`${prefix}--link`, className);
15+
const Link = ({ children, className, href, disabled, inline, ...other }) => {
16+
const classNames = classnames(`${prefix}--link`, className, {
17+
[`${prefix}--link--disabled`]: disabled,
18+
[`${prefix}--link--inline`]: inline,
19+
});
20+
const Tag = disabled ? 'p' : 'a';
1721
return (
18-
<a href={other.disabled ? null : href} className={classNames} {...other}>
22+
<Tag href={disabled ? null : href} className={classNames} {...other}>
1923
{children}
20-
</a>
24+
</Tag>
2125
);
2226
};
2327

@@ -36,6 +40,16 @@ Link.propTypes = {
3640
* Provide the `href` attribute for the <a> node
3741
*/
3842
href: PropTypes.string,
43+
44+
/**
45+
* Specify if the control should be disabled, or not
46+
*/
47+
disabled: PropTypes.bool,
48+
49+
/**
50+
* Specify whether you want the inline version of this control
51+
*/
52+
inline: PropTypes.bool,
3953
};
4054

4155
export default Link;

0 commit comments

Comments
 (0)