Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Sass variable for CSS variable prefix #31684

Merged
merged 3 commits into from
Sep 30, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions scss/_root.scss
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
:root {
// Custom variable values only support SassScript inside `#{}`.
@each $color, $value in $colors {
--bs-#{$color}: #{$value};
--#{$variable-prefix}#{$color}: #{$value};
}

@each $color, $value in $theme-colors {
--bs-#{$color}: #{$value};
--#{$variable-prefix}#{$color}: #{$value};
}

// Use `inspect` for lists so that quoted items keep the quotes.
// See https://github.com/sass/sass/issues/2383#issuecomment-336349172
--bs-font-sans-serif: #{inspect($font-family-sans-serif)};
--bs-font-monospace: #{inspect($font-family-monospace)};
--bs-gradient: #{$gradient};
--#{$variable-prefix}font-sans-serif: #{inspect($font-family-sans-serif)};
--#{$variable-prefix}font-monospace: #{inspect($font-family-monospace)};
--#{$variable-prefix}gradient: #{$gradient};
}
32 changes: 16 additions & 16 deletions scss/_tables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
//

.table {
--bs-table-bg: #{$table-bg};
--bs-table-accent-bg: transparent;
--bs-table-striped-color: #{$table-striped-color};
--bs-table-striped-bg: #{$table-striped-bg};
--bs-table-active-color: #{$table-active-color};
--bs-table-active-bg: #{$table-active-bg};
--bs-table-hover-color: #{$table-hover-color};
--bs-table-hover-bg: #{$table-hover-bg};
--#{$variable-prefix}table-bg: #{$table-bg};
--#{$variable-prefix}table-accent-bg: transparent;
--#{$variable-prefix}table-striped-color: #{$table-striped-color};
--#{$variable-prefix}table-striped-bg: #{$table-striped-bg};
--#{$variable-prefix}table-active-color: #{$table-active-color};
--#{$variable-prefix}table-active-bg: #{$table-active-bg};
--#{$variable-prefix}table-hover-color: #{$table-hover-color};
--#{$variable-prefix}table-hover-bg: #{$table-hover-bg};

width: 100%;
margin-bottom: $spacer;
Expand All @@ -25,8 +25,8 @@
// stylelint-disable-next-line selector-max-universal
> :not(caption) > * > * {
padding: $table-cell-padding-y $table-cell-padding-x;
background-color: var(--bs-table-bg);
background-image: linear-gradient(var(--bs-table-accent-bg), var(--bs-table-accent-bg));
background-color: var(--#{$variable-prefix}table-bg);
background-image: linear-gradient(var(--#{$variable-prefix}table-accent-bg), var(--#{$variable-prefix}table-accent-bg));
border-bottom-width: $table-border-width;
}

Expand Down Expand Up @@ -99,8 +99,8 @@

.table-striped {
> tbody > tr:nth-of-type(#{$table-striped-order}) {
--bs-table-accent-bg: var(--bs-table-striped-bg);
color: var(--bs-table-striped-color);
--#{$variable-prefix}table-accent-bg: var(--#{$variable-prefix}table-striped-bg);
color: var(--#{$variable-prefix}table-striped-color);
}
}

Expand All @@ -109,8 +109,8 @@
// The `.table-active` class can be added to highlight rows or cells

.table-active {
--bs-table-accent-bg: var(--bs-table-active-bg);
color: var(--bs-table-active-color);
--#{$variable-prefix}table-accent-bg: var(--#{$variable-prefix}table-active-bg);
color: var(--#{$variable-prefix}table-active-color);
}

// Hover effect
Expand All @@ -119,8 +119,8 @@

.table-hover {
> tbody > tr:hover {
--bs-table-accent-bg: var(--bs-table-hover-bg);
color: var(--bs-table-hover-color);
--#{$variable-prefix}table-accent-bg: var(--#{$variable-prefix}table-hover-bg);
color: var(--#{$variable-prefix}table-hover-color);
}
}

Expand Down
4 changes: 2 additions & 2 deletions scss/_utilities.scss
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ $utilities: map-merge(
"gradient": (
property: background-image,
class: bg,
values: (gradient: var(--bs-gradient))
values: (gradient: var(--#{$variable-prefix}gradient))
),
"white-space": (
property: white-space,
Expand All @@ -475,7 +475,7 @@ $utilities: map-merge(
"font-family": (
property: font-family,
class: font,
values: (monospace: var(--bs-font-monospace))
values: (monospace: var(--#{$variable-prefix}font-monospace))
),
"user-select": (
property: user-select,
Expand Down
8 changes: 6 additions & 2 deletions scss/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ $enable-negative-margins: false !default;
$enable-deprecation-messages: true !default;
$enable-important-utilities: true !default;

// Prefix for :root CSS variables

$variable-prefix: bs- !default;

// Gradient
//
// The gradient which is added to components if `$enable-gradients` is `true`
Expand Down Expand Up @@ -395,8 +399,8 @@ $aspect-ratios: (
$font-family-sans-serif: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji" !default;
$font-family-monospace: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace !default;
// stylelint-enable value-keyword-case
$font-family-base: var(--bs-font-sans-serif) !default;
$font-family-code: var(--bs-font-monospace) !default;
$font-family-base: var(--#{$variable-prefix}font-sans-serif) !default;
$font-family-code: var(--#{$variable-prefix}font-monospace) !default;

// $font-size-root effects the value of `rem`, which is used for as well font sizes, paddings and margins
// $font-size-base effects the font size of the body text
Expand Down
8 changes: 4 additions & 4 deletions scss/forms/_form-check.scss
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@

&[type="checkbox"] {
@if $enable-gradients {
background-image: escape-svg($form-check-input-checked-bg-image), var(--bs-gradient);
background-image: escape-svg($form-check-input-checked-bg-image), var(--#{$variable-prefix}gradient);
} @else {
background-image: escape-svg($form-check-input-checked-bg-image);
}
}

&[type="radio"] {
@if $enable-gradients {
background-image: escape-svg($form-check-radio-checked-bg-image), var(--bs-gradient);
background-image: escape-svg($form-check-radio-checked-bg-image), var(--#{$variable-prefix}gradient);
} @else {
background-image: escape-svg($form-check-radio-checked-bg-image);
}
Expand All @@ -73,7 +73,7 @@
border-color: $form-check-input-indeterminate-border-color;

@if $enable-gradients {
background-image: escape-svg($form-check-input-indeterminate-bg-image), var(--bs-gradient);
background-image: escape-svg($form-check-input-indeterminate-bg-image), var(--#{$variable-prefix}gradient);
} @else {
background-image: escape-svg($form-check-input-indeterminate-bg-image);
}
Expand Down Expand Up @@ -122,7 +122,7 @@
background-position: $form-switch-checked-bg-position;

@if $enable-gradients {
background-image: escape-svg($form-switch-checked-bg-image), var(--bs-gradient);
background-image: escape-svg($form-switch-checked-bg-image), var(--#{$variable-prefix}gradient);
} @else {
background-image: escape-svg($form-switch-checked-bg-image);
}
Expand Down
10 changes: 5 additions & 5 deletions scss/forms/_form-file.scss
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
.form-file {
--bs-form-file-height: #{$form-file-height};
--#{$variable-prefix}form-file-height: #{$form-file-height};
position: relative;
}

.form-file-input {
position: relative;
z-index: 2;
width: 100%;
height: var(--bs-form-file-height);
height: var(--#{$variable-prefix}form-file-height);
margin: 0;
opacity: 0;

Expand All @@ -32,7 +32,7 @@
left: 0;
z-index: 1;
display: flex;
height: var(--bs-form-file-height);
height: var(--#{$variable-prefix}form-file-height);
border-color: $form-file-border-color;
@include border-radius($form-file-border-radius);
@include box-shadow($form-file-box-shadow);
Expand Down Expand Up @@ -71,7 +71,7 @@
}

.form-file-sm {
--bs-form-file-height: #{$form-file-height-sm};
--#{$variable-prefix}form-file-height: #{$form-file-height-sm};
@include font-size($form-file-font-size-sm);

.form-file-text,
Expand All @@ -81,7 +81,7 @@
}

.form-file-lg {
--bs-form-file-height: #{$form-file-height-lg};
--#{$variable-prefix}form-file-height: #{$form-file-height-lg};
@include font-size($form-file-font-size-lg);

.form-file-text,
Expand Down
2 changes: 1 addition & 1 deletion scss/mixins/_gradients.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
background-color: $color;

@if $enable-gradients {
background-image: var(--bs-gradient);
background-image: var(--#{$variable-prefix}gradient);
}
}

Expand Down
20 changes: 10 additions & 10 deletions scss/mixins/_grid.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
// Generate semantic grid columns with these mixins.

@mixin make-row($gutter: $grid-gutter-width) {
--bs-gutter-x: #{$gutter};
--bs-gutter-y: 0;
--#{$variable-prefix}gutter-x: #{$gutter};
--#{$variable-prefix}gutter-y: 0;
display: flex;
flex-wrap: wrap;
margin-top: calc(var(--bs-gutter-y) * -1); // stylelint-disable-line function-disallowed-list
margin-right: calc(var(--bs-gutter-x) / -2); // stylelint-disable-line function-disallowed-list
margin-left: calc(var(--bs-gutter-x) / -2); // stylelint-disable-line function-disallowed-list
margin-top: calc(var(--#{$variable-prefix}gutter-y) * -1); // stylelint-disable-line function-disallowed-list
margin-right: calc(var(--#{$variable-prefix}gutter-x) / -2); // stylelint-disable-line function-disallowed-list
margin-left: calc(var(--#{$variable-prefix}gutter-x) / -2); // stylelint-disable-line function-disallowed-list
}

@mixin make-col-ready($gutter: $grid-gutter-width) {
Expand All @@ -21,9 +21,9 @@
flex-shrink: 0;
width: 100%;
max-width: 100%; // Prevent `.col-auto`, `.col` (& responsive variants) from breaking out the grid
padding-right: calc(var(--bs-gutter-x) / 2); // stylelint-disable-line function-disallowed-list
padding-left: calc(var(--bs-gutter-x) / 2); // stylelint-disable-line function-disallowed-list
margin-top: var(--bs-gutter-y);
padding-right: calc(var(--#{$variable-prefix}gutter-x) / 2); // stylelint-disable-line function-disallowed-list
padding-left: calc(var(--#{$variable-prefix}gutter-x) / 2); // stylelint-disable-line function-disallowed-list
margin-top: var(--#{$variable-prefix}gutter-y);
}

@mixin make-col($size, $columns: $grid-columns) {
Expand Down Expand Up @@ -107,12 +107,12 @@
@each $key, $value in $gutters {
.g#{$infix}-#{$key},
.gx#{$infix}-#{$key} {
--bs-gutter-x: #{$value};
--#{$variable-prefix}gutter-x: #{$value};
}

.g#{$infix}-#{$key},
.gy#{$infix}-#{$key} {
--bs-gutter-y: #{$value};
--#{$variable-prefix}gutter-y: #{$value};
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions scss/mixins/_table-variants.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
$striped-bg: mix($color, $background, percentage($table-striped-bg-factor));
$active-bg: mix($color, $background, percentage($table-active-bg-factor));

--bs-table-bg: #{$background};
--bs-table-striped-bg: #{$striped-bg};
--bs-table-striped-color: #{color-contrast($striped-bg)};
--bs-table-active-bg: #{$active-bg};
--bs-table-active-color: #{color-contrast($active-bg)};
--bs-table-hover-bg: #{$hover-bg};
--bs-table-hover-color: #{color-contrast($hover-bg)};
--#{$variable-prefix}table-bg: #{$background};
--#{$variable-prefix}table-striped-bg: #{$striped-bg};
--#{$variable-prefix}table-striped-color: #{color-contrast($striped-bg)};
--#{$variable-prefix}table-active-bg: #{$active-bg};
--#{$variable-prefix}table-active-color: #{color-contrast($active-bg)};
--#{$variable-prefix}table-hover-bg: #{$hover-bg};
--#{$variable-prefix}table-hover-color: #{color-contrast($hover-bg)};

color: $color;
border-color: mix($color, $background, percentage($table-border-factor));
Expand Down