Answer the question
In order to leave comments, you need to log in
What is the correct syntax for variables?
Trying to rewrite mixin from SASS to STYLUS .
here is the original in SASS
@mixin adaptive-value($property, $startSize, $minSize, $type){
$addSize: $startSize - $minSize;
@if $type== 1 {
#{$property}: $startSize + px;
@media(max-width: #{$maxWidthContainer + px}) {
#{$property}: calc(#{$minSize + px} + #{$addSize} * ((100vw - 320px) / #{$maxWidthContainer - 320}));
}
}
@else if $type== 2{
#{$property}: $startSize + px;
@media(min-width: #{$maxWidthContainer + px}) {
#{$property}: calc(#{$minSize + px } + #{$addSize} * ((100vw - 320px) / #{$maxWidth- 320}));
}
}
@else {
#{$property}: calc(#{minSize + px } + #{$addSize} * ((100vw - 320px) / #{$maxWidth- 320} ));
}
}
adaptive-value(property, startSize, minSize, type )
addSize = startSize - minSize
if type==1
{property}: startSize
@media(max-width: $maxWidthContainer px)
{property}: calc(var(minSize) + addSize * ((100vw - 320px) / ($maxWidthContainer - 320)))
else if type==2
{property}: startSize
@media(min-width: $maxWidthContainer px)
{property}: calc(minSize + addSize * ((100vw - 320px) / ($maxWidth- 320)))
else
{property}: calc(minSize + addSize * ((100vw - 320px) / ($maxWidth- 320)))
Answer the question
In order to leave comments, you need to log in
It was worth reformulating the question - and the answer was found. The problem is not with interpolation at all, but with the use of a variable inside the calc function.
Here it is necessary to apply the following syntax
- quote the calc function itself as a string, and substitute the sign %s instead of variables, followed by decoding in brackets.
mixin works. already checked
it looks like this
adaptive-value(property, startSize, minSize, type)
addSize= startSize - minSize;
if type== 1
{property}: startSize px;
@media(max-width: $maxWidthContainer px)
{property}: "calc(%spx + %s * ((100vw - 320px) / (%s - 320)))" % (minSize addSize $maxWidthContainer)
else if type== 2
{property}: startSize px;
@media(min-width: $maxWidthContainer px)
{property}: "calc(%spx + %s * ((100vw - 320px) / (%s - 320)))" % (minSize addSize $maxWidth)
else
{property}: "calc(%spx + %s * ((100vw - 320px) / (%s - 320)))" % (minSize addSize $maxWidth)
In general, braces are used for interpolation in stylus
https://stylus-lang.com/docs/interpolation.html
How exactly does your compiler swear?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question