-
-
Notifications
You must be signed in to change notification settings - Fork 79k
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
Switch to custom properties for colorizing buttons #30500
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,34 +4,48 @@ | |
|
||
.btn { | ||
display: inline-block; | ||
padding: $btn-padding-y $btn-padding-x; | ||
@include font-size($btn-font-size); | ||
font-family: $btn-font-family; | ||
font-weight: $btn-font-weight; | ||
line-height: $btn-line-height; | ||
color: $body-color; | ||
color: var(--btn-accent-contrast-color); | ||
text-align: center; | ||
text-decoration: if($link-decoration == none, null, none); | ||
white-space: $btn-white-space; | ||
vertical-align: middle; | ||
cursor: if($enable-pointer-cursor-for-buttons, pointer, null); | ||
user-select: none; | ||
background-color: transparent; | ||
border: $btn-border-width solid transparent; | ||
@include button-size($btn-padding-y, $btn-padding-x, $btn-font-size, $btn-border-radius); | ||
background-color: var(--btn-accent-color); | ||
border: $btn-border-width solid $btn-border-color; | ||
|
||
@include transition($btn-transition); | ||
@include gradient-bg(); | ||
@include border-radius($btn-border-radius, 0); // Manually declare to provide an override to the browser default | ||
@include box-shadow($btn-box-shadow); | ||
|
||
&:hover { | ||
color: $body-color; | ||
color: var(--btn-accent-contrast-color); | ||
text-decoration: if($link-hover-decoration == underline, none, null); | ||
} | ||
|
||
&:focus, | ||
&.focus { | ||
outline: 0; | ||
box-shadow: $btn-focus-box-shadow; | ||
|
||
// Avoid using mixin so we can pass custom focus shadow properly | ||
@if $enable-shadows { | ||
box-shadow: $btn-box-shadow, $btn-focus-box-shadow; | ||
} @else { | ||
box-shadow: $btn-focus-box-shadow; | ||
} | ||
} | ||
|
||
&:active, | ||
&.active { | ||
&.active, | ||
.show > &.dropdown-toggle { | ||
// Remove CSS gradients if they're enabled | ||
background-image: if($enable-gradients, none, null); | ||
@include box-shadow($btn-active-box-shadow); | ||
|
||
&:focus { | ||
|
@@ -43,38 +57,82 @@ | |
&.disabled, | ||
fieldset:disabled & { // stylelint-disable-line selector-no-qualifying-type | ||
pointer-events: none; | ||
// Remove CSS gradients if they're enabled | ||
background-image: if($enable-gradients, none, null); | ||
opacity: $btn-disabled-opacity; | ||
@include box-shadow(none); | ||
} | ||
} | ||
|
||
.btn-outline { | ||
color: var(--btn-accent-color); | ||
background-color: transparent; | ||
border-color: currentColor; | ||
|
||
&:hover { | ||
background-color: var(--btn-accent-color); | ||
border-color: var(--btn-accent-color); | ||
} | ||
|
||
&:focus, | ||
&.focus { | ||
color: var(--btn-accent-contrast-color); | ||
background-color: var(--btn-accent-color); | ||
border-color: var(--btn-accent-color); | ||
} | ||
|
||
&.active, | ||
&:active { | ||
color: var(--btn-accent-contrast-color); | ||
background-color: var(--btn-accent-color); | ||
border-color: var(--btn-accent-color); | ||
} | ||
Comment on lines
+77
to
+89
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those are the same, can't we have a single selector stack? |
||
} | ||
Comment on lines
+67
to
+90
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I am not mistaken, the approach would be something like, .btn {
--btn-color: default here;
--btn-background-color: default here;
--btn-border-color: currentColor;
color: var(--btn-color);
background-color: var(--btn-background-color);
border-color: var(--btn-border-color);
}
.btn-outline {
--btn-color: change me;
--btn-background-color: change me;
--btn-border-color: change me;
&:hover {
--btn-color: change me;
--btn-background-color: change me;
--btn-border-color: change me;
}
&:focus,
&.focus {
--btn-color: default here;
--btn-background-color: default here;
--btn-border-color: currentColor;
}
&.active,
&:active {
--btn-color: change me;
--btn-background-color: change me;
--btn-border-color: change me;
}
} the idea is that you focus more on swapping the values than overriding styles. At least that is how I understand it. |
||
|
||
// | ||
// Alternate buttons | ||
// | ||
|
||
@each $color, $value in $theme-colors { | ||
.btn-#{$color} { | ||
@include button-variant($value, $value); | ||
} | ||
} | ||
$contrast-color: color-contrast($value); | ||
|
||
@each $color, $value in $theme-colors { | ||
.btn-outline-#{$color} { | ||
@include button-outline-variant($value); | ||
--btn-accent-color: #{$value}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm a bit confused by the fact that the variables are set here. The nice thing about CSS variables are that they cascade through the DOM hierarchy, so that devs can set these e.g. at the But if the variable is set here on the How I imagine it, components like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have the same impression, looks like CSS custom properties here used to refactor code in a cool way, not to increase customization capabilities and flexibility... So, it's improves only internal Bootstrap development experience, decreases bundles size, provides some additional usages of modifiers, but not improves customization. |
||
--btn-accent-contrast-color: #{$contrast-color}; | ||
|
||
&:hover { | ||
$accent-hover: darken($value, 5%); | ||
$accent-hover-contrast-color: color-contrast($accent-hover); | ||
|
||
--btn-accent-color: #{$accent-hover}; | ||
@if ($contrast-color != $accent-hover-contrast-color) { | ||
--btn-accent-contrast-color: #{$accent-hover-contrast-color}; | ||
} | ||
} | ||
|
||
&.active, | ||
&:active { | ||
$accent-active: darken($value, 15%); | ||
$accent-active-contrast-color: color-contrast($accent-active); | ||
|
||
--btn-accent-color: #{$accent-active}; | ||
@if ($contrast-color != $accent-active-contrast-color) { | ||
--btn-accent-contrast-color: #{$accent-active-contrast-color}; | ||
} | ||
} | ||
} | ||
} | ||
|
||
|
||
// | ||
// Link buttons | ||
// | ||
|
||
// Make a button look and behave like a link | ||
.btn-link { | ||
font-weight: $font-weight-normal; | ||
font-weight: $font-weight-base; | ||
color: $btn-link-color; | ||
text-decoration: $link-decoration; | ||
border-color: if($btn-border-color != transparent, transparent, null); | ||
|
||
&:hover { | ||
color: $btn-link-hover-color; | ||
|
@@ -84,27 +142,30 @@ | |
&:focus, | ||
&.focus { | ||
text-decoration: $link-hover-decoration; | ||
box-shadow: 0 0 0 $btn-focus-offset $body-bg, 0 0 0 $btn-focus-width; | ||
} | ||
|
||
&:disabled, | ||
&.disabled { | ||
color: $btn-link-disabled-color; | ||
} | ||
|
||
// No need for an active state here | ||
} | ||
|
||
|
||
// | ||
// Button Sizes | ||
// | ||
|
||
.btn-lg { | ||
@include button-size($btn-padding-y-lg, $btn-padding-x-lg, $btn-font-size-lg, $btn-border-radius-lg); | ||
.btn-sm { | ||
padding: $btn-padding-y-sm $btn-padding-x-sm; | ||
@include font-size($btn-font-size-sm); | ||
@include border-radius($btn-border-radius-sm); | ||
} | ||
|
||
.btn-sm { | ||
@include button-size($btn-padding-y-sm, $btn-padding-x-sm, $btn-font-size-sm, $btn-border-radius-sm); | ||
.btn-lg { | ||
padding: $btn-padding-y-lg $btn-padding-x-lg; | ||
@include font-size($btn-font-size-lg); | ||
@include border-radius($btn-border-radius-lg); | ||
} | ||
|
||
|
||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we put here
--btn-accent-color
for hoverbackground-color
and forcolor
library user can't make these values different without styles overwrite or setting own selectors with variables values.For example I want to set
color
asred
, butbackground-color
asgreen
I will need to write:
I think better do config just with set of variables without writing new nested selectors. What do you think?
And, btw, isn't there color will be the same as background color or not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we use approach similar to #31708 with placing in SCSS styles only SCSS variables, but in SCSS variables set CSS variables, we could do: