-
-
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
How to override theme colors now? #23112
Comments
While it does appear you cannot override part of the Sass maps, much like our variables, they do have the
We also still have all the regular color variables, so you can customize the Sass map or you can change the base variables. See the variables file: $blue: #007bff !default;
$indigo: #6610f2 !default;
$purple: #6f42c1 !default;
$pink: #e83e8c !default;
$red: #dc3545 !default;
$orange: #fd7e14 !default;
$yellow: #ffc107 !default;
$green: #28a745 !default;
$teal: #20c997 !default;
$cyan: #17a2b8 !default;
$colors: (
blue: $blue,
indigo: $indigo,
purple: $purple,
pink: $pink,
red: $red,
orange: $orange,
yellow: $yellow,
green: $green,
teal: $teal,
cyan: $cyan,
white: $white,
gray: $gray-600,
gray-dark: $gray-800
) !default;
$theme-colors: (
primary: $blue,
secondary: $gray-600,
success: $green,
info: $cyan,
warning: $yellow,
danger: $red,
light: $gray-100,
dark: $gray-800
) !default; |
@mdo I get that the theme colours have been mapped to “named” colour variables, but if I want my theme to be primarily green, I don’t want to be changing the value of I’m not liking the fact I have to copy-and-paste and override X, Y and Z just to change one setting. What happens if the keys in the map change? My theme’s going to break. Why do I have all these dependencies just to change one single colour in Bootstrap? |
@martinbean you don't need to change the value of |
@dushkostanoeski But I have to copy the whole of All that, just to change one colour! |
You don't have to import the color variables if you import the |
@houfio That defeats the point of them having the |
I guess so. Are you sure you have to copy them if you don't reference the file? It should work fine, because the bootstrap base file imports it too. |
@houfio Did you take a look at my original post? I define custom variable values in a _custom.scss file that‘s included before Bootstrap. It’s in fact, what the comments say to do in the _variables.scss file: https://github.com/twbs/bootstrap/blob/v4-dev/scss/_variables.scss#L3-L4 However, with colours now being nested in a map, it’s created this awkward scenario where I need to copy whole blocks of variable definitions and hope Bootstrap doesn’t change the name or “shape” of the map (which is has been known to do in the past); or include its variables files before mine, making the point specifying values to override the defaults pointless. |
I know it it included before bootstrap, but because of the |
@houfio My problem is, I just want to set the primary brand colour to be something other than blue. Before, I could have a _custom.scss file with this in: $brand-primary: #006400; That was it. Everything the “primary” colour (buttons etc) would then be a dark green when Bootstrap was compiled. Now I can’t do that as that variable’s been removed and instead the theme colours folded into a map. |
If you don't need any of the other colors you can just do $theme-colors: (
primary: #006400
) since all the calls to the map are loops. |
@houfio I do want the other colours though! I just want to override one of the theme’s colours, and not have to copy a whole map to do so! |
I suppose this change is good if you want much customization, but not so much if you just want to change one color. You can also just import the variables file, which does defeat the point of the |
@houfio My gripe with copying a whole map (and its dependent variables) is that, I’m then relying on Bootstrap not to change anything, which was the point of having a file of variable overrides in the first place. It just seems I have to go “too deep” into Bootstrap now to change one thing. |
This change makes overriding not work. Coming from a Rails example. I too want to change my theme to green. The following doesn't work. And it's not feasible for me to go and change the variables.scss // Custom bootstrap variables must be set or imported *before* bootstrap.
$green: #89B630;
$theme-colors: (
primary: $green
);
@import "bootstrap"; Currently have to change |
@kartikluke Ideas in #22891 might help |
@cr101 Doesn’t really help, as it seems to be people discussing the same issue as in here. |
Bringing over the entire Sass map doesn't seem unreasonable to me... is the biggest concern that this feels heavy handed when compared to the old |
@mdo Exactly that. When overriding a $brand-primary: #006600; To this: $gray-100: #f8f9fa;
$gray-600: #868e96;
$gray-800: #343a40;
$red: #dc3545;
$yellow: #ffc107;
$green: #006600; // This is the only variable I wanted to change
$cyan: #17a2b8;
$theme-colors: (
primary: $green,
secondary: $gray-600,
success: $green,
info: $cyan,
warning: $yellow,
danger: $red,
light: $gray-100,
dark: $gray-800
); |
will this not work?
|
@bkdotcom Not unless I import the whole of _variables.scss first 😩 |
@martinbean @mdo The solution outlined here seems to be the best option. #22891 (comment)
|
@kartikluke Nice! That does work: https://codepen.io/anon/pen/XaJeVd. I'll see about a PR shortly. |
@hokiecoder figured it out. This should make it much easier to work with the new maps. |
Please see #23260 for @hokiecoder's suggestion that @kartikluke pointed out here. Any feedback is most definitely welcomed! |
I understand the concern. I honestly like this map feature. |
I’ve noticed in _variables.scss that the brand colours have been moved to a nested object.
Up to now, I‘ve been specifying variable overrides in a _custom.scss in my projects like this:
I’d then override the variables I wanted in my _custom.scss file like this:
How do I override values on a per-variable basis now that they’re inside an object? For example, I have a project where I want the brand’s primary color to be green and not blue.
Sorry if this a n00b question, but I’m under the impression that object members like
$theme-colors[primary]
aren’t overridable in Sass without overriding the whole object, in which case these seriously reduces the configurability of Bootstrap in version 4.If I’m doing something wrong, or I can override specific members of objects in Sass, then please let me know.
The text was updated successfully, but these errors were encountered: