Skip to content

[BD-9545][BpkLink] Add bpk-link--explicit for the new bpk-link design. #3768

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 10, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions examples/bpk-component-link/examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ const LinkExample = () => (
</div>
);

const ImplicitLinkExample = () => (
<div>
<BpkLink href="#" onClick={action('#1 clicked')} implicit>
Link #1
</BpkLink>
<br />
<BpkLink href="#" onClick={action('#2 clicked')} implicit>
Link #2
</BpkLink>
</div>
);

const ButtonLinkExample = () => (
<div>
<BpkButtonLink onClick={action('#1 clicked')}>Link #1</BpkButtonLink>
Expand Down Expand Up @@ -103,6 +115,7 @@ const MixedExample = () => (

export {
LinkExample,
ImplicitLinkExample,
ButtonLinkExample,
LinkAlternativeExample,
ButtonLinkAlternativeExample,
Expand Down
2 changes: 2 additions & 0 deletions examples/bpk-component-link/stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import BpkLink from '../../packages/bpk-component-link/src/BpkLink';

import {
LinkExample,
ImplicitLinkExample,
ButtonLinkExample,
LinkAlternativeExample,
ButtonLinkAlternativeExample,
Expand All @@ -39,6 +40,7 @@ export default {
};

export const Example = LinkExample;
export const ExampleImplicit = ImplicitLinkExample;
export const ExampleButtons = ButtonLinkExample;

export const ExampleAlternate = LinkAlternativeExample;
Expand Down
7 changes: 7 additions & 0 deletions packages/bpk-component-link/src/BpkLink.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Props = {
blank: boolean,
rel: ?string,
alternate: boolean,
implicit: boolean,
};

const BpkLink = forwardRef((props: Props, ref) => {
Expand All @@ -48,6 +49,7 @@ const BpkLink = forwardRef((props: Props, ref) => {
children,
className,
href,
implicit,
onClick,
rel: propRel,
...rest
Expand All @@ -64,6 +66,9 @@ const BpkLink = forwardRef((props: Props, ref) => {
if (className) {
classNames.push(className);
}
if (implicit) {
classNames.push(getClassName('bpk-link--implicit'));
}

return (
// $FlowFixMe[cannot-spread-inexact] - inexact rest. See 'decisions/flowfixme.md'.
Expand Down Expand Up @@ -92,6 +97,7 @@ BpkLink.propTypes = {
blank: PropTypes.bool,
rel: PropTypes.string,
alternate: PropTypes.bool,
implicit: PropTypes.bool,
};

BpkLink.defaultProps = {
Expand All @@ -100,6 +106,7 @@ BpkLink.defaultProps = {
blank: false,
rel: null,
alternate: false,
implicit: false,
};

export default BpkLink;
Expand Down
4 changes: 4 additions & 0 deletions packages/bpk-component-link/src/BpkLink.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,8 @@
&--alternate {
@include typography.bpk-link--alternate;
}

&--implicit {
@include typography.bpk-link--implicit;
}
}
63 changes: 60 additions & 3 deletions packages/bpk-mixins/_typography.scss
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,8 @@
/// }

@mixin bpk-link {
position: relative;
display: inline-block;
padding: 0;
border: 0;
background-color: transparent;
Expand All @@ -792,13 +794,17 @@
@include bpk-themeable-property(color, --bpk-link-color, $bpk-text-link-day);

@include bpk-hover {
text-decoration: underline;
text-decoration: none;

@include bpk-themeable-property(
color,
--bpk-link-hover-color,
$bpk-text-link-day
);

&::after {
width: 0%;
}
}

&:visited {
Expand All @@ -810,13 +816,64 @@
}

&:active {
text-decoration: underline;

@include bpk-themeable-property(
color,
--bpk-link-active-color,
$bpk-text-link-day
);

&::after {
width: 0%;
}
}

&::after {
position: absolute;
bottom: 0;
content: '';
display: block;
width: 100%;
height: tokens.$bpk-border-size-sm;
transition:
width 0.2s ease 0s,
left 0.2s ease 0s;

@include bpk-themeable-property(
background,
--bpk-link-color,
$bpk-text-link-day
);

@media (prefers-reduced-motion) {
transition:
width 0s ease 0s,
left 0s ease 0s;
}
}
}

/// Implicit inline link.
///
/// @example scss
/// .selector {
/// @include bpk-link();
/// @include bpk-link--implicit();
/// }

@mixin bpk-link--implicit {
display: inline;

@include bpk-hover {
text-decoration: underline;
}

&::after {
content: none;
display: none;
}

&:active {
text-decoration: underline;
}
}

Expand Down
Loading