I have the following scss file being imported into my Angular Project
#import '~#angular/material/theming';
#import "./mat-palette.scss";
#include mat-core();
$ombi-app-primary: mat-palette($ombi-primary, 500);
$ombi-app-accent : mat-palette($ombi-accent, A200, A100, A400);
$background: white;
$ombi-app-warn : mat-palette($mat-deep-orange);
$ombi-app-theme: mat-light-theme($ombi-app-primary, $ombi-app-accent, $ombi-app-warn);
#include angular-material-theme($ombi-app-theme);
// Define an alternate dark theme.
$ombi-dark-app-primary: mat-palette($mat-grey, 800);
$ombi-dark-app-accent: mat-palette($mat-amber, A200, A100, A400);
$ombi-dark-app-warn: mat-palette($mat-deep-orange);
$dark-theme: mat-dark-theme($ombi-dark-app-primary, $ombi-dark-app-accent, $ombi-dark-app-warn);
$primary: mat-color($ombi-app-primary);
$accent: mat-color($ombi-app-accent);
$warn: mat-color($ombi-app-warn);
.dark {
#include angular-material-theme($dark-theme);
$panel: mat-color(mat-palette($mat-grey, 800));
$primary: mat-color($ombi-dark-app-primary);
$accent: mat-color($ombi-dark-app-accent);
$warn: mat-color($ombi-dark-app-warn);
$background: #424242;
}
Now when the .dark class is applied to the body I expect it to apply the variables inside the .dark section above.
I am importing this file into other scss files so I can use the variables e.g. $background.
So when the .dark class is applied, it seems that $background is set to white and not #424242 and I cannot work out why.
Here is an example on how I am importing it:
#import "~styles/Styles.scss";
.details {
background: $background;
}
Related
Hello i am getting error while i am trying to inject variables from .css to .scss .
Reason why i am doing this is because javascript(React) changes the colors in .css and then these css variables are used in scss. It works as it should but not when i try to modify bootstrap of version 5 colors with css variables it throws errors. (using normal colors , non-variables for bootstrap works ).
Code looks like this:
The CSS file:injectors.css
--primary: #757575;
--secondary: #757575;
--success: #757575;
--info: #757575;
--warning: #757575;
--danger: #757575;
--light: #757575;
--dark: #757575;
The variables.scss
//Fonts
$mainfont: var(--fontFamily);
$lighterFont: var(--lighterFont);
//Colors
$grey: var(--greyColor);
//Bootstrap theming
$primary: var(--primary);
$secondary: var(--secondary);
$success: var(--success);
$info: var(--info);
$warning: var(--warning);
$danger: var(--danger);
$light: var(--light);
$dark: var(--dark);
#import "bootstrap/scss/functions";
#import "bootstrap/scss/variables";
#import "injectors.css";
#import "bootstrap/scss/bootstrap.scss";
And the error message is this one:
Compiled with problems:X
ERROR in ./src/common/styles/authPage.scss (./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[2].use[1]!./node_modules/sass-loader/dist/cjs.js!./src/common/styles/authPage.scss)
Module build failed (from ./node_modules/sass-loader/dist/cjs.js):
SassError: $color: var(--primary) is not a color.
╷
37 │ #return red($value), green($value), blue($value);
│ ^^^^^^^^^^^
╵
node_modules/bootstrap/scss/_functions.scss 37:11 to-rgb()
node_modules/bootstrap/scss/_functions.scss 61:36 map-loop()
node_modules/bootstrap/scss/_variables.scss 94:20 #import
src/common/styles/variables.scss 30:9 #import
src/common/styles/authPage.scss 1:9 root stylesheet
I'm trying to add some color variables such as "blue", "indigo" ... to $theme-colors map it's work but after compiling it shows duplicated in :root selector like the image below.
Here is the result:
Image
this is my _variables.scss file:
// Import functions
#import "../../../node_modules/bootstrap/scss/functions";
$white: #fff;
$gray-100: #f8f9fa;
$gray-200: #e9ecef;
$gray-300: #dee2e6;
$gray-400: #ced4da;
$gray-500: #adb5bd;
$gray-600: #6c757d;
$gray-700: #495057;
$gray-800: #343a40;
$gray-900: #212529;
$black: #000;
$blue: #0d6efd;
$indigo: #6610f2;
$purple: #6f42c1;
$pink: #d63384;
$red: #dc3545;
$orange: #fd7e14;
$yellow: #ffc107;
$green: #198754;
$teal: #20c997;
$cyan: #0dcaf0;
$primary: #c55e0a;
$secondary: $gray-600;
$success: $green;
$info: $cyan;
$warning: $yellow;
$danger: $red;
$light: $gray-100;
$dark: $gray-900;
$theme-colors: (
"primary": $primary,
"secondary": $secondary,
"success": $success,
"info": $info,
"warning": $warning,
"danger": $danger,
"light": $light,
"dark": $dark
);
$custom-theme-colors: (
"blue": $blue,
"indigo": $blue,
"purple": $blue,
"pink": $blue,
"yellow": $blue,
"teal": $teal
);
$theme-colors: map-merge($theme-colors, $custom-theme-colors);
// Import required Bootstrap stylesheets
#import "../../../node_modules/bootstrap/scss/variables";
#import "../../../node_modules/bootstrap/scss/mixins";
#import "../../../node_modules/bootstrap/scss/utilities";
#import "../../../node_modules/bootstrap/scss/bootstrap";
How I can fix this?
As you can read in the Bootstrap docs, customizations should be kept in a separate file. Therefore, you shouldn't modify _variables.scss but instead create seperate file with your custom colors.
The custom file portion would look like this
ex: custom.scss
#import "bootstrap/functions";
#import "bootstrap/variables";
$custom-colors: (
"blue": $blue,
"indigo": $indigo,
"purple": $purple,
"pink": $pink,
"yellow": $yellow,
"teal": $teal
);
$theme-colors: map-merge($theme-colors, $custom-colors);
#import "bootstrap";
Also, it's expected that the :root variables would appear twice since you're merging them with the theme-colors map. Take a look at how the :root gets built in _root.scss...
First the $colors map is iterated.. then the $theme-colors map is iterated so it would make perfect since you're seeing --bs-blue, --bs-indigo, etc... twice in the :root...
#each $color, $value in $colors {
--#{$variable-prefix}#{$color}: #{$value};
}
....
#each $color, $value in $theme-colors {
--#{$variable-prefix}#{$color}: #{$value};
}
There is nothing to fix, it's working as expected. Maybe if you can describe what you're trying to achieve instead of describing a symptom there would be a different answer or better solution.
i am using bootstrap v5 using npm and using sass compiler to compile the scss. i want to customize .btn-primary .so in my dirctory _button.sccs file i made a .btn-primary class with icluding the button-variant mixin given from bootstrap.
but at compiling time it gives an error.
The code is below :
This is my _custom.scss file.
$yellow: #f8b534;
$small: 576px;
$medium: 768px;
$large: 992px;
//bootstrap imported
// Option A: Include all of Bootstrap
// Include any default variable overrides here (though functions won't be available)
#import "../node_modules/bootstrap/scss/bootstrap";
// Then add additional custom code here
// Copy
// Custom.scss
// Option B: Include parts of Bootstrap
// 1. Include functions first (so you can manipulate colors, SVGs, calc, etc)
#import "../node_modules/bootstrap/scss/functions";
// 2. Include any default variable overrides here
// 3. Include remainder of required Bootstrap stylesheets
#import "../node_modules/bootstrap/scss/variables";
#import "../node_modules/bootstrap/scss/mixins";
// 4. Include any optional Bootstrap components as you like
#import "../node_modules/bootstrap/scss/root";
#import "../node_modules/bootstrap/scss/reboot";
#import "../node_modules/bootstrap/scss/type";
#import "../node_modules/bootstrap/scss/images";
#import "../node_modules/bootstrap/scss/containers";
#import "../node_modules/bootstrap/scss/grid";
Then my _button.scss file:
#use '../custom' as *;
$btn-padding-y: $input-btn-padding-y;
$btn-padding-x: $input-btn-padding-x;
$btn-font-family: $input-btn-font-family;
$btn-font-size: $input-btn-font-size;
$btn-line-height: $input-btn-line-height;
$btn-white-space: null; // Set to `nowrap` to prevent text wrapping
$btn-padding-y-sm: $input-btn-padding-y-sm;
$btn-padding-x-sm: $input-btn-padding-x-sm;
$btn-font-size-sm: $input-btn-font-size-sm;
$btn-padding-y-lg: $input-btn-padding-y-lg;
$btn-padding-x-lg: $input-btn-padding-x-lg;
$btn-font-size-lg: $input-btn-font-size-lg;
$btn-border-width: $input-btn-border-width;
$btn-font-weight: $font-weight-normal;
$btn-box-shadow: inset 0 1px 0 rgba($white, .15), 0 1px 1px rgba($black, .075);
$btn-focus-width: $input-btn-focus-width;
$btn-focus-box-shadow: $input-btn-focus-box-shadow;
$btn-disabled-opacity: .65;
$btn-active-box-shadow: inset 0 3px 5px rgba($black, .125);
$btn-link-color: $link-color;
$btn-link-hover-color: $link-hover-color;
$btn-link-disabled-color: $gray-600;
// Allows for customizing button radius independently from global border radius
$btn-border-radius: $border-radius;
$btn-border-radius-sm: $border-radius-sm;
$btn-border-radius-lg: $border-radius-lg;
$btn-transition: color .15s ease-in-out, background-color .15s ease-in-out, border-color .15s ease-in-out, box-shadow .15s ease-in-out;
$btn-hover-bg-shade-amount: 15%;
$btn-hover-bg-tint-amount: 15%;
$btn-hover-border-shade-amount: 20%;
$btn-hover-border-tint-amount: 10%;
$btn-active-bg-shade-amount: 20%;
$btn-active-bg-tint-amount: 20%;
$btn-active-border-shade-amount: 25%;
$btn-active-border-tint-amount: 10%;
.btn-primary {
#include button-variant(
$background,
$border,
$color: color-contrast($background),
$hover-background:
if(
$color == $color-contrast-light,
shade-color($background, $btn-hover-bg-shade-amount),
tint-color($background, $btn-hover-bg-tint-amount)
),
$hover-border:
if(
$color == $color-contrast-light,
shade-color($border, $btn-hover-border-shade-amount),
tint-color($border, $btn-hover-border-tint-amount)
),
$hover-color: color-contrast($hover-background),
$active-background:
if(
$color == $color-contrast-light,
shade-color($background, $btn-active-bg-shade-amount),
tint-color($background, $btn-active-bg-tint-amount)
),
$active-border:
if(
$color == $color-contrast-light,
shade-color($border, $btn-active-border-shade-amount),
tint-color($border, $btn-active-border-tint-amount)
),
$active-color: color-contrast($active-background),
$disabled-background: $background,
$disabled-border: $border,
$disabled-color: color-contrast($disabled-background)
)
};
But when compiling gives this error in below:
Error: Undefined variable.
╷
49 │ $background,
│ ^^^^^^^^^^^
╵
scss\components\_button.scss 49:3 #use
scss\sections\_navbar.scss 2:1 #use
scss\style.scss 6:1 root stylesheet
How to invert the colors of a mat-checkbox so that the border and check mark are colored and the rest transparent?
Creating a global style for a given class (outline) and adding that class to the mat-checkbox.
src/style.scss
#import '~#angular/material/theming';
#include mat-core();
$app-primary: mat-palette($mat-indigo);
$app-accent: mat-palette($mat-pink, A200, A100, A400);
$app-warn: mat-palette($mat-red);
$theme: mat-light-theme($app-primary, $app-accent);
#include angular-material-theme($theme);
$primary: mat-color($app-primary);
$accent: mat-color($app-accent);
$warn: mat-color($app-warn);
#mixin checkbox-color($color) {
.mat-checkbox-frame {
border-color: $color;
}
&.mat-checkbox-checked .mat-checkbox-checkmark-path {
stroke: $color !important;
}
}
mat-checkbox.mat-checkbox.outline {
.mat-checkbox-background {
background-color: transparent;
}
&.mat-primary {
#include checkbox-color($primary);
}
&.mat-warn {
#include checkbox-color($warn)
}
&.mat-accent {
#include checkbox-color($accent)
}
}
<mat-checkbox class="outline" color="primary"></mat-checkbox>
Example
I am looking to utilize a SASS Rules (#mixin, #extend, etc.) and/or control directives (#if, #for, #each, etc.) to generate classes for the color variables that I have defined.
Below is an example of what I am using currently, but I know that I can further simplify this to make it significantly less redundant.
// Colors
$navy: #37455a;
$blue: #abbdd3;
$cyan: #a3d9cb;
$peach: #ff9d7a;
// Backgrounds
.bg-navy{
background: $navy;
}
.bg-blue{
background: $blue;
}
.bg-cyan{
background: $cyan;
}
.bg-peach{
background: $peach;
}
// Text
.text-navy{
color: $navy;
}
.text-blue{
color: $blue;
}
.text-cyan{
color: $cyan;
}
.text-peach{
color: $peach;
}
I have tried a few different methods, but I always run into conflicts with mapping. I want to preserve the mapped variable in the object to use outside of these functions. This is what I have come up with so far:
// Colors for use in other partials
$navy: #37455a;
$blue: #abbdd3;
$cyan: #a3d9cb;
$peach: #ff9d7a;
// Mapped colors used for generating classes (Duplicated unfortunately)
$colors: (
$navy: #37455a;
$blue: #abbdd3;
$cyan: #a3d9cb;
$peach: #ff9d7a;
)
// Background class definition
#mixin bg{
.bg-#{$color}{
background: $color;
}
}
// Text class definition
#mixin text{
.text-#{$color}{
color: $color;
}
}
// Background class generation
#each $color in $colors{
#include bg($color);
}
// Text class generation
#each $color in $colors{
#include text($color);
}
While what I have above does not work, it's closer to what I am trying do accomplish. Has anybody solved for what I am attempting to do here? Any insight would be much appreciated as well!
One mixin to do it all!
$navy: #37455a;
$blue: #abbdd3;
$cyan: #a3d9cb;
$peach: #ff9d7a;
$colors: (
navy: $navy,
blue: $blue,
cyan: $cyan,
peach: $peach
);
#mixin gen-props($prefix, $property) {
#each $color-name, $color in $colors {
.#{$prefix}-#{$color-name} {
#{$property}: $color
}
}
}
#include gen-props('text', 'color');
#include gen-props('bg', 'background');