Skip to content

Commit

Permalink
fix(utilities): use the right orange color for texts based on the lig…
Browse files Browse the repository at this point in the history
…ht/dark variant (#872)

Signed-off-by: louismaximepiton <[email protected]>
Co-authored-by: Julien Déramond <[email protected]>
  • Loading branch information
louismaximepiton and julien-deramond authored Nov 23, 2022
1 parent 8d4e2bf commit e918550
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 3 deletions.
3 changes: 3 additions & 0 deletions scss/_root.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
--#{$prefix}#{$color}-rgb: #{$value};
}

--#{$prefix}primary-text-rgb: #{to-rgb($accessible-orange)}; // Boosted mod
--#{$prefix}white-rgb: #{to-rgb($white)};
--#{$prefix}black-rgb: #{to-rgb($black)};
--#{$prefix}body-color-rgb: #{to-rgb($body-color)};
Expand Down Expand Up @@ -84,6 +85,7 @@
[class*="bg-black"],
[class*="-dark"]:not(.border-dark):not(.text-dark),
[class*="bg-secondary"] {
--#{$prefix}primary-text-rgb: #{to-rgb($brand-orange)};
--#{$prefix}link-color: #{$link-color-dark};
--#{$prefix}link-hover-color: #{$link-hover-color-dark};
--#{$boosted-prefix}caption-color: #{$table-caption-color-dark};
Expand All @@ -96,6 +98,7 @@

// stylelint-disable-next-line scss/selector-no-redundant-nesting-selector
[class*="bg-"]:not(&):not(.bg-transparent) {
--#{$prefix}primary-text-rgb: #{to-rgb($accessible-orange)};
--#{$prefix}link-color: #{$link-color};
--#{$prefix}link-hover-color: #{$link-hover-color};
--#{$boosted-prefix}caption-color: #{$table-caption-color};
Expand Down
1 change: 1 addition & 0 deletions scss/_utilities.scss
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,7 @@ $utilities: map-merge(
"black-50": rgba($black, .5), // deprecated
"white-50": rgba($white, .5), // deprecated
"reset": inherit,
"primary": rgba(var(--#{$prefix}primary-text-rgb), var(--#{$prefix}text-opacity)), // Boosted mod: redefine primary value
)
)
),
Expand Down
2 changes: 1 addition & 1 deletion scss/mixins/_utilities.scss
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
}
}
}
@if "inherit" != inspect($value) and $accessible-orange != $value and $primary != $value and $text-muted != $value {
@if "inherit" != inspect($value) and $accessible-orange != $value and $primary != $value and $text-muted != $value and "rgba(var(--#{$prefix}primary-text-rgb), var(--#{$prefix}text-opacity))" != $value {
background-color: color-contrast($value);
}
}
Expand Down
1 change: 1 addition & 0 deletions site/content/docs/5.2/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ If you need more details about the changes, please refer to the [v5.2.2 release]
<summary><span class="badge bg-success">New</span> CSS variables:</summary>
<ul>
<li><code>--bs-btn-letter-spacing</code></li>
<li><code>--bs-primary-text-rgb</code></li>
</ul>
</details>

Expand Down
6 changes: 4 additions & 2 deletions site/content/docs/5.2/utilities/colors.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,13 @@ Consider our default `.text-primary` utility.
```css
.text-primary {
--bs-text-opacity: 1;
color: rgba(var(--bs-primary-rgb), var(--bs-text-opacity)) !important;
color: rgba(var(--bs-primary-text-rgb), var(--bs-text-opacity)) !important;
}
```

We use an RGB version of our `--bs-primary` (with the value of `13, 110, 253`) CSS variable and attached a second CSS variable, `--bs-text-opacity`, for the alpha transparency (with a default value `1` thanks to a local CSS variable). That means anytime you use `.text-primary` now, your computed `color` value is `rgba(13, 110, 253, 1)`. The local CSS variable inside each `.text-*` class avoids inheritance issues so nested instances of the utilities don't automatically have a modified alpha transparency.
We use an RGB version of our `$accessible-orange` (with the value of `241, 110, 0`) Sass variable as a CSS variable and attached a second CSS variable, `--bs-text-opacity`, for the alpha transparency (with a default value `1` thanks to a local CSS variable). That means anytime you use `.text-primary` now, your computed `color` value is `rgba(241, 110, 0, 1)`. The local CSS variable inside each `.text-*` class avoids inheritance issues so nested instances of the utilities don't automatically have a modified alpha transparency.

When used in a dark variant context, `--bs-primary-text-rgb` will use the value of `$brand-orange` (with the value of `255, 121, 0`).

### Example

Expand Down

0 comments on commit e918550

Please sign in to comment.