You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Ability to define the type of a custom variable inside @function #14945
I have a custom @function which uses a random() value to generate a different background:
Problem - custom variable defined inside @function is untyped and does not match the style query
@function --random-number(){result:random(1,7,1);}@function --random-item-bg(){--random-number:--random-number();/* returns an untyped number and is equivalent to --random-number: random(1,7,1); */result:if(style(--random-number:1): var(--color1);style(--random-number:2):var(--color2);style(--random-number:3):var(--color3);style(--random-number:4):var(--color4);style(--random-number:5):var(--color5);style(--random-number:6):var(--color6);style(--random-number:7):var(--color7);else: black;);}.box{background-color:--random-item-bg();}
This gives all black divs because the syntax of the --random-number is not <number> and the style query does not match.
A way around - typed variable by using another @function with a returns <number>
If I use --random-number: --random-number-typed(); then it works as expected because --random-number gets a typed value back and so is of the type of <number> and the style query works as expected.
@function --random-number-typed() returns <number>{result:random(1,7,1);}@function --random-item-bg(){--random-number:--random-number-typed();/* --random-number is now typed and is of type <number> */result:if(style(--random-number:1): var(--color1);style(--random-number:2):var(--color2);style(--random-number:3):var(--color3);style(--random-number:4):var(--color4);style(--random-number:5):var(--color5);style(--random-number:6):var(--color6);style(--random-number:7):var(--color7);else: black;);}.box{background-color:--random-item-bg();}
Expected
As a developer I would expect that --random-number has the correct type, either by setting the type when the variable was defined, or by inference from the random() function.
Activity