Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
10 changes: 9 additions & 1 deletion docs/elements/anchor/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,12 @@ $name: 'anchor';

@include docs.demo($name, 'default') {
@include anchor.styles;
};
}

@include docs.demo($name, 'no-visited-styles') {
@include anchor.styles(
(
emit-visited: false,
)
);
}
19 changes: 19 additions & 0 deletions docs/elements/anchor/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,24 @@ export const meta = {
type: 'selector',
default: 'a',
},
{
key: 'emit-visited',
type: 'boolean',
default: 'true',
},
],
} as const satisfies Meta;

const html = /* html */`
<a href="https://ibm.com">IBM.com</a>
<br />
<a href="${window.location.href}">Visited link</a>

<br /><br />

<a href="https://ibm.com">IBM.com ${launchIcon}</a>
<br />
<a href="${window.location.href}">Visited link${launchIcon}</a>
`;

export const demos: Demo[] = [
Expand All @@ -47,4 +56,14 @@ export const demos: Demo[] = [
raw: html,
},
},
{
id: 'no-visited-styles',
name: 'No visited styles',
html: {
raw: html,
},
config: {
'emit-visited': 'false',
},
},
];
17 changes: 16 additions & 1 deletion scss/elements/anchor/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,41 @@ $config: () !default;

$-default-config: (
selector: 'a',
emit-visited: true,
);

/// @group anchor
/// @param {Map} config [()]
/// @param {Selector} config.selector ['a']
/// @param {Bool} config.emit-visited [true] - Enable visited link styles using theme.$link-visited
@mixin styles($config: $config) {
$props: map.deep-merge($-default-config, $config);
$emit-visited: map.get($props, 'emit-visited') == true;

#{map.get($props, 'selector')} {
display: inline-flex;
align-items: center;
column-gap: spacing.$spacing-03;
color: theme.$link-primary;
text-decoration: underline;
transition: color layout.$mode--transition-duration layout.$mode--transition-timing-function;
transition: if(
sass($emit-visited): none; else: color layout.$mode--transition-duration
layout.$mode--transition-timing-function
);

&:hover {
color: theme.$link-primary-hover;
}

@if $emit-visited {
&:visited {
color: theme.$link-visited;
}
&:visited svg {
fill: theme.$link-visited;
}
}

&:focus {
@include focus-outline.focus-outline('outline');
}
Expand Down
Loading