Skip to content

Commit 06641ca

Browse files
authored
Gradients and shadows (twbs#24429)
* Update the form focus mixin to use a manual `$enable-shadows` check so we can always ensure a focus state for accessibility and consistency * - Add new `$input-btn-focus-width` and `$input-btn-focus-color` variables. - Replace separate `$btn-focus-box-shadow` and `$input-focus-box-shadow` variables with unified `$input-btn-focus-box-shadow` to match our combined variables approach elsewhere. * Put new focus width var to use in buttons mixins * use new button input-box shadow var * Add a new mixin for quickly adding linear gradient to components when $enable-gradients is set to true * use correct var * fix focus shadows in button mixins * Add opt-in gradients to alerts, buttons, carousel, custom radios and checkboxes, custom file input, and dropdown items * Generate .bg-gradient- utilities * add headings to colors page and document bg-gradient utils * update the button color for active status, check with yiq as it's done for basic state and hover state
1 parent d763d01 commit 06641ca

File tree

12 files changed

+76
-19
lines changed

12 files changed

+76
-19
lines changed

docs/4.0/utilities/colors.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ group: utilities
66
toc: true
77
---
88

9+
## Color
10+
911
{% example html %}
1012
{% for color in site.data.theme-colors %}
1113
<p class="text-{{ color.name }}{% if color.name == "light" %} bg-dark{% endif %}">.text-{{ color.name }}</p>{% endfor %}
@@ -22,6 +24,8 @@ Contextual text classes also work well on anchors with the provided hover and fo
2224
<p><a href="#" class="text-white bg-dark">White link</a></p>
2325
{% endexample %}
2426

27+
## Background color
28+
2529
Similar to the contextual text color classes, easily set the background of an element to any contextual class. Anchor components will darken on hover, just like the text classes. Background utilities **do not set `color`**, so in some cases you'll want to use `.text-*` utilities.
2630

2731
{% example html %}
@@ -30,6 +34,15 @@ Similar to the contextual text color classes, easily set the background of an el
3034
<div class="p-3 mb-2 bg-white text-dark">.bg-white</div>
3135
{% endexample %}
3236

37+
## Background gradient
38+
39+
When `$enable-shadows` is set to true, you'll be able to use `.bg-gradient-` utility classes. **By default, `$enable-shadows` is disabled and the example below is intentionally broken.** This is done for easier customization from moment you start using Bootstrap. [Learn about our Sass options]({{ site.baseurl }}/docs/{{ site.docs_version }}/getting-started/theming/#sass-options) to enable these classes and more.
40+
41+
{% example html %}
42+
{% for color in site.data.theme-colors %}
43+
<div class="p-3 mb-2 bg-gradient-{{ color.name }} {% if color.name == "light" %}text-dark{% else %}text-white{% endif %}">.bg-gradient-{{ color.name }}</div>{% endfor %}
44+
{% endexample %}
45+
3346
{% callout info %}
3447
#### Dealing with specificity
3548

scss/_buttons.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
&:focus,
2323
&.focus {
2424
outline: 0;
25-
box-shadow: $btn-focus-box-shadow;
25+
box-shadow: $input-btn-focus-box-shadow;
2626
}
2727

2828
// Disabled comes first so active can properly restyle
@@ -35,7 +35,7 @@
3535
&:not([disabled]):not(.disabled):active,
3636
&:not([disabled]):not(.disabled).active {
3737
background-image: none;
38-
@include box-shadow($btn-focus-box-shadow, $btn-active-box-shadow);
38+
@include box-shadow($input-btn-focus-box-shadow, $btn-active-box-shadow);
3939
}
4040
}
4141

scss/_carousel.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,15 @@
9090
}
9191
.carousel-control-prev {
9292
left: 0;
93+
@if $enable-gradients {
94+
background: linear-gradient(90deg, rgba(0,0,0,.25), rgba(0,0,0,.001));
95+
}
9396
}
9497
.carousel-control-next {
9598
right: 0;
99+
@if $enable-gradients {
100+
background: linear-gradient(270deg, rgba(0,0,0,.25), rgba(0,0,0,.001));
101+
}
96102
}
97103

98104
// Icons for within

scss/_custom-forms.scss

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
&:checked ~ .custom-control-indicator {
2424
color: $custom-control-indicator-checked-color;
25-
background-color: $custom-control-indicator-checked-bg;
25+
@include gradient-bg($custom-control-indicator-checked-bg);
2626
@include box-shadow($custom-control-indicator-checked-box-shadow);
2727
}
2828

@@ -33,7 +33,7 @@
3333

3434
&:active ~ .custom-control-indicator {
3535
color: $custom-control-indicator-active-color;
36-
background-color: $custom-control-indicator-active-bg;
36+
@include gradient-bg($custom-control-indicator-active-bg);
3737
@include box-shadow($custom-control-indicator-active-box-shadow);
3838
}
3939

@@ -244,7 +244,7 @@
244244
padding: $custom-file-padding-y $custom-file-padding-x;
245245
line-height: $custom-file-line-height;
246246
color: $custom-file-button-color;
247-
background-color: $custom-file-button-bg;
247+
@include gradient-bg($custom-file-button-bg);
248248
border: $custom-file-border-width solid $custom-file-border-color;
249249
@include border-radius(0 $custom-file-border-radius $custom-file-border-radius 0);
250250
}

scss/_dropdown.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,14 @@
6767
@include hover-focus {
6868
color: $dropdown-link-hover-color;
6969
text-decoration: none;
70-
background-color: $dropdown-link-hover-bg;
70+
@include gradient-bg($dropdown-link-hover-bg);
7171
}
7272

7373
&.active,
7474
&:active {
7575
color: $dropdown-link-active-color;
7676
text-decoration: none;
77-
background-color: $dropdown-link-active-bg;
77+
@include gradient-bg($dropdown-link-active-bg);
7878
}
7979

8080
&.disabled,

scss/_variables.scss

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,10 @@ $input-btn-padding-y: .375rem !default;
314314
$input-btn-padding-x: .75rem !default;
315315
$input-btn-line-height: $line-height-base !default;
316316

317+
$input-btn-focus-width: .2rem !default;
318+
$input-btn-focus-color: rgba(theme-color("primary"), .25) !default;
319+
$input-btn-focus-box-shadow: 0 0 0 $input-btn-focus-width $input-btn-focus-color !default;
320+
317321
$input-btn-padding-y-sm: .25rem !default;
318322
$input-btn-padding-x-sm: .5rem !default;
319323
$input-btn-line-height-sm: $line-height-sm !default;
@@ -324,7 +328,6 @@ $input-btn-line-height-lg: $line-height-lg !default;
324328

325329
$btn-font-weight: $font-weight-normal !default;
326330
$btn-box-shadow: inset 0 1px 0 rgba($white,.15), 0 1px 1px rgba($black,.075) !default;
327-
$btn-focus-box-shadow: 0 0 0 3px rgba(theme-color("primary"), .25) !default;
328331
$btn-active-box-shadow: inset 0 3px 5px rgba($black,.125) !default;
329332

330333
$btn-link-disabled-color: $gray-600 !default;
@@ -355,7 +358,6 @@ $input-border-radius-sm: $border-radius-sm !default;
355358

356359
$input-focus-bg: $input-bg !default;
357360
$input-focus-border-color: lighten(theme-color("primary"), 25%) !default;
358-
$input-focus-box-shadow: $input-box-shadow, $btn-focus-box-shadow !default;
359361
$input-focus-color: $input-color !default;
360362

361363
$input-placeholder-color: $gray-600 !default;
@@ -404,7 +406,7 @@ $custom-control-indicator-checked-color: $white !default;
404406
$custom-control-indicator-checked-bg: theme-color("primary") !default;
405407
$custom-control-indicator-checked-box-shadow: none !default;
406408

407-
$custom-control-indicator-focus-box-shadow: 0 0 0 1px $body-bg, 0 0 0 3px theme-color("primary") !default;
409+
$custom-control-indicator-focus-box-shadow: 0 0 0 1px $body-bg, $input-btn-focus-box-shadow !default;
408410

409411
$custom-control-indicator-active-color: $white !default;
410412
$custom-control-indicator-active-bg: lighten(theme-color("primary"), 35%) !default;

scss/mixins/_alert.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@mixin alert-variant($background, $border, $color) {
22
color: $color;
3-
background-color: $background;
3+
@include gradient-bg($background);
44
border-color: $border;
55

66
hr {

scss/mixins/_background-variant.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,9 @@
1212
}
1313
}
1414
}
15+
16+
@mixin bg-gradient-variant($parent, $color) {
17+
#{$parent} {
18+
background: $color linear-gradient(180deg, mix($body-bg, $color, 15%), $color) repeat-x !important;
19+
}
20+
}

scss/mixins/_buttons.scss

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@
55

66
@mixin button-variant($background, $border, $hover-background: darken($background, 7.5%), $hover-border: darken($border, 10%), $active-background: darken($background, 10%), $active-border: darken($border, 12.5%)) {
77
color: color-yiq($background);
8-
background-color: $background;
8+
@include gradient-bg($background);
99
border-color: $border;
1010
@include box-shadow($btn-box-shadow);
1111

1212
@include hover {
1313
color: color-yiq($hover-background);
14-
background-color: $hover-background;
14+
@include gradient-bg($hover-background);
1515
border-color: $hover-border;
1616
}
1717

1818
&:focus,
1919
&.focus {
2020
// Avoid using mixin so we can pass custom focus shadow properly
2121
@if $enable-shadows {
22-
box-shadow: $btn-box-shadow, 0 0 0 3px rgba($border, .5);
22+
box-shadow: $btn-box-shadow, 0 0 0 $input-btn-focus-width rgba($border, .5);
2323
} @else {
24-
box-shadow: 0 0 0 3px rgba($border, .5);
24+
box-shadow: 0 0 0 $input-btn-focus-width rgba($border, .5);
2525
}
2626
}
2727

@@ -35,10 +35,19 @@
3535
&:not([disabled]):not(.disabled):active,
3636
&:not([disabled]):not(.disabled).active,
3737
.show > &.dropdown-toggle {
38+
color: color-yiq($active-background);
3839
background-color: $active-background;
39-
background-image: none; // Remove the gradient for the pressed/active state
40+
@if $enable-gradients {
41+
background-image: none; // Remove the gradient for the pressed/active state
42+
}
4043
border-color: $active-border;
41-
@include box-shadow($btn-active-box-shadow);
44+
45+
// Avoid using mixin so we can pass custom focus shadow properly
46+
@if $enable-shadows {
47+
box-shadow: $btn-active-box-shadow, 0 0 0 $input-btn-focus-width rgba($border, .5);
48+
} @else {
49+
box-shadow: 0 0 0 $input-btn-focus-width rgba($border, .5);
50+
}
4251
}
4352
}
4453

@@ -56,7 +65,7 @@
5665

5766
&:focus,
5867
&.focus {
59-
box-shadow: 0 0 0 3px rgba($color, .5);
68+
box-shadow: 0 0 0 $input-btn-focus-width rgba($color, .5);
6069
}
6170

6271
&.disabled,
@@ -71,6 +80,8 @@
7180
color: $color-hover;
7281
background-color: $color;
7382
border-color: $color;
83+
// Avoid using mixin so we can pass custom focus shadow properly
84+
box-shadow: 0 0 0 $input-btn-focus-width rgba($color, .5);
7485
}
7586
}
7687

scss/mixins/_forms.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,12 @@
1616
background-color: $input-focus-bg;
1717
border-color: $input-focus-border-color;
1818
outline: none;
19-
@include box-shadow($input-focus-box-shadow);
19+
// Avoid using mixin so we can pass custom focus shadow properly
20+
@if $enable-shadows {
21+
box-shadow: $input-box-shadow, $input-btn-focus-box-shadow;
22+
} @else {
23+
box-shadow: $input-btn-focus-box-shadow;
24+
}
2025
}
2126
}
2227

scss/mixins/_gradients.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
// Gradients
22

3+
@mixin gradient-bg($color) {
4+
@if $enable-gradients {
5+
background: $color linear-gradient(180deg, mix($body-bg, $color, 15%), $color) repeat-x;
6+
} @else {
7+
background-color: $color;
8+
}
9+
}
10+
311
// Horizontal gradient, from left to right
412
//
513
// Creates two color stops, start and end, by specifying a color and position for each color stop.

scss/utilities/_background.scss

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
@include bg-variant(".bg-#{$color}", $value);
55
}
66

7+
@if $enable-gradients {
8+
@each $color, $value in $theme-colors {
9+
@include bg-gradient-variant(".bg-gradient-#{$color}", $value);
10+
}
11+
}
12+
713
.bg-white {
814
background-color: $white !important;
915
}

0 commit comments

Comments
 (0)