Convert alerts to CSS variables (#35401)

Co-authored-by: XhmikosR <xhmikosr@gmail.com>
This commit is contained in:
Mark Otto 2021-12-16 21:16:24 -08:00 committed by GitHub
parent 4a66f229ed
commit f729e4c7d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 36 additions and 12 deletions

View File

@ -26,11 +26,11 @@
}, },
{ {
"path": "./dist/css/bootstrap.css", "path": "./dist/css/bootstrap.css",
"maxSize": "25.5 kB" "maxSize": "26 kB"
}, },
{ {
"path": "./dist/css/bootstrap.min.css", "path": "./dist/css/bootstrap.min.css",
"maxSize": "23.25 kB" "maxSize": "23.5 kB"
}, },
{ {
"path": "./dist/js/bootstrap.bundle.js", "path": "./dist/js/bootstrap.bundle.js",

View File

@ -3,11 +3,22 @@
// //
.alert { .alert {
// scss-docs-start alert-css-vars
--#{$variable-prefix}alert-bg: transparent;
--#{$variable-prefix}alert-padding: #{$alert-padding-y $alert-padding-x};
--#{$variable-prefix}alert-margin-bottom: #{$alert-margin-bottom};
--#{$variable-prefix}alert-color: #{$alert-padding-y $alert-padding-x};
--#{$variable-prefix}alert-border-color: transparent;
--#{$variable-prefix}alert-border: #{$alert-border-width} solid var(--#{$variable-prefix}alert-border-color);
--#{$variable-prefix}alert-border-radius: #{$alert-border-radius};
// scss-docs-end alert-css-vars
position: relative; position: relative;
padding: $alert-padding-y $alert-padding-x; padding: var(--#{$variable-prefix}alert-padding);
margin-bottom: $alert-margin-bottom; margin-bottom: var(--#{$variable-prefix}alert-margin-bottom);
border: $alert-border-width solid transparent; background-color: var(--#{$variable-prefix}alert-bg);
@include border-radius($alert-border-radius); border: var(--#{$variable-prefix}alert-border);
border-radius: var(--#{$variable-prefix}alert-border-radius, 0); // stylelint-disable-line property-disallowed-list
} }
// Headings for larger alerts // Headings for larger alerts
@ -47,6 +58,7 @@
$alert-background: shift-color($value, $alert-bg-scale); $alert-background: shift-color($value, $alert-bg-scale);
$alert-border: shift-color($value, $alert-border-scale); $alert-border: shift-color($value, $alert-border-scale);
$alert-color: shift-color($value, $alert-color-scale); $alert-color: shift-color($value, $alert-color-scale);
@if (contrast-ratio($alert-background, $alert-color) < $min-contrast-ratio) { @if (contrast-ratio($alert-background, $alert-color) < $min-contrast-ratio) {
$alert-color: mix($value, color-contrast($alert-background), abs($alert-color-scale)); $alert-color: mix($value, color-contrast($alert-background), abs($alert-color-scale));
} }

View File

@ -1,8 +1,12 @@
// scss-docs-start alert-variant-mixin // scss-docs-start alert-variant-mixin
@mixin alert-variant($background, $border, $color) { @mixin alert-variant($background, $border, $color) {
color: $color; --#{$variable-prefix}alert-color: #{$color};
@include gradient-bg($background); --#{$variable-prefix}alert-bg: #{$background};
border-color: $border; --#{$variable-prefix}alert-border-color: #{$border};
@if $enable-gradients {
background-image: var(--#{$variable-prefix}gradient);
}
.alert-link { .alert-link {
color: shade-color($color, 20%); color: shade-color($color, 20%);

View File

@ -156,19 +156,27 @@ You can see this in action with a live demo:
When an alert is dismissed, the element is completely removed from the page structure. If a keyboard user dismisses the alert using the close button, their focus will suddenly be lost and, depending on the browser, reset to the start of the page/document. For this reason, we recommend including additional JavaScript that listens for the `closed.bs.alert` event and programmatically sets `focus()` to the most appropriate location in the page. If you're planning to move focus to a non-interactive element that normally does not receive focus, make sure to add `tabindex="-1"` to the element. When an alert is dismissed, the element is completely removed from the page structure. If a keyboard user dismisses the alert using the close button, their focus will suddenly be lost and, depending on the browser, reset to the start of the page/document. For this reason, we recommend including additional JavaScript that listens for the `closed.bs.alert` event and programmatically sets `focus()` to the most appropriate location in the page. If you're planning to move focus to a non-interactive element that normally does not receive focus, make sure to add `tabindex="-1"` to the element.
{{< /callout >}} {{< /callout >}}
## Sass ## CSS
### Variables ### Variables
<small class="d-inline-flex px-2 py-1 font-monospace text-muted border rounded-3">Added in v5.2.0</small>
As part of Bootstrap's evolving CSS variables approach, buttons now use local CSS variables on `.alert` for enhanced real-time customization. Values for the CSS variables are set via Sass, so Sass customization is still supported, too.
{{< scss-docs name="alert-css-vars" file="scss/_alert.scss" >}}
### Sass variables
{{< scss-docs name="alert-variables" file="scss/_variables.scss" >}} {{< scss-docs name="alert-variables" file="scss/_variables.scss" >}}
### Variant mixin ### Sass mixin
Used in combination with `$theme-colors` to create contextual modifier classes for our alerts. Used in combination with `$theme-colors` to create contextual modifier classes for our alerts.
{{< scss-docs name="alert-variant-mixin" file="scss/mixins/_alert.scss" >}} {{< scss-docs name="alert-variant-mixin" file="scss/mixins/_alert.scss" >}}
### Loop ### Sass loop
Loop that generates the modifier classes with the `alert-variant()` mixin. Loop that generates the modifier classes with the `alert-variant()` mixin.