Skip to content

Commit 00c3cbb

Browse files
authored
Tokenize icon-link and stretched-link helpers (#42696)
* Convert icon-link and stretched-link variables to Sass token maps Move the icon-link and stretched-link Sass variables out of _config.scss and into component-scoped token maps, generating scoped CSS custom properties instead. Updates each helper docs page to document the new CSS variables. * Fix icon-link underline color referencing a nonexistent v5 variable .icon-link relied on the removed --link-color-rgb and --link-opacity variables, so its underline never picked up custom link colors. Use color-mix() against --link-color instead.
1 parent a5ea45c commit 00c3cbb

5 files changed

Lines changed: 69 additions & 34 deletions

File tree

scss/_config.scss

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -178,18 +178,6 @@ $position-values: (
178178
$link-decoration: underline !default;
179179
$link-underline-offset: .2em !default;
180180

181-
$stretched-link-pseudo-element: after !default;
182-
$stretched-link-z-index: 1 !default;
183-
184-
// Icon links
185-
// scss-docs-start icon-link-variables
186-
$icon-link-gap: .375rem !default;
187-
$icon-link-underline-offset: .25em !default;
188-
$icon-link-icon-size: 1em !default;
189-
$icon-link-icon-transition: .2s ease-in-out transform !default;
190-
$icon-link-icon-transform: translate3d(.25em, 0, 0) !default;
191-
// scss-docs-end icon-link-variables
192-
193181
// Components
194182
//
195183
// Define common padding and border radius sizes and more.

scss/helpers/_icon-link.scss

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,48 @@
1-
@use "../config" as *;
1+
@use "../functions" as *;
2+
@use "../mixins/tokens" as *;
23
@use "../mixins/transition" as *;
34

5+
$icon-link-tokens: () !default;
6+
7+
// scss-docs-start icon-link-tokens
8+
// stylelint-disable-next-line scss/dollar-variable-default
9+
$icon-link-tokens: defaults(
10+
(
11+
--icon-link-gap: .375rem,
12+
--icon-link-underline-offset: .25em,
13+
--icon-link-icon-size: 1em,
14+
--icon-link-icon-transition: .2s ease-in-out transform,
15+
--icon-link-icon-transform: translate3d(.25em, 0, 0),
16+
),
17+
$icon-link-tokens
18+
);
19+
// scss-docs-end icon-link-tokens
20+
421
@layer helpers {
522
.icon-link {
23+
@include tokens($icon-link-tokens);
24+
625
display: inline-flex;
7-
gap: $icon-link-gap;
26+
gap: var(--icon-link-gap);
827
align-items: center;
9-
text-decoration-color: rgba(var(--link-color-rgb), var(--link-opacity, .5));
10-
text-underline-offset: $icon-link-underline-offset;
28+
text-decoration-color: color-mix(in oklch, var(--link-color) 50%, transparent);
29+
text-underline-offset: var(--icon-link-underline-offset);
1130
backface-visibility: hidden;
1231

1332
> .bi {
1433
flex-shrink: 0;
15-
width: $icon-link-icon-size;
16-
height: $icon-link-icon-size;
34+
width: var(--icon-link-icon-size);
35+
height: var(--icon-link-icon-size);
1736
fill: currentcolor;
18-
@include transition($icon-link-icon-transition);
37+
@include transition(var(--icon-link-icon-transition));
1938
}
2039
}
2140

2241
.icon-link-hover {
2342
&:hover,
2443
&:focus-visible {
2544
> .bi {
26-
transform: var(--icon-link-transform, $icon-link-icon-transform);
45+
transform: var(--icon-link-transform, var(--icon-link-icon-transform));
2746
}
2847
}
2948
}

scss/helpers/_stretched-link.scss

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
1-
@use "../config" as *;
1+
@use "../functions" as *;
2+
@use "../mixins/tokens" as *;
3+
4+
// scss-docs-start stretched-link-pseudo-element
5+
$stretched-link-pseudo-element: after !default;
6+
// scss-docs-end stretched-link-pseudo-element
7+
8+
$stretched-link-tokens: () !default;
9+
10+
// scss-docs-start stretched-link-tokens
11+
// stylelint-disable-next-line scss/dollar-variable-default
12+
$stretched-link-tokens: defaults(
13+
(
14+
--stretched-link-z-index: 1,
15+
),
16+
$stretched-link-tokens
17+
);
18+
// scss-docs-end stretched-link-tokens
219

320
@layer helpers {
421
.stretched-link {
22+
@include tokens($stretched-link-tokens);
23+
524
&::#{$stretched-link-pseudo-element} {
625
position: absolute;
726
inset: 0;
8-
z-index: $stretched-link-z-index;
27+
z-index: var(--stretched-link-z-index);
928
content: "";
1029
}
1130
}

site/src/content/docs/helpers/icon-link.mdx

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,13 @@ Add `.icon-link-hover` to move the icon to the right on hover.
4141
</svg>
4242
</a>`} />
4343

44-
## Customize
44+
## CSS
4545

46-
Modify the styling of an icon link with our link CSS variables, Sass variables, utilities, or custom styles.
46+
### Variables
4747

48-
### CSS variables
48+
<CSSVariables component="Icon links" className="icon-link" />
4949

50-
Modify the `--bs-link-*` and `--bs-icon-link-*` CSS variables as needed to change the default appearance.
50+
<ScssDocs name="icon-link-tokens" file="scss/helpers/_icon-link.scss" />
5151

5252
Customize the hover `transform` by overriding the `--bs-icon-link-transform` CSS variable:
5353

@@ -59,21 +59,15 @@ Customize the hover `transform` by overriding the `--bs-icon-link-transform` CSS
5959
Icon link
6060
</a>`} />
6161

62-
Customize the color by overriding the `--bs-link-*` CSS variable:
62+
The icon link’s underline color is derived from `--bs-link-color`, so overriding it updates both the text and the underline together:
6363

64-
<Example code={`<a class="icon-link icon-link-hover" style="--bs-link-hover-color-rgb: 25, 135, 84;" href="#">
64+
<Example code={`<a class="icon-link icon-link-hover" style="--bs-link-color: #198754;" href="#">
6565
Icon link
6666
<svg xmlns="http://www.w3.org/2000/svg" class="bi" viewBox="0 0 16 16" aria-hidden="true">
6767
<path d="M1 8a.5.5 0 0 1 .5-.5h11.793l-3.147-3.146a.5.5 0 0 1 .708-.708l4 4a.5.5 0 0 1 0 .708l-4 4a.5.5 0 0 1-.708-.708L13.293 8.5H1.5A.5.5 0 0 1 1 8z"/>
6868
</svg>
6969
</a>`} />
7070

71-
### Sass variables
72-
73-
Customize the icon link Sass variables to modify all icon link styles across your Bootstrap-powered project.
74-
75-
<ScssDocs name="icon-link-variables" file="scss/_config.scss" />
76-
7771
### Sass utilities API
7872

7973
Modify icon links with any of [our link utilities]([[docsref:/utilities/link/]]) for modifying underline color and offset.

site/src/content/docs/helpers/stretched-link.mdx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
---
22
title: Stretched link
33
description: Make any HTML element or Bootstrap component clickable by “stretching” a nested link via CSS.
4+
toc: true
45
---
56

67
Add `.stretched-link` to a link to make its [containing block](https://developer.mozilla.org/en-US/docs/Web/CSS/Containing_block) clickable via a `::after` pseudo element. In most cases, this means that an element with `position: relative;` that contains a link with the `.stretched-link` class is clickable. Please note given [how CSS `position` works](https://www.w3.org/TR/CSS21/visuren.html#propdef-position), `.stretched-link` cannot be mixed with most table elements.
@@ -62,3 +63,17 @@ If the stretched link doesn’t seem to work, the [containing block](https://dev
6263
</p>
6364
</div>
6465
</div>`} />
66+
67+
## CSS
68+
69+
### Variables
70+
71+
<CSSVariables component="Stretched links" className="stretched-link" />
72+
73+
<ScssDocs name="stretched-link-tokens" file="scss/helpers/_stretched-link.scss" />
74+
75+
### Sass variable
76+
77+
The pseudo-element used to stretch the link defaults to `after` and can be changed via the `$stretched-link-pseudo-element` Sass variable. This can’t be a CSS variable since it’s compiled directly into the generated selector.
78+
79+
<ScssDocs name="stretched-link-pseudo-element" file="scss/helpers/_stretched-link.scss" />

0 commit comments

Comments
 (0)