I have a util scss file for my breakpoints to reuse them through my Angular project:
$breakpoints: (
sm: 768px,
md: 1024px,
lg: 1280px,
xl: 1400px
);
$bp-sm: get-bp('sm');
$bp-md: get-bp('md');
$bp-lg: get-bp('lg');
$bp-xl: get-bp('xl');
@function get-bp($bp) {
@if $bp {
$bp: map-get($breakpoints, $bp);
} @else {
@error "Parameter #{$bp} is unknown or empty.";
}
@return $bp;
}
I have a list of breakpoints. I need the function for another util file, where I loop through the list and render media queries for each breakpoint. The scss variables are used for hardcoded media queries in an Angular component styling. So I try to set the value of the variable by also calling the function, so I avoid redundancy for the values and use the same list.
.logo {
width: 250px;
@media (min-width: $bp-md) {
width: 650px;
}
}
.button {
padding: 20px;
@media (min-width: $bp-md) {
padding: 50px;
}
}
My problem is, when checking my compiled css for the logo the media query looks like this: @media (min-width: 1024px) {...} (so it has the expected value, but for my button it looks like this: @media (min-width: get-bp('md')) {...} (so it does not map the value it shows the function call as value). Both are independent Angular components importing the breakpoint util.
So my question, is it possible to assign values to scss variables by calling a function? And why does it work for one component but on the other it doesn't work? I know I could do it with map-get(), but I do this already in the function so it would be also somehow redundant.
.buttoncan be overriden