Closed olivierpascal closed 3 months ago
The existing stylex.firstThatWorks
will soon be extended to support this use-case.
Shouldn't undefined
be disallowed for values in defineVars
, and then the type system can tell you if you're using a var that's actually undefined
? The value in defineVars
is the fallback as currently defined.
@necolas There are cases when you need a variable to either be defined or not defined. This is particularly useful with Container Style Queries. For this use-case undefined
and null
are valid values for defineVars
, although you need to manually type cast them to null | string
so that a theme can set a value for it.
Has this been released yet?
When I try:
backgroundColor: stylex.firstThatWorks("color-mix(in srgb, currentColor 20%, transparent)", cssVars.accent),
I get:
Looks like its unpacking the string as an array for some reason? 🤔
@pnegahdar Please share the definition for cssVars
so I can test this and verify.
Reopening Issue to investigate bug report.
@nmn The basic example seems to cause the issue:
const cssVars = stylex.defineVars({
accent: "#42D80D"
})
Then used with a color-mix style:
const styles = stlyex.create({
root: {
backgroundColor: stylex.firstThatWorks("color-mix(in srgb, currentColor 20%, transparent)", cssVars.accent),
}
})
Feature request
I would like to be able to use fallback for css variables.
Suggestion 1
I suggest an API like:
Which would be compiled to:
Suggestion 2
Today,
null
andundefined
values for style properties are not used:Also, in this example:
The final color is
undefined
because "The last style applied always wins".I suggest that "the last defined style applied always wins", so that the
textColor
fallback is used.Workaround