Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MartijnCuppens committed Sep 23, 2020
1 parent 27dba2e commit 6e8a4bb
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 34 deletions.
2 changes: 1 addition & 1 deletion scss/_alert.scss
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

@each $color, $value in $theme-colors {
.alert-#{$color} {
@include alert-variant(color-level($value, $alert-bg-level), color-level($value, $alert-border-level), color-level($value, $alert-color-level));
@include alert-variant(scale-color($value, $alert-bg-scale), scale-color($value, $alert-border-scale), scale-color($value, $alert-color-scale));
}
}
// scss-docs-end alert-modifiers
23 changes: 12 additions & 11 deletions scss/_functions.scss
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,23 @@ $_luminance-list: .0008 .001 .0011 .0013 .0015 .0017 .002 .0022 .0025 .0027 .003
@return mix(rgba($foreground, 1), $background, opacity($foreground) * 100);
}

// Request a color level
// scss-docs-start color-level
@function color-level($color: $primary, $level: 0) {
// stylelint-disable-next-line color-named
$color-base: if($level > 0, black, white);
@return mix($color-base, $color, abs($level));
// scss-docs-start color-functions
// Tint a color: mix a color with white
@function tint-color($color, $weight) {
@return mix(white, $color, $weight);
}
// scss-docs-end color-level

@function tint-color($color, $level) {
@return mix(white, $color, $level);
// Shade a color: mix a color with black
@function shade-color($color, $weight) {
@return mix(black, $color, $weight);
}

@function shade-color($color, $level) {
@return mix(black, $color, $level);
// Scale a color:
// Shade the color if the weight is positive, else tint it
@function scale-color($color, $weight) {
@return if($weight > 0, shade-color($color, $weight), tint-color($color, -$weight));
}
// scss-docs-end color-functions

// Return valid calc
@function add($value1, $value2, $return-calc: true) {
Expand Down
2 changes: 1 addition & 1 deletion scss/_list-group.scss
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,6 @@
// Organizationally, this must come after the `:hover` states.

@each $color, $value in $theme-colors {
@include list-group-item-variant($color, color-level($value, $list-group-item-bg-level), color-level($value, $list-group-item-color-level));
@include list-group-item-variant($color, scale-color($value, $list-group-item-bg-scale), scale-color($value, $list-group-item-color-scale));
}
// scss-docs-end list-group-modifiers
26 changes: 13 additions & 13 deletions scss/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ $body-text-align: null !default;
$link-color: $primary !default;
$link-decoration: underline !default;
$link-shade-percentage: 20% !default;
$link-hover-color: shade-color($link-color, $link-shade-percentage) !default;
$link-hover-color: scale-color($link-color, $link-shade-percentage) !default;
$link-hover-decoration: null !default;

$stretched-link-pseudo-element: after !default;
Expand Down Expand Up @@ -526,15 +526,15 @@ $table-group-separator-color: currentColor !default;

$table-caption-color: $text-muted !default;

$table-bg-level: -80% !default;
$table-bg-scale: -80% !default;

$table-variants: (
"primary": color-level($primary, $table-bg-level),
"secondary": color-level($secondary, $table-bg-level),
"success": color-level($success, $table-bg-level),
"info": color-level($info, $table-bg-level),
"warning": color-level($warning, $table-bg-level),
"danger": color-level($danger, $table-bg-level),
"primary": scale-color($primary, $table-bg-scale),
"secondary": scale-color($secondary, $table-bg-scale),
"success": scale-color($success, $table-bg-scale),
"info": scale-color($info, $table-bg-scale),
"warning": scale-color($warning, $table-bg-scale),
"danger": scale-color($danger, $table-bg-scale),
"light": $light,
"dark": $dark,
) !default;
Expand Down Expand Up @@ -1148,9 +1148,9 @@ $alert-border-radius: $border-radius !default;
$alert-link-font-weight: $font-weight-bold !default;
$alert-border-width: $border-width !default;

$alert-bg-level: -80% !default;
$alert-border-level: -70% !default;
$alert-color-level: 50% !default;
$alert-bg-scale: -80% !default;
$alert-border-scale: -70% !default;
$alert-color-scale: 50% !default;

$alert-dismissible-padding-r: $alert-padding-x * 3 !default; // 3x covers width of x plus default padding on either side

Expand Down Expand Up @@ -1178,8 +1178,8 @@ $list-group-border-radius: $border-radius !default;

$list-group-item-padding-y: $spacer / 2 !default;
$list-group-item-padding-x: $spacer !default;
$list-group-item-bg-level: -80% !default;
$list-group-item-color-level: 50% !default;
$list-group-item-bg-scale: -80% !default;
$list-group-item-color-scale: 50% !default;

$list-group-hover-bg: $gray-100 !default;
$list-group-active-color: $component-active-color !default;
Expand Down
4 changes: 2 additions & 2 deletions scss/helpers/_colored-links.scss
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
.link-#{$color} {
color: $value;

@if $emphasized-link-hover-darken-percentage != 0 {
@if $link-shade-percentage != 0 {
&:hover,
&:focus {
color: if(color-contrast($value) == $color-contrast-light, shade-color($value, $emphasized-link-hover-darken-percentage), tint-color($value, $emphasized-link-hover-darken-percentage));
color: scale-color($value, $link-shade-percentage);
}
}
}
Expand Down
14 changes: 9 additions & 5 deletions site/content/docs/5.0/customize/sass.md
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ For example, we use the `primary`, `success`, and `danger` keys from `$theme-col

### Colors

In Bootstrap 5, we've dropped the `color()`, `theme-color()` and `gray()` functions because the values are also available as standalone variables. So instead of using `theme-color("primary")`, you can now just use the `$primary` variable.
Next to the [Sass maps]({{< docsref "/customize/color#color-sass-maps" >}}) we have, theme colors can also be used as standalone variables, like `$primary`.

{{< highlight scss >}}
.custom-element {
Expand All @@ -161,15 +161,19 @@ In Bootstrap 5, we've dropped the `color()`, `theme-color()` and `gray()` functi
}
{{< /highlight >}}

We also have a function for getting a particular _level_ of color. Negative level values will lighten the color, while higher levels will darken.
You can lighten or darken colors with Bootstrap's `tint-color()` and `shade-color()` functions. These functions will mix colors with black or white, unlike Sass' native `lighten()` and `darken()` functions which will change the lightness by a fixed amount, which often doesn't lead to the desired effect.

{{< scss-docs name="color-level" file="scss/_functions.scss" >}}
{{< scss-docs name="color-functions" file="scss/_functions.scss" >}}

In practice, you'd call the function and pass in two parameters: the name of the color from `$theme-colors` (e.g., primary or danger) and a numeric level.
In practice, you'd call the function and pass in the color and weight parameters.

{{< highlight scss >}}
.custom-element {
color: color-level($primary, -10);
color: tint-color($primary, 10%);
}

.custom-element-2 {
color: shade-color($danger, 30%);
}
{{< /highlight >}}

Expand Down
11 changes: 10 additions & 1 deletion site/content/docs/5.0/migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ aliases: "/migration/"
toc: true
---

## v5.0.0-alpha3

### Colors

- The color system which worked with `color-level()` and `$theme-color-interval` was removed in favor of a new color system.
- All `lighten()` and `darken()` functions in our codebase are replaced by `tint-color()` and `shade-color()`. These functions provide will mix a color with either white or black instead of changing the lightness by a fixed amount.
- The `scale-color()` will either tint or shade a color depending on whether its weight parameter is positive or negative.
- See [this PR](https://github.com/twbs/bootstrap/pull/30622) for more details.

## v5.0.0-alpha2

### Sass
Expand Down Expand Up @@ -104,7 +113,7 @@ Changes to our source Sass files and compiled CSS.
- Rearranged forms source files under `scss/forms/`. [See Forms section for more details.](#forms)
- Removed print styles and `$enable-print-styles` variable. Print display classes, however, have remained intact. [See #28339](https://github.com/twbs/bootstrap/pull/28339).
- Dropped `color()`, `theme-color()` & `gray()` functions in favor of variables. [See #29083](https://github.com/twbs/bootstrap/pull/29083)
- The `theme-color-level()` function is renamed to `color-level()` and now accepts any color you want instead of only `$theme-color` colors. [See #29083](https://github.com/twbs/bootstrap/pull/29083)
- The `theme-color-level()` function is renamed to `color-level()` and now accepts any color you want instead of only `$theme-color` colors. [See #29083](https://github.com/twbs/bootstrap/pull/29083) **Watch out:** `color-level()` was later on dropped in `v5.0.0-alpha3`.
- `$enable-grid-classes` doesn't disable the generation of container classes anymore [See #29146](https://github.com/twbs/bootstrap/pull/29146)
- Renamed `$enable-prefers-reduced-motion-media-query` and `$enable-pointer-cursor-for-buttons` to `$enable-reduced-motion` and `$enable-button-pointers` for brevity.
- Line heights are dropped from several components to simplify our codebase. The `button-size()` and `pagination-size()` do not accept line height parameters anymore. [See #29271](https://github.com/twbs/bootstrap/pull/29271)
Expand Down

0 comments on commit 6e8a4bb

Please sign in to comment.